Skip to content

Commit 36de5b2

Browse files
6543delvh
andauthored
Highlight archived labels (#29680)
the issue is, that you can not distinguish between normal and archived labels. So this will make archived labels 80% **grayscale**. And prepend "Archived: " to the tooltip info ![image](https://github.com/go-gitea/gitea/assets/24977596/fd77c4d2-eff5-4afd-9bfa-19cb9991c5e7) ![image](https://github.com/go-gitea/gitea/assets/24977596/2e0f30e5-f301-4c9c-8e9f-677298d90b27) ![image](https://github.com/go-gitea/gitea/assets/24977596/53d70abf-b306-453d-aa95-a3a035b19a33) ![image](https://github.com/go-gitea/gitea/assets/24977596/6020e5f5-2364-4807-979f-37dffa8735e5) --- *Sponsored by Kithara Software GmbH* --------- Co-authored-by: delvh <[email protected]>
1 parent e5e2b2f commit 36de5b2

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

modules/templates/util_render.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"code.gitea.io/gitea/modules/markup"
2121
"code.gitea.io/gitea/modules/markup/markdown"
2222
"code.gitea.io/gitea/modules/setting"
23+
"code.gitea.io/gitea/modules/translation"
2324
"code.gitea.io/gitea/modules/util"
2425
)
2526

@@ -118,10 +119,15 @@ func RenderIssueTitle(ctx context.Context, text string, metas map[string]string)
118119
}
119120

120121
// RenderLabel renders a label
121-
func RenderLabel(ctx context.Context, label *issues_model.Label) template.HTML {
122-
labelScope := label.ExclusiveScope()
122+
// locale is needed due to an import cycle with our context providing the `Tr` function
123+
func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_model.Label) template.HTML {
124+
var (
125+
archivedCSSClass string
126+
textColor = "#111"
127+
isArchived = !label.ArchivedUnix.IsZero()
128+
labelScope = label.ExclusiveScope()
129+
)
123130

124-
textColor := "#111"
125131
r, g, b := util.HexToRBGColor(label.Color)
126132
// Determine if label text should be light or dark to be readable on background color
127133
if util.UseLightTextOnBackground(r, g, b) {
@@ -130,10 +136,15 @@ func RenderLabel(ctx context.Context, label *issues_model.Label) template.HTML {
130136

131137
description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description))
132138

139+
if isArchived {
140+
archivedCSSClass = "archived-label"
141+
description = fmt.Sprintf("(%s) %s", locale.TrString("archived"), description)
142+
}
143+
133144
if labelScope == "" {
134145
// Regular label
135-
s := fmt.Sprintf("<div class='ui label' style='color: %s !important; background-color: %s !important' data-tooltip-content title='%s'>%s</div>",
136-
textColor, label.Color, description, RenderEmoji(ctx, label.Name))
146+
s := fmt.Sprintf("<div class='ui label %s' style='color: %s !important; background-color: %s !important;' data-tooltip-content title='%s'>%s</div>",
147+
archivedCSSClass, textColor, label.Color, description, RenderEmoji(ctx, label.Name))
137148
return template.HTML(s)
138149
}
139150

@@ -166,11 +177,11 @@ func RenderLabel(ctx context.Context, label *issues_model.Label) template.HTML {
166177
itemColor := "#" + hex.EncodeToString(itemBytes)
167178
scopeColor := "#" + hex.EncodeToString(scopeBytes)
168179

169-
s := fmt.Sprintf("<span class='ui label scope-parent' data-tooltip-content title='%s'>"+
180+
s := fmt.Sprintf("<span class='ui label %s scope-parent' data-tooltip-content title='%s'>"+
170181
"<div class='ui label scope-left' style='color: %s !important; background-color: %s !important'>%s</div>"+
171182
"<div class='ui label scope-right' style='color: %s !important; background-color: %s !important'>%s</div>"+
172183
"</span>",
173-
description,
184+
archivedCSSClass, description,
174185
textColor, scopeColor, scopeText,
175186
textColor, itemColor, itemText)
176187
return template.HTML(s)
@@ -211,15 +222,15 @@ func RenderMarkdownToHtml(ctx context.Context, input string) template.HTML { //n
211222
return output
212223
}
213224

214-
func RenderLabels(ctx context.Context, labels []*issues_model.Label, repoLink string) template.HTML {
225+
func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string) template.HTML {
215226
htmlCode := `<span class="labels-list">`
216227
for _, label := range labels {
217228
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
218229
if label == nil {
219230
continue
220231
}
221232
htmlCode += fmt.Sprintf("<a href='%s/issues?labels=%d'>%s</a> ",
222-
repoLink, label.ID, RenderLabel(ctx, label))
233+
repoLink, label.ID, RenderLabel(ctx, locale, label))
223234
}
224235
htmlCode += "</span>"
225236
return template.HTML(htmlCode)

templates/repo/issue/filter_actions.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{end}}
3131
{{$previousExclusiveScope = $exclusiveScope}}
3232
<div class="item issue-action gt-df gt-sb" data-action="toggle" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/labels">
33-
{{if SliceUtils.Contains $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel $.Context .}}
33+
{{if SliceUtils.Contains $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel $.Context ctx.Locale .}}
3434
{{template "repo/issue/labels/label_archived" .}}
3535
</div>
3636
{{end}}

templates/repo/issue/filter_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{{svg "octicon-check"}}
4343
{{end}}
4444
{{end}}
45-
{{RenderLabel $.Context .}}
45+
{{RenderLabel $.Context ctx.Locale .}}
4646
<p class="gt-ml-auto">{{template "repo/issue/labels/label_archived" .}}</p>
4747
</a>
4848
{{end}}

templates/repo/issue/labels/label.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
id="label_{{.label.ID}}"
44
href="{{.root.RepoLink}}/{{if or .root.IsPull .root.Issue.IsPull}}pulls{{else}}issues{{end}}?labels={{.label.ID}}"{{/* FIXME: use .root.Issue.Link or create .root.Link */}}
55
>
6-
{{- RenderLabel $.Context .label -}}
6+
{{- RenderLabel $.Context ctx.Locale .label -}}
77
</a>

templates/repo/issue/labels/label_list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{{range .Labels}}
3333
<li class="item">
3434
<div class="label-title">
35-
{{RenderLabel $.Context .}}
35+
{{RenderLabel $.Context ctx.Locale .}}
3636
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
3737
</div>
3838
<div class="label-issues">
@@ -72,7 +72,7 @@
7272
{{range .OrgLabels}}
7373
<li class="item org-label">
7474
<div class="label-title">
75-
{{RenderLabel $.Context .}}
75+
{{RenderLabel $.Context ctx.Locale .}}
7676
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
7777
</div>
7878
<div class="label-issues">

templates/repo/issue/labels/labels_selector_field.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="divider"></div>
2222
{{end}}
2323
{{$previousExclusiveScope = $exclusiveScope}}
24-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}tw-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
24+
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}tw-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context ctx.Locale .}}
2525
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
2626
<p class="archived-label-hint">{{template "repo/issue/labels/label_archived" .}}</p>
2727
</a>
@@ -34,7 +34,7 @@
3434
<div class="divider"></div>
3535
{{end}}
3636
{{$previousExclusiveScope = $exclusiveScope}}
37-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}tw-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
37+
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" {{if .IsArchived}}data-is-archived{{end}} data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}tw-invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context ctx.Locale .}}
3838
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}
3939
<p class="archived-label-hint">{{template "repo/issue/labels/label_archived" .}}</p>
4040
</a>

templates/repo/issue/view_content/comments.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@
173173
<span class="text grey muted-links">
174174
{{template "shared/user/authorlink" .Poster}}
175175
{{if and .AddedLabels (not .RemovedLabels)}}
176-
{{ctx.Locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels $.Context .AddedLabels $.RepoLink) $createdStr}}
176+
{{ctx.Locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels $.Context ctx.Locale .AddedLabels $.RepoLink) $createdStr}}
177177
{{else if and (not .AddedLabels) .RemovedLabels}}
178-
{{ctx.Locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels $.Context .RemovedLabels $.RepoLink) $createdStr}}
178+
{{ctx.Locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels $.Context ctx.Locale .RemovedLabels $.RepoLink) $createdStr}}
179179
{{else}}
180-
{{ctx.Locale.Tr "repo.issues.add_remove_labels" (RenderLabels $.Context .AddedLabels $.RepoLink) (RenderLabels $.Context .RemovedLabels $.RepoLink) $createdStr}}
180+
{{ctx.Locale.Tr "repo.issues.add_remove_labels" (RenderLabels $.Context ctx.Locale .AddedLabels $.RepoLink) (RenderLabels $.Context ctx.Locale .RemovedLabels $.RepoLink) $createdStr}}
181181
{{end}}
182182
</span>
183183
</div>

templates/shared/issuelist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{{end}}
2222
<span class="labels-list gt-ml-2">
2323
{{range .Labels}}
24-
<a href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}{{if ne $.listType "milestone"}}&milestone={{$.MilestoneID}}{{end}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{RenderLabel $.Context .}}</a>
24+
<a href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}{{if ne $.listType "milestone"}}&milestone={{$.MilestoneID}}{{end}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{RenderLabel $.Context ctx.Locale .}}</a>
2525
{{end}}
2626
</span>
2727
</div>

web_src/css/repo.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,10 @@
24172417
gap: 0 !important;
24182418
}
24192419

2420+
.archived-label {
2421+
filter: grayscale(0.8);
2422+
}
2423+
24202424
.ui.label.scope-left {
24212425
border-bottom-right-radius: 0;
24222426
border-top-right-radius: 0;

0 commit comments

Comments
 (0)