code.gitea.io/gitea@v1.22.3/templates/repo/diff/box.tmpl (about)

     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
    13  					const diffTreeVisible = localStorage?.getItem('diff_file_tree_visible') !== 'false';
    14  					const diffTreeBtn = document.querySelector('.diff-toggle-file-tree-button');
    15  					const diffTreeIcon = `.octicon-sidebar-${diffTreeVisible ? 'expand' : 'collapse'}`;
    16  					diffTreeBtn.querySelector(diffTreeIcon).classList.remove('tw-hidden');
    17  					diffTreeBtn.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  					{{/*
    40  						the following will be replaced by vue component
    41  						but 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">
    64  			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}}];
    65  			const diffData = {
    66  				isIncomplete: {{.Diff.IsIncomplete}},
    67  				tooManyFilesMessage: "{{ctx.Locale.Tr "repo.diff.too_many_files"}}",
    68  				binaryFileMessage: "{{ctx.Locale.Tr "repo.diff.bin"}}",
    69  				showMoreMessage: "{{ctx.Locale.Tr "repo.diff.show_more"}}",
    70  				statisticsMessage: "{{ctx.Locale.Tr "repo.diff.stats_desc_file"}}",
    71  				linkLoadMore: "?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"
    77  			let diffFileInfo = window.config.pageData.diffFileInfo || {
    78  				files:[],
    79  				fileTreeIsVisible: false,
    80  				fileListIsVisible: false,
    81  				isLoadingNewData: false,
    82  				selectedItem: '',
    83  			};
    84  			diffFileInfo = Object.assign(diffFileInfo, diffData);
    85  			diffFileInfo.files.push(...diffDataFiles);
    86  			window.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>
    94  				if (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 not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
   163  									<button class="ui basic tiny button unescape-button not-mobile">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
   164  									<button class="ui basic tiny button escape-button tw-hidden">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
   165  								{{end}}
   166  								{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
   167  									{{if $file.IsDeleted}}
   168  										<a class="ui basic tiny button" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
   169  									{{else}}
   170  										<a class="ui basic tiny button" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
   171  										{{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}}
   172  											<a class="ui basic tiny button" 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>
   173  										{{end}}
   174  									{{end}}
   175  								{{end}}
   176  								{{if $isReviewFile}}
   177  									<label data-link="{{$.Issue.Link}}/viewed-files" data-headcommit="{{$.AfterCommitID}}" class="viewed-file-form unselectable{{if $file.IsViewed}} viewed-file-checked-form{{end}}">
   178  										<input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
   179  									</label>
   180  								{{end}}
   181  							</div>
   182  						</h4>
   183  						<div class="diff-file-body ui attached unstackable table segment" {{if and $file.IsViewed $.IsShowingAllCommits}}data-folded="true"{{end}}>
   184  							<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}}">
   185  								{{if or $file.IsIncomplete $file.IsBin}}
   186  									<div class="diff-file-body binary">
   187  										{{if $file.IsIncomplete}}
   188  											{{if $file.IsIncompleteLineTooLong}}
   189  												{{ctx.Locale.Tr "repo.diff.file_suppressed_line_too_long"}}
   190  											{{else}}
   191  												{{ctx.Locale.Tr "repo.diff.file_suppressed"}}
   192  												<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>
   193  											{{end}}
   194  										{{else}}
   195  											{{ctx.Locale.Tr "repo.diff.bin_not_shown"}}
   196  										{{end}}
   197  									</div>
   198  								{{else}}
   199  									<table class="chroma" data-new-comment-url="{{$.Issue.Link}}/files/reviews/new_comment" data-path="{{$file.Name}}">
   200  										{{if $.IsSplitStyle}}
   201  											{{template "repo/diff/section_split" dict "file" . "root" $}}
   202  										{{else}}
   203  											{{template "repo/diff/section_unified" dict "file" . "root" $}}
   204  										{{end}}
   205  									</table>
   206  								{{end}}
   207  							</div>
   208  							{{if $showFileViewToggle}}
   209  								{{/* 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" */}}
   210  								<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">
   211  									<table class="chroma tw-w-full">
   212  										{{if $isImage}}
   213  											{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
   214  										{{else}}
   215  											{{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead "sniffedTypeBase" $sniffedTypeBase "sniffedTypeHead" $sniffedTypeHead}}
   216  										{{end}}
   217  									</table>
   218  								</div>
   219  							{{end}}
   220  						</div>
   221  					</div>
   222  				{{end}}
   223  
   224  				{{if .Diff.IsIncomplete}}
   225  					<div class="diff-file-box diff-box file-content tw-mt-2" id="diff-incomplete">
   226  						<h4 class="ui top attached header tw-font-normal tw-flex tw-items-center tw-justify-between">
   227  							{{ctx.Locale.Tr "repo.diff.too_many_files"}}
   228  							<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>
   229  						</h4>
   230  					</div>
   231  				{{end}}
   232  			</div>
   233  		{{end}}
   234  	</div>
   235  
   236  	{{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
   237  		<template id="issue-comment-editor-template">
   238  			<div class="ui form comment">
   239  				{{template "shared/combomarkdowneditor" (dict
   240  					"MarkdownPreviewUrl" (print $.Repository.Link "/markup")
   241  					"MarkdownPreviewContext" $.RepoLink
   242  					"TextareaName" "content"
   243  					"DropzoneParentContainer" ".ui.form"
   244  				)}}
   245  				{{if .IsAttachmentEnabled}}
   246  					<div class="field">
   247  						{{template "repo/upload" .}}
   248  					</div>
   249  				{{end}}
   250  				<div class="text right edit buttons">
   251  					<button class="ui cancel button">{{ctx.Locale.Tr "repo.issues.cancel"}}</button>
   252  					<button class="ui primary button">{{ctx.Locale.Tr "repo.issues.save"}}</button>
   253  				</div>
   254  			</div>
   255  		</template>
   256  	{{end}}
   257  	{{if (not .DiffNotAvailable)}}
   258  		{{template "repo/issue/view_content/reference_issue_dialog" .}}
   259  		{{template "shared/user/block_user_dialog" .}}
   260  	{{end}}
   261  </div>