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