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

Side by Side Diff: appengine/swarming/elements/res/imp/common/pageable-data.html

Issue 2375963003: Move bot-list and task-list to use pageable-data (Closed) Base URL: git@github.com:luci/luci-py@limit-tasks
Patch Set: rename Created 4 years, 2 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 <!-- 1 <!--
2 This in an HTML Import-able file that contains the definition 2 This in an HTML Import-able file that contains the definition
3 of the following elements: 3 of the following elements:
4 4
5 <pageable-data> 5 <pageable-data>
6 6
7 The pageable-data element allows for easy paging of data from the swarming 7 The pageable-data element allows for easy paging of data from the swarming
8 server. It displays a button to the user to go fetch more data, which will 8 server. It displays a button to the user to go fetch more data, which will
9 be appended to the output, rather than replaced, which is typical in 9 be appended to the output, rather than replaced, which is typical in
10 elements like iron-ajax. 10 elements like iron-ajax.
(...skipping 16 matching lines...) Expand all
27 27
28 // output 28 // output
29 busy: Boolean, if a request is in flight. Calls to page() while busy will 29 busy: Boolean, if a request is in flight. Calls to page() while busy will
30 be ignored. 30 be ignored.
31 output: Array<Object> the accumulated values from the server. 31 output: Array<Object> the accumulated values from the server.
32 32
33 Methods: 33 Methods:
34 clear(): Reset the element, emptying output. page() will not work until 34 clear(): Reset the element, emptying output. page() will not work until
35 a call to load() has been made. 35 a call to load() has been made.
36 36
37 load(url, headers, pageSize): Initialize the element and make a call to 37 load(url, headers, [pageSize]): Initialize the element and make a call to
38 the server for the first batch of data. 38 the server for the first batch of data. If [pageSize] is omitted, the
39 server default (or those specified in the url) will be used
39 40
40 page(): Must be called after a call to load(). Fetch the next batch of 41 page(): Must be called after a call to load(). Fetch the next batch of
41 data from the server. 42 data from the server.
42 43
43 Events: 44 Events:
44 None. 45 None.
45 --> 46 -->
46 47
47 <link rel="import" href="/res/imp/common/swarming-app.html"> 48 <link rel="import" href="/res/imp/common/swarming-app.html">
48 49
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 type: Object, 102 type: Object,
102 }, 103 },
103 _page_size: { 104 _page_size: {
104 type: Number, 105 type: Number,
105 } 106 }
106 }, 107 },
107 108
108 clear: function() { 109 clear: function() {
109 this.set("output", []); 110 this.set("output", []);
110 this._cursor = null; 111 this._cursor = null;
112 this._url = "";
111 }, 113 },
112 114
113 load: function(url, headers, pageSize) { 115 load: function(url, headers, pageSize) {
114 if (!url) { 116 if (!url) {
115 throw "url can't be blank"; 117 throw "url can't be blank";
116 } 118 }
117 if (url.indexOf("?") === -1) { 119 if (url.indexOf("?") === -1) {
118 url += "?"; 120 url += "?";
119 } 121 }
120 this._url = url; 122 this._url = url;
121 this._headers = headers; 123 this._headers = headers;
122 this._page_size = pageSize || 50; 124 this._page_size = pageSize;
125 this._cursor = null;
123 this.page(); 126 this.page();
124 }, 127 },
125 128
126 page: function() { 129 page: function() {
127 if (this.busy || this._cursor === END) { 130 if (this.busy || this._cursor === END) {
128 // ignore pages while we are loading or are at the end of the data. 131 // ignore pages while we are loading or are at the end of the data.
129 return; 132 return;
130 } 133 }
131 if (!this._url) { 134 if (!this._url) {
132 throw "You must first call load() before calling page()"; 135 throw "You must first call load() before calling page()";
133 } 136 }
134 this.set("busy", true); 137 this.set("busy", true);
135 138
136 var url = this._url + "&limit=" + this._page_size; 139 var url = this._url;
140 if (this._page_size) {
141 url += "&limit=" + this._page_size;
142 }
137 if (this._cursor) { 143 if (this._cursor) {
138 url += "&cursor=" + this._cursor; 144 url += "&cursor=" + this._cursor;
139 } 145 }
140 146
141 sk.request("GET", url, "", this._headers).then(JSON.parse).then(function (json){ 147 sk.request("GET", url, "", this._headers).then(JSON.parse).then(function (json){
142 var vals = this.parse(json); 148 var vals = this.parse(json);
143 if (!this.output) { 149 // !this._cursor means this is our first load and we should empty the
150 // array
151 if (!this._cursor || !this.output) {
144 this.set("output", vals); 152 this.set("output", vals);
145 } else { 153 } else {
146 this.push("output", ...vals); 154 this.push("output", ...vals);
147 } 155 }
148 this.set("_cursor", json.cursor || END); 156 this.set("_cursor", json.cursor || END);
149 this.set("busy", false); 157 this.set("busy", false);
150 }.bind(this)).catch(function(reason){ 158 }.bind(this)).catch(function(reason){
151 console.log("Reason for failure of request to " + this._url, reason); 159 console.log("Reason for failure of request to " + this._url, reason);
152 sk.errorMessage("Could not get next set of results. Try reloading the page?", 0); 160 sk.errorMessage("Could not get next set of results. Try reloading the page?", 0);
153 this.set("busy", false); 161 this.set("busy", false);
154 }.bind(this)); 162 }.bind(this));
155 }, 163 },
156 164
157 _noMore: function(cursor) { 165 _noMore: function(cursor) {
158 return cursor === END; 166 return cursor === END;
159 } 167 }
160 }); 168 });
161 })(); 169 })();
162 </script> 170 </script>
163 </dom-module> 171 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698