Skip to content

Commit eb8c54d

Browse files
committed
Add compare tag dropdown to releases page
1 parent ae6d786 commit eb8c54d

File tree

9 files changed

+78
-36
lines changed

9 files changed

+78
-36
lines changed

modules/context/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ func RepoRefByType(refType RepoRefType) func(*Context) {
834834
ctx.Data["IsViewTag"] = ctx.Repo.IsViewTag
835835
ctx.Data["IsViewCommit"] = ctx.Repo.IsViewCommit
836836
ctx.Data["CanCreateBranch"] = ctx.Repo.CanCreateBranch()
837+
ctx.Data["ShowBranchesInDropdown"] = true
838+
ctx.Data["ShowTagsInDropdown"] = true
837839

838840
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
839841
if err != nil {

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ branch = Branch
855855
tree = Tree
856856
clear_ref = `Clear current reference`
857857
filter_branch_and_tag = Filter branch or tag
858+
find_tag = Find tag
858859
branches = Branches
859860
tags = Tags
860861
issues = Issues
@@ -1913,6 +1914,7 @@ release.new_release = New Release
19131914
release.draft = Draft
19141915
release.prerelease = Pre-Release
19151916
release.stable = Stable
1917+
release.compare = Compare
19161918
release.edit = edit
19171919
release.ahead.commits = <strong>%d</strong> commits
19181920
release.ahead.target = to %s since this release

routers/repo/release.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ func TagsList(ctx *context.Context) {
7070
func releasesOrTags(ctx *context.Context, isTagList bool) {
7171
ctx.Data["PageIsReleaseList"] = true
7272
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch
73+
ctx.Data["IsViewBranch"] = false
74+
ctx.Data["IsViewTag"] = true
75+
// Disable the showCreateNewBranch form on this page.
76+
ctx.Data["CanCreateBranch"] = false
77+
ctx.Data["ShowBranchesInDropdown"] = false
78+
ctx.Data["ShowTagsInDropdown"] = true
7379

7480
if isTagList {
7581
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
@@ -79,6 +85,13 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
7985
ctx.Data["PageIsTagList"] = false
8086
}
8187

88+
tags, err := ctx.Repo.GitRepo.GetTags()
89+
if err != nil {
90+
ctx.ServerError("GetTags", err)
91+
return
92+
}
93+
ctx.Data["Tags"] = tags
94+
8295
writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases)
8396
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
8497

templates/repo/branch_dropdown.tmpl

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
1-
<div class="fitted item choose reference mr-1">
2-
<div class="ui floating filter dropdown custom" data-can-create-branch="{{.CanCreateBranch}}" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
1+
{{$release := .release}}
2+
<div class="fitted item choose reference{{if not $release}} mr-1{{end}}">
3+
<div class="ui floating filter dropdown custom" data-can-create-branch="{{.root.CanCreateBranch}}" data-no-results="{{.root.i18n.Tr "repo.pulls.no_results"}}">
34
<div class="ui basic small compact button" @click="menuVisible = !menuVisible" @keyup.enter="menuVisible = !menuVisible">
45
<span class="text">
5-
{{svg "octicon-git-branch"}}
6-
{{if .IsViewBranch}}{{.i18n.Tr "repo.branch"}}{{else}}{{.i18n.Tr "repo.tree"}}{{end}}:
7-
<strong>{{if .IsViewBranch}}{{.BranchName}}{{else}}{{ShortSha .BranchName}}{{end}}</strong>
6+
{{if $release}}
7+
{{.root.i18n.Tr "repo.release.compare"}}
8+
{{else}}
9+
{{svg "octicon-git-branch"}}
10+
{{if .root.IsViewBranch}}{{.root.i18n.Tr "repo.branch"}}{{else}}{{.root.i18n.Tr "repo.tree"}}{{end}}:
11+
<strong>{{if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.BranchName}}{{end}}</strong>
12+
{{end}}
813
</span>
914
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
1015
</div>
11-
<div class="data" style="display: none" data-mode="{{if .IsViewTag}}tags{{else}}branches{{end}}">
12-
{{range .Branches}}
13-
<div class="item branch {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/branch/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
16+
<div class="data" style="display: none" data-mode="{{if .root.IsViewTag}}tags{{else}}branches{{end}}">
17+
{{if .root.ShowBranchesInDropdown}}
18+
{{range .root.Branches}}
19+
<div class="item branch {{if eq $.root.BranchName .}}selected{{end}}" data-url="{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{EscapePound .}}{{if $.root.TreePath}}/{{EscapePound $.root.TreePath}}{{end}}">{{.}}</div>
20+
{{end}}
1421
{{end}}
15-
{{range .Tags}}
16-
<div class="item tag {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/tag/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
22+
{{if .root.ShowTagsInDropdown}}
23+
{{range .root.Tags}}
24+
<div class="item tag {{if eq $.root.BranchName .}}selected{{end}}" data-url="{{$.root.RepoLink}}/{{if $release}}compare/{{EscapePound .}}...{{if $release.TagName}}{{EscapePound $release.TagName}}{{else}}{{EscapePound $release.Sha1}}{{end}}{{else}}{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{EscapePound .}}{{if $.root.TreePath}}/{{EscapePound $.root.TreePath}}{{end}}{{end}}">{{.}}</div>
25+
{{end}}
1726
{{end}}
1827
</div>
1928
<div class="menu transition" :class="{visible: menuVisible}" v-if="menuVisible" v-cloak>
2029
<div class="ui icon search input">
2130
<i class="icon df ac jc m-0">{{svg "octicon-filter" 16}}</i>
22-
<input name="search" ref="searchField" v-model="searchTerm" @keydown="keydown($event)" placeholder="{{.i18n.Tr "repo.filter_branch_and_tag"}}...">
31+
<input name="search" ref="searchField" v-model="searchTerm" @keydown="keydown($event)" placeholder="{{if .root.ShowBranchesInDropdown}}{{.root.i18n.Tr "repo.filter_branch_and_tag"}}{{else}}{{.root.i18n.Tr "repo.find_tag"}}{{end}}...">
2332
</div>
24-
<div class="header branch-tag-choice">
25-
<div class="ui grid">
26-
<div class="two column row">
27-
<a class="reference column" href="#" @click="createTag = false; mode = 'branches'; focusSearchField()">
28-
<span class="text" :class="{black: mode == 'branches'}">
29-
{{svg "octicon-git-branch" 16 "mr-2"}}{{.i18n.Tr "repo.branches"}}
30-
</span>
31-
</a>
32-
<a class="reference column" href="#" @click="createTag = true; mode = 'tags'; focusSearchField()">
33-
<span class="text" :class="{black: mode == 'tags'}">
34-
{{svg "octicon-tag" 16 "mr-2"}}{{.i18n.Tr "repo.tags"}}
35-
</span>
36-
</a>
33+
{{if and .root.ShowBranchesInDropdown .root.ShowTagsInDropdown}}
34+
<div class="header branch-tag-choice">
35+
<div class="ui grid">
36+
<div class="two column row">
37+
<a class="reference column" href="#" @click="createTag = false; mode = 'branches'; focusSearchField()">
38+
<span class="text" :class="{black: mode == 'branches'}">
39+
{{svg "octicon-git-branch" 16 "mr-2"}}{{.root.i18n.Tr "repo.branches"}}
40+
</span>
41+
</a>
42+
<a class="reference column" href="#" @click="createTag = true; mode = 'tags'; focusSearchField()">
43+
<span class="text" :class="{black: mode == 'tags'}">
44+
{{svg "octicon-tag" 16 "mr-2"}}{{.root.i18n.Tr "repo.tags"}}
45+
</span>
46+
</a>
47+
</div>
3748
</div>
3849
</div>
39-
</div>
50+
{{end}}
4051
<div class="scrolling menu" ref="scrollContainer">
4152
<div v-for="(item, index) in filteredItems" :key="item.name" class="item" :class="{selected: item.selected, active: active == index}" @click="selectItem(item)" :ref="'listItem' + index">${ item.name }</div>
4253
<div class="item" v-if="showCreateNewBranch" :class="{active: active == filteredItems.length}" :ref="'listItem' + filteredItems.length">
4354
<a href="#" @click="createNewBranch()">
4455
<div v-show="createTag">
4556
<i class="reference tags icon"></i>
46-
{{.i18n.Tr "repo.tag.create_tag" `${ searchTerm }` | Safe}}
57+
{{.root.i18n.Tr "repo.tag.create_tag" `${ searchTerm }` | Safe}}
4758
</div>
4859
<div v-show="!createTag">
4960
{{svg "octicon-git-branch"}}
50-
{{.i18n.Tr "repo.branch.create_branch" `${ searchTerm }` | Safe}}
61+
{{.root.i18n.Tr "repo.branch.create_branch" `${ searchTerm }` | Safe}}
5162
</div>
5263
<div class="text small">
53-
{{if .IsViewBranch}}
54-
{{.i18n.Tr "repo.branch.create_from" .BranchName}}
64+
{{if or .root.IsViewBranch $release}}
65+
{{.root.i18n.Tr "repo.branch.create_from" .root.BranchName}}
5566
{{else}}
56-
{{.i18n.Tr "repo.branch.create_from" (ShortSha .BranchName)}}
67+
{{.root.i18n.Tr "repo.branch.create_from" (ShortSha .root.BranchName)}}
5768
{{end}}
5869
</div>
5970
</a>
60-
<form ref="newBranchForm" action="{{.RepoLink}}/branches/_new/{{EscapePound .BranchNameSubURL}}" method="post">
61-
{{.CsrfTokenHtml}}
71+
<form ref="newBranchForm" action="{{.root.RepoLink}}/branches/_new/{{EscapePound .root.BranchNameSubURL}}" method="post">
72+
{{.root.CsrfTokenHtml}}
6273
<input type="hidden" name="new_branch_name" v-model="searchTerm">
6374
<input type="hidden" name="create_tag" v-model="createTag">
6475
</form>

templates/repo/commits.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="ui container">
55
{{template "repo/sub_menu" .}}
66
<div class="ui secondary stackable menu mobile--margin-between-items">
7-
{{template "repo/branch_dropdown" .}}
7+
{{template "repo/branch_dropdown" dict "root" .}}
88
<div class="fitted item">
99
<a href="{{.RepoLink}}/graph" class="ui basic small compact button">
1010
<span class="text">

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
{{end}}
5858
{{template "repo/sub_menu" .}}
5959
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
60-
{{template "repo/branch_dropdown" .}}
60+
{{template "repo/branch_dropdown" dict "root" .}}
6161
{{ $n := len .TreeNames}}
6262
{{ $l := Subtract $n 1}}
6363
<!-- If home page, show new PR. If not, show breadcrumb -->

templates/repo/release/list.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<span class="commit">
8181
<a class="mono" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "mr-2"}}{{ShortSha .Sha1}}</a>
8282
</span>
83+
{{template "repo/branch_dropdown" dict "root" $ "release" .}}
8384
{{end}}
8485
</div>
8586
<div class="ui twelve wide column detail">

web_src/js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ async function initRepository() {
781781
});
782782

783783
// File list and commits
784-
if ($('.repository.file.list').length > 0 || ('.repository.commits').length > 0) {
784+
if ($('.repository.file.list').length > 0 ||
785+
$('.repository.commits').length > 0 || $('.repository.release').length > 0) {
785786
initFilterBranchTagDropdown('.choose.reference .dropdown');
786787
}
787788

web_src/less/_repository.less

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,10 @@
18031803
text-align: right;
18041804
position: relative;
18051805

1806+
.label {
1807+
margin-right: 0;
1808+
}
1809+
18061810
.tag:not(.icon) {
18071811
display: block;
18081812
margin-top: 15px;
@@ -1812,6 +1816,14 @@
18121816
display: block;
18131817
margin-top: 10px;
18141818
}
1819+
1820+
.choose {
1821+
margin-top: 15px;
1822+
1823+
.button {
1824+
margin-right: 0;
1825+
}
1826+
}
18151827
}
18161828

18171829
.detail {
@@ -1855,7 +1867,7 @@
18551867
width: 9px;
18561868
height: 9px;
18571869
background-color: #ddd;
1858-
z-index: 999;
1870+
z-index: 9;
18591871
position: absolute;
18601872
display: block;
18611873
left: -5px;

0 commit comments

Comments
 (0)