diff --git a/data.go b/data.go index 1e1c59c..4b782eb 100644 --- a/data.go +++ b/data.go @@ -61,7 +61,10 @@ func NewData(ctx context.Context, url, token string, num int) *Data { ctx: ctx, num: num, } - data.tmpl = template.Must(template.New("index").ParseFS(content, "*.tmpl")) + funcMap := map[string]any{ + "OrderedBy": OrderedBy, + } + data.tmpl = template.Must(template.New("index").Funcs(funcMap).ParseFS(content, "*.tmpl")) return data } diff --git a/issues.go b/issues.go index 055b720..48ced5f 100644 --- a/issues.go +++ b/issues.go @@ -21,6 +21,7 @@ package main */ import ( + "log" "sort" "strings" "time" @@ -103,7 +104,7 @@ func (b ByCategory) Less(i, j int) bool { } func (b ByCategory) Swap(i, j int) { b[i], b[j] = b[j], b[i] } -type ByAssignment []Issue +type ByAssignment []Issue func (b ByAssignment) Len() int { return len(b) } func (b ByAssignment) Less(i, j int) bool { @@ -111,7 +112,6 @@ func (b ByAssignment) Less(i, j int) bool { } func (b ByAssignment) Swap(i, j int) { b[i], b[j] = b[j], b[i] } - type ById []Issue func (b ById) Len() int { return len(b) } @@ -199,7 +199,7 @@ func (i Issues) ByCategory(cat string) (issues Issues) { issues = append(issues, issue) } } - sort.Sort(sort.Reverse(ByHandlerAndId(issues))) + sort.Sort(sort.Reverse(ByHandlerAndId(issues))) return issues } @@ -213,3 +213,82 @@ func (i Issues) ByCategoryAndTarget(cat, tar string) (issues Issues) { sort.Sort(sort.Reverse(ByHandlerAndId(issues))) return } + +// Follow the example for multiSort in https://pkg.go.dev/sort + +type lessFunc func(i1, i2 *Issue) bool + +type multiSorter struct { + issues Issues + less []lessFunc +} + +func (ms *multiSorter) Len() int { + return len(ms.issues) +} + +func (ms *multiSorter) Sort(issues Issues) Issues { + ms.issues = issues + sort.Sort(ms) + return ms.issues +} + +func (ms *multiSorter) Swap(i, j int) { + ms.issues[i], ms.issues[j] = ms.issues[j], ms.issues[i] +} + +func (ms *multiSorter) Less(i, j int) bool { + p, q := &ms.issues[i], &ms.issues[j] + var k int + for k = 0; k < len(ms.less)-1; k++ { + less := ms.less[k] + switch { + case less(p, q): + return true + case less(q, p): + return false + } + } + return ms.less[k](p, q) +} + +var severityOrder = map[string]int{ + "block": 0, + "crash": 1, + "major": 2, + "minor": 3, + "text": 4, + "trivial": 5, + "tweak": 6} + +var lessFuncs = map[string]lessFunc{ + "Category": func(i1, i2 *Issue) bool { return strings.Compare(i1.Category.Name, i2.Category.Name) < 0 }, + "Assignment": func(i1, i2 *Issue) bool { return strings.Compare(i1.Handler.Name, i2.Handler.Name) < 0 }, + "Handler": func(i1, i2 *Issue) bool { return strings.Compare(i1.Handler.Name, i2.Handler.Name) < 0 }, + "Target": func(i1, i2 *Issue) bool { return strings.Compare(i1.TargetVersion.Name, i2.TargetVersion.Name) < 0 }, + "Id": func(i1, i2 *Issue) bool { return i1.Id < i2.Id }, + "Severity": func(i1, i2 *Issue) bool { + s1, ok := severityOrder[i1.Severity.Name] + if !ok { + return true + } + s2, ok := severityOrder[i2.Severity.Name] + if !ok { + return false + } + return s1 < s2 + }, +} + +func OrderedBy(fields ...string) *multiSorter { + m := &multiSorter{} + for _, field := range fields { + fn, ok := lessFuncs[field] + if !ok { + log.Printf("unknown field to order by: %s\n", field) + return nil + } + m.less = append(m.less, fn) + } + return m +} diff --git a/list.tmpl b/list.tmpl index 0433d0c..90b6fe0 100644 --- a/list.tmpl +++ b/list.tmpl @@ -1,75 +1,70 @@ -
{{ .Description }}-
{{ .Description }}-
- taler-dashboard - version: {{.Commit}} - https://git.kesim.org/taler/taler-dashboard - + {{- range $cat := $top.Categories }} +
{{ .Description }}+
{{ .Description }}+
+ taler-dashboard - version: {{.Commit}} - https://git.kesim.org/taler/taler-dashboard + diff --git a/severity.tmpl b/severity.tmpl new file mode 100644 index 0000000..d8a7230 --- /dev/null +++ b/severity.tmpl @@ -0,0 +1,7 @@ +.severity-block { color: red; font-weight: bold; } +.severity-crash { color: deeppink; font-weight: bold; } +.severity-major { color: crimson; } +.severity-minor { color: sienna; } +.severity-text { color: black; } +.severity-trivial { color: grey; } +.severity-tweak { color: steelblue; } diff --git a/table.tmpl b/table.tmpl index d28833e..43925a2 100644 --- a/table.tmpl +++ b/table.tmpl @@ -26,21 +26,15 @@ tr:hover { background: #efefef; } .feature { - background: #cdf; + background: powderblue; } .issue { - background: #edc; + background: navajowhite; } .minh { min-height: 5em; } -.severity-block { color: red; font-style: bold; } -.severity-crash { color: red; } -.severity-major { color: brown; } -.severity-minor { color: darkorange; } -.severity-text { color: black; } -.severity-trivial { color: blue; } -.severity-tweak { color: grey; } +{{template "severity.tmpl"}} summary { display: flex; justify-content: space-between; @@ -74,19 +68,19 @@ details.version { text-align: justify; } details[open].feature { - background: aliceblue; - border: 2px midnightblue solid; + background: ghostwhite; + border: 4px powderblue solid; } details[open].issue { - background: lightyellow; - border: 2px brown solid; + background: ghostwhite; + border: 4px navajowhite solid; }