mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-22 12:23:38 +08:00
render issue-link in go-template
This commit is contained in:
parent
58d7e4f318
commit
e0a4164595
|
@ -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.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_following = blocks: %s
|
||||
issues.dependency.blocks_following = blocks:
|
||||
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.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?
|
||||
|
|
|
@ -43,6 +43,7 @@ import (
|
|||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
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/timeutil"
|
||||
"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]) {
|
||||
var err error
|
||||
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 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)
|
||||
if err != nil {
|
||||
ctx.ServerError("BlockingDependenciesMap", err)
|
||||
return
|
||||
}
|
||||
for i, blockingDependencies := range blockingDependenciesMap {
|
||||
blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies)
|
||||
}
|
||||
|
||||
blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("BlockedByDependenciesMap", err)
|
||||
return
|
||||
}
|
||||
for i, blockedByDependencies := range blockedByDependenciesMap {
|
||||
blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies)
|
||||
}
|
||||
|
||||
ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates
|
||||
ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates
|
||||
ctx.Data["BlockingDependenciesMap"] = blockingDependenciesMap
|
||||
ctx.Data["BlockedByDependenciesMap"] = blockedByDependenciesMap
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
{{if .Dependencies}}
|
||||
<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>
|
||||
{{end}}
|
||||
|
|
1
templates/shared/issue_link.tmpl
Normal file
1
templates/shared/issue_link.tmpl
Normal file
|
@ -0,0 +1 @@
|
|||
<a href="{{.Link}}" class="{{if .IsClosed}}gt-line-through {{end}}gt-ml-2 ref-issue">#{{.Index}}</a>
|
|
@ -118,14 +118,14 @@
|
|||
</span>
|
||||
</span>
|
||||
{{end}}
|
||||
{{if $.BlockedByDependenciesTemplates}}
|
||||
{{if $.BlockedByDependenciesMap}}
|
||||
{{template "shared/issue_dependency" (dict
|
||||
"Dependencies" (index $.BlockedByDependenciesTemplates .ID)
|
||||
"Dependencies" (index $.BlockedByDependenciesMap .ID)
|
||||
"TitleKey" "repo.issues.dependency.blocked_by_following")}}
|
||||
{{end}}
|
||||
{{if $.BlockingDependenciesTemplates}}
|
||||
{{if $.BlockingDependenciesMap}}
|
||||
{{template "shared/issue_dependency" (dict
|
||||
"Dependencies" (index $.BlockingDependenciesTemplates .ID)
|
||||
"Dependencies" (index $.BlockingDependenciesMap .ID)
|
||||
"TitleKey" "repo.issues.dependency.blocks_following")}}
|
||||
{{end}}
|
||||
{{if .IsPull}}
|
||||
|
|
|
@ -103,6 +103,7 @@ Gitea's private styles use `g-` prefix.
|
|||
.gt-m-4 { margin: 1rem !important; }
|
||||
.gt-m-5 { margin: 2rem !important; }
|
||||
|
||||
.gt-ml--2 { margin-left: -.25rem !important; }
|
||||
.gt-ml-0 { margin-left: 0 !important; }
|
||||
.gt-ml-1 { margin-left: .125rem !important; }
|
||||
.gt-ml-2 { margin-left: .25rem !important; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user