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

Side by Side Diff: appengine/swarming/elements/res/imp/botpage/bot-page-data.html

Issue 2372323002: Add pageable data widget (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: Add docs 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 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 This in an HTML Import-able file that contains the definition 6 This in an HTML Import-able file that contains the definition
7 of the following elements: 7 of the following elements:
8 8
9 <bot-page-data> 9 <bot-page-data>
10 10
(...skipping 15 matching lines...) Expand all
26 tasks: Array<Object>, The most recent tasks done by this bot. 26 tasks: Array<Object>, The most recent tasks done by this bot.
27 Contains the following fields: "abandoned_ts", "bot_version", "duration" , 27 Contains the following fields: "abandoned_ts", "bot_version", "duration" ,
28 "failure", "internal_failure", "modified_ts", "name", "started_ts", 28 "failure", "internal_failure", "modified_ts", "name", "started_ts",
29 "state", "task_id", "try_number". 29 "state", "task_id", "try_number".
30 30
31 Methods: 31 Methods:
32 request(): Force a fetch of the data. This happens automatically when 32 request(): Force a fetch of the data. This happens automatically when
33 auth_headers is set or bot_id is changed. 33 auth_headers is set or bot_id is changed.
34 34
35 Events: 35 Events:
36 None. 36 reload: When this element is making a request for data. Other data sources
37 should also reload themselves.
37 --> 38 -->
38 39
39 40
40 <link rel="import" href="bot-page-shared-behavior.html"> 41 <link rel="import" href="bot-page-shared-behavior.html">
41 42
42 <dom-module id="bot-page-data"> 43 <dom-module id="bot-page-data">
43 <script> 44 <script>
44 (function(){ 45 (function(){
45 // Time to wait before requesting a new bot. This is to allow a user to 46 // Time to wait before requesting a new bot. This is to allow a user to
46 // type in a name and not have it make one set of requests for each 47 // type in a name and not have it make one set of requests for each
(...skipping 28 matching lines...) Expand all
75 auth_headers: { 76 auth_headers: {
76 type: Object, 77 type: Object,
77 }, 78 },
78 bot_id: { 79 bot_id: {
79 type: String, 80 type: String,
80 }, 81 },
81 82
82 // outputs 83 // outputs
83 busy: { 84 busy: {
84 type: Boolean, 85 type: Boolean,
85 computed: "_or(_busy1,_busy2,_busy3)", 86 computed: "_or(_busy1)",
86 notify: true, 87 notify: true,
87 }, 88 },
88 bot: { 89 bot: {
89 type: Object, 90 type: Object,
90 computed: "_parseBot(_bot)", 91 computed: "_parseBot(_bot)",
91 notify: true, 92 notify: true,
92 }, 93 },
93 events: {
94 type: Array,
95 computed: "_parseEvents(_events)",
96 notify: true,
97 },
98 tasks: {
99 type: Array,
100 computed: "_parseTasks(_tasks)",
101 notify: true,
102 },
103 94
104 // private 95 // private
105 _busy1: { 96 _busy1: {
106 type: Boolean, 97 type: Boolean,
107 value: false 98 value: false
108 }, 99 },
109 _busy2: {
110 type: Boolean,
111 value: false
112 },
113 _busy3: {
114 type: Boolean,
115 value: false
116 },
117 _bot: { 100 _bot: {
118 type: Object, 101 type: Object,
119 }, 102 },
120 _events: { 103 _events: {
121 type: Object, 104 type: Object,
122 }, 105 },
123 _tasks: { 106 _tasks: {
124 type: Object, 107 type: Object,
125 }, 108 },
126 }, 109 },
127 110
128 observers: [ 111 observers: [
129 "request(auth_headers,bot_id)", 112 "request(auth_headers,bot_id)",
130 ], 113 ],
131 114
132 request: function(){ 115 request: function(){
133 if (!this.bot_id || !this.auth_headers) { 116 if (!this.bot_id || !this.auth_headers) {
134 return; 117 return;
135 } 118 }
136 if (lastRequest) { 119 if (lastRequest) {
137 this.cancelAsync(lastRequest); 120 this.cancelAsync(lastRequest);
138 } 121 }
139 122
140 lastRequest = this.async(function(){ 123 lastRequest = this.async(function(){
141 lastRequest = undefined; 124 lastRequest = undefined;
142 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id; 125 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id;
143 this._getJsonAsync("_bot", baseUrl + "/get", 126 this._getJsonAsync("_bot", baseUrl + "/get",
144 "_busy1", this.auth_headers); 127 "_busy1", this.auth_headers);
145 // We limit the fields on these two queries to make them faster. 128 this.fire("reload", {id: this.bot_id});
146 this._getJsonAsync("_events",
147 baseUrl + "/events?fields=items(event_type%2Cmessage%2Cquarantined%2 Ctask_id%2Cts%2Cversion)",
148 "_busy2", this.auth_headers);
149 this._getJsonAsync("_tasks",
150 baseUrl + "/tasks?fields=items(abandoned_ts%2Cbot_version%2Ccomplete d_ts%2Cduration%2Cexit_code%2Cfailure%2Cinternal_failure%2Cmodified_ts%2Cname%2C started_ts%2Cstate%2Ctask_id%2Ctry_number)",
151 "_busy3", this.auth_headers);
152 }, BOT_ID_DEBOUNCE_MS); 129 }, BOT_ID_DEBOUNCE_MS);
153 130
154 }, 131 },
155 132
156 _parseBot: function(bot) { 133 _parseBot: function(bot) {
157 if (!bot) { 134 if (!bot) {
158 return {}; 135 return {};
159 } 136 }
160 // Do any preprocessing here 137 // Do any preprocessing here
161 bot.state = bot.state || "{}"; 138 bot.state = bot.state || "{}";
(...skipping 26 matching lines...) Expand all
188 165
189 BOT_TIMES.forEach(function(time) { 166 BOT_TIMES.forEach(function(time) {
190 if (bot[time]) { 167 if (bot[time]) {
191 bot[time] = new Date(bot[time]); 168 bot[time] = new Date(bot[time]);
192 bot["human_"+time] = formatDate(bot[time]); 169 bot["human_"+time] = formatDate(bot[time]);
193 } 170 }
194 }); 171 });
195 return bot; 172 return bot;
196 }, 173 },
197 174
198 _parseEvents: function(events) { 175 parseEvents: function(events) {
199 if (!events || !events.items) { 176 if (!events || !events.items) {
200 return []; 177 return [];
201 } 178 }
202 var events = events.items; 179 var events = events.items;
203 events.forEach(function(event){ 180 events.forEach(function(event){
204 // Do any preprocessing here 181 // Do any preprocessing here
205 if (event.ts) { 182 if (event.ts) {
206 event.ts = new Date(event.ts); 183 event.ts = new Date(event.ts);
207 event.human_ts = formatDate(event.ts); 184 event.human_ts = formatDate(event.ts);
208 } 185 }
209 }); 186 });
210 187
211 // Sort the most recent events first. 188 // Sort the most recent events first.
212 events.sort(function(a,b) { 189 events.sort(function(a,b) {
213 return b.ts - a.ts; 190 return b.ts - a.ts;
214 }); 191 });
215 192
216 return events; 193 return events;
217 }, 194 },
218 195
219 _parseTasks: function(tasks) { 196 parseTasks: function(tasks) {
220 if (!tasks || !tasks.items) { 197 if (!tasks || !tasks.items) {
221 return []; 198 return [];
222 } 199 }
223 var tasks = tasks.items; 200 var tasks = tasks.items;
224 201
225 tasks.forEach(function(task){ 202 tasks.forEach(function(task){
226 // Do any preprocessing here 203 // Do any preprocessing here
227 TASK_TIMES.forEach(function(time) { 204 TASK_TIMES.forEach(function(time) {
228 if (task[time]) { 205 if (task[time]) {
229 task[time] = new Date(task[time]); 206 task[time] = new Date(task[time]);
(...skipping 24 matching lines...) Expand all
254 return b.started_ts - a.started_ts; 231 return b.started_ts - a.started_ts;
255 }); 232 });
256 233
257 return tasks; 234 return tasks;
258 } 235 }
259 236
260 }); 237 });
261 })(); 238 })();
262 </script> 239 </script>
263 </dom-module> 240 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698