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

Side by Side Diff: milo/appengine/buildbot/html.go

Issue 2748073006: Milo Refactor: Remove theme support (Closed)
Patch Set: Fix builder.html pointer Created 3 years, 9 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
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
10 "os"
11 "strconv" 10 "strconv"
12 11
13 » "github.com/julienschmidt/httprouter" 12 » "github.com/luci/luci-go/milo/appengine/common"
14 » "golang.org/x/net/context" 13 » "github.com/luci/luci-go/server/router"
15
16 » "github.com/luci/luci-go/milo/appengine/settings"
17 » "github.com/luci/luci-go/milo/common/miloerror"
18 "github.com/luci/luci-go/server/templates" 14 "github.com/luci/luci-go/server/templates"
19 ) 15 )
20 16
21 // Build is the container struct for methods related to buildbot build pages. 17 // BuildHandler Renders the buildbot build page.
22 type Build struct{} 18 func BuildHandler(c *router.Context) {
23 19 » master := c.Params.ByName("master")
24 // Builder is the container struct for methods related to buildbot builder pages .
25 type Builder struct{}
26
27 // GetTemplateName returns the template name for build pages.
28 func (b Build) GetTemplateName(t settings.Theme) string {
29 » return "build.html"
30 }
31
32 // Render Render the buildbot build page.
33 func (b Build) Render(c context.Context, r *http.Request, p httprouter.Params) ( *templates.Args, error) {
34 » master := p.ByName("master")
35 if master == "" { 20 if master == "" {
36 » » return nil, &miloerror.Error{ 21 » » common.ErrorPage(c, http.StatusBadRequest, "No master specified" )
37 » » » Message: "No master", 22 » » return
38 » » » Code: http.StatusBadRequest,
39 » » }
40 } 23 }
41 » builder := p.ByName("builder") 24 » builder := c.Params.ByName("builder")
42 if builder == "" { 25 if builder == "" {
43 » » return nil, &miloerror.Error{ 26 » » common.ErrorPage(c, http.StatusBadRequest, "No builder specified ")
44 » » » Message: "No builder", 27 » » return
45 » » » Code: http.StatusBadRequest,
46 » » }
47 } 28 }
48 » buildNum := p.ByName("build") 29 » buildNum := c.Params.ByName("build")
49 if buildNum == "" { 30 if buildNum == "" {
50 » » return nil, &miloerror.Error{ 31 » » common.ErrorPage(c, http.StatusBadRequest, "No build number")
51 » » » Message: "No build num", 32 » » return
52 » » » Code: http.StatusBadRequest,
53 » » }
54 } 33 }
55 num, err := strconv.Atoi(buildNum) 34 num, err := strconv.Atoi(buildNum)
56 if err != nil { 35 if err != nil {
57 » » return nil, &miloerror.Error{ 36 » » common.ErrorPage(c, http.StatusBadRequest,
58 » » » Message: fmt.Sprintf("%s does not look like a number", b uildNum), 37 » » » fmt.Sprintf("%s does not look like a number", buildNum))
59 » » » Code: http.StatusBadRequest, 38 » » return
60 » » }
61 } 39 }
62 40
63 » result, err := build(c, master, builder, num) 41 » result, err := build(c.Context, master, builder, num)
64 if err != nil { 42 if err != nil {
65 » » return nil, err 43 » » var code int
44 » » switch err {
nodir 2017/03/20 19:11:36 nice
hinoka 2017/03/20 19:16:31 Acknowledged.
45 » » case errBuildNotFound:
46 » » » code = http.StatusNotFound
47 » » case errNotAuth:
48 » » » code = http.StatusUnauthorized
49 » » default:
50 » » » code = http.StatusInternalServerError
51 » » }
52 » » common.ErrorPage(c, code, err.Error())
53 » » return
66 } 54 }
67 55
68 » // Render into the template 56 » templates.MustRender(c.Context, c.Writer, "pages/build.html", templates. Args{
69 » fmt.Fprintf(os.Stderr, "Result: %#v\n\n", result)
70 » args := &templates.Args{
71 "Build": result, 57 "Build": result,
72 » } 58 » })
73 » return args, nil
74 } 59 }
75 60
76 // GetTemplateName returns the template name for builder pages. 61 // BuilderHandler renders the buildbot builder page.
77 func (b Builder) GetTemplateName(t settings.Theme) string {
78 » return "builder.html"
79 }
80
81 // Render renders the buildbot builder page.
82 // Note: The builder html template contains self links to "?limit=123", which co uld 62 // Note: The builder html template contains self links to "?limit=123", which co uld
83 // potentially override any other request parameters set. 63 // potentially override any other request parameters set.
84 func (b Builder) Render(c context.Context, r *http.Request, p httprouter.Params) (*templates.Args, error) { 64 func BuilderHandler(c *router.Context) {
85 » master := p.ByName("master") 65 » master := c.Params.ByName("master")
86 if master == "" { 66 if master == "" {
87 » » return nil, &miloerror.Error{ 67 » » common.ErrorPage(c, http.StatusBadRequest, "No master specified" )
88 » » » Message: "No master specified", 68 » » return
89 » » » Code: http.StatusBadRequest,
90 » » }
91 } 69 }
92 » builder := p.ByName("builder") 70 » builder := c.Params.ByName("builder")
93 if builder == "" { 71 if builder == "" {
94 » » return nil, &miloerror.Error{ 72 » » common.ErrorPage(c, http.StatusBadRequest, "No builder specified ")
95 » » » Message: "No builder specified", 73 » » return
96 » » » Code: http.StatusBadRequest,
97 » » }
98 } 74 }
99 » limit, err := settings.GetLimit(r) 75 » limit, err := common.GetLimit(c.Request)
100 if err != nil { 76 if err != nil {
101 » » return nil, err 77 » » common.ErrorPage(c, http.StatusBadRequest, err.Error())
78 » » return
102 } 79 }
103 if limit < 0 { 80 if limit < 0 {
104 limit = 25 81 limit = 25
105 } 82 }
106 83
107 » result, err := builderImpl(c, master, builder, limit) 84 » result, err := builderImpl(c.Context, master, builder, limit)
108 if err != nil { 85 if err != nil {
109 » » return nil, err 86 » » common.ErrorPage(c, http.StatusInternalServerError, err.Error())
87 » » return
110 } 88 }
111 89
112 // Render into the template 90 // Render into the template
113 » args := &templates.Args{ 91 » templates.MustRender(c.Context, c.Writer, "pages/builder.html", template s.Args{
114 "Builder": result, 92 "Builder": result,
115 » } 93 » })
116 » return args, nil
117 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698