You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

box.tmpl 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. {{$showFileTree := (and (not .DiffNotAvailable) (gt .Diff.NumFiles 1))}}
  2. <div>
  3. <div class="diff-detail-box diff-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" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion}}
  23. </div>
  24. {{end}}
  25. </div>
  26. <div class="diff-detail-actions">
  27. {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived) (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 .Diff.NumFiles}}
  31. </label>
  32. <progress id="viewed-files-summary" value="{{.Diff.NumViewedFiles}}" max="{{.Diff.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-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. {{/*
  40. the following will be replaced by vue component
  41. but this avoids any loading artifacts till the vue component is initialized
  42. */}}
  43. <div class="ui jump dropdown basic button custom">
  44. {{svg "octicon-git-commit"}}
  45. </div>
  46. </div>
  47. {{end}}
  48. {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
  49. {{template "repo/diff/new_review" .}}
  50. {{end}}
  51. </div>
  52. </div>
  53. {{if not .DiffNotAvailable}}
  54. {{if and .IsShowingOnlySingleCommit .PageIsPullFiles}}
  55. <div class="ui info message">
  56. <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>
  57. </div>
  58. {{else if and (not .IsShowingAllCommits) .PageIsPullFiles}}
  59. <div class="ui info message">
  60. <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>
  61. </div>
  62. {{end}}
  63. <script id="diff-data-script" type="module">
  64. const diffDataFiles = [{{range $i, $file := .Diff.Files}}{Name:"{{$file.Name}}",NameHash:"{{$file.NameHash}}",Type:{{$file.Type}},IsBin:{{$file.IsBin}},Addition:{{$file.Addition}},Deletion:{{$file.Deletion}},IsViewed:{{$file.IsViewed}}},{{end}}];
  65. const diffData = {
  66. isIncomplete: {{.Diff.IsIncomplete}},
  67. tooManyFilesMessage: "{{ctx.Locale.Tr "repo.diff.too_many_files"}}",
  68. binaryFileMessage: "{{ctx.Locale.Tr "repo.diff.bin"}}",
  69. showMoreMessage: "{{ctx.Locale.Tr "repo.diff.show_more"}}",
  70. statisticsMessage: "{{ctx.Locale.Tr "repo.diff.stats_desc_file"}}",
  71. linkLoadMore: "?skip-to={{.Diff.End}}&file-only=true",
  72. };
  73. // for first time loading, the diffFileInfo is a plain object
  74. // after the Vue component is mounted, the diffFileInfo is a reactive object
  75. // keep in mind that this script block would be executed many times when loading more files, by "loadMoreFiles"
  76. let diffFileInfo = window.config.pageData.diffFileInfo || {
  77. files:[],
  78. fileTreeIsVisible: false,
  79. fileListIsVisible: false,
  80. isLoadingNewData: false,
  81. selectedItem: '',
  82. };
  83. diffFileInfo = Object.assign(diffFileInfo, diffData);
  84. diffFileInfo.files.push(...diffDataFiles);
  85. window.config.pageData.diffFileInfo = diffFileInfo;
  86. </script>
  87. <div id="diff-file-list"></div>
  88. {{end}}
  89. <div id="diff-container">
  90. {{if $showFileTree}}
  91. <div id="diff-file-tree" class="tw-hidden not-mobile"></div>
  92. <script>
  93. if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('tw-hidden');
  94. </script>
  95. {{end}}
  96. {{if .DiffNotAvailable}}
  97. <h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
  98. {{else}}
  99. <div id="diff-file-boxes" class="sixteen wide column">
  100. {{range $i, $file := .Diff.Files}}
  101. {{/*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*/}}
  102. {{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
  103. {{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
  104. {{$sniffedTypeBase := call $.GetSniffedTypeForBlob $blobBase}}
  105. {{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}}
  106. {{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}}
  107. {{$isCsv := (call $.IsCsvFile $file)}}
  108. {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
  109. {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}}
  110. {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived) $.IsShowingAllCommits}}
  111. <div class="diff-file-box diff-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}}>
  112. <h4 class="diff-file-header sticky-2nd-row ui top attached header tw-font-normal tw-flex tw-items-center tw-justify-between tw-flex-wrap">
  113. <div class="diff-file-name tw-flex tw-items-center tw-gap-1 tw-flex-wrap">
  114. <button class="fold-file btn interact-bg tw-p-1{{if not $isExpandable}} tw-invisible{{end}}">
  115. {{if $file.ShouldBeHidden}}
  116. {{svg "octicon-chevron-right" 18}}
  117. {{else}}
  118. {{svg "octicon-chevron-down" 18}}
  119. {{end}}
  120. </button>
  121. <div class="tw-font-semibold tw-flex tw-items-center tw-font-mono">
  122. {{if $file.IsBin}}
  123. <span class="tw-ml-0.5 tw-mr-2">
  124. {{ctx.Locale.Tr "repo.diff.bin"}}
  125. </span>
  126. {{else}}
  127. {{template "repo/diff/stats" dict "file" . "root" $}}
  128. {{end}}
  129. </div>
  130. <span class="file tw-font-mono"><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>{{if .IsLFSFile}} ({{ctx.Locale.Tr "repo.stored_lfs"}}){{end}}</span>
  131. <button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.Name}}">{{svg "octicon-copy" 14}}</button>
  132. {{if $file.IsGenerated}}
  133. <span class="ui label">{{ctx.Locale.Tr "repo.diff.generated"}}</span>
  134. {{end}}
  135. {{if $file.IsVendored}}
  136. <span class="ui label">{{ctx.Locale.Tr "repo.diff.vendored"}}</span>
  137. {{end}}
  138. {{if and $file.Mode $file.OldMode}}
  139. {{$old := ctx.Locale.Tr ($file.ModeTranslationKey $file.OldMode)}}
  140. {{$new := ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}
  141. <span class="tw-ml-4 tw-font-mono">{{ctx.Locale.Tr "git.filemode.changed_filemode" $old $new}}</span>
  142. {{else if $file.Mode}}
  143. <span class="tw-ml-4 tw-font-mono">{{ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}</span>
  144. {{end}}
  145. </div>
  146. <div class="diff-file-header-actions tw-flex tw-items-center tw-gap-1 tw-flex-wrap">
  147. {{if $showFileViewToggle}}
  148. <div class="ui compact icon buttons">
  149. <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>
  150. <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>
  151. </div>
  152. {{end}}
  153. {{if $file.IsProtected}}
  154. <span class="ui basic label">{{ctx.Locale.Tr "repo.diff.protected"}}</span>
  155. {{end}}
  156. {{if and $isReviewFile $file.HasChangedSinceLastReview}}
  157. <span class="changed-since-last-review unselectable not-mobile">{{ctx.Locale.Tr "repo.pulls.has_changed_since_last_review"}}</span>
  158. {{end}}
  159. {{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
  160. <button class="ui basic tiny button unescape-button not-mobile">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
  161. <button class="ui basic tiny button escape-button tw-hidden">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
  162. {{end}}
  163. {{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
  164. {{if $file.IsDeleted}}
  165. <a class="ui basic tiny button" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
  166. {{else}}
  167. <a class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
  168. {{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}}
  169. <a class="ui basic tiny button" 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>
  170. {{end}}
  171. {{end}}
  172. {{end}}
  173. {{if $isReviewFile}}
  174. <label data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.AfterCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
  175. <input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
  176. </label>
  177. {{end}}
  178. </div>
  179. </h4>
  180. <div class="diff-file-body ui attached unstackable table segment" {{if and $file.IsViewed $.IsShowingAllCommits}}data-folded="true"{{end}}>
  181. <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}}">
  182. {{if or $file.IsIncomplete $file.IsBin}}
  183. <div class="diff-file-body binary">
  184. {{if $file.IsIncomplete}}
  185. {{if $file.IsIncompleteLineTooLong}}
  186. {{ctx.Locale.Tr "repo.diff.file_suppressed_line_too_long"}}
  187. {{else}}
  188. {{ctx.Locale.Tr "repo.diff.file_suppressed"}}
  189. <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>
  190. {{end}}
  191. {{else}}
  192. {{ctx.Locale.Tr "repo.diff.bin_not_shown"}}
  193. {{end}}
  194. </div>
  195. {{else}}
  196. <table class="chroma" data-new-comment-url="{{$.Issue.Link}}/files/reviews/new_comment" data-path="{{$file.Name}}">
  197. {{if $.IsSplitStyle}}
  198. {{template "repo/diff/section_split" dict "file" . "root" $}}
  199. {{else}}
  200. {{template "repo/diff/section_unified" dict "file" . "root" $}}
  201. {{end}}
  202. </table>
  203. {{end}}
  204. </div>
  205. {{if $showFileViewToggle}}
  206. {{/* 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" */}}
  207. <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">
  208. <table class="chroma tw-w-full">
  209. {{if $isImage}}
  210. {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
  211. {{else}}
  212. {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
  213. {{end}}
  214. </table>
  215. </div>
  216. {{end}}
  217. </div>
  218. </div>
  219. {{end}}
  220. {{if .Diff.IsIncomplete}}
  221. <div class="diff-file-box diff-box file-content tw-mt-2" id="diff-incomplete">
  222. <h4 class="ui top attached header tw-font-normal tw-flex tw-items-center tw-justify-between">
  223. {{ctx.Locale.Tr "repo.diff.too_many_files"}}
  224. <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>
  225. </h4>
  226. </div>
  227. {{end}}
  228. </div>
  229. {{end}}
  230. </div>
  231. {{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
  232. <template id="issue-comment-editor-template">
  233. <div class="ui comment form">
  234. {{template "shared/combomarkdowneditor" (dict
  235. "MarkdownPreviewUrl" (print $.Repository.Link "/markup")
  236. "MarkdownPreviewContext" $.RepoLink
  237. "TextareaName" "content"
  238. "DropzoneParentContainer" ".ui.form"
  239. )}}
  240. {{if .IsAttachmentEnabled}}
  241. <div class="field">
  242. {{template "repo/upload" .}}
  243. </div>
  244. {{end}}
  245. <div class="text right edit buttons">
  246. <button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
  247. <button class="ui primary save button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
  248. </div>
  249. </div>
  250. </template>
  251. {{end}}
  252. {{if (not .DiffNotAvailable)}}
  253. {{template "repo/issue/view_content/reference_issue_dialog" .}}
  254. {{template "shared/user/block_user_dialog" .}}
  255. {{end}}
  256. </div>