Skip to content

Commit 30c1cd9

Browse files
Zettat123wxiaoguangGiteaBot
authored
Add tags list for repos whose release setting is disabled (#23465)
Close #23427 Co-Author: @wxiaoguang If a repo's release setting is enabled, the logic has't changed. Clicking the "Tags" button will jump to `/{user}/{repo}/tags` and `templates/repo/release/list.tmpl` template will be used. <img src="https://user-images.githubusercontent.com/15528715/224939362-bd8974fd-08b0-4f79-a114-3389d15847ca.png" width="600px" /> If the release setting is disabled, clicking the "Tags" button will still jump to `/{user}/{repo}/tags` but a new template `templates/repo/tag/list.tmpl` will be used. <img src="https://user-images.githubusercontent.com/15528715/233834564-74741e49-f4e9-47c8-ac12-e306642798dc.png" width="600px" /> Since both templates above need to render the tags list, I moved the tags list to a shared template located in `templates/repo/tag/table.tmpl`. --------- Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 5cf7da6 commit 30c1cd9

File tree

9 files changed

+281
-231
lines changed

9 files changed

+281
-231
lines changed

routers/web/repo/release.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929
)
3030

3131
const (
32-
tplReleases base.TplName = "repo/release/list"
33-
tplReleaseNew base.TplName = "repo/release/new"
32+
tplReleasesList base.TplName = "repo/release/list"
33+
tplReleaseNew base.TplName = "repo/release/new"
34+
tplTagsList base.TplName = "repo/tag/list"
3435
)
3536

3637
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
@@ -58,31 +59,26 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model
5859

5960
// Releases render releases list page
6061
func Releases(ctx *context.Context) {
62+
ctx.Data["PageIsReleaseList"] = true
63+
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
6164
releasesOrTags(ctx, false)
6265
}
6366

6467
// TagsList render tags list page
6568
func TagsList(ctx *context.Context) {
69+
ctx.Data["PageIsTagList"] = true
70+
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
6671
releasesOrTags(ctx, true)
6772
}
6873

6974
func releasesOrTags(ctx *context.Context, isTagList bool) {
70-
ctx.Data["PageIsReleaseList"] = true
7175
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch
7276
ctx.Data["IsViewBranch"] = false
7377
ctx.Data["IsViewTag"] = true
7478
// Disable the showCreateNewBranch form in the dropdown on this page.
7579
ctx.Data["CanCreateBranch"] = false
7680
ctx.Data["HideBranchesInDropdown"] = true
7781

78-
if isTagList {
79-
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
80-
ctx.Data["PageIsTagList"] = true
81-
} else {
82-
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
83-
ctx.Data["PageIsTagList"] = false
84-
}
85-
8682
listOptions := db.ListOptions{
8783
Page: ctx.FormInt("page"),
8884
PageSize: ctx.FormInt("limit"),
@@ -196,7 +192,11 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
196192
pager.SetDefaultParams(ctx)
197193
ctx.Data["Page"] = pager
198194

199-
ctx.HTML(http.StatusOK, tplReleases)
195+
if isTagList {
196+
ctx.HTML(http.StatusOK, tplTagsList)
197+
} else {
198+
ctx.HTML(http.StatusOK, tplReleasesList)
199+
}
200200
}
201201

202202
// ReleasesFeedRSS get feeds for releases in RSS format
@@ -282,7 +282,7 @@ func SingleRelease(ctx *context.Context) {
282282
}
283283

284284
ctx.Data["Releases"] = []*repo_model.Release{release}
285-
ctx.HTML(http.StatusOK, tplReleases)
285+
ctx.HTML(http.StatusOK, tplReleasesList)
286286
}
287287

288288
// LatestRelease redirects to the latest release

routers/web/web.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ func RegisterRoutes(m *web.Route) {
11981198
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
11991199
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
12001200

1201-
// Releases
1201+
// Tags
12021202
m.Group("/{username}/{reponame}", func() {
12031203
m.Group("/tags", func() {
12041204
m.Get("", repo.TagsList)
@@ -1207,6 +1207,12 @@ func RegisterRoutes(m *web.Route) {
12071207
}, func(ctx *context.Context) {
12081208
ctx.Data["EnableFeed"] = setting.Other.EnableFeed
12091209
}, repo.MustBeNotEmpty, reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag, true))
1210+
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
1211+
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
1212+
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
1213+
1214+
// Releases
1215+
m.Group("/{username}/{reponame}", func() {
12101216
m.Group("/releases", func() {
12111217
m.Get("/", repo.Releases)
12121218
m.Get("/tag/*", repo.SingleRelease)
@@ -1224,8 +1230,6 @@ func RegisterRoutes(m *web.Route) {
12241230
m.Post("/attachments", repo.UploadReleaseAttachment)
12251231
m.Post("/attachments/remove", repo.DeleteAttachment)
12261232
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
1227-
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
1228-
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
12291233
m.Group("/releases", func() {
12301234
m.Get("/edit/*", repo.EditRelease)
12311235
m.Post("/edit/*", web.Bind(forms.EditReleaseForm{}), repo.EditReleasePost)

templates/repo/release/list.tmpl

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,16 @@
11
{{template "base/head" .}}
2-
<div role="main" aria-label="{{.Title}}" class="page-content repository release">
2+
<div role="main" aria-label="{{.Title}}" class="page-content repository releases">
33
{{template "repo/header" .}}
44
<div class="ui container">
55
{{template "base/alert" .}}
6-
<h2 class="ui compact small menu header">
7-
{{if .Permission.CanRead $.UnitTypeReleases}}
8-
<a class="{{if (and (not .PageIsSingleTag) (not .PageIsTagList))}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
9-
{{end}}
10-
{{if .Permission.CanRead $.UnitTypeCode}}
11-
<a class="{{if (or .PageIsSingleTag .PageIsTagList)}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
12-
{{end}}
13-
</h2>
14-
{{if .EnableFeed}}
15-
<a href="{{.RepoLink}}/{{if .PageIsTagList}}tags{{else}}releases{{end}}.rss"><i class="ui grey icon gt-ml-3" data-tooltip-content="{{.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 18}}</i></a>
16-
{{end}}
17-
{{if (and .CanCreateRelease (not .PageIsTagList))}}
6+
{{template "repo/sub_menu_release_tag" .}}
7+
8+
{{if .CanCreateRelease}}
189
<a class="ui right small green button" href="{{$.RepoLink}}/releases/new">
1910
{{.locale.Tr "repo.release.new_release"}}
2011
</a>
2112
{{end}}
22-
{{if .PageIsTagList}}
23-
<div class="ui divider"></div>
24-
{{if gt .ReleasesNum 0}}
25-
<h4 class="ui top attached header">
26-
<div class="five wide column gt-df gt-ac">
27-
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
28-
</div>
29-
</h4>
30-
<div class="ui attached table segment">
31-
<table class="ui very basic striped fixed table single line" id="tags-table">
32-
<thead></thead>
33-
<tbody class="tag-list">
34-
{{range $idx, $release := .Releases}}
35-
<tr>
36-
<td class="tag">
37-
<h3 class="release-tag-name gt-mb-3">
38-
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
39-
</h3>
40-
<div class="download gt-df gt-ac">
41-
{{if $.Permission.CanRead $.UnitTypeCode}}
42-
{{if .CreatedUnix}}
43-
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
44-
{{end}}
45-
<a class="gt-mr-3 gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
46-
{{if not $.DisableDownloadSourceArchives}}
47-
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}ZIP</a>
48-
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}TAR.GZ</a>
49-
{{end}}
50-
{{if (and $.CanCreateRelease $release.IsTag)}}
51-
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/new?tag={{.TagName}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.new_release"}}</a>
52-
{{end}}
53-
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
54-
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
55-
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
56-
</a>
57-
{{end}}
58-
{{if (not $release.IsTag)}}
59-
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.detail"}}</a>
60-
{{end}}
61-
{{end}}
62-
</div>
63-
</td>
64-
</tr>
65-
{{end}}
66-
</tbody>
67-
</table>
68-
</div>
69-
{{end}}
70-
{{else}}
13+
7114
<ul id="release-list">
7215
{{range $idx, $release := .Releases}}
7316
<li class="ui grid">
@@ -178,7 +121,7 @@
178121
</li>
179122
{{end}}
180123
</ul>
181-
{{end}}
124+
182125
{{template "base/paginate" .}}
183126
</div>
184127
</div>

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="{{.RepoLink}}/branches">{{svg "octicon-git-branch"}} <b>{{.BranchesCount}}</b> {{.locale.TrN .BranchesCount "repo.branch" "repo.branches"}}</a>
1111
</div>
1212
{{if $.Permission.CanRead $.UnitTypeCode}}
13-
<div class="item">
13+
<div class="item{{if .PageIsTagList}} active{{end}}">
1414
<a href="{{.RepoLink}}/tags">{{svg "octicon-tag"}} <b>{{.NumTags}}</b> {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
1515
</div>
1616
{{end}}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{$canReadReleases := $.Permission.CanRead $.UnitTypeReleases}}
2+
{{$canReadCode := $.Permission.CanRead $.UnitTypeCode}}
3+
4+
{{if $canReadReleases}}
5+
<h2 class="ui compact small menu header">
6+
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
7+
{{if $canReadCode}}
8+
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
9+
{{end}}
10+
</h2>
11+
12+
{{if .EnableFeed}}
13+
<a href="{{.RepoLink}}/{{if .PageIsTagList}}tags{{else}}releases{{end}}.rss"><i class="ui grey icon gt-ml-3" data-tooltip-content="{{.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 18}}</i></a>
14+
{{end}}
15+
{{else if $canReadCode}}
16+
{{template "repo/sub_menu" .}}
17+
{{end}}

templates/repo/tag/list.tmpl

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{{template "base/head" .}}
2+
3+
<div role="main" aria-label="{{.Title}}" class="page-content repository tags">
4+
{{template "repo/header" .}}
5+
<div class="ui container">
6+
{{template "base/alert" .}}
7+
{{template "repo/sub_menu_release_tag" .}}
8+
9+
<div class="ui divider"></div>
10+
11+
<h4 class="ui top attached header">
12+
<div class="five wide column gt-df gt-ac">
13+
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
14+
</div>
15+
</h4>
16+
17+
{{$canReadReleases := $.Permission.CanRead $.UnitTypeReleases}}
18+
19+
<div class="ui attached table segment">
20+
<table class="ui very basic striped fixed table single line" id="tags-table">
21+
<tbody class="tag-list">
22+
{{range $idx, $release := .Releases}}
23+
<tr>
24+
<td class="tag">
25+
<h3 class="release-tag-name gt-mb-3">
26+
{{if $canReadReleases}}
27+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
28+
{{else}}
29+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
30+
{{end}}
31+
</h3>
32+
<div class="download gt-df gt-ac">
33+
{{if $.Permission.CanRead $.UnitTypeCode}}
34+
{{if .CreatedUnix}}
35+
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
36+
{{end}}
37+
38+
<a class="gt-mr-3 gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
39+
40+
{{if not $.DisableDownloadSourceArchives}}
41+
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}ZIP</a>
42+
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}TAR.GZ</a>
43+
{{end}}
44+
45+
{{if (and $canReadReleases $.CanCreateRelease $release.IsTag)}}
46+
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/new?tag={{.TagName}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.new_release"}}</a>
47+
{{end}}
48+
49+
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
50+
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
51+
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
52+
</a>
53+
{{end}}
54+
55+
{{if and $canReadReleases (not $release.IsTag)}}
56+
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.detail"}}</a>
57+
{{end}}
58+
{{end}}
59+
</div>
60+
</td>
61+
</tr>
62+
{{end}}
63+
</tbody>
64+
</table>
65+
</div>
66+
67+
{{template "base/paginate" .}}
68+
</div>
69+
</div>
70+
71+
{{if $.Permission.CanWrite $.UnitTypeCode}}
72+
<div class="ui g-modal-confirm delete modal">
73+
<div class="header">
74+
{{svg "octicon-trash"}}
75+
{{.locale.Tr "repo.release.delete_tag"}}
76+
</div>
77+
<div class="content">
78+
<p>{{.locale.Tr "repo.release.deletion_tag_desc"}}</p>
79+
</div>
80+
{{template "base/modal_actions_confirm" .}}
81+
</div>
82+
{{end}}
83+
84+
85+
{{template "base/footer" .}}

web_src/css/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@import "./install.css";
3131
@import "./form.css";
3232
@import "./repository.css";
33+
@import "./repository-release-tag.css";
3334
@import "./editor.css";
3435
@import "./editor-markdown.css";
3536
@import "./organization.css";

0 commit comments

Comments
 (0)