Make labels clickable in the comments section. (#21137)

This commit adds the possibility to click the labels in the message
"User added/removed the X label", which will lead to the issues page,
filtered by the clicked label.

This pull requests aims to fix #19768

_I've tried to follow the contribution guidelines as carefully as
possible, but in case I made a mistake: Please correct me._

<!--

Please check the following:

1. Make sure you are targeting the `main` branch, pull requests on
release branches are only allowed for bug fixes.
2. Read contributing guidelines:
https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md
3. Describe what your pull request does and which issue you're targeting
(if any)

-->

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
Blender Defender 2022-09-12 19:45:14 +02:00 committed by GitHub
parent afdab9d8d4
commit defc401b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -376,15 +376,15 @@ func NewFuncMap() []template.FuncMap {
// the table is NOT sorted with this header // the table is NOT sorted with this header
return "" return ""
}, },
"RenderLabels": func(labels []*issues_model.Label) template.HTML { "RenderLabels": func(labels []*issues_model.Label, repoLink string) template.HTML {
html := `<span class="labels-list">` html := `<span class="labels-list">`
for _, label := range labels { for _, label := range labels {
// Protect against nil value in labels - shouldn't happen but would cause a panic if so // Protect against nil value in labels - shouldn't happen but would cause a panic if so
if label == nil { if label == nil {
continue continue
} }
html += fmt.Sprintf("<div class='ui label' style='color: %s; background-color: %s'>%s</div> ", html += fmt.Sprintf("<a href='%s/issues?labels=%d' class='ui label' style='color: %s !important; background-color: %s !important'>%s</a> ",
label.ForegroundColor(), label.Color, RenderEmoji(label.Name)) repoLink, label.ID, label.ForegroundColor(), label.Color, RenderEmoji(label.Name))
} }
html += "</span>" html += "</span>"
return template.HTML(html) return template.HTML(html)

View File

@ -182,11 +182,11 @@
<span class="text grey"> <span class="text grey">
{{template "shared/user/authorlink" .Poster}} {{template "shared/user/authorlink" .Poster}}
{{if and .AddedLabels (not .RemovedLabels)}} {{if and .AddedLabels (not .RemovedLabels)}}
{{$.locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels .AddedLabels) $createdStr | Safe}} {{$.locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels .AddedLabels $.RepoLink) $createdStr | Safe}}
{{else if and (not .AddedLabels) .RemovedLabels}} {{else if and (not .AddedLabels) .RemovedLabels}}
{{$.locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels .RemovedLabels) $createdStr | Safe}} {{$.locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels .RemovedLabels $.RepoLink) $createdStr | Safe}}
{{else}} {{else}}
{{$.locale.Tr "repo.issues.add_remove_labels" (RenderLabels .AddedLabels) (RenderLabels .RemovedLabels) $createdStr | Safe}} {{$.locale.Tr "repo.issues.add_remove_labels" (RenderLabels .AddedLabels $.RepoLink) (RenderLabels .RemovedLabels $.RepoLink) $createdStr | Safe}}
{{end}} {{end}}
</span> </span>
</div> </div>