|
|
|
@ -122,8 +122,23 @@ func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML {
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RenderLabel renders a label
|
|
|
|
func (ut *RenderUtils) RenderLabelWithLink(label *issues_model.Label, link any) template.HTML {
|
|
|
|
|
|
|
|
var attrHref template.HTML
|
|
|
|
|
|
|
|
switch link.(type) {
|
|
|
|
|
|
|
|
case template.URL, string:
|
|
|
|
|
|
|
|
attrHref = htmlutil.HTMLFormat(`href="%s"`, link)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("unexpected type %T for link", link))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ut.renderLabelWithTag(label, "a", attrHref)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
|
|
|
|
func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
|
|
|
|
|
|
|
|
return ut.renderLabelWithTag(label, "span", "")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RenderLabel renders a label
|
|
|
|
|
|
|
|
func (ut *RenderUtils) renderLabelWithTag(label *issues_model.Label, tagName, tagAttrs template.HTML) template.HTML {
|
|
|
|
locale := ut.ctx.Value(translation.ContextKey).(translation.Locale)
|
|
|
|
locale := ut.ctx.Value(translation.ContextKey).(translation.Locale)
|
|
|
|
var extraCSSClasses string
|
|
|
|
var extraCSSClasses string
|
|
|
|
textColor := util.ContrastColor(label.Color)
|
|
|
|
textColor := util.ContrastColor(label.Color)
|
|
|
|
@ -137,8 +152,8 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
|
|
|
|
|
|
|
|
|
|
|
|
if labelScope == "" {
|
|
|
|
if labelScope == "" {
|
|
|
|
// Regular label
|
|
|
|
// Regular label
|
|
|
|
return htmlutil.HTMLFormat(`<div class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s">%s</div>`,
|
|
|
|
return htmlutil.HTMLFormat(`<%s %s class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s"><span class="gt-ellipsis">%s</span></%s>`,
|
|
|
|
extraCSSClasses, textColor, label.Color, descriptionText, ut.RenderEmoji(label.Name))
|
|
|
|
tagName, tagAttrs, extraCSSClasses, textColor, label.Color, descriptionText, ut.RenderEmoji(label.Name), tagName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Scoped label
|
|
|
|
// Scoped label
|
|
|
|
@ -152,7 +167,7 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
|
|
|
|
// Ensure we add the same amount of contrast also near 0 and 1.
|
|
|
|
// Ensure we add the same amount of contrast also near 0 and 1.
|
|
|
|
darken := contrast + math.Max(luminance+contrast-1.0, 0.0)
|
|
|
|
darken := contrast + math.Max(luminance+contrast-1.0, 0.0)
|
|
|
|
lighten := contrast + math.Max(contrast-luminance, 0.0)
|
|
|
|
lighten := contrast + math.Max(contrast-luminance, 0.0)
|
|
|
|
// Compute factor to keep RGB values proportional.
|
|
|
|
// Compute the factor to keep RGB values proportional.
|
|
|
|
darkenFactor := math.Max(luminance-darken, 0.0) / math.Max(luminance, 1.0/255.0)
|
|
|
|
darkenFactor := math.Max(luminance-darken, 0.0) / math.Max(luminance, 1.0/255.0)
|
|
|
|
lightenFactor := math.Min(luminance+lighten, 1.0) / math.Max(luminance, 1.0/255.0)
|
|
|
|
lightenFactor := math.Min(luminance+lighten, 1.0) / math.Max(luminance, 1.0/255.0)
|
|
|
|
|
|
|
|
|
|
|
|
@ -173,26 +188,29 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
|
|
|
|
|
|
|
|
|
|
|
|
if label.ExclusiveOrder > 0 {
|
|
|
|
if label.ExclusiveOrder > 0 {
|
|
|
|
// <scope> | <label> | <order>
|
|
|
|
// <scope> | <label> | <order>
|
|
|
|
return htmlutil.HTMLFormat(`<span class="ui label %s scope-parent" data-tooltip-content title="%s">`+
|
|
|
|
return htmlutil.HTMLFormat(`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">`+
|
|
|
|
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-middle" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-middle" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-right">%d</div>`+
|
|
|
|
`<div class="ui label scope-right">%d</div>`+
|
|
|
|
`</span>`,
|
|
|
|
`</%s>`,
|
|
|
|
|
|
|
|
tagName, tagAttrs,
|
|
|
|
extraCSSClasses, descriptionText,
|
|
|
|
extraCSSClasses, descriptionText,
|
|
|
|
textColor, scopeColor, scopeHTML,
|
|
|
|
textColor, scopeColor, scopeHTML,
|
|
|
|
textColor, itemColor, itemHTML,
|
|
|
|
textColor, itemColor, itemHTML,
|
|
|
|
label.ExclusiveOrder)
|
|
|
|
label.ExclusiveOrder,
|
|
|
|
|
|
|
|
tagName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <scope> | <label>
|
|
|
|
// <scope> | <label>
|
|
|
|
return htmlutil.HTMLFormat(`<span class="ui label %s scope-parent" data-tooltip-content title="%s">`+
|
|
|
|
return htmlutil.HTMLFormat(`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">`+
|
|
|
|
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-right" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`<div class="ui label scope-right" style="color: %s !important; background-color: %s !important">%s</div>`+
|
|
|
|
`</span>`,
|
|
|
|
`</%s>`,
|
|
|
|
|
|
|
|
tagName, tagAttrs,
|
|
|
|
extraCSSClasses, descriptionText,
|
|
|
|
extraCSSClasses, descriptionText,
|
|
|
|
textColor, scopeColor, scopeHTML,
|
|
|
|
textColor, scopeColor, scopeHTML,
|
|
|
|
textColor, itemColor, itemHTML,
|
|
|
|
textColor, itemColor, itemHTML,
|
|
|
|
)
|
|
|
|
tagName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// RenderEmoji renders html text with emoji post processors
|
|
|
|
// RenderEmoji renders html text with emoji post processors
|
|
|
|
@ -235,7 +253,8 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin
|
|
|
|
if label == nil {
|
|
|
|
if label == nil {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
htmlCode += fmt.Sprintf(`<a href="%s?labels=%d">%s</a>`, baseLink, label.ID, ut.RenderLabel(label))
|
|
|
|
link := fmt.Sprintf("%s?labels=%d", baseLink, label.ID)
|
|
|
|
|
|
|
|
htmlCode += string(ut.RenderLabelWithLink(label, template.URL(link)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
htmlCode += "</span>"
|
|
|
|
htmlCode += "</span>"
|
|
|
|
return template.HTML(htmlCode)
|
|
|
|
return template.HTML(htmlCode)
|
|
|
|
|