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

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list.html

Issue 2269643002: Extract shared filters and aliasing code (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Documentation Created 4 years, 4 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-list> 9 <bot-list>
10 10
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 "device_type": "Device Type", 227 "device_type": "Device Type",
228 "disk_space": "Free Space (MB)", 228 "disk_space": "Free Space (MB)",
229 "gpu": "GPU", 229 "gpu": "GPU",
230 "os": "OS", 230 "os": "OS",
231 "pool": "Pool", 231 "pool": "Pool",
232 "status": "Status", 232 "status": "Status",
233 "xcode_version": "XCode Version", 233 "xcode_version": "XCode Version",
234 }; 234 };
235 235
236 var columnMap = { 236 var columnMap = {
237 android_devices: function(bot) {
238 var devs = this._attribute(bot, "android_devices", "0");
239 if (this._verbose) {
240 return devs.join(" | ") + " devices available";
241 }
242 // max() works on strings as long as they can be coerced to Number.
243 return Math.max(...devs) + " devices available";
244 },
245 device_type: function(bot) {
246 var dt = this._attribute(bot, "device_type", "none");
247 dt = dt[0];
248 var alias = this._androidAlias(dt);
249 if (alias === "unknown") {
250 return dt;
251 }
252 return this._applyAlias(dt, alias);
253 },
254 disk_space: function(bot) { 237 disk_space: function(bot) {
255 var aliased = []; 238 var aliased = [];
256 bot.disks.forEach(function(disk){ 239 bot.disks.forEach(function(disk){
257 var alias = sk.human.bytes(disk.mb, swarming.MB); 240 var alias = sk.human.bytes(disk.mb, swarming.MB);
258 aliased.push(this._applyAlias(disk.mb, disk.id + " "+ alias)); 241 aliased.push(this._applyAlias(disk.mb, disk.id + " "+ alias));
259 }.bind(this)); 242 }.bind(this));
260 if (this._verbose) { 243 if (this._verbose) {
261 return aliased.join(" | "); 244 return aliased.join(" | ");
262 } 245 }
263 return aliased[0]; 246 return aliased[0];
264 }, 247 },
265 gpu: function(bot){
266 var gpus = this._attribute(bot, "gpu", "none")
267 var verbose = []
268 var named = [];
269 // non-verbose mode has only the top level GPU info "e.g. NVidia"
270 // which is found by looking for gpu ids w/o a colon.
271 gpus.forEach(function(g){
272 var alias = this._gpuAlias(g);
273 if (alias === "unknown") {
274 verbose.push(g);
275 if (g.indexOf(":") === -1) {
276 named.push(g);
277 }
278 return;
279 }
280 verbose.push(this._applyAlias(g, alias));
281 if (g.indexOf(":") === -1) {
282 named.push(this._applyAlias(g, alias));
283 }
284 }.bind(this))
285 if (this._verbose) {
286 return verbose.join(" | ");
287 }
288 return named.join(" | ");
289 },
290 id: function(bot) { 248 id: function(bot) {
291 return bot.bot_id; 249 return bot.bot_id;
292 }, 250 },
293 pool: function(bot) {
294 var pool = this._attribute(bot, "pool");
295 return pool.join(" | ");
296 },
297 status: function(bot) { 251 status: function(bot) {
298 // If a bot is both dead and quarantined, show the deadness over the 252 // If a bot is both dead and quarantined, show the deadness over the
299 // quarentinedness. 253 // quarentinedness.
300 if (bot.is_dead) { 254 if (bot.is_dead) {
301 return "Dead. Last seen " + sk.human.diffDate(bot.last_seen_ts) + 255 return "Dead. Last seen " + sk.human.diffDate(bot.last_seen_ts) +
302 " ago"; 256 " ago";
303 } 257 }
304 if (bot.quarantined) { 258 if (bot.quarantined) {
305 return "Quarantined: " + this._attribute(bot, "quarantined"); 259 var msg = this._state(bot, "quarantined")[0];
260 // Sometimes, the quarantined message is actually in "error". This
261 // happens when the bot code has thrown an exception.
262 if (msg === "unknown" || msg === "true" || msg === true) {
263 msg = this._attribute(bot, "error");
264 }
265 return "Quarantined: " + msg;
306 } 266 }
307 return "Alive"; 267 return "Alive";
308 }, 268 },
309 task: function(bot){ 269 task: function(bot){
310 return this._taskId(bot); 270 return this._taskId(bot);
311 }, 271 },
312 }; 272 };
313 273
314 var deviceColumnMap = { 274 var deviceColumnMap = {
315 android_devices: function(device) { 275 android_devices: function(device) {
(...skipping 29 matching lines...) Expand all
345 disk_space: function(dir, botA, botB) { 305 disk_space: function(dir, botA, botB) {
346 // We sort based on the raw number of MB of the first disk. 306 // We sort based on the raw number of MB of the first disk.
347 var botACol = botA.disks[0].mb; 307 var botACol = botA.disks[0].mb;
348 var botBCol = botB.disks[0].mb;; 308 var botBCol = botB.disks[0].mb;;
349 return dir * swarming.naturalCompare(botACol, botBCol); 309 return dir * swarming.naturalCompare(botACol, botBCol);
350 }, 310 },
351 }; 311 };
352 312
353 Polymer({ 313 Polymer({
354 is: 'bot-list', 314 is: 'bot-list',
355 behaviors: [SwarmingBehaviors.BotListBehavior, 315
356 SwarmingBehaviors.DynamicTableBehavior], 316 // The order behaviors are applied in matters - later ones overwrite
317 // attributes of earlier ones
318 behaviors: [
319 SwarmingBehaviors.BotListBehavior,
320 SwarmingBehaviors.DynamicTableBehavior,
jcgregorio 2016/08/23 13:07:44 So we have SwarmingBehaviors.BotListBehavior which
kjlubick 2016/08/23 17:43:19 Done.
321 ],
357 322
358 properties: { 323 properties: {
359 client_id: { 324 client_id: {
360 type: String, 325 type: String,
361 }, 326 },
362 327
363 // For dynamic table. 328 // For dynamic table.
364 _columnMap: { 329 _columnMap: {
365 type: Object, 330 type: Object,
366 value: columnMap, 331 value: function() {
332 var base = this._commonColumns();
333 for (var attr in columnMap) {
334 base[attr] = columnMap[attr];
335 }
336 return base;
337 },
367 }, 338 },
368 _headerMap: { 339 _headerMap: {
369 type: Object, 340 type: Object,
370 value: headerMap, 341 value: headerMap,
371 }, 342 },
372 _specialColumns: { 343 _specialColumns: {
373 type: Array, 344 type: Array,
374 value: specialColumns, 345 value: specialColumns,
375 }, 346 },
376 _specialSort: { 347 _specialSort: {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (data && data.task_id) { 393 if (data && data.task_id) {
423 return "/user/task/" + data.task_id; 394 return "/user/task/" + data.task_id;
424 } 395 }
425 return undefined; 396 return undefined;
426 } 397 }
427 398
428 }); 399 });
429 })(); 400 })();
430 </script> 401 </script>
431 </dom-module> 402 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698