mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-22 12:47:24 +08:00
review: Dependencies as template.HTML
This commit is contained in:
parent
5b8d4aa865
commit
20dcbade91
@ -165,7 +165,6 @@ func NewFuncMap() template.FuncMap {
|
||||
"RenderMarkdownToHtml": RenderMarkdownToHtml,
|
||||
"RenderLabel": RenderLabel,
|
||||
"RenderLabels": RenderLabels,
|
||||
"RenderDependencies": RenderDependencies,
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// misc
|
||||
|
@ -224,25 +224,3 @@ func RenderLabels(ctx context.Context, labels []*issues_model.Label, repoLink st
|
||||
htmlCode += "</span>"
|
||||
return template.HTML(htmlCode)
|
||||
}
|
||||
|
||||
func RenderDependencies(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"
|
||||
if dependency.Issue.IsClosed {
|
||||
anchorClasses += " term-fg9"
|
||||
}
|
||||
htmlCode += fmt.Sprintf(`<a href="%s" data-tooltip-content="#%d %s" class="%s">#%d</a>`,
|
||||
dependency.Issue.Link(), dependency.Issue.Index, RenderEmoji(ctx, dependency.Issue.Title), anchorClasses, dependency.Issue.Index)
|
||||
}
|
||||
|
||||
return template.HTML(htmlCode + "</span>")
|
||||
}
|
||||
|
@ -141,6 +141,28 @@ 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"
|
||||
if dependency.Issue.IsClosed {
|
||||
anchorClasses += " gt-line-through"
|
||||
}
|
||||
htmlCode += fmt.Sprintf(`<a href="%s" data-tooltip-content="#%d %s" class="%s">#%d</a>`,
|
||||
dependency.Issue.Link(), dependency.Issue.Index, templates.RenderEmoji(ctx, dependency.Issue.Title), 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")
|
||||
@ -324,8 +346,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||
return
|
||||
}
|
||||
|
||||
blockingDependenciesMap := make(map[int64][]*issues_model.DependencyInfo, len(issues))
|
||||
blockedByDependenciesMap := make(map[int64][]*issues_model.DependencyInfo, len(issues))
|
||||
blockingDependenciesMap := make(map[int64]template.HTML, len(issues))
|
||||
blockedByDependenciesMap := make(map[int64]template.HTML, len(issues))
|
||||
// Get posters.
|
||||
for i := range issues {
|
||||
// Check read status
|
||||
@ -341,7 +363,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||
return
|
||||
}
|
||||
slices.Reverse(blockingDependencies)
|
||||
blockingDependenciesMap[issues[i].ID] = blockingDependencies
|
||||
blockingDependenciesMap[issues[i].ID] = dependenciesToHTML(ctx, blockingDependencies)
|
||||
|
||||
blockedByDependencies, err := issues[i].BlockedByDependencies(ctx, db.ListOptions{})
|
||||
if err != nil {
|
||||
@ -349,7 +371,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||
return
|
||||
}
|
||||
slices.Reverse(blockedByDependencies)
|
||||
blockedByDependenciesMap[issues[i].ID] = blockedByDependencies
|
||||
blockedByDependenciesMap[issues[i].ID] = dependenciesToHTML(ctx, blockedByDependencies)
|
||||
}
|
||||
ctx.Data["BlockingDependenciesMap"] = blockingDependenciesMap
|
||||
ctx.Data["BlockedByDependenciesMap"] = blockedByDependenciesMap
|
||||
|
@ -1,5 +1,5 @@
|
||||
{{if .Dependencies}}
|
||||
<div class="flex-text-inline">
|
||||
{{(ctx.Locale.Tr .TitleKey (RenderDependencies ctx .Dependencies)) | Safe}}
|
||||
{{(ctx.Locale.Tr .TitleKey .Dependencies) | Safe}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -49,6 +49,7 @@ Gitea's private styles use `g-` prefix.
|
||||
/* below class names match Tailwind CSS */
|
||||
.gt-object-contain { object-fit: contain !important; }
|
||||
.gt-no-underline { text-decoration-line: none !important; }
|
||||
.gt-line-through { text-decoration-line: line-through !important; }
|
||||
.gt-normal-case { text-transform: none !important; }
|
||||
.gt-italic { font-style: italic !important; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user