gitea源码

box.tmpl 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. {{$showFileTree := (and (not .DiffNotAvailable) (gt .DiffShortStat.NumFiles 1))}}
  2. <div>
  3. <div class="diff-detail-box">
  4. <div class="tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-ml-0.5">
  5. {{if $showFileTree}}
  6. <button class="diff-toggle-file-tree-button not-mobile btn interact-fg" data-show-text="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{ctx.Locale.Tr "repo.diff.hide_file_tree"}}">
  7. {{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}}
  8. {{svg "octicon-sidebar-collapse" 20 "icon tw-hidden"}}
  9. {{svg "octicon-sidebar-expand" 20 "icon tw-hidden"}}
  10. </button>
  11. <script>
  12. // Default to true if unset
  13. const diffTreeVisible = localStorage?.getItem('diff_file_tree_visible') !== 'false';
  14. const diffTreeBtn = document.querySelector('.diff-toggle-file-tree-button');
  15. const diffTreeIcon = `.octicon-sidebar-${diffTreeVisible ? 'expand' : 'collapse'}`;
  16. diffTreeBtn.querySelector(diffTreeIcon).classList.remove('tw-hidden');
  17. diffTreeBtn.setAttribute('data-tooltip-content', diffTreeBtn.getAttribute(diffTreeVisible ? 'data-hide-text' : 'data-show-text'));
  18. </script>
  19. {{end}}
  20. {{if not .DiffNotAvailable}}
  21. <div class="diff-detail-stats tw-flex tw-items-center tw-flex-wrap">
  22. {{svg "octicon-diff" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.diff.stats_desc" .DiffShortStat.NumFiles .DiffShortStat.TotalAddition .DiffShortStat.TotalDeletion}}
  23. </div>
  24. {{end}}
  25. </div>
  26. <div class="diff-detail-actions">
  27. {{if and .PageIsPullFiles $.SignedUserID (not .DiffNotAvailable)}}
  28. <div class="not-mobile tw-flex tw-items-center tw-flex-col tw-whitespace-nowrap tw-mr-1">
  29. <label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{ctx.Locale.Tr "repo.pulls.viewed_files_label"}}">
  30. {{ctx.Locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .DiffShortStat.NumFiles}}
  31. </label>
  32. <progress id="viewed-files-summary" value="{{.Diff.NumViewedFiles}}" max="{{.DiffShortStat.NumFiles}}"></progress>
  33. </div>
  34. {{end}}
  35. {{template "repo/diff/whitespace_dropdown" .}}
  36. {{template "repo/diff/options_dropdown" .}}
  37. {{if .PageIsPullFiles}}
  38. <div id="diff-commit-select" data-merge-base="{{.MergeBase}}" data-issuelink="{{$.Issue.Link}}" data-queryparams="?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}" data-filter_changes_by_commit="{{ctx.Locale.Tr "repo.pulls.filter_changes_by_commit"}}">
  39. {{/* the following will be replaced by vue component, but this avoids any loading artifacts till the vue component is initialized */}}
  40. <div class="ui jump dropdown tiny basic button custom">
  41. {{svg "octicon-git-commit"}}
  42. </div>
  43. </div>
  44. {{end}}
  45. {{if and .PageIsPullFiles $.SignedUserID}}
  46. {{template "repo/diff/new_review" .}}
  47. {{end}}
  48. </div>
  49. </div>
  50. {{if not .DiffNotAvailable}}
  51. {{if and .IsShowingOnlySingleCommit .PageIsPullFiles}}
  52. <div class="ui info message">
  53. <div>{{ctx.Locale.Tr "repo.pulls.showing_only_single_commit" (ShortSha .AfterCommitID)}} - <a href="{{$.Issue.Link}}/files?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}">{{ctx.Locale.Tr "repo.pulls.show_all_commits"}}</a></div>
  54. </div>
  55. {{else if and (not .IsShowingAllCommits) .PageIsPullFiles}}
  56. <div class="ui info message">
  57. <div>{{ctx.Locale.Tr "repo.pulls.showing_specified_commit_range" (ShortSha .BeforeCommitID) (ShortSha .AfterCommitID)}} - <a href="{{$.Issue.Link}}/files?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}">{{ctx.Locale.Tr "repo.pulls.show_all_commits"}}</a></div>
  58. </div>
  59. {{end}}
  60. {{end}}
  61. <div id="diff-container">
  62. {{if $showFileTree}}
  63. {{$.FileIconPoolHTML}}
  64. <div id="diff-file-tree" class="tw-hidden not-mobile"></div>
  65. <script>
  66. if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('tw-hidden');
  67. </script>
  68. {{end}}
  69. {{if .DiffNotAvailable}}
  70. <h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
  71. {{else}}
  72. <div id="diff-file-boxes" class="sixteen wide column">
  73. {{range $i, $file := .Diff.Files}}
  74. {{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}}
  75. {{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
  76. {{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
  77. {{$sniffedTypeBase := call $.GetSniffedTypeForBlob $blobBase}}
  78. {{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}}
  79. {{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}}
  80. {{$isCsv := (call $.IsCsvFile $file)}}
  81. {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
  82. {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}}
  83. {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.Repository.IsArchived) $.IsShowingAllCommits}}
  84. <div class="diff-file-box file-content {{TabSizeClass $.Editorconfig $file.Name}} tw-mt-0" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if or ($file.ShouldBeHidden) (not $isExpandable)}}data-folded="true"{{end}}>
  85. <h4 class="diff-file-header sticky-2nd-row ui top attached header">
  86. <div class="diff-file-name tw-flex tw-flex-1 tw-items-center tw-gap-1 tw-flex-wrap">
  87. <button class="fold-file btn interact-bg tw-p-1{{if not $isExpandable}} tw-invisible{{end}}">
  88. {{if $file.ShouldBeHidden}}
  89. {{svg "octicon-chevron-right" 18}}
  90. {{else}}
  91. {{svg "octicon-chevron-down" 18}}
  92. {{end}}
  93. </button>
  94. <div class="tw-font-semibold tw-flex tw-items-center tw-font-mono">
  95. {{if $file.IsBin}}
  96. <span class="tw-ml-0.5 tw-mr-2">
  97. {{ctx.Locale.Tr "repo.diff.bin"}}
  98. </span>
  99. {{else}}
  100. {{template "repo/diff/stats" dict "file" . "root" $}}
  101. {{end}}
  102. </div>
  103. <span class="file tw-flex tw-items-center tw-font-mono tw-flex-1"><a class="muted file-link" title="{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}" href="#diff-{{$file.NameHash}}">{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}</a>
  104. <button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button>
  105. {{if .IsLFSFile}}<span class="ui label">LFS</span>{{end}}
  106. {{if $file.IsGenerated}}
  107. <span class="ui label">{{ctx.Locale.Tr "repo.diff.generated"}}</span>
  108. {{end}}
  109. {{if $file.IsVendored}}
  110. <span class="ui label">{{ctx.Locale.Tr "repo.diff.vendored"}}</span>
  111. {{end}}
  112. {{if and $file.Mode $file.OldMode}}
  113. {{$old := ctx.Locale.Tr ($file.ModeTranslationKey $file.OldMode)}}
  114. {{$new := ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}
  115. <span class="tw-mx-2 tw-font-mono tw-whitespace-nowrap">{{ctx.Locale.Tr "git.filemode.changed_filemode" $old $new}}</span>
  116. {{else if $file.Mode}}
  117. <span class="tw-mx-2 tw-font-mono tw-whitespace-nowrap">{{ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}</span>
  118. {{end}}
  119. </span>
  120. </div>
  121. <div class="diff-file-header-actions tw-flex tw-items-center tw-gap-1 tw-flex-wrap">
  122. {{if $showFileViewToggle}}
  123. <div class="ui compact icon buttons">
  124. <button class="ui tiny basic button file-view-toggle" data-toggle-selector="#diff-source-{{$file.NameHash}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_source"}}">{{svg "octicon-code"}}</button>
  125. <button class="ui tiny basic button file-view-toggle active" data-toggle-selector="#diff-rendered-{{$file.NameHash}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_rendered"}}">{{svg "octicon-file"}}</button>
  126. </div>
  127. {{end}}
  128. {{if $file.IsProtected}}
  129. <span class="ui basic label">{{ctx.Locale.Tr "repo.diff.protected"}}</span>
  130. {{end}}
  131. {{if and $isReviewFile $file.HasChangedSinceLastReview}}
  132. <span class="changed-since-last-review unselectable not-mobile">{{ctx.Locale.Tr "repo.pulls.has_changed_since_last_review"}}</span>
  133. {{end}}
  134. {{if $isReviewFile}}
  135. <label data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.AfterCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
  136. <input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
  137. </label>
  138. {{end}}
  139. {{if not $file.IsSubmodule}}
  140. <button class="btn diff-header-popup-btn tw-p-1">{{svg "octicon-kebab-horizontal" 18}}</button>
  141. <div class="tippy-target">
  142. {{if not (or $file.IsIncomplete $file.IsBin)}}
  143. <button class="unescape-button item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
  144. <button class="escape-button tw-hidden item" data-unicode-content-selector="#diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
  145. {{end}}
  146. {{if not $.PageIsWiki}}
  147. {{if $file.IsDeleted}}
  148. <a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
  149. {{else}}
  150. <a class="item" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
  151. {{if and $.Repository.CanEnableEditor $.CanEditFile}}
  152. <a class="item" rel="nofollow" href="{{$.HeadRepoLink}}/_edit/{{PathEscapeSegments $.HeadBranchName}}/{{PathEscapeSegments $file.Name}}?return_uri={{print $.BackToLink "#diff-" $file.NameHash | QueryEscape}}">{{ctx.Locale.Tr "repo.editor.edit_this_file"}}</a>
  153. {{end}}
  154. {{end}}
  155. {{end}}
  156. </div>
  157. {{end}}
  158. </div>
  159. </h4>
  160. <div class="diff-file-body ui attached unstackable table segment" {{if and $file.IsViewed $.IsShowingAllCommits}}data-folded="true"{{end}}>
  161. <div id="diff-source-{{$file.NameHash}}" class="file-body file-code unicode-escaped code-diff{{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}{{if $showFileViewToggle}} tw-hidden{{end}}">
  162. {{if or $file.IsIncomplete $file.IsBin}}
  163. <div class="diff-file-body binary">
  164. {{if $file.IsIncomplete}}
  165. {{if $file.IsIncompleteLineTooLong}}
  166. {{ctx.Locale.Tr "repo.diff.file_suppressed_line_too_long"}}
  167. {{else}}
  168. {{ctx.Locale.Tr "repo.diff.file_suppressed"}}
  169. <a class="ui basic tiny button diff-load-button" data-href="?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{ctx.Locale.Tr "repo.diff.load"}}</a>
  170. {{end}}
  171. {{else}}
  172. {{ctx.Locale.Tr "repo.diff.bin_not_shown"}}
  173. {{end}}
  174. </div>
  175. {{else if $file.SubmoduleDiffInfo}}
  176. <div class="tw-p-3">{{svg "octicon-file-submodule"}} {{$submoduleDiffInfo := $file.SubmoduleDiffInfo -}}
  177. {{- $submoduleName := $submoduleDiffInfo.SubmoduleRepoLinkHTML ctx -}}
  178. {{- if $file.IsDeleted -}}
  179. {{- ctx.Locale.Tr "repo.diff.submodule_deleted" $submoduleName ($submoduleDiffInfo.CommitRefIDLinkHTML ctx $submoduleDiffInfo.PreviousRefID) -}}
  180. {{- else if $file.IsCreated -}}
  181. {{- ctx.Locale.Tr "repo.diff.submodule_added" $submoduleName ($submoduleDiffInfo.CommitRefIDLinkHTML ctx $submoduleDiffInfo.NewRefID) -}}
  182. {{- else -}}
  183. {{- ctx.Locale.Tr "repo.diff.submodule_updated" $submoduleName ($submoduleDiffInfo.CompareRefIDLinkHTML ctx) -}}
  184. {{end}}
  185. </div>
  186. {{else}}
  187. <table class="chroma" data-new-comment-url="{{$.Issue.Link}}/files/reviews/new_comment" data-path="{{$file.Name}}">
  188. {{if $.IsSplitStyle}}
  189. {{template "repo/diff/section_split" dict "file" . "root" $}}
  190. {{else}}
  191. {{template "repo/diff/section_unified" dict "file" . "root" $}}
  192. {{end}}
  193. </table>
  194. {{end}}
  195. </div>
  196. {{if $showFileViewToggle}}
  197. {{/* for image or CSV, it can have a horizontal scroll bar, there won't be review comment context menu (position absolute) which would be clipped by "overflow" */}}
  198. <div id="diff-rendered-{{$file.NameHash}}" class="file-body file-code {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}} tw-overflow-x-scroll">
  199. <table class="chroma tw-w-full">
  200. {{if $isImage}}
  201. {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
  202. {{else}}
  203. {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
  204. {{end}}
  205. </table>
  206. </div>
  207. {{end}}
  208. </div>
  209. </div>
  210. {{end}}
  211. {{if .Diff.IsIncomplete}}
  212. <div class="diff-file-box file-content tw-mt-2" id="diff-incomplete">
  213. <h4 class="ui top attached header tw-font-normal tw-flex tw-items-center tw-justify-between">
  214. {{ctx.Locale.Tr "repo.diff.too_many_files"}}
  215. <a class="ui basic tiny button" id="diff-show-more-files" data-href="?skip-to={{.Diff.End}}&file-only=true">{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
  216. </h4>
  217. </div>
  218. {{end}}
  219. </div>
  220. {{end}}
  221. </div>
  222. {{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
  223. <template id="issue-comment-editor-template">
  224. <form class="ui form comment">
  225. <div class="field">
  226. {{template "shared/combomarkdowneditor" (dict
  227. "CustomInit" true
  228. "MarkdownPreviewInRepo" $.Repository
  229. "MarkdownPreviewMode" "comment"
  230. "TextareaName" "content"
  231. "DropzoneParentContainer" ".ui.form"
  232. )}}
  233. </div>
  234. {{if .IsAttachmentEnabled}}
  235. <div class="field">
  236. {{template "repo/upload" .}}
  237. </div>
  238. {{end}}
  239. <div class="field flex-text-block tw-justify-end">
  240. <button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
  241. <button class="ui primary button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
  242. </div>
  243. </form>
  244. </template>
  245. {{end}}
  246. {{if (not .DiffNotAvailable)}}
  247. {{template "repo/issue/view_content/reference_issue_dialog" .}}
  248. {{template "shared/user/block_user_dialog" .}}
  249. {{end}}
  250. </div>