| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package admin | 5 package admin |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | |
| 9 "sort" | 8 "sort" |
| 10 "time" | 9 "time" |
| 11 | 10 |
| 12 "github.com/dustin/go-humanize" | 11 "github.com/dustin/go-humanize" |
| 13 "github.com/julienschmidt/httprouter" | |
| 14 "golang.org/x/net/context" | |
| 15 | 12 |
| 16 "github.com/luci/luci-go/common/clock" | 13 "github.com/luci/luci-go/common/clock" |
| 14 "github.com/luci/luci-go/server/router" |
| 17 "github.com/luci/luci-go/server/settings" | 15 "github.com/luci/luci-go/server/settings" |
| 18 "github.com/luci/luci-go/server/templates" | 16 "github.com/luci/luci-go/server/templates" |
| 19 ) | 17 ) |
| 20 | 18 |
| 21 type pageIndexEntry struct { | 19 type pageIndexEntry struct { |
| 22 ID string | 20 ID string |
| 23 Title string | 21 Title string |
| 24 } | 22 } |
| 25 | 23 |
| 26 type pageIndexEntries []pageIndexEntry | 24 type pageIndexEntries []pageIndexEntry |
| 27 | 25 |
| 28 func (a pageIndexEntries) Len() int { return len(a) } | 26 func (a pageIndexEntries) Len() int { return len(a) } |
| 29 func (a pageIndexEntries) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | 27 func (a pageIndexEntries) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
| 30 func (a pageIndexEntries) Less(i, j int) bool { return a[i].Title < a[j].Title } | 28 func (a pageIndexEntries) Less(i, j int) bool { return a[i].Title < a[j].Title } |
| 31 | 29 |
| 32 func indexPage(c context.Context, rw http.ResponseWriter, r *http.Request, p htt
prouter.Params) { | 30 func indexPage(ctx *router.Context) { |
| 31 » c, rw := ctx.Context, ctx.Writer |
| 32 |
| 33 entries := pageIndexEntries{} | 33 entries := pageIndexEntries{} |
| 34 for id, p := range settings.GetUIPages() { | 34 for id, p := range settings.GetUIPages() { |
| 35 title, err := p.Title(c) | 35 title, err := p.Title(c) |
| 36 if err != nil { | 36 if err != nil { |
| 37 replyError(c, rw, err) | 37 replyError(c, rw, err) |
| 38 return | 38 return |
| 39 } | 39 } |
| 40 entries = append(entries, pageIndexEntry{ | 40 entries = append(entries, pageIndexEntry{ |
| 41 ID: id, | 41 ID: id, |
| 42 Title: title, | 42 Title: title, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 now := clock.Now(c).UTC() | 59 now := clock.Now(c).UTC() |
| 60 templates.MustRender(c, rw, "pages/index.html", templates.Args{ | 60 templates.MustRender(c, rw, "pages/index.html", templates.Args{ |
| 61 "Entries": entries, | 61 "Entries": entries, |
| 62 "WaitingForConsistency": !consistencyTime.IsZero() && now.Before
(consistencyTime), | 62 "WaitingForConsistency": !consistencyTime.IsZero() && now.Before
(consistencyTime), |
| 63 "TimeToConsistency": humanize.RelTime(consistencyTime, now,
"", ""), | 63 "TimeToConsistency": humanize.RelTime(consistencyTime, now,
"", ""), |
| 64 }) | 64 }) |
| 65 } | 65 } |
| OLD | NEW |