aboutsummaryrefslogtreecommitdiffstats
path: root/templates/repo/diff/box.tmpl
blob: 331a17a5e9a6c62f03257f8fbaf54a3a8f4cf0ef (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
{{if .DiffNotAvailable}}
	<div class="diff-detail-box diff-box ui sticky">
		<div>
			<div class="ui right">
				{{if .PageIsPullFiles}}
					{{template "repo/diff/whitespace_dropdown" .}}
				{{else}}
					<a class="ui tiny basic toggle button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}">{{ if .IsSplitStyle }}{{.i18n.Tr "repo.diff.show_unified_view"}}{{else}}{{.i18n.Tr "repo.diff.show_split_view"}}{{end}}</a>
				{{end}}
				<a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
				{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
					{{template "repo/diff/new_review" .}}
				{{end}}
			</div>
		</div>
	</div>
	<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}}
	<div class="diff-detail-box diff-box ui sticky">
		<div>
			<i class="fa fa-retweet"></i>
			{{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
			<div class="ui right">
				{{if .PageIsPullFiles}}
					{{template "repo/diff/whitespace_dropdown" .}}
				{{else}}
					<a class="ui tiny basic toggle button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}">{{ if .IsSplitStyle }}{{.i18n.Tr "repo.diff.show_unified_view"}}{{else}}{{.i18n.Tr "repo.diff.show_split_view"}}{{end}}</a>
				{{end}}
				<a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
				{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
					{{template "repo/diff/new_review" .}}
				{{end}}
			</div>
		</div>
		<ol class="detail-files hide" id="diff-files">
			{{range .Diff.Files}}
				<li>
					<div class="diff-counter count pull-right">
						{{if not .IsBin}}
							<span class="add" data-line="{{.Addition}}">{{.Addition}}</span>
							<span class="bar">
								<div class="pull-left add"></div>
								<div class="pull-left del"></div>
							</span>
							<span class="del" data-line="{{.Deletion}}">{{.Deletion}}</span>
						{{else}}
							<span>{{$.i18n.Tr "repo.diff.bin"}}</span>
						{{end}}
					</div>
					<!-- todo finish all file status, now modify, add, delete and rename -->
					<span class="status {{DiffTypeToStr .GetType}} poping up" data-content="{{DiffTypeToStr .GetType}}" data-variation="inverted tiny" data-position="right center">&nbsp;</span>
					<a class="file" href="#diff-{{.Index}}">{{.Name}}</a>
				</li>
			{{end}}
		</ol>
	</div>

	{{range $i, $file := .Diff.Files}}
		{{if $file.IsIncomplete}}
			<div class="diff-file-box diff-box file-content">
				<h4 class="ui top attached normal header rounded">
					<div class="diff-counter count ui left">
						{{if not $file.IsRenamed}}
							<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
							<span class="bar">
								<div class="pull-left add"></div>
								<div class="pull-left del"></div>
							</span>
							<span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
						{{end}}
					</div>
					<span class="file">{{$file.Name}}</span>
					<div>{{$.i18n.Tr "repo.diff.file_suppressed"}}</div>
					{{if not $file.IsSubmodule}}
						{{if $file.IsDeleted}}
							<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
						{{else}}
							<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
						{{end}}
					{{end}}
				</h4>
			</div>
		{{else}}
			<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}}" id="diff-{{.Index}}">
				<h4 class="ui top attached normal header">
					<div class="diff-counter count">
						{{if $file.IsBin}}
							{{$.i18n.Tr "repo.diff.bin"}}
						{{else if not $file.IsRenamed}}
							<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
							<span class="bar">
								<div class="pull-left add"></div>
								<div class="pull-left del"></div>
							</span>
							<span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
						{{end}}
					</div>
					<span class="file">{{if $file.IsRenamed}}{{$file.OldName}} &rarr; {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}}</span>
					{{if not $file.IsSubmodule}}
						{{if $file.IsDeleted}}
							<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
						{{else}}
							<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
						{{end}}
					{{end}}
				</h4>
				<div class="ui attached unstackable table segment">
					{{if ne $file.Type 4}}
						{{$isImage := (call $.IsImageFile $file.Name)}}
						{{if and $isImage}}
							<div class="center">
								<img src="{{$.RawPath}}/{{EscapePound .Name}}">
							</div>
						{{else}}
							<div class="file-body file-code code-view code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
								<table>
									<tbody>
										{{if $.IsSplitStyle}}
											{{$highlightClass := $file.GetHighlightClass}}
											{{range $j, $section := $file.Sections}}
												{{range $k, $line := $section.Lines}}
													<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
														<td class="lines-num lines-num-old">
															<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
														</td>
														<td class="lines-code lines-code-old halfwidth">
															{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}
																<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
															{{end}}
															<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
														</td>
														<td class="lines-num lines-num-new">
															<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
														</td>

														<td class="lines-code lines-code-new halfwidth">
															{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}
																<a class="ui green button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
															{{end}}
															<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
														</td>
													</tr>
													{{if gt (len $line.Comments) 0}}
														<tr class="add-code-comment">
															<td class="lines-num"></td>
															<td class="add-comment-left">
																{{if eq $line.GetCommentSide "previous"}}
																	<div class="field comment-code-cloud">
																		<div class="comment-list">
																			<ui class="ui comments">
																			{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
																			</ui>
																		</div>
																	{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
																	</div>
																{{end}}
															</td>
															<td class="lines-num"></td>
															<td class="add-comment-right">
																{{if eq $line.GetCommentSide "proposed"}}
																	<div class="field comment-code-cloud">
																		<div class="comment-list">
																			<ui class="ui comments">
																			{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
																			</ui>
																		</div>
																		{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
																	</div>
																{{end}}
															</td>
														</tr>
													{{end}}
												{{end}}
											{{end}}
										{{else}}
											{{template "repo/diff/section_unified" dict "file" . "root" $}}
										{{end}}
									</tbody>
								</table>
							</div>
						{{end}}
					{{end}}
				</div>
			</div>
		{{end}}
	<br>
	{{end}}

	{{if .Diff.IsIncomplete}}
		<div class="diff-file-box diff-box file-content">
			<h4 class="ui top attached normal header">
				{{$.i18n.Tr "repo.diff.too_many_files"}}
			</h4>
		</div>
	{{end}}

	{{if not $.Repository.IsArchived}}
		<div id="pull_review_add_comment" class="hide">
		    {{template "repo/diff/new_comment" dict "root" .}}
        </div>
        <div class="hide" id="edit-content-form">
            <div class="ui comment form">
                <div class="ui top attached tabular menu">
                    <a class="active write item">{{$.i18n.Tr "write"}}</a>
                    <a class="preview item" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{$.RepoLink}}">{{$.i18n.Tr "preview"}}</a>
                </div>
                <div class="ui bottom attached active write tab segment">
                    <textarea tabindex="1" name="content"></textarea>
                </div>
                <div class="ui bottom attached tab preview segment markdown">
                {{$.i18n.Tr "loading"}}
                </div>
                <div class="text right edit buttons">
                    <div class="ui basic blue cancel button" tabindex="3">{{.i18n.Tr "repo.issues.cancel"}}</div>
                    <div class="ui green save button" tabindex="2">{{.i18n.Tr "repo.issues.save"}}</div>
                </div>
            </div>
        </div>
	 {{end}}

	{{if .IsSplitStyle}}
		<script>
			document.addEventListener('DOMContentLoaded', function() {
				$('tr.add-code').each(function() {
					var prev = $(this).prev();
					if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') {
						while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') {
							prev = prev.prev();
						}
						prev.children().eq(2).html($(this).children().eq(2).html());
						prev.children().eq(3).html($(this).children().eq(3).html());

						prev.children().eq(0).addClass('del-code');
						prev.children().eq(1).addClass('del-code');
						prev.children().eq(2).addClass('add-code');
						prev.children().eq(3).addClass('add-code');
						$(this).remove();
					}
				});
			});
		</script>
	{{end}}
{{end}}