Merge pull request #2710 from lukasdietrich/develop
Add ForegroundColor for labels to resolve #2033
This commit is contained in:
commit
8e160edbd5
|
@ -8,10 +8,12 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -958,6 +960,26 @@ func (m *Label) CalOpenIssues() {
|
||||||
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
|
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForegroundColor calculates the text color for labels based
|
||||||
|
// on their background color
|
||||||
|
func (l *Label) ForegroundColor() template.CSS {
|
||||||
|
if strings.HasPrefix(l.Color, "#") {
|
||||||
|
if color, err := strconv.ParseUint(l.Color[1:], 16, 64); err == nil {
|
||||||
|
r := float32(0xFF & (color >> 16))
|
||||||
|
g := float32(0xFF & (color >> 8))
|
||||||
|
b := float32(0xFF & color)
|
||||||
|
luminance := (0.2126*r + 0.7152*g + 0.0722*b) / 255
|
||||||
|
|
||||||
|
if luminance < 0.5 {
|
||||||
|
return template.CSS("rgba(255,255,255,.8)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default to black
|
||||||
|
return template.CSS("rgba(0,0,0,.8)")
|
||||||
|
}
|
||||||
|
|
||||||
// NewLabel creates new label of repository.
|
// NewLabel creates new label of repository.
|
||||||
func NewLabel(l *Label) error {
|
func NewLabel(l *Label) error {
|
||||||
_, err := x.Insert(l)
|
_, err := x.Insert(l)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<div class="label list">
|
<div class="label list">
|
||||||
{{range .Labels}}
|
{{range .Labels}}
|
||||||
<li class="item">
|
<li class="item">
|
||||||
<div class="ui label" style="background-color: {{.Color}}"><i class="octicon octicon-tag"></i> {{.Name}}</div>
|
<div class="ui label" style="color: {{.ForegroundColor}}; background-color: {{.Color}}"><i class="octicon octicon-tag"></i> {{.Name}}</div>
|
||||||
{{if $.IsRepositoryAdmin}}
|
{{if $.IsRepositoryAdmin}}
|
||||||
<a class="ui right delete-button" href="#" data-url="{{$.RepoLink}}/labels/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
|
<a class="ui right delete-button" href="#" data-url="{{$.RepoLink}}/labels/delete" data-id="{{.ID}}"><i class="octicon octicon-trashcan"></i> {{$.i18n.Tr "repo.issues.label_delete"}}</a>
|
||||||
<a class="ui right edit-label-button" href="#" data-id={{.ID}} data-title={{.Name}} data-color={{.Color}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
|
<a class="ui right edit-label-button" href="#" data-id={{.ID}} data-title={{.Name}} data-color={{.Color}}><i class="octicon octicon-pencil"></i> {{$.i18n.Tr "repo.issues.label_edit"}}</a>
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
<a class="title" href="{{$.Link}}/{{.Index}}">{{.Name}}</a>
|
<a class="title" href="{{$.Link}}/{{.Index}}">{{.Name}}</a>
|
||||||
|
|
||||||
{{range .Labels}}
|
{{range .Labels}}
|
||||||
<a class="ui label" href="{{$.Link}}?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="background-color: {{.Color}}">{{.Name}}</a>
|
<a class="ui label" href="{{$.Link}}?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{if .NumComments}}
|
{{if .NumComments}}
|
||||||
|
|
Loading…
Reference in a new issue