Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: milo/frontend/view_console.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « milo/frontend/view_config.go ('k') | milo/frontend/view_error.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. 1 // Copyright 2017 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package console 15 package frontend
16 16
17 import ( 17 import (
18 "fmt" 18 "fmt"
19 "net/http" 19 "net/http"
20 "strings" 20 "strings"
21 21
22 "golang.org/x/net/context" 22 "golang.org/x/net/context"
23 23
24 "github.com/luci/luci-go/common/api/gitiles" 24 "github.com/luci/luci-go/common/api/gitiles"
25 "github.com/luci/luci-go/common/clock" 25 "github.com/luci/luci-go/common/clock"
26 "github.com/luci/luci-go/common/errors"
26 "github.com/luci/luci-go/common/logging" 27 "github.com/luci/luci-go/common/logging"
28 "github.com/luci/luci-go/server/router"
29 "github.com/luci/luci-go/server/templates"
30
27 "github.com/luci/luci-go/milo/api/config" 31 "github.com/luci/luci-go/milo/api/config"
28 "github.com/luci/luci-go/milo/api/resp" 32 "github.com/luci/luci-go/milo/api/resp"
29 "github.com/luci/luci-go/milo/common" 33 "github.com/luci/luci-go/milo/common"
30 "github.com/luci/luci-go/milo/common/model" 34 "github.com/luci/luci-go/milo/common/model"
31 "github.com/luci/luci-go/server/router"
32 ) 35 )
33 36
34 // Returns results of build[commit_index][builder_index] 37 // Returns results of build[commit_index][builder_index]
35 func GetConsoleBuilds( 38 func getConsoleBuilds(
36 c context.Context, builders []resp.BuilderRef, commits []string) ( 39 c context.Context, builders []resp.BuilderRef, commits []string) (
37 [][]*model.BuildSummary, error) { 40 [][]*model.BuildSummary, error) {
38 41
39 panic("Nothing to see here, check back later.") 42 panic("Nothing to see here, check back later.")
40 } 43 }
41 44
42 // getConsoleDef finds the console definition as defined by any project. 45 // getConsoleDef finds the console definition as defined by any project.
43 // If the user is not a reader of the project, this will return a 404. 46 // If the user is not a reader of the project, this will return a 404.
44 // TODO(hinoka): If the user is not a reader of any of of the builders returned, 47 // TODO(hinoka): If the user is not a reader of any of of the builders returned,
45 // that builder will be removed from list of results. 48 // that builder will be removed from list of results.
46 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) { 49 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) {
47 cs, err := common.GetConsole(c, project, name) 50 cs, err := common.GetConsole(c, project, name)
48 if err != nil { 51 if err != nil {
49 return nil, err 52 return nil, err
50 } 53 }
51 // TODO(hinoka): Remove builders that the user does not have access to. 54 // TODO(hinoka): Remove builders that the user does not have access to.
52 return cs, nil 55 return cs, nil
53 } 56 }
54 57
55 // Main is a redirect handler that redirects the user to the main console for a
56 // particular project.
57 func Main(ctx *router.Context) {
58 w, r, p := ctx.Writer, ctx.Request, ctx.Params
59 proj := p.ByName("project")
60 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently)
61 return
62 }
63
64 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild { 58 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild {
65 cb := make([]*resp.ConsoleBuild, 0, len(bs)) 59 cb := make([]*resp.ConsoleBuild, 0, len(bs))
66 for _, b := range bs { 60 for _, b := range bs {
67 cb = append(cb, &resp.ConsoleBuild{ 61 cb = append(cb, &resp.ConsoleBuild{
68 // TODO(hinoka): This should link to the actual build. 62 // TODO(hinoka): This should link to the actual build.
69 Link: resp.NewLink(b.BuildKey.String(), "#"), 63 Link: resp.NewLink(b.BuildKey.String(), "#"),
70 Status: b.Summary.Status, 64 Status: b.Summary.Status,
71 }) 65 })
72 } 66 }
73 return cb 67 return cb
(...skipping 18 matching lines...) Expand all
92 commitLinks[i] = commit.Revision 86 commitLinks[i] = commit.Revision
93 } 87 }
94 88
95 // HACK(hinoka): This only supports buildbot.... 89 // HACK(hinoka): This only supports buildbot....
96 builders := make([]resp.BuilderRef, len(def.Builders)) 90 builders := make([]resp.BuilderRef, len(def.Builders))
97 for i, b := range def.Builders { 91 for i, b := range def.Builders {
98 builders[i] = resp.BuilderRef{ 92 builders[i] = resp.BuilderRef{
99 b.Name, strings.Split(b.Category, "|"), b.ShortName, 93 b.Name, strings.Split(b.Category, "|"), b.ShortName,
100 } 94 }
101 } 95 }
102 » cb, err := GetConsoleBuilds(c, builders, commitNames) 96 » cb, err := getConsoleBuilds(c, builders, commitNames)
103 tConsole := clock.Now(c) 97 tConsole := clock.Now(c)
104 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su b(tGitiles)) 98 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su b(tGitiles))
105 if err != nil { 99 if err != nil {
106 return nil, err 100 return nil, err
107 } 101 }
108 ccb := make([]resp.CommitBuild, len(commits)) 102 ccb := make([]resp.CommitBuild, len(commits))
109 for i, commit := range commitLinks { 103 for i, commit := range commitLinks {
110 // TODO(hinoka): Not like this 104 // TODO(hinoka): Not like this
111 ccb[i].Commit = resp.Commit{Revision: commit} 105 ccb[i].Commit = resp.Commit{Revision: commit}
112 ccb[i].Build = summaryToConsole(cb[i]) 106 ccb[i].Build = summaryToConsole(cb[i])
(...skipping 21 matching lines...) Expand all
134 Repo: repoURL, 128 Repo: repoURL,
135 Revision: resp.NewLink(log.Commit, repoURL+"/+/"+log. Commit), 129 Revision: resp.NewLink(log.Commit, repoURL+"/+/"+log. Commit),
136 Description: log.Message, 130 Description: log.Message,
137 Title: strings.SplitN(log.Message, "\n", 2)[0], 131 Title: strings.SplitN(log.Message, "\n", 2)[0],
138 // TODO(hinoka): Fill in the rest of resp.Commit and add those details 132 // TODO(hinoka): Fill in the rest of resp.Commit and add those details
139 // in the html. 133 // in the html.
140 } 134 }
141 } 135 }
142 return result, nil 136 return result, nil
143 } 137 }
138
139 // ConsoleHandler renders the console page.
140 func ConsoleHandler(c *router.Context) {
141 project := c.Params.ByName("project")
142 if project == "" {
143 ErrorHandler(c, errors.New("Missing Project", common.CodeParamet erError))
144 return
145 }
146 name := c.Params.ByName("name")
147
148 result, err := console(c.Context, project, name)
149 if err != nil {
150 ErrorHandler(c, err)
151 return
152 }
153
154 templates.MustRender(c.Context, c.Writer, "pages/console.html", template s.Args{
155 "Console": result,
156 })
157 }
158
159 // ConsoleMainHandler is a redirect handler that redirects the user to the main
160 // console for a particular project.
161 func ConsoleMainHandler(ctx *router.Context) {
162 w, r, p := ctx.Writer, ctx.Request, ctx.Params
163 proj := p.ByName("project")
164 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently)
165 return
166 }
OLDNEW
« no previous file with comments | « milo/frontend/view_config.go ('k') | milo/frontend/view_error.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698