render issue-link in go-template

This commit is contained in:
Tim-Niclas Oelschläger 2024-02-22 22:33:38 +01:00 committed by Lunny Xiao
parent 58d7e4f318
commit e0a4164595
6 changed files with 16 additions and 39 deletions

View File

@ -1685,9 +1685,9 @@ issues.dependency.issue_close_blocked = You need to close all issues blocking th
issues.dependency.issue_batch_close_blocked = "Cannot batch close issues that you choose, because issue #%d still has open dependencies" issues.dependency.issue_batch_close_blocked = "Cannot batch close issues that you choose, because issue #%d still has open dependencies"
issues.dependency.pr_close_blocked = You need to close all issues blocking this pull request before you can merge it. issues.dependency.pr_close_blocked = You need to close all issues blocking this pull request before you can merge it.
issues.dependency.blocks_short = Blocks issues.dependency.blocks_short = Blocks
issues.dependency.blocks_following = blocks: %s issues.dependency.blocks_following = blocks:
issues.dependency.blocked_by_short = Depends on issues.dependency.blocked_by_short = Depends on
issues.dependency.blocked_by_following = depends on: %s issues.dependency.blocked_by_following = depends on:
issues.dependency.remove_header = Remove Dependency issues.dependency.remove_header = Remove Dependency
issues.dependency.issue_remove_text = This will remove the dependency from this issue. Continue? issues.dependency.issue_remove_text = This will remove the dependency from this issue. Continue?
issues.dependency.pr_remove_text = This will remove the dependency from this pull request. Continue? issues.dependency.pr_remove_text = This will remove the dependency from this pull request. Continue?

View File

@ -43,6 +43,7 @@ import (
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/templates/vars" "code.gitea.io/gitea/modules/templates/vars"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -140,27 +141,6 @@ func MustAllowPulls(ctx *context.Context) {
} }
} }
func dependenciesToHTML(ctx *context.Context, dependencies []*issues_model.DependencyInfo) template.HTML {
if len(dependencies) == 0 {
return ""
}
htmlCode := "<span>"
for index, dependency := range dependencies {
if index != 0 {
htmlCode += `<span>,</span>`
}
anchorClasses := "gt-ml-2 ref-issue"
if dependency.Issue.IsClosed {
anchorClasses += " gt-line-through"
}
htmlCode += fmt.Sprintf(`<a href="%s" class="%s">#%d</a>`, dependency.Issue.Link(), anchorClasses, dependency.Issue.Index)
}
return template.HTML(htmlCode + "</span>")
}
func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption optional.Option[bool]) { func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption optional.Option[bool]) {
var err error var err error
viewType := ctx.FormString("type") viewType := ctx.FormString("type")
@ -346,29 +326,20 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil { if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil {
if config := unit.PullRequestsConfig(); config.ShowDependencies { if config := unit.PullRequestsConfig(); config.ShowDependencies {
blockingDependenciesTemplates := make(map[int64]template.HTML, len(issues))
blockedByDependenciesTemplates := make(map[int64]template.HTML, len(issues))
blockingDependenciesMap, err := issues.BlockingDependenciesMap(ctx) blockingDependenciesMap, err := issues.BlockingDependenciesMap(ctx)
if err != nil { if err != nil {
ctx.ServerError("BlockingDependenciesMap", err) ctx.ServerError("BlockingDependenciesMap", err)
return return
} }
for i, blockingDependencies := range blockingDependenciesMap {
blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies)
}
blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx) blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx)
if err != nil { if err != nil {
ctx.ServerError("BlockedByDependenciesMap", err) ctx.ServerError("BlockedByDependenciesMap", err)
return return
} }
for i, blockedByDependencies := range blockedByDependenciesMap {
blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies)
}
ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates ctx.Data["BlockingDependenciesMap"] = blockingDependenciesMap
ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates ctx.Data["BlockedByDependenciesMap"] = blockedByDependenciesMap
} }
} }

View File

@ -1,5 +1,9 @@
{{if .Dependencies}} {{if .Dependencies}}
<div class="flex-text-inline"> <div class="flex-text-inline">
{{ctx.Locale.Tr .TitleKey .Dependencies}} {{ctx.Locale.Tr .TitleKey}}
{{range $i, $dependency := .Dependencies}}
{{if gt $i 0}}<span class="gt-ml--2">, </span>{{end}}
{{template "shared/issue_link" $dependency.Issue}}
{{end}}
</div> </div>
{{end}} {{end}}

View File

@ -0,0 +1 @@
<a href="{{.Link}}" class="{{if .IsClosed}}gt-line-through {{end}}gt-ml-2 ref-issue">#{{.Index}}</a>

View File

@ -118,14 +118,14 @@
</span> </span>
</span> </span>
{{end}} {{end}}
{{if $.BlockedByDependenciesTemplates}} {{if $.BlockedByDependenciesMap}}
{{template "shared/issue_dependency" (dict {{template "shared/issue_dependency" (dict
"Dependencies" (index $.BlockedByDependenciesTemplates .ID) "Dependencies" (index $.BlockedByDependenciesMap .ID)
"TitleKey" "repo.issues.dependency.blocked_by_following")}} "TitleKey" "repo.issues.dependency.blocked_by_following")}}
{{end}} {{end}}
{{if $.BlockingDependenciesTemplates}} {{if $.BlockingDependenciesMap}}
{{template "shared/issue_dependency" (dict {{template "shared/issue_dependency" (dict
"Dependencies" (index $.BlockingDependenciesTemplates .ID) "Dependencies" (index $.BlockingDependenciesMap .ID)
"TitleKey" "repo.issues.dependency.blocks_following")}} "TitleKey" "repo.issues.dependency.blocks_following")}}
{{end}} {{end}}
{{if .IsPull}} {{if .IsPull}}

View File

@ -103,6 +103,7 @@ Gitea's private styles use `g-` prefix.
.gt-m-4 { margin: 1rem !important; } .gt-m-4 { margin: 1rem !important; }
.gt-m-5 { margin: 2rem !important; } .gt-m-5 { margin: 2rem !important; }
.gt-ml--2 { margin-left: -.25rem !important; }
.gt-ml-0 { margin-left: 0 !important; } .gt-ml-0 { margin-left: 0 !important; }
.gt-ml-1 { margin-left: .125rem !important; } .gt-ml-1 { margin-left: .125rem !important; }
.gt-ml-2 { margin-left: .25rem !important; } .gt-ml-2 { margin-left: .25rem !important; }