diff_box.tmpl 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. {{if .DiffNotAvailable}}
  2. <h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
  3. {{else}}
  4. <div class="diff-detail-box diff-box">
  5. <div>
  6. <i class="fa fa-retweet"></i>
  7. {{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
  8. <div class="ui right">
  9. <a class="ui tiny basic toggle button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}">{{ if .IsSplitStyle }}{{.i18n.Tr "repo.diff.show_unified_view"}}{{else}}{{.i18n.Tr "repo.diff.show_split_view"}}{{end}}</a>
  10. <a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
  11. </div>
  12. </div>
  13. <ol class="detail-files hide" id="diff-files">
  14. {{range .Diff.Files}}
  15. <li>
  16. <div class="diff-counter count pull-right">
  17. {{if not .IsBin}}
  18. <span class="add" data-line="{{.Addition}}">{{.Addition}}</span>
  19. <span class="bar">
  20. <span class="pull-left add"></span>
  21. <span class="pull-left del"></span>
  22. </span>
  23. <span class="del" data-line="{{.Deletion}}">{{.Deletion}}</span>
  24. {{else}}
  25. <span>{{$.i18n.Tr "repo.diff.bin"}}</span>
  26. {{end}}
  27. </div>
  28. <!-- todo finish all file status, now modify, add, delete and rename -->
  29. <span class="status {{DiffTypeToStr .GetType}} poping up" data-content="{{DiffTypeToStr .GetType}}" data-variation="inverted tiny" data-position="right center">&nbsp;</span>
  30. <a class="file" href="#diff-{{.Index}}">{{.Name}}</a>
  31. </li>
  32. {{end}}
  33. </ol>
  34. </div>
  35. {{range $i, $file := .Diff.Files}}
  36. {{if $file.IsIncomplete}}
  37. <div class="diff-file-box diff-box file-content">
  38. <h4 class="ui top attached normal header">
  39. {{$.i18n.Tr "repo.diff.file_suppressed"}}
  40. <div class="diff-counter count ui left">
  41. {{if not $file.IsRenamed}}
  42. <span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
  43. <span class="bar">
  44. <span class="pull-left add"></span>
  45. <span class="pull-left del"></span>
  46. </span>
  47. <span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
  48. {{end}}
  49. </div>
  50. <span class="file">{{$file.Name}}</span>
  51. </h4>
  52. </div>
  53. {{else}}
  54. {{$highlightClass := $file.GetHighlightClass}}
  55. <div class="diff-file-box diff-box file-content" id="diff-{{.Index}}">
  56. <h4 class="ui top attached normal header">
  57. <div class="diff-counter count ui left">
  58. {{if $file.IsBin}}
  59. {{$.i18n.Tr "repo.diff.bin"}}
  60. {{else if not $file.IsRenamed}}
  61. <span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
  62. <span class="bar">
  63. <span class="pull-left add"></span>
  64. <span class="pull-left del"></span>
  65. </span>
  66. <span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
  67. {{end}}
  68. </div>
  69. <span class="file">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}</span>
  70. <div class="ui right">
  71. {{if $file.IsDeleted}}
  72. <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
  73. {{else}}
  74. <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
  75. {{end}}
  76. </div>
  77. </h4>
  78. <div class="ui attached table segment">
  79. {{if not $file.IsRenamed}}
  80. {{$isImage := (call $.IsImageFile $file.Name)}}
  81. {{if and $isImage}}
  82. <div class="center">
  83. <img src="{{$.RawPath}}/{{EscapePound .Name}}">
  84. </div>
  85. {{else}}
  86. <div class="file-body file-code code-view code-diff">
  87. <table>
  88. <tbody>
  89. {{if $.IsSplitStyle}}
  90. {{range $j, $section := .Sections}}
  91. {{range $k, $line := .Lines}}
  92. <tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
  93. <td class="lines-num lines-num-old">
  94. <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
  95. </td>
  96. <td class="lines-code halfwidth">
  97. <pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
  98. </td>
  99. <td class="lines-num lines-num-new">
  100. <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
  101. </td>
  102. <td class="lines-code halfwidth">
  103. <pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
  104. </td>
  105. </tr>
  106. {{end}}
  107. {{end}}
  108. {{else}}
  109. {{range $j, $section := .Sections}}
  110. {{range $k, $line := .Lines}}
  111. <tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
  112. {{if eq .GetType 4}}
  113. <td colspan="2" class="lines-num">
  114. {{/* {{if gt $j 0}}<span class="fold octicon octicon-fold"></span>{{end}} */}}
  115. </td>
  116. {{else}}
  117. <td class="lines-num lines-num-old">
  118. <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
  119. </td>
  120. <td class="lines-num lines-num-new">
  121. <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
  122. </td>
  123. {{end}}
  124. <td class="lines-code">
  125. <pre><code class="{{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
  126. </td>
  127. </tr>
  128. {{end}}
  129. {{end}}
  130. {{end}}
  131. </tbody>
  132. </table>
  133. </div>
  134. {{end}}
  135. {{end}}
  136. </div>
  137. </div>
  138. {{end}}
  139. <br>
  140. {{end}}
  141. {{if .Diff.IsIncomplete}}
  142. <div class="diff-file-box diff-box file-content">
  143. <h4 class="ui top attached normal header">
  144. {{$.i18n.Tr "repo.diff.too_many_files"}}
  145. </h4>
  146. </div>
  147. {{end}}
  148. {{if .IsSplitStyle}}
  149. <script>
  150. (function() {
  151. $('.add-code').each(function() {
  152. var prev = $(this).prev();
  153. if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') {
  154. while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') {
  155. prev = prev.prev();
  156. }
  157. prev.children().eq(3).html($(this).children().eq(3).html());
  158. prev.children().eq(2).html($(this).children().eq(2).html());
  159. prev.children().eq(3).addClass('add-code');
  160. prev.children().eq(2).addClass('add-code');
  161. $(this).remove();
  162. }
  163. });
  164. }());
  165. </script>
  166. {{end}}
  167. {{end}}