Skip to content

Commit 3a548cb

Browse files
committed
fix
1 parent 79d593a commit 3a548cb

File tree

7 files changed

+278
-287
lines changed

7 files changed

+278
-287
lines changed

templates/repo/branch_dropdown.tmpl

+40-70
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,57 @@
11
{{/* Attributes:
2-
* root
32
* ContainerClasses
4-
* (TODO: search "branch_dropdown" in the template directory)
5-
*/}}
6-
{{$defaultSelectedRefName := $.root.BranchName}}
7-
{{if and .root.IsViewTag (not .noTag)}}
8-
{{$defaultSelectedRefName = .root.TagName}}
9-
{{end}}
10-
{{if eq $defaultSelectedRefName ""}}
11-
{{$defaultSelectedRefName = $.root.Repository.DefaultBranch}}
12-
{{end}}
13-
14-
{{$type := ""}}
15-
{{if and .root.IsViewTag (not .noTag)}}
16-
{{$type = "tag"}}
17-
{{else if .root.IsViewBranch}}
18-
{{$type = "branch"}}
19-
{{else}}
20-
{{$type = "tree"}}
21-
{{end}}
3+
* Repository
4+
* CurrentRefType: eg. "branch", "tag"
5+
* CurrentRefShortName: eg. "master", "v1.0"
6+
* CurrentTreePath
7+
* RefLinkTemplate: redirect to the link when a branch/tag is selected
8+
* RefFormActionTemplate: change the parent form's action when a branch/tag is selected
9+
* DropdownFixedText: the text to show in the dropdown (mainly used by "release page"), if empty, the text will be the branch/tag name
10+
* ShowTabBranches
11+
* ShowTabTagsTab
12+
* AllowCreateNewRef
2213

23-
{{$showBranchesInDropdown := not .root.HideBranchesInDropdown}}
14+
Search "repo/branch_dropdown" in the template directory to find all occurrences.
15+
*/}}
16+
<div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}"
17+
data-text-release-compare="{{ctx.Locale.Tr "repo.release.compare"}}"
18+
data-text-branches="{{ctx.Locale.Tr "repo.branches"}}"
19+
data-text-tags="{{ctx.Locale.Tr "repo.tags"}}"
20+
data-text-filter-branch="{{ctx.Locale.Tr "repo.pulls.filter_branch"}}"
21+
data-text-filter-tag="{{ctx.Locale.Tr "repo.find_tag"}}"
22+
data-text-default-branch-label="{{ctx.Locale.Tr "repo.default_branch_label"}}"
23+
data-text-create-tag="{{ctx.Locale.Tr "repo.tag.create_tag"}}"
24+
data-text-create-branch="{{ctx.Locale.Tr "repo.branch.create_branch"}}"
25+
data-text-create-ref-from="{{ctx.Locale.Tr "repo.branch.create_from"}}"
26+
data-text-no-results="{{ctx.Locale.Tr "no_results_found"}}"
2427

25-
<script type="module">
26-
const data = {
27-
'textReleaseCompare': {{ctx.Locale.Tr "repo.release.compare"}},
28-
'textCreateTag': {{ctx.Locale.Tr "repo.tag.create_tag"}},
29-
'textCreateBranch': {{ctx.Locale.Tr "repo.branch.create_branch"}},
30-
'textCreateBranchFrom': {{ctx.Locale.Tr "repo.branch.create_from"}},
31-
'textBranches': {{ctx.Locale.Tr "repo.branches"}},
32-
'textTags': {{ctx.Locale.Tr "repo.tags"}},
33-
'textDefaultBranchLabel': {{ctx.Locale.Tr "repo.default_branch_label"}},
28+
data-current-repo-default-branch="{{.Repository.DefaultBranch}}"
29+
data-current-repo-link="{{.Repository.Link}}"
30+
data-current-tree-path="{{.CurrentTreePath}}"
31+
data-current-ref-type="{{.CurrentRefType}}"
32+
data-current-ref-short-name="{{.CurrentRefShortName}}"
3433

35-
'mode': '{{if or .root.IsViewTag .isTag}}tags{{else}}branches{{end}}',
36-
'showBranchesInDropdown': {{$showBranchesInDropdown}},
37-
'searchFieldPlaceholder': '{{if $.noTag}}{{ctx.Locale.Tr "repo.pulls.filter_branch"}}{{else if $showBranchesInDropdown}}{{ctx.Locale.Tr "repo.filter_branch_and_tag"}}{{else}}{{ctx.Locale.Tr "repo.find_tag"}}{{end}}...',
38-
'branchForm': {{$.branchForm}},
39-
'disableCreateBranch': {{if .disableCreateBranch}}{{.disableCreateBranch}}{{else}}{{not .root.CanCreateBranch}}{{end}},
40-
'setAction': {{.setAction}},
41-
'submitForm': {{.submitForm}},
42-
'viewType': {{$type}},
43-
'refName': {{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}},
44-
'commitIdShort': {{ShortSha .root.CommitID}},
45-
'tagName': {{.root.TagName}},
46-
'branchName': {{.root.BranchName}},
47-
'noTag': {{.noTag}},
48-
'defaultSelectedRefName': {{$defaultSelectedRefName}},
49-
'repoDefaultBranch': {{.root.Repository.DefaultBranch}},
50-
'enableFeed': {{.root.EnableFeed}},
51-
'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/',
52-
'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}',
53-
'branchURLSuffix': '{{if .branchURLSuffix}}{{.branchURLSuffix}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}',
54-
'tagURLPrefix': '{{if .tagURLPrefix}}{{.tagURLPrefix}}{{else if .release}}{{$.root.RepoLink}}/compare/{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{end}}',
55-
'tagURLSuffix': '{{if .tagURLSuffix}}{{.tagURLSuffix}}{{else if .release}}...{{if .release.IsDraft}}{{PathEscapeSegments .release.Target}}{{else}}{{if .release.TagName}}{{PathEscapeSegments .release.TagName}}{{else}}{{PathEscapeSegments .release.Sha1}}{{end}}{{end}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}',
56-
'repoLink': {{.root.RepoLink}},
57-
'treePath': {{.root.TreePath}},
58-
'branchNameSubURL': {{.root.BranchNameSubURL}},
59-
'noResults': {{ctx.Locale.Tr "no_results_found"}},
60-
};
61-
{{if .release}}
62-
data.release = {
63-
'tagName': {{.release.TagName}},
64-
};
65-
{{end}}
66-
window.config.pageData.branchDropdownDataList = window.config.pageData.branchDropdownDataList || [];
67-
window.config.pageData.branchDropdownDataList.push(data);
68-
</script>
34+
data-ref-link-template="{{.RefLinkTemplate}}"
35+
data-ref-form-action-template="{{.RefFormActionTemplate}}"
36+
data-dropdown-fixed-text="{{.DropdownFixedText}}"
37+
data-show-tab-branches="{{.ShowTabBranches}}"
38+
data-show-tab-tags="{{.ShowTabTags}}"
39+
data-allow-create-new-ref="{{.AllowCreateNewRef}}"
6940

70-
<div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}">
41+
data-enable-feed="{{ctx.RootData.EnableFeed}}"
42+
>
7143
{{/* show dummy elements before Vue componment is mounted, this code must match the code in BranchTagSelector.vue */}}
7244
<div class="ui dropdown custom branch-selector-dropdown ellipsis-items-nowrap">
7345
<div class="ui button branch-dropdown-button">
7446
<span class="flex-text-block gt-ellipsis">
75-
{{if .release}}
76-
{{ctx.Locale.Tr "repo.release.compare"}}
77-
{{else}}
78-
{{if eq $type "tag"}}
47+
{{if not .DropdownFixedText}}
48+
{{if .ShowTabTags}}
7949
{{svg "octicon-tag"}}
80-
{{else}}
50+
{{else if .ShowTabBranches}}
8151
{{svg "octicon-git-branch"}}
8252
{{end}}
83-
<strong ref="dropdownRefName" class="tw-ml-2 tw-inline-block gt-ellipsis">{{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
8453
{{end}}
54+
<strong class="tw-ml-2 tw-inline-block gt-ellipsis">{{Iif .DropdownFixedText .SelectedRefShortName}}</strong>
8555
</span>
8656
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
8757
</div>

templates/repo/commit_page.tmpl

+9-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@
6666
</div>
6767
<div class="content">
6868
<p id="cherry-pick-content" class="branch-dropdown"></p>
69-
{{template "repo/branch_dropdown" dict "root" .
70-
"noTag" true "disableCreateBranch" true
71-
"branchForm" "branch-dropdown-form"
72-
"branchURLPrefix" (printf "%s/_cherrypick/%s/" $.RepoLink .CommitID) "branchURLSuffix" ""
73-
"setAction" true "submitForm" true}}
74-
<form method="get" action="{{$.RepoLink}}/_cherrypick/{{.CommitID}}/{{if $.BranchName}}{{PathEscapeSegments $.BranchName}}{{else}}{{PathEscapeSegments $.Repository.DefaultBranch}}{{end}}" id="branch-dropdown-form">
75-
<input type="hidden" name="ref" value="{{if $.BranchName}}{{$.BranchName}}{{else}}{{$.Repository.DefaultBranch}}{{end}}">
76-
<input type="hidden" name="refType" value="branch">
69+
70+
<form method="get">
71+
{{template "repo/branch_dropdown" dict
72+
"Repository" .Repository
73+
"ShowTabBranches" true
74+
"CurrentRefType" "branch"
75+
"CurrentRefShortName" (Iif $.BranchName $.Repository.DefaultBranch)
76+
"RefFormActionTemplate" (print "{RepoLink}/_cherrypick/" .CommitID "/{RefShortName}")
77+
}}
7778
<input type="hidden" id="cherry-pick-type" name="cherry-pick-type"><br>
7879
<button type="submit" id="cherry-pick-submit" class="ui primary button"></button>
7980
</form>

templates/repo/commits.tmpl

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
{{template "repo/sub_menu" .}}
66
<div class="repo-button-row">
77
<div class="repo-button-row-left">
8-
{{template "repo/branch_dropdown" dict "root" .}}
8+
9+
{{$branchDropdownCurrentRefType := "branch"}}
10+
{{$branchDropdownCurrentRefShortName := .BranchName}}
11+
{{if .IsViewTag}}
12+
{{$branchDropdownCurrentRefType := "tag"}}
13+
{{$branchDropdownCurrentRefShortName := .TagName}}
14+
{{end}}
15+
{{template "repo/branch_dropdown" dict
16+
"Repository" .Repository
17+
"ShowTabBranches" true
18+
"ShowTabTags" true
19+
"CurrentRefType" $branchDropdownCurrentRefType
20+
"CurrentRefShortName" $branchDropdownCurrentRefShortName
21+
"CurrentTreePath" .TreePath
22+
"RefLinkTemplate" "{RepoLink}/commits/{RefType}/{RefShortName}/{TreePath}"
23+
"AllowCreateNewRef" .CanCreateBranch
24+
}}
25+
926
<a href="{{.RepoLink}}/graph" class="ui basic small compact button">
1027
{{svg "octicon-git-branch"}}
1128
{{ctx.Locale.Tr "repo.commit_graph"}}

templates/repo/home.tmpl

+16-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,22 @@
4747
{{$isHomepage := (eq $n 0)}}
4848
<div class="repo-button-row" data-is-homepage="{{$isHomepage}}">
4949
<div class="repo-button-row-left">
50-
{{template "repo/branch_dropdown" dict "root" .}}
50+
{{$branchDropdownCurrentRefType := "branch"}}
51+
{{$branchDropdownCurrentRefShortName := .BranchName}}
52+
{{if .IsViewTag}}
53+
{{$branchDropdownCurrentRefType := "tag"}}
54+
{{$branchDropdownCurrentRefShortName := .TagName}}
55+
{{end}}
56+
{{template "repo/branch_dropdown" dict
57+
"Repository" .Repository
58+
"ShowTabBranches" true
59+
"ShowTabTags" true
60+
"CurrentRefType" $branchDropdownCurrentRefType
61+
"CurrentRefShortName" $branchDropdownCurrentRefShortName
62+
"CurrentTreePath" .TreePath
63+
"RefLinkTemplate" "{RepoLink}/src/{RefType}/{RefShortName}/{TreePath}"
64+
"AllowCreateNewRef" .CanCreateBranch
65+
}}
5166
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
5267
{{$cmpBranch := ""}}
5368
{{if ne .Repository.ID .BaseRepo.ID}}

templates/repo/release/list.tmpl

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
<a class="muted" href="{{if not (and $release.Sha1 ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode))}}#{{else}}{{$.RepoLink}}/src/tag/{{$release.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "tw-mr-1"}}{{$release.TagName}}</a>
1313
{{if and $release.Sha1 ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
1414
<a class="muted tw-font-mono" href="{{$.RepoLink}}/src/commit/{{$release.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha $release.Sha1}}</a>
15-
{{template "repo/branch_dropdown" dict "root" $ "release" $release}}
15+
{{$compareTarget := ""}}
16+
{{if $release.IsDraft}}
17+
{{$compareTarget = $release.Target}}
18+
{{else if $release.TagName}}
19+
{{$compareTarget = $release.TagName}}
20+
{{else}}
21+
{{$compareTarget = $release.Sha1}}
22+
{{end}}
23+
{{template "repo/branch_dropdown" dict
24+
"Repository" $.Repository
25+
"ShowTabTags" true
26+
"DropdownFixedText" (ctx.Locale.Tr "repo.release.compare")
27+
"RefLinkTemplate" (print "{RepoLink}/compare/{RefShortName}..." (PathEscapeSegments $compareTarget))
28+
}}
1629
{{end}}
1730
</div>
1831
<div class="ui segment detail">

0 commit comments

Comments
 (0)