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

Unified Diff: milo/appengine/common/funcs.go

Issue 2810113002: Milo buildbot builder page: Add pagnation with cursors. (Closed)
Patch Set: train Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/buildbot/html.go ('k') | milo/appengine/common/middleware.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/common/funcs.go
diff --git a/milo/appengine/common/funcs.go b/milo/appengine/common/funcs.go
index aedbfe62f6666b6586ed9de62dd2f96e175d2ad5..dcf5e490dcb98d571b5832e2289f0e0ceb724cff 100644
--- a/milo/appengine/common/funcs.go
+++ b/milo/appengine/common/funcs.go
@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"html/template"
+ "net/http"
"strings"
"time"
@@ -28,6 +29,7 @@ var funcMap = template.FuncMap{
"startswith": strings.HasPrefix,
"sub": sub,
"consoleHeader": consoleHeader,
+ "pagedURL": pagedURL,
}
// localTime returns a <span> element with t in human format
@@ -201,6 +203,42 @@ func shortHash(s string) string {
return s
}
+// pagedURL returns a self URL with the given cursor and limit paging options.
+// if limit is set to 0, then inherit whatever limit is set in request. If
+// both are unspecified, then limit is omitted.
+func pagedURL(r *http.Request, limit int, cursor string) string {
+ if limit == 0 {
+ var err error
+ limit, err = GetLimit(r)
+ if err != nil {
+ // This should not happen because the handler should've already validated the
+ // limit earlier in the process.
+ panic(err)
+ }
+ if limit < 0 {
+ limit = 0
+ }
+ }
+ values := r.URL.Query()
+ switch cursor {
+ case "EMPTY":
+ values.Del("cursor")
+ case "":
+ // Do nothing, just leave the cursor in.
+ default:
+ values.Set("cursor", cursor)
+ }
+ switch {
+ case limit < 0:
+ values.Del("limit")
+ case limit > 0:
+ values.Set("limit", fmt.Sprintf("%d", limit))
+ }
+ result := *r.URL
+ result.RawQuery = values.Encode()
+ return result.String()
+}
+
func init() {
linkifySetTemplate = template.Must(
template.New("linkifySet").
« no previous file with comments | « milo/appengine/buildbot/html.go ('k') | milo/appengine/common/middleware.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698