mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Adds side-by-side diff for images (#6784)
* Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
This commit is contained in:
		
				
					committed by
					
						
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							a5f87feefd
						
					
				
				
					commit
					a37236314c
				
			@@ -107,14 +107,12 @@
 | 
			
		||||
				<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>
 | 
			
		||||
						<div class="file-body file-code code-view code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
 | 
			
		||||
							<table>
 | 
			
		||||
								<tbody>
 | 
			
		||||
									{{if $isImage}}
 | 
			
		||||
										{{template "repo/diff/image_diff" dict "file" . "root" $}}
 | 
			
		||||
									{{else}}
 | 
			
		||||
										{{if $.IsSplitStyle}}
 | 
			
		||||
											{{$highlightClass := $file.GetHighlightClass}}
 | 
			
		||||
											{{range $j, $section := $file.Sections}}
 | 
			
		||||
@@ -164,10 +162,10 @@
 | 
			
		||||
										{{else}}
 | 
			
		||||
											{{template "repo/diff/section_unified" dict "file" . "root" $}}
 | 
			
		||||
										{{end}}
 | 
			
		||||
									</tbody>
 | 
			
		||||
								</table>
 | 
			
		||||
							</div>
 | 
			
		||||
						{{end}}
 | 
			
		||||
									{{end}}
 | 
			
		||||
								</tbody>
 | 
			
		||||
							</table>
 | 
			
		||||
						</div>
 | 
			
		||||
					{{end}}
 | 
			
		||||
				</div>
 | 
			
		||||
			</div>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								templates/repo/diff/image_diff.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								templates/repo/diff/image_diff.tmpl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
{{ $imagePathOld := printf "%s/%s" .root.BeforeRawPath (EscapePound .file.OldName)  }}
 | 
			
		||||
{{ $imagePathNew := printf "%s/%s" .root.RawPath (EscapePound .file.Name)  }}
 | 
			
		||||
 | 
			
		||||
<tr>
 | 
			
		||||
 	<th class="halfwidth center">
 | 
			
		||||
 		{{.root.i18n.Tr "repo.diff.file_before"}}
 | 
			
		||||
 	</th>
 | 
			
		||||
 	<th class="halfwidth center">
 | 
			
		||||
 		{{.root.i18n.Tr "repo.diff.file_after"}}
 | 
			
		||||
 	</th>
 | 
			
		||||
</tr>
 | 
			
		||||
<tr>
 | 
			
		||||
 	<td class="halfwidth center">
 | 
			
		||||
 	    {{ $oldImageExists := (call .root.FileExistsInBaseCommit .file.OldName) }}
 | 
			
		||||
 	    {{if $oldImageExists}}
 | 
			
		||||
            <a href="{{$imagePathOld}}" target="_blank">
 | 
			
		||||
                <img src="{{$imagePathOld}}" class="border red" />
 | 
			
		||||
            </a>
 | 
			
		||||
 	    {{end}}
 | 
			
		||||
 	</td>
 | 
			
		||||
 	<td class="halfwidth center">
 | 
			
		||||
 		<a href="{{$imagePathNew}}" target="_blank">
 | 
			
		||||
 			<img src="{{$imagePathNew}}" class="border green" />
 | 
			
		||||
 		</a>
 | 
			
		||||
 	</td>
 | 
			
		||||
</tr>
 | 
			
		||||
{{ $imageInfoBase := (call .root.ImageInfoBase .file.OldName) }}
 | 
			
		||||
{{ $imageInfoHead := (call .root.ImageInfo .file.Name) }}
 | 
			
		||||
{{if and $imageInfoBase $imageInfoHead }}
 | 
			
		||||
<tr>
 | 
			
		||||
 	<td class="halfwidth center">
 | 
			
		||||
 		{{.root.i18n.Tr "repo.diff.file_image_width"}}: <span class="text {{if not (eq $imageInfoBase.Width $imageInfoHead.Width)}}red{{end}}">{{$imageInfoBase.Width}}</span>
 | 
			
		||||
 		 | 
 | 
			
		||||
 	    {{.root.i18n.Tr "repo.diff.file_image_height"}}: <span class="text {{if not (eq $imageInfoBase.Height $imageInfoHead.Height)}}red{{end}}">{{$imageInfoBase.Height}}</span>
 | 
			
		||||
 		 | 
 | 
			
		||||
 	    {{.root.i18n.Tr "repo.diff.file_byte_size"}}: <span class="text {{if not (eq $imageInfoBase.ByteSize $imageInfoHead.ByteSize)}}red{{end}}">{{FileSize $imageInfoBase.ByteSize}}</span>
 | 
			
		||||
 	</td>
 | 
			
		||||
 	<td class="halfwidth center">
 | 
			
		||||
 		{{.root.i18n.Tr "repo.diff.file_image_width"}}: <span class="text {{if not (eq $imageInfoBase.Width $imageInfoHead.Width)}}green{{end}}">{{$imageInfoHead.Width}}</span>
 | 
			
		||||
 		 | 
 | 
			
		||||
 	    {{.root.i18n.Tr "repo.diff.file_image_height"}}: <span class="text {{if not (eq $imageInfoBase.Height $imageInfoHead.Height)}}green{{end}}">{{$imageInfoHead.Height}}</span>
 | 
			
		||||
 		 | 
 | 
			
		||||
 	    {{.root.i18n.Tr "repo.diff.file_byte_size"}}: <span class="text {{if not (eq $imageInfoBase.ByteSize $imageInfoHead.ByteSize)}}green{{end}}">{{FileSize $imageInfoHead.ByteSize}}</span>
 | 
			
		||||
 	</td>
 | 
			
		||||
 </tr>
 | 
			
		||||
{{end}}
 | 
			
		||||
		Reference in New Issue
	
	Block a user