| 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 frontend | 5 package frontend |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 "github.com/julienschmidt/httprouter" | 10 "github.com/julienschmidt/httprouter" |
| 11 "github.com/luci/luci-go/server/templates" | 11 "github.com/luci/luci-go/server/templates" |
| 12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 | 13 |
| 14 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
| 15 "github.com/luci/luci-go/common/sync/parallel" | 15 "github.com/luci/luci-go/common/sync/parallel" |
| 16 "github.com/luci/luci-go/milo/api/resp" | 16 "github.com/luci/luci-go/milo/api/resp" |
| 17 "github.com/luci/luci-go/milo/appengine/buildbot" | 17 "github.com/luci/luci-go/milo/appengine/buildbot" |
| 18 "github.com/luci/luci-go/milo/appengine/buildbucket" | 18 "github.com/luci/luci-go/milo/appengine/buildbucket" |
| 19 "github.com/luci/luci-go/milo/appengine/settings" | 19 "github.com/luci/luci-go/milo/appengine/settings" |
| 20 ) | 20 ) |
| 21 | 21 |
| 22 type frontpage struct{} | 22 func frontpageHandler(c context.Context, r *http.Request, p httprouter.Params) (
*templates.Args, error) { |
| 23 | |
| 24 func (f frontpage) GetTemplateName(t settings.Theme) string { | |
| 25 » return "frontpage.html" | |
| 26 } | |
| 27 | |
| 28 func (f frontpage) Render(c context.Context, r *http.Request, p httprouter.Param
s) (*templates.Args, error) { | |
| 29 fp := resp.FrontPage{} | 23 fp := resp.FrontPage{} |
| 30 var mBuildbot, mBuildbucket *resp.CIService | 24 var mBuildbot, mBuildbucket *resp.CIService |
| 31 | 25 |
| 32 err := parallel.FanOutIn(func(ch chan<- func() error) { | 26 err := parallel.FanOutIn(func(ch chan<- func() error) { |
| 33 ch <- func() (err error) { | 27 ch <- func() (err error) { |
| 34 mBuildbot, err = buildbot.GetAllBuilders(c) | 28 mBuildbot, err = buildbot.GetAllBuilders(c) |
| 35 return err | 29 return err |
| 36 } | 30 } |
| 37 ch <- func() (err error) { | 31 ch <- func() (err error) { |
| 38 mBuildbucket, err = buildbucket.GetAllBuilders(c) | 32 mBuildbucket, err = buildbucket.GetAllBuilders(c) |
| 39 return err | 33 return err |
| 40 } | 34 } |
| 41 }) | 35 }) |
| 42 if err != nil { | 36 if err != nil { |
| 43 log.WithError(err).Errorf(c, "Encountered error while loading mo
dules") | 37 log.WithError(err).Errorf(c, "Encountered error while loading mo
dules") |
| 44 return nil, err | 38 return nil, err |
| 45 } | 39 } |
| 46 | 40 |
| 47 fp.CIServices = append(fp.CIServices, *mBuildbucket) | 41 fp.CIServices = append(fp.CIServices, *mBuildbucket) |
| 48 fp.CIServices = append(fp.CIServices, *mBuildbot) | 42 fp.CIServices = append(fp.CIServices, *mBuildbot) |
| 49 return &templates.Args{"frontpage": fp}, nil | 43 return &templates.Args{"frontpage": fp}, nil |
| 50 } | 44 } |
| 51 | 45 func frontpageTestData() []settings.TestBundle { |
| 52 type testableFrontpage struct{ frontpage } | |
| 53 | |
| 54 func (l testableFrontpage) TestData() []settings.TestBundle { | |
| 55 data := &templates.Args{ | 46 data := &templates.Args{ |
| 56 "frontpage": resp.FrontPage{ | 47 "frontpage": resp.FrontPage{ |
| 57 CIServices: []resp.CIService{ | 48 CIServices: []resp.CIService{ |
| 58 { | 49 { |
| 59 Name: "Module 1", | 50 Name: "Module 1", |
| 60 BuilderGroups: []resp.BuilderGroup{ | 51 BuilderGroups: []resp.BuilderGroup{ |
| 61 { | 52 { |
| 62 Name: "Example master A"
, | 53 Name: "Example master A"
, |
| 63 Builders: []resp.Link{ | 54 Builders: []resp.Link{ |
| 64 { | 55 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 }, | 67 }, |
| 77 }, | 68 }, |
| 78 } | 69 } |
| 79 return []settings.TestBundle{ | 70 return []settings.TestBundle{ |
| 80 { | 71 { |
| 81 Description: "Basic frontpage", | 72 Description: "Basic frontpage", |
| 82 Data: *data, | 73 Data: *data, |
| 83 }, | 74 }, |
| 84 } | 75 } |
| 85 } | 76 } |
| OLD | NEW |