aboutsummaryrefslogtreecommitdiffstats
path: root/templates/repo/diff/box.tmpl
blob: e72ac1eeaefee664c6da21d51df408aeb788cc05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
{{$showFileTree := (and (not .DiffNotAvailable) (gt .Diff.NumFiles 1))}}
<div>
	<div class="diff-detail-box diff-box">
		<div class="gt-df gt-ac gt-fw">
			{{if $showFileTree}}
				<button class="diff-toggle-file-tree-button gt-df gt-ac not-mobile" data-show-text="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{ctx.Locale.Tr "repo.diff.hide_file_tree"}}">
					{{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}}
					{{svg "octicon-sidebar-collapse" 20 "icon gt-hidden"}}
					{{svg "octicon-sidebar-expand" 20 "icon gt-hidden"}}
				</button>
				<script>
					// Default to true if unset
					const diffTreeVisible = localStorage?.getItem('diff_file_tree_visible') !== 'false';
					const diffTreeBtn = document.querySelector('.diff-toggle-file-tree-button');
					const diffTreeIcon = `.octicon-sidebar-${diffTreeVisible ? 'expand' : 'collapse'}`;
					diffTreeBtn.querySelector(diffTreeIcon).classList.remove('gt-hidden');
					diffTreeBtn.setAttribute('data-tooltip-content', diffTreeBtn.getAttribute(diffTreeVisible ? 'data-hide-text' : 'data-show-text'));
				</script>
			{{end}}
			{{if not .DiffNotAvailable}}
				<div class="diff-detail-stats gt-df gt-ac gt-fw">
					{{svg "octicon-diff" 16 "gt-mr-2"}}{{ctx.Locale.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
				</div>
			{{end}}
		</div>
		<div class="diff-detail-actions">
			{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived) (not .DiffNotAvailable)}}
				<div class="not-mobile gt-df gt-ac gt-fc gt-whitespace-nowrap gt-mr-2">
					<label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{ctx.Locale.Tr "repo.pulls.viewed_files_label"}}">
						{{ctx.Locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}}
					</label>
					<progress id="viewed-files-summary" value="{{.Diff.NumViewedFiles}}" max="{{.Diff.NumFiles}}"></progress>
				</div>
			{{end}}
			{{template "repo/diff/whitespace_dropdown" .}}
			{{template "repo/diff/options_dropdown" .}}
			{{if .PageIsPullFiles}}
				<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"}}">
					{{/*
						the following will be replaced by vue component
						but this avoids any loading artifacts till the vue component is initialized
					*/}}
					<div class="ui jump dropdown basic button custom">
						{{svg "octicon-git-commit"}}
					</div>
				</div>
			{{end}}
			{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
				{{template "repo/diff/new_review" .}}
			{{end}}
		</div>
	</div>
	{{if not .DiffNotAvailable}}
		{{if and .IsShowingOnlySingleCommit .PageIsPullFiles}}
			<div class="ui info message">
				<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>
			</div>
		{{else if and (not .IsShowingAllCommits) .PageIsPullFiles}}
			<div class="ui info message">
				<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>
			</div>
		{{end}}
		<script id="diff-data-script" type="module">
			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}}];
			const diffData = {
				isIncomplete: {{.Diff.IsIncomplete}},
				tooManyFilesMessage: "{{ctx.Locale.Tr "repo.diff.too_many_files"}}",
				binaryFileMessage: "{{ctx.Locale.Tr "repo.diff.bin"}}",
				showMoreMessage: "{{ctx.Locale.Tr "repo.diff.show_more"}}",
				statisticsMessage: "{{ctx.Locale.Tr "repo.diff.stats_desc_file"}}",
				linkLoadMore: "{{$.Link}}?skip-to={{.Diff.End}}&file-only=true",
			};

			// for first time loading, the diffFileInfo is a plain object
			// after the Vue component is mounted, the diffFileInfo is a reactive object
			// keep in mind that this script block would be executed many times when loading more files, by "loadMoreFiles"
			let diffFileInfo = window.config.pageData.diffFileInfo || {
				files:[],
				fileTreeIsVisible: false,
				fileListIsVisible: false,
				isLoadingNewData: false,
				selectedItem: '',
			};
			diffFileInfo = Object.assign(diffFileInfo, diffData);
			diffFileInfo.files.push(...diffDataFiles);
			window.config.pageData.diffFileInfo = diffFileInfo;
		</script>
		<div id="diff-file-list"></div>
	{{end}}
	<div id="diff-container">
		{{if $showFileTree}}
			<div id="diff-file-tree" class="gt-hidden"></div>
			<script>
				if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('gt-hidden');
			</script>
		{{end}}
		{{if .DiffNotAvailable}}
			<h4>{{ctx.Locale.Tr "repo.diff.data_not_available"}}</h4>
		{{else}}
			<div id="diff-file-boxes" class="sixteen wide column">
				{{range $i, $file := .Diff.Files}}
					{{/*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*/}}
					{{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
					{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
					{{$sniffedTypeBase := call $.GetSniffedTypeForBlob $blobBase}}
					{{$sniffedTypeHead := call $.GetSniffedTypeForBlob $blobHead}}
					{{$isImage:= or (call $.IsSniffedTypeAnImage $sniffedTypeBase) (call $.IsSniffedTypeAnImage $sniffedTypeHead)}}
					{{$isCsv := (call $.IsCsvFile $file)}}
					{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
					{{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}}
					{{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived) $.IsShowingAllCommits}}
					<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} gt-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}}>
						<h4 class="diff-file-header sticky-2nd-row ui top attached normal header gt-df gt-ac gt-sb gt-fw">
							<div class="diff-file-name gt-df gt-ac gt-gap-2 gt-fw">
								<button class="fold-file btn interact-bg gt-p-2{{if not $isExpandable}} gt-invisible{{end}}">
									{{if $file.ShouldBeHidden}}
										{{svg "octicon-chevron-right" 18}}
									{{else}}
										{{svg "octicon-chevron-down" 18}}
									{{end}}
								</button>
								<div class="gt-font-semibold gt-df gt-ac gt-mono">
									{{if $file.IsBin}}
										<span class="gt-ml-1 gt-mr-3">
											{{ctx.Locale.Tr "repo.diff.bin"}}
										</span>
									{{else}}
										{{template "repo/diff/stats" dict "file" . "root" $}}
									{{end}}
								</div>
								<span class="file gt-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>
								<button class="btn interact-fg gt-p-3" data-clipboard-text="{{$file.Name}}">{{svg "octicon-copy" 14}}</button>
								{{if $file.IsGenerated}}
									<span class="ui label">{{ctx.Locale.Tr "repo.diff.generated"}}</span>
								{{end}}
								{{if $file.IsVendored}}
									<span class="ui label">{{ctx.Locale.Tr "repo.diff.vendored"}}</span>
								{{end}}
								{{if and $file.Mode $file.OldMode}}
									{{$old := ctx.Locale.Tr ($file.ModeTranslationKey $file.OldMode)}}
									{{$new := ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}
									<span class="gt-ml-4 gt-mono">{{ctx.Locale.Tr "git.filemode.changed_filemode" $old $new}}</span>
								{{else if $file.Mode}}
									<span class="gt-ml-4 gt-mono">{{ctx.Locale.Tr ($file.ModeTranslationKey $file.Mode)}}</span>
								{{end}}
							</div>
							<div class="diff-file-header-actions gt-df gt-ac gt-gap-2 gt-fw">
								{{if $showFileViewToggle}}
									<div class="ui compact icon buttons">
										<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>
										<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>
									</div>
								{{end}}
								{{if $file.IsProtected}}
									<span class="ui basic label">{{ctx.Locale.Tr "repo.diff.protected"}}</span>
								{{end}}
								{{if and $isReviewFile $file.HasChangedSinceLastReview}}
									<span class="changed-since-last-review unselectable not-mobile">{{ctx.Locale.Tr "repo.pulls.has_changed_since_last_review"}}</span>
								{{end}}
								{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
									<button class="ui basic tiny button unescape-button not-mobile">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
									<button class="ui basic tiny button escape-button gt-hidden">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
								{{end}}
								{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
									{{if $file.IsDeleted}}
										<a class="ui basic tiny button" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
									{{else}}
										<a class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
									{{end}}
								{{end}}
								{{if $isReviewFile}}
									<label data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.AfterCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
										<input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
									</label>
								{{end}}
							</div>
						</h4>
						<div class="diff-file-body ui attached unstackable table segment" {{if and $file.IsViewed $.IsShowingAllCommits}}data-folded="true"{{end}}>
							<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}} gt-hidden{{end}}">
								{{if or $file.IsIncomplete $file.IsBin}}
									<div class="diff-file-body binary" style="padding: 5px 10px;">
										{{if $file.IsIncomplete}}
											{{if $file.IsIncompleteLineTooLong}}
												{{ctx.Locale.Tr "repo.diff.file_suppressed_line_too_long"}}
											{{else}}
												{{ctx.Locale.Tr "repo.diff.file_suppressed"}}
												<a class="ui basic tiny button diff-load-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{ctx.Locale.Tr "repo.diff.load"}}</a>
											{{end}}
										{{else}}
											{{ctx.Locale.Tr "repo.diff.bin_not_shown"}}
										{{end}}
									</div>
								{{else}}
									<table class="chroma" data-new-comment-url="{{$.Issue.Link}}/files/reviews/new_comment" data-path="{{$file.Name}}">
										{{if $.IsSplitStyle}}
											{{template "repo/diff/section_split" dict "file" . "root" $}}
										{{else}}
											{{template "repo/diff/section_unified" dict "file" . "root" $}}
										{{end}}
									</table>
								{{end}}
							</div>
							{{if $showFileViewToggle}}
								{{/* 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" */}}
								<div id="diff-rendered-{{$file.NameHash}}" class="file-body file-code {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}} gt-overflow-x-scroll">
									<table class="chroma gt-w-100">
										{{if $isImage}}
											{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
										{{else}}
											{{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
										{{end}}
									</table>
								</div>
							{{end}}
						</div>
					</div>
				{{end}}

				{{if .Diff.IsIncomplete}}
					<div class="diff-file-box diff-box file-content gt-mt-3" id="diff-incomplete">
						<h4 class="ui top attached normal header gt-df gt-ac gt-sb">
							{{ctx.Locale.Tr "repo.diff.too_many_files"}}
							<a class="ui basic tiny button" id="diff-show-more-files" data-href="{{$.Link}}?skip-to={{.Diff.End}}&file-only=true">{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
						</h4>
					</div>
				{{end}}
			</div>
		{{end}}
	</div>

	{{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
		<template id="issue-comment-editor-template">
			<div class="ui comment form">
				{{template "shared/combomarkdowneditor" (dict
					"MarkdownPreviewUrl" (print $.Repository.Link "/markup")
					"MarkdownPreviewContext" $.RepoLink
					"TextareaName" "content"
					"DropzoneParentContainer" ".ui.form"
				)}}
				<div class="text right edit buttons">
					<button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
					<button class="ui primary save button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
				</div>
			</div>
		</template>
	{{end}}
	{{if (not .DiffNotAvailable)}}
		{{template "repo/issue/view_content/reference_issue_dialog" .}}
	{{end}}
</div>