| 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(c *router.Context) { |
| 33 entries := pageIndexEntries{} | 31 entries := pageIndexEntries{} |
| 34 for id, p := range settings.GetUIPages() { | 32 for id, p := range settings.GetUIPages() { |
| 35 » » title, err := p.Title(c) | 33 » » title, err := p.Title(c.Context) |
| 36 if err != nil { | 34 if err != nil { |
| 37 » » » replyError(c, rw, err) | 35 » » » replyError(c.Context, c.Writer, err) |
| 36 » » » c.Abort() |
| 38 return | 37 return |
| 39 } | 38 } |
| 40 entries = append(entries, pageIndexEntry{ | 39 entries = append(entries, pageIndexEntry{ |
| 41 ID: id, | 40 ID: id, |
| 42 Title: title, | 41 Title: title, |
| 43 }) | 42 }) |
| 44 } | 43 } |
| 45 sort.Sort(entries) | 44 sort.Sort(entries) |
| 46 | 45 |
| 47 // Grab timestamp when last settings change hits all instances. | 46 // Grab timestamp when last settings change hits all instances. |
| 48 consistencyTime := time.Time{} | 47 consistencyTime := time.Time{} |
| 49 » if s := settings.GetSettings(c); s != nil { | 48 » if s := settings.GetSettings(c.Context); s != nil { |
| 50 if storage, _ := s.GetStorage().(settings.EventualConsistentStor
age); storage != nil { | 49 if storage, _ := s.GetStorage().(settings.EventualConsistentStor
age); storage != nil { |
| 51 var err error | 50 var err error |
| 52 » » » if consistencyTime, err = storage.GetConsistencyTime(c);
err != nil { | 51 » » » if consistencyTime, err = storage.GetConsistencyTime(c.C
ontext); err != nil { |
| 53 » » » » replyError(c, rw, err) | 52 » » » » replyError(c.Context, c.Writer, err) |
| 53 » » » » c.Abort() |
| 54 return | 54 return |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 » now := clock.Now(c).UTC() | 59 » now := clock.Now(c.Context).UTC() |
| 60 » templates.MustRender(c, rw, "pages/index.html", templates.Args{ | 60 » templates.MustRender(c.Context, c.Writer, "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 |