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

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

Issue 2748073006: Milo Refactor: Remove theme support (Closed)
Patch Set: Review 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 » » common.ErrorPage(c, http.StatusInternalServerError, err.Error())
44 » » return
66 } 45 }
67 46
68 » // Render into the template 47 » 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, 48 "Build": result,
72 » } 49 » })
73 » return args, nil
74 } 50 }
75 51
76 // GetTemplateName returns the template name for builder pages. 52 // 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 53 // Note: The builder html template contains self links to "?limit=123", which co uld
83 // potentially override any other request parameters set. 54 // potentially override any other request parameters set.
84 func (b Builder) Render(c context.Context, r *http.Request, p httprouter.Params) (*templates.Args, error) { 55 func BuilderHandler(c *router.Context) {
85 » master := p.ByName("master") 56 » master := c.Params.ByName("master")
86 if master == "" { 57 if master == "" {
87 » » return nil, &miloerror.Error{ 58 » » common.ErrorPage(c, http.StatusBadRequest, "No master specified" )
88 » » » Message: "No master specified", 59 » » return
89 » » » Code: http.StatusBadRequest,
90 » » }
91 } 60 }
92 » builder := p.ByName("builder") 61 » builder := c.Params.ByName("builder")
93 if builder == "" { 62 if builder == "" {
94 » » return nil, &miloerror.Error{ 63 » » common.ErrorPage(c, http.StatusBadRequest, "No builder specified ")
95 » » » Message: "No builder specified", 64 » » return
96 » » » Code: http.StatusBadRequest,
97 » » }
98 } 65 }
99 » limit, err := settings.GetLimit(r) 66 » limit, err := common.GetLimit(c.Request)
100 if err != nil { 67 if err != nil {
101 » » return nil, err 68 » » common.ErrorPage(c, http.StatusBadRequest, err.Error())
69 » » return
102 } 70 }
103 if limit < 0 { 71 if limit < 0 {
104 limit = 25 72 limit = 25
105 } 73 }
106 74
107 » result, err := builderImpl(c, master, builder, limit) 75 » result, err := builderImpl(c.Context, master, builder, limit)
nodir 2017/03/17 20:47:57 nice, builderImpl still does not deal with respons
hinoka 2017/03/17 22:04:54 Ack?
108 if err != nil { 76 if err != nil {
109 » » return nil, err 77 » » common.ErrorPage(c, http.StatusInternalServerError, err.Error())
78 » » return
110 } 79 }
111 80
112 // Render into the template 81 // Render into the template
113 » args := &templates.Args{ 82 » templates.MustRender(c.Context, c.Writer, "pages/builders.html", templat es.Args{
114 "Builder": result, 83 "Builder": result,
115 » } 84 » })
116 » return args, nil
117 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698