devapp: sort dashboard by milestone

Milestones are more useful if it's easy to see issues grouped by
milestone; this resorts the dashboard issues by milestone due date
before displaying them. Thus Go1.7 comes first, then Go1.7Maybe, then
Go1.8Early, etc.

Change-Id: I75aa32e00842413dcd62d6ec30893c8359cff44f
Reviewed-on: https://go-review.googlesource.com/23720
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Quentin Smith 2016-06-02 18:26:56 -04:00
Родитель 4976a6a50e
Коммит 89e8d00eaf
1 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -11,9 +11,11 @@ import (
"html/template"
"io/ioutil"
"net/http"
"sort"
"strings"
"time"
"github.com/google/go-github/github"
"golang.org/x/build/godash"
"golang.org/x/net/context"
"google.golang.org/appengine"
@ -31,6 +33,55 @@ func findEmail(ctx context.Context, data *godash.Data) string {
return ""
}
type itemsByMilestone struct {
list []*godash.Item
milestones []string
}
func (x itemsByMilestone) Len() int { return len(x.list) }
func (x itemsByMilestone) Swap(i, j int) { x.list[i], x.list[j] = x.list[j], x.list[i] }
func (x itemsByMilestone) Less(i, j int) bool { return x.index(x.list[i]) < x.index(x.list[j]) }
func (x itemsByMilestone) index(i *godash.Item) int {
if i.Issue == nil {
return len(x.milestones)
}
milestone := i.Issue.Milestone
for i, m := range x.milestones {
if m == milestone {
return i
}
}
return len(x.milestones)
}
type byDate []*github.Milestone
func (x byDate) Len() int { return len(x) }
func (x byDate) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x byDate) Less(i, j int) bool {
a, b := x[i].DueOn, x[j].DueOn
if a == nil {
return false
}
if b == nil {
return true
}
return a.Before(*b)
}
func datedMilestones(milestones []*github.Milestone) []string {
milestones = append([]*github.Milestone{}, milestones...)
sort.Stable(byDate(milestones))
var names []string
for _, m := range milestones {
if m.Title != nil {
names = append(names, *m.Title)
}
}
return names
}
func showDash(w http.ResponseWriter, req *http.Request) {
ctx := appengine.NewContext(req)
req.ParseForm()
@ -84,6 +135,7 @@ func showDash(w http.ResponseWriter, req *http.Request) {
if group.Dir == "closed" || group.Dir == "proposal" {
continue
}
sort.Stable(itemsByMilestone{group.Items, datedMilestones(data.Milestones)})
filtered = append(filtered, group)
}