gitea源码

section_split.tmpl 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {{$file := .file}}
  2. {{$blobExcerptLink := print (or ctx.RootData.CommitRepoLink ctx.RootData.RepoLink) (Iif $.root.PageIsWiki "/wiki" "") "/blob_excerpt/" (PathEscape $.root.AfterCommitID) "?"}}
  3. <colgroup>
  4. <col width="50">
  5. <col width="10">
  6. <col width="10">
  7. <col>
  8. <col width="50">
  9. <col width="10">
  10. <col width="10">
  11. <col>
  12. </colgroup>
  13. {{range $j, $section := $file.Sections}}
  14. {{range $k, $line := $section.Lines}}
  15. {{$hasmatch := ne $line.Match -1}}
  16. {{if or (ne .GetType 2) (not $hasmatch)}}
  17. <tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}}" data-line-type="{{.GetHTMLDiffLineType}}">
  18. {{if eq .GetType 4}}
  19. {{$expandDirection := $line.GetExpandDirection}}
  20. <td class="lines-num lines-num-old">
  21. <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
  22. {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
  23. <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=down&&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
  24. {{svg "octicon-fold-down"}}
  25. </button>
  26. {{end}}
  27. {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
  28. <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&direction=up&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
  29. {{svg "octicon-fold-up"}}
  30. </button>
  31. {{end}}
  32. {{if eq $expandDirection 2}}
  33. <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptLink}}&{{$line.GetBlobExcerptQuery}}&style=split&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
  34. {{svg "octicon-fold"}}
  35. </button>
  36. {{end}}
  37. </div>
  38. </td>{{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}}
  39. <td class="lines-escape lines-escape-old">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
  40. <td colspan="6" class="lines-code lines-code-old">{{template "repo/diff/section_code" dict "diff" $inlineDiff}}</td>
  41. {{else if and (eq .GetType 3) $hasmatch}}{{/* DEL */}}
  42. {{$match := index $section.Lines $line.Match}}
  43. {{- $leftDiff := ""}}{{if $line.LeftIdx}}{{$leftDiff = $section.GetComputedInlineDiffFor $line ctx.Locale}}{{end}}
  44. {{- $rightDiff := ""}}{{if $match.RightIdx}}{{$rightDiff = $section.GetComputedInlineDiffFor $match ctx.Locale}}{{end}}
  45. <td class="lines-num lines-num-old del-code" data-line-num="{{$line.LeftIdx}}"><span rel="diff-{{$file.NameHash}}L{{$line.LeftIdx}}"></span></td>
  46. <td class="lines-escape del-code lines-escape-old">{{if $line.LeftIdx}}{{if $leftDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $leftDiff}}"></button>{{end}}{{end}}</td>
  47. <td class="lines-type-marker lines-type-marker-old del-code"><span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
  48. <td class="lines-code lines-code-old del-code">
  49. {{- if and $.root.SignedUserID $.root.PageIsPullFiles -}}
  50. <button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">
  51. {{- svg "octicon-plus" -}}
  52. </button>
  53. {{- end -}}
  54. {{- if $line.LeftIdx -}}
  55. {{- template "repo/diff/section_code" dict "diff" $leftDiff -}}
  56. {{- else -}}
  57. <code class="code-inner"></code>
  58. {{- end -}}
  59. </td>
  60. <td class="lines-num lines-num-new add-code" data-line-num="{{if $match.RightIdx}}{{$match.RightIdx}}{{end}}"><span rel="{{if $match.RightIdx}}diff-{{$file.NameHash}}R{{$match.RightIdx}}{{end}}"></span></td>
  61. <td class="lines-escape add-code lines-escape-new">{{if $match.RightIdx}}{{if $rightDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $rightDiff}}"></button>{{end}}{{end}}</td>
  62. <td class="lines-type-marker lines-type-marker-new add-code">{{if $match.RightIdx}}<span class="tw-font-mono" data-type-marker="{{$match.GetLineTypeMarker}}"></span>{{end}}</td>
  63. <td class="lines-code lines-code-new add-code">
  64. {{- if and $.root.SignedUserID $.root.PageIsPullFiles -}}
  65. <button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-right{{if (not $match.CanComment)}} tw-invisible{{end}}" data-side="right" data-idx="{{$match.RightIdx}}">
  66. {{- svg "octicon-plus" -}}
  67. </button>
  68. {{- end -}}
  69. {{- if $match.RightIdx -}}
  70. {{- template "repo/diff/section_code" dict "diff" $rightDiff -}}
  71. {{- else -}}
  72. <code class="code-inner"></code>
  73. {{- end -}}
  74. </td>
  75. {{else}}
  76. {{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}}
  77. <td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$file.NameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
  78. <td class="lines-escape lines-escape-old">{{if $line.LeftIdx}}{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}{{end}}</td>
  79. <td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
  80. <td class="lines-code lines-code-old">
  81. {{- if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 2)) -}}
  82. <button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-left{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="left" data-idx="{{$line.LeftIdx}}">
  83. {{- svg "octicon-plus" -}}
  84. </button>
  85. {{- end -}}
  86. {{- if $line.LeftIdx -}}
  87. {{- template "repo/diff/section_code" dict "diff" $inlineDiff -}}
  88. {{- else -}}
  89. <code class="code-inner"></code>
  90. {{- end -}}
  91. </td>
  92. <td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{$file.NameHash}}R{{$line.RightIdx}}{{end}}"></span></td>
  93. <td class="lines-escape lines-escape-new">{{if $line.RightIdx}}{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}{{end}}</td>
  94. <td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
  95. <td class="lines-code lines-code-new">
  96. {{- if and $.root.SignedUserID $.root.PageIsPullFiles (not (eq .GetType 3)) -}}
  97. <button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-right{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="right" data-idx="{{$line.RightIdx}}">
  98. {{- svg "octicon-plus" -}}
  99. </button>
  100. {{- end -}}
  101. {{- if $line.RightIdx -}}
  102. {{- template "repo/diff/section_code" dict "diff" $inlineDiff -}}
  103. {{- else -}}
  104. <code class="code-inner"></code>
  105. {{- end -}}
  106. </td>
  107. {{end}}
  108. </tr>
  109. {{if and (eq .GetType 3) $hasmatch}}
  110. {{$match := index $section.Lines $line.Match}}
  111. {{if or $line.Comments $match.Comments}}
  112. <tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
  113. <td class="add-comment-left" colspan="4">
  114. {{if $line.Comments}}
  115. {{if eq $line.GetCommentSide "previous"}}
  116. {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
  117. {{end}}
  118. {{end}}
  119. {{if $match.Comments}}
  120. {{if eq $match.GetCommentSide "previous"}}
  121. {{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}}
  122. {{end}}
  123. {{end}}
  124. </td>
  125. <td class="add-comment-right" colspan="4">
  126. {{if $line.Comments}}
  127. {{if eq $line.GetCommentSide "proposed"}}
  128. {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
  129. {{end}}
  130. {{end}}
  131. {{if $match.Comments}}
  132. {{if eq $match.GetCommentSide "proposed"}}
  133. {{template "repo/diff/conversation" dict "." $.root "comments" $match.Comments}}
  134. {{end}}
  135. {{end}}
  136. </td>
  137. </tr>
  138. {{end}}
  139. {{else if $line.Comments}}
  140. <tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
  141. <td class="add-comment-left" colspan="4">
  142. {{if eq $line.GetCommentSide "previous"}}
  143. {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
  144. {{end}}
  145. </td>
  146. <td class="add-comment-right" colspan="4">
  147. {{if eq $line.GetCommentSide "proposed"}}
  148. {{template "repo/diff/conversation" dict "." $.root "comments" $line.Comments}}
  149. {{end}}
  150. </td>
  151. </tr>
  152. {{end}}
  153. {{end}}
  154. {{end}}
  155. {{end}}