Implements request #14320 The rendering of CSV files does match the diff style. * Moved CSV logic into base package. * Added method to create a tabular diff. * Added CSV compare context. * Added CSV diff template. * Use new table style in CSV markup. * Added file size limit for CSV rendering. * Display CSV parser errors in diff. * Lazy read single file. * Lazy read rows for full diff. * Added unit tests for various CSV changes.
		
			
				
	
	
		
			137 lines
		
	
	
	
		
			6 KiB
		
	
	
	
		
			Handlebars
		
	
	
	
	
	
			
		
		
	
	
			137 lines
		
	
	
	
		
			6 KiB
		
	
	
	
		
			Handlebars
		
	
	
	
	
	
| <div class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
 | |
| 	<h4 class="file-header ui top attached header df ac sb">
 | |
| 		<div class="file-header-left df ac">
 | |
| 			{{if .ReadmeInList}}
 | |
| 				{{svg "octicon-book" 16 "mr-3"}}
 | |
| 				<strong>{{.FileName}}</strong>
 | |
| 			{{else}}
 | |
| 				<div class="file-info text grey normal mono">
 | |
| 					{{if .FileIsSymlink}}
 | |
| 						<div class="file-info-entry">
 | |
| 							{{.i18n.Tr "repo.symbolic_link"}}
 | |
| 						</div>
 | |
| 					{{end}}
 | |
| 					{{if .NumLinesSet}}
 | |
| 						<div class="file-info-entry">
 | |
| 							{{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}
 | |
| 						</div>
 | |
| 					{{end}}
 | |
| 					{{if .FileSize}}
 | |
| 						<div class="file-info-entry">
 | |
| 							{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}
 | |
| 						</div>
 | |
| 					{{end}}
 | |
| 					{{if .LFSLock}}
 | |
| 						<div class="file-info-entry ui poping up" data-content="{{.LFSLockHint}}">
 | |
| 							{{svg "octicon-lock" 16 "mr-2"}}
 | |
| 							<a href="{{AppSubUrl}}/{{.LFSLock.Owner.Name}}">{{.LFSLockOwner}}</a>
 | |
| 						</div>
 | |
| 					{{end}}
 | |
| 				</div>
 | |
| 			{{end}}
 | |
| 		</div>
 | |
| 		{{if not .ReadmeInList}}
 | |
| 		<div class="file-header-right file-actions df ac">
 | |
| 			{{if .HasSourceRenderedToggle}}
 | |
| 				<div class="ui compact icon buttons">
 | |
| 					<a href="{{$.Link}}?display=source" class="ui tiny basic button poping up {{if .IsDisplayingSource}}active{{end}}" data-content="{{.i18n.Tr "repo.file_view_source"}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-code"}}</a>
 | |
| 					<a href="{{$.Link}}" class="ui tiny basic button poping up {{if .IsDisplayingRendered}}active{{end}}" data-content="{{.i18n.Tr "repo.file_view_rendered"}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-file"}}</a>
 | |
| 				</div>
 | |
| 			{{end}}
 | |
| 			<div class="ui buttons mr-2">
 | |
| 				<a class="ui mini basic button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
 | |
| 				{{if not .IsViewCommit}}
 | |
| 					<a class="ui mini basic button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
 | |
| 				{{end}}
 | |
| 				{{if .IsRepresentableAsText}}
 | |
| 					<a class="ui mini basic button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
 | |
| 				{{end}}
 | |
| 				<a class="ui mini basic button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
 | |
| 			</div>
 | |
| 			{{if .Repository.CanEnableEditor}}
 | |
| 				{{if .CanEditFile}}
 | |
| 					<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><span class="btn-octicon poping up"  data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-pencil"}}</span></a>
 | |
| 				{{else}}
 | |
| 					<span class="btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-pencil"}}</span>
 | |
| 				{{end}}
 | |
| 				{{if .CanDeleteFile}}
 | |
| 					<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><span class="btn-octicon btn-octicon-danger poping up"  data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-trash"}}</span></a>
 | |
| 				{{else}}
 | |
| 					<span class="btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-trash"}}</span>
 | |
| 				{{end}}
 | |
| 			{{end}}
 | |
| 		</div>
 | |
| 		{{end}}
 | |
| 	</h4>
 | |
| 	<div class="ui attached table unstackable segment">
 | |
| 		<div class="file-view {{if .IsMarkup}}{{.MarkupType}} {{if ne "csv" .MarkupType}}markdown{{end}}{{else if .IsRenderedHTML}}plain-text{{else if .IsTextSource}}code-view{{end}}">
 | |
| 			{{if .IsMarkup}}
 | |
| 				{{if .FileContent}}{{.FileContent | Safe}}{{end}}
 | |
| 			{{else if .IsRenderedHTML}}
 | |
| 				<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre>
 | |
| 			{{else if not .IsTextSource}}
 | |
| 				<div class="view-raw ui center">
 | |
| 					{{if .IsImageFile}}
 | |
| 						<img src="{{EscapePound $.RawFileLink}}">
 | |
| 					{{else if .IsVideoFile}}
 | |
| 						<video controls src="{{EscapePound $.RawFileLink}}">
 | |
| 							<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
 | |
| 						</video>
 | |
| 					{{else if .IsAudioFile}}
 | |
| 						<audio controls src="{{EscapePound $.RawFileLink}}">
 | |
| 							<strong>{{.i18n.Tr "repo.audio_not_supported_in_browser"}}</strong>
 | |
| 						</audio>
 | |
| 					{{else if .IsPDFFile}}
 | |
| 						<iframe width="100%" height="600px" src="{{StaticUrlPrefix}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
 | |
| 					{{else}}
 | |
| 						<a href="{{EscapePound $.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.i18n.Tr "repo.file_view_raw"}}</a>
 | |
| 					{{end}}
 | |
| 				</div>
 | |
| 			{{else if .FileSize}}
 | |
| 				{{if .IsFileTooLarge}}
 | |
| 				<table>
 | |
| 					<tbody>
 | |
| 						<tr>
 | |
| 							<td><strong>{{.i18n.Tr "repo.file_too_large"}}</strong></td>
 | |
| 						</tr>
 | |
| 					</tbody>
 | |
| 				</table>
 | |
| 				{{else}}
 | |
| 				<table>
 | |
| 					<tbody>
 | |
| 						{{range $line, $code := .FileContent}}
 | |
| 						<tr>
 | |
| 							<td id="L{{$line}}" class="lines-num">
 | |
| 								<span id="L{{$line}}" data-line-number="{{$line}}"></span>
 | |
| 							</td>
 | |
| 							<td rel="L{{$line}}" class="lines-code chroma">
 | |
| 								<code class="code-inner">{{$code | Safe}}</code>
 | |
| 							</td>
 | |
| 						</tr>
 | |
| 						{{end}}
 | |
| 					</tbody>
 | |
| 				</table>
 | |
| 				<div class="code-view-menu-list ui fluid popup transition hidden">
 | |
| 					<div class="ui column relaxed equal height">
 | |
| 						<div class="column">
 | |
| 							<div class="ui link list">
 | |
| 								<a class="item ref-in-new-issue" href="{{.RepoLink}}/issues/new?body={{URLJoin AppUrl .RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.issues.context.reference_issue"}}</a>
 | |
| 							</div>
 | |
| 						</div>
 | |
| 					</div>
 | |
| 				</div>
 | |
| 				{{end}}
 | |
| 			{{end}}
 | |
| 		</div>
 | |
| 	</div>
 | |
| </div>
 | |
| 
 | |
| <script>
 | |
| function submitDeleteForm() {
 | |
|     var message = prompt("{{.i18n.Tr "repo.delete_confirm_message"}}\n\n{{.i18n.Tr "repo.delete_commit_summary"}}", "Delete '{{.TreeName}}'");
 | |
|     if (message != null) {
 | |
|         $("#delete-message").val(message);
 | |
|         $("#delete-file-form").submit()
 | |
|     }
 | |
| }
 | |
| </script>
 |