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

Side by Side Diff: milo/appengine/common/funcs.go

Issue 2931773004: Milo: Add machine pool info for buildbot builder view. (Closed)
Patch Set: Rebase Created 3 years, 6 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 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 common 5 package common
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "html/template" 10 "html/template"
(...skipping 13 matching lines...) Expand all
24 "linkify": linkify, 24 "linkify": linkify,
25 "linkifySet": linkifySet, 25 "linkifySet": linkifySet,
26 "obfuscateEmail": obfuscateEmail, 26 "obfuscateEmail": obfuscateEmail,
27 "localTime": localTime, 27 "localTime": localTime,
28 "shortHash": shortHash, 28 "shortHash": shortHash,
29 "startswith": strings.HasPrefix, 29 "startswith": strings.HasPrefix,
30 "sub": sub, 30 "sub": sub,
31 "consoleHeader": consoleHeader, 31 "consoleHeader": consoleHeader,
32 "pagedURL": pagedURL, 32 "pagedURL": pagedURL,
33 "formatTime": formatTime, 33 "formatTime": formatTime,
34 "percent": percent,
34 } 35 }
35 36
36 // localTime returns a <span> element with t in human format 37 // localTime returns a <span> element with t in human format
37 // that will be converted to local timezone in the browser. 38 // that will be converted to local timezone in the browser.
38 // Recommended usage: {{ .Date | localTime "N/A" }} 39 // Recommended usage: {{ .Date | localTime "N/A" }}
39 func localTime(ifZero string, t time.Time) template.HTML { 40 func localTime(ifZero string, t time.Time) template.HTML {
40 if t.IsZero() { 41 if t.IsZero() {
41 return template.HTML(template.HTMLEscapeString(ifZero)) 42 return template.HTML(template.HTMLEscapeString(ifZero))
42 } 43 }
43 milliseconds := t.UnixNano() / 1e6 44 milliseconds := t.UnixNano() / 1e6
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 case limit < 0: 239 case limit < 0:
239 values.Del("limit") 240 values.Del("limit")
240 case limit > 0: 241 case limit > 0:
241 values.Set("limit", fmt.Sprintf("%d", limit)) 242 values.Set("limit", fmt.Sprintf("%d", limit))
242 } 243 }
243 result := *r.URL 244 result := *r.URL
244 result.RawQuery = values.Encode() 245 result.RawQuery = values.Encode()
245 return result.String() 246 return result.String()
246 } 247 }
247 248
249 // percent divides two numbers and returns the percentage in string form.
nodir 2017/06/13 02:38:40 i think it divides one number
Ryan Tseng 2017/06/13 23:10:33 Done.
250 func percent(numerator, divisor int) string {
251 p := float64(numerator) * 100.0 / float64(divisor)
252 return fmt.Sprintf("%.1f", p)
253 }
254
248 func init() { 255 func init() {
249 linkifySetTemplate = template.Must( 256 linkifySetTemplate = template.Must(
250 template.New("linkifySet"). 257 template.New("linkifySet").
251 Funcs(template.FuncMap{ 258 Funcs(template.FuncMap{
252 "linkify": linkify, 259 "linkify": linkify,
253 }).Parse( 260 }).Parse(
254 `{{ range $i, $link := . }}` + 261 `{{ range $i, $link := . }}` +
255 `{{ if gt $i 0 }} {{ end }}` + 262 `{{ if gt $i 0 }} {{ end }}` +
256 `{{ $link | linkify}}` + 263 `{{ $link | linkify}}` +
257 `{{ end }}`)) 264 `{{ end }}`))
258 265
259 linkifyTemplate = template.Must( 266 linkifyTemplate = template.Must(
260 template.New("linkify"). 267 template.New("linkify").
261 Parse( 268 Parse(
262 `<a href="{{.URL}}">` + 269 `<a href="{{.URL}}">` +
263 `{{if .Img}}<img src="{{.Img}}"{{if .Alt }} alt="{{.Alt}}"{{end}}>` + 270 `{{if .Img}}<img src="{{.Img}}"{{if .Alt }} alt="{{.Alt}}"{{end}}>` +
264 `{{else if .Alias}}[{{.Label}}]` + 271 `{{else if .Alias}}[{{.Label}}]` +
265 `{{else}}{{.Label}}{{end}}` + 272 `{{else}}{{.Label}}{{end}}` +
266 `</a>`)) 273 `</a>`))
267 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698