diff_box.tmpl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. <div class="diff-file-box diff-box file-content" id="diff-{{.Index}}">
  37. <h4 class="ui top attached normal header">
  38. <div class="diff-counter count ui left">
  39. {{if $file.IsBin}}
  40. {{$.i18n.Tr "repo.diff.bin"}}
  41. {{else 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">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}</span>
  51. <div class="ui right">
  52. {{if $file.IsDeleted}}
  53. <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
  54. {{else}}
  55. <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
  56. {{end}}
  57. </div>
  58. </h4>
  59. <div class="ui attached table segment">
  60. {{if not $file.IsRenamed}}
  61. {{$isImage := (call $.IsImageFile $file.Name)}}
  62. {{if and $isImage}}
  63. <div class="center">
  64. <img src="{{$.RawPath}}/{{EscapePound .Name}}">
  65. </div>
  66. {{else}}
  67. <div class="file-body file-code code-view code-diff">
  68. <table>
  69. <tbody>
  70. {{if $.IsSplitStyle}}
  71. {{range $j, $section := .Sections}}
  72. {{range $k, $line := .Lines}}
  73. <tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
  74. <td class="lines-num lines-num-old">
  75. <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
  76. </td>
  77. <td class="lines-code halfwidth">
  78. <pre class="wrap">{{if $line.LeftIdx}}{{$line.ParsedContent}}{{end}}</pre>
  79. </td>
  80. <td class="lines-num lines-num-new">
  81. <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
  82. </td>
  83. <td class="lines-code halfwidth">
  84. <pre class="wrap">{{if $line.RightIdx}}{{$line.ParsedContent}}{{end}}</pre>
  85. </td>
  86. </tr>
  87. {{end}}
  88. {{end}}
  89. {{else}}
  90. {{range $j, $section := .Sections}}
  91. {{range $k, $line := .Lines}}
  92. <tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
  93. {{if eq .GetType 4}}
  94. <td colspan="2" class="lines-num">
  95. {{/* {{if gt $j 0}}<span class="fold octicon octicon-fold"></span>{{end}} */}}
  96. </td>
  97. {{else}}
  98. <td class="lines-num lines-num-old">
  99. <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
  100. </td>
  101. <td class="lines-num lines-num-new">
  102. <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
  103. </td>
  104. {{end}}
  105. <td class="lines-code">
  106. <pre>{{$line.ParsedContent}}</pre>
  107. </td>
  108. </tr>
  109. {{end}}
  110. {{end}}
  111. {{end}}
  112. </tbody>
  113. </table>
  114. </div>
  115. {{end}}
  116. {{end}}
  117. </div>
  118. </div>
  119. <br>
  120. {{end}}
  121. {{if .IsSplitStyle}}
  122. <script>
  123. (function() {
  124. $('.add-code').each(function() {
  125. var prev = $(this).prev();
  126. if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') {
  127. while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') {
  128. prev = prev.prev();
  129. }
  130. prev.children().eq(3).html($(this).children().eq(3).html());
  131. prev.children().eq(2).html($(this).children().eq(2).html());
  132. prev.children().eq(3).addClass('add-code');
  133. prev.children().eq(2).addClass('add-code');
  134. $(this).remove();
  135. }
  136. });
  137. }());
  138. </script>
  139. {{end}}
  140. {{end}}