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

Side by Side Diff: appengine/swarming/elements/res/imp/botpage/bot-page.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> 9 <bot-page>
10 10
(...skipping 17 matching lines...) Expand all
28 <link rel="import" href="/res/imp/bower_components/iron-icon/iron-icon.html"> 28 <link rel="import" href="/res/imp/bower_components/iron-icon/iron-icon.html">
29 <link rel="import" href="/res/imp/bower_components/iron-icons/iron-icons.html"> 29 <link rel="import" href="/res/imp/bower_components/iron-icons/iron-icons.html">
30 <link rel="import" href="/res/imp/bower_components/paper-button/paper-button.htm l"> 30 <link rel="import" href="/res/imp/bower_components/paper-button/paper-button.htm l">
31 <link rel="import" href="/res/imp/bower_components/paper-checkbox/paper-checkbox .html"> 31 <link rel="import" href="/res/imp/bower_components/paper-checkbox/paper-checkbox .html">
32 <link rel="import" href="/res/imp/bower_components/paper-dialog/paper-dialog.htm l"> 32 <link rel="import" href="/res/imp/bower_components/paper-dialog/paper-dialog.htm l">
33 <link rel="import" href="/res/imp/bower_components/paper-input/paper-input.html" > 33 <link rel="import" href="/res/imp/bower_components/paper-input/paper-input.html" >
34 <link rel="import" href="/res/imp/bower_components/paper-tabs/paper-tabs.html"> 34 <link rel="import" href="/res/imp/bower_components/paper-tabs/paper-tabs.html">
35 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html"> 35 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html">
36 36
37 <link rel="import" href="/res/imp/common/error-toast.html"> 37 <link rel="import" href="/res/imp/common/error-toast.html">
38 <link rel="import" href="/res/imp/common/pageable-data.html">
38 <link rel="import" href="/res/imp/common/single-page-style.html"> 39 <link rel="import" href="/res/imp/common/single-page-style.html">
39 <link rel="import" href="/res/imp/common/swarming-app.html"> 40 <link rel="import" href="/res/imp/common/swarming-app.html">
40 <link rel="import" href="/res/imp/common/task-behavior.html"> 41 <link rel="import" href="/res/imp/common/task-behavior.html">
41 <link rel="import" href="/res/imp/common/url-param.html"> 42 <link rel="import" href="/res/imp/common/url-param.html">
42 43
43 <link rel="import" href="bot-page-data.html"> 44 <link rel="import" href="bot-page-data.html">
44 <link rel="import" href="bot-page-shared-behavior.html"> 45 <link rel="import" href="bot-page-shared-behavior.html">
45 46
46 47
47 <dom-module id="bot-page"> 48 <dom-module id="bot-page">
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 <url-param name="show_state" 89 <url-param name="show_state"
89 value="{{_show_state}}"> 90 value="{{_show_state}}">
90 </url-param> 91 </url-param>
91 92
92 <swarming-app 93 <swarming-app
93 client_id="[[client_id]]" 94 client_id="[[client_id]]"
94 auth_headers="{{_auth_headers}}" 95 auth_headers="{{_auth_headers}}"
95 permissions="{{_permissions}}" 96 permissions="{{_permissions}}"
96 signed_in="{{_signed_in}}" 97 signed_in="{{_signed_in}}"
97 98
98 busy="[[_busy]]" 99 busy="[[_or(_busy1,_busy2,_busy3)]]"
99 name="Swarming Bot Page"> 100 name="Swarming Bot Page">
100 101
101 <h2 hidden$="[[_signed_in]]">You must sign in to see anything useful.</h2> 102 <h2 hidden$="[[_signed_in]]">You must sign in to see anything useful.</h2>
102 103
103 <div hidden$="[[_not(_signed_in)]]"> 104 <div hidden$="[[_not(_signed_in)]]">
104 105
105 <bot-page-data 106 <bot-page-data
106 id="data" 107 id="data"
107 auth_headers="[[_auth_headers]]" 108 auth_headers="[[_auth_headers]]"
108 bot_id="[[bot_id]]" 109 bot_id="[[bot_id]]"
109 110
110 bot="{{_bot}}" 111 bot="{{_bot}}"
111 busy="{{_busy}}" 112 busy="{{_busy1}}"
112 events="{{_events}}" 113 events="{{_events}}"
113 tasks="{{_tasks}}"> 114 tasks="{{_tasks}}"
115 on-reload="_clearAndReload">
114 </bot-page-data> 116 </bot-page-data>
115 117
116 <div class="header horizontal layout"> 118 <div class="header horizontal layout">
117 <paper-input class="id_input" label="Bot id" value="{{bot_id}}"></pape r-input> 119 <paper-input class="id_input" label="Bot id" value="{{bot_id}}"></pape r-input>
118 <button on-click="_refresh"> 120 <button on-click="_refresh">
119 <iron-icon class="refresh" icon="icons:refresh"></iron-icon> 121 <iron-icon class="refresh" icon="icons:refresh"></iron-icon>
120 </button> 122 </button>
121 </div> 123 </div>
122 124
123 <div> 125 <div>
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 <thead> 261 <thead>
260 <tr> 262 <tr>
261 <th>Message</th> 263 <th>Message</th>
262 <th>Type</th> 264 <th>Type</th>
263 <th>Timestamp</th> 265 <th>Timestamp</th>
264 <th>Task ID</th> 266 <th>Task ID</th>
265 <th>Version</th> 267 <th>Version</th>
266 </tr> 268 </tr>
267 </thead> 269 </thead>
268 <tbody> 270 <tbody>
269 <template is="dom-repeat" items="{{_eventList(_events,_show_all)}} " as="event"> 271 <template is="dom-repeat" items="{{_eventList(_show_all,_events.*) }}" as="event">
270 <tr> 272 <tr>
271 <td class="message">[[event.message]]</a></td> 273 <td class="message">[[event.message]]</a></td>
272 <td>[[event.event_type]]</td> 274 <td>[[event.event_type]]</td>
273 <td>[[event.human_ts]]</td> 275 <td>[[event.human_ts]]</td>
274 <td><a target="_blank" href$="[[_taskLink(event.task_id)]]">[[ event.task_id]]</a></td> 276 <td><a target="_blank" href$="[[_taskLink(event.task_id)]]">[[ event.task_id]]</a></td>
275 <td> 277 <td>
276 <a target="_blank" href$="[[_luciLink(event.version)]]">[[_s horten(event.version,'8')]]</a> 278 <a target="_blank" href$="[[_luciLink(event.version)]]">[[_s horten(event.version,'8')]]</a>
277 </td> 279 </td>
278 </tr> 280 </tr>
279 </template> 281 </template>
280 </tbody> 282 </tbody>
281 </table> 283 </table>
282 </template> 284 </template>
285 <pageable-data
286 id="page_tasks"
287 hidden$="[[_truthy(_selected)]]"
stephana 2016/09/28 13:25:23 who does 'selected' alone not work here ?
kjlubick 2016/09/28 13:50:36 I'm not entirely sure, but it seems that when _sel
stephana 2016/09/28 15:45:33 if _selected is string "0", _truthy will return tr
288 busy="{{_busy2}}"
289 label="Show more tasks"
290 output="{{_tasks}}"
291 parse="[[_parseTasks]]">
292 </pageable-data>
293 <pageable-data
294 id="page_events"
295 hidden$="[[_not(_selected)]]"
296 busy="{{_busy3}}"
297 label="Show more events"
298 output="{{_events}}"
299 parse="[[_parseEvents]]">
300 </pageable-data>
283 </div> 301 </div>
284 </swarming-app> 302 </swarming-app>
285 303
286 <paper-dialog id="prompt" modal on-iron-overlay-closed="_promptClosed"> 304 <paper-dialog id="prompt" modal on-iron-overlay-closed="_promptClosed">
287 <h2>Are you sure?</h2> 305 <h2>Are you sure?</h2>
288 <div>Are you sure you want to [[_dialogPrompt]]?</div> 306 <div>Are you sure you want to [[_dialogPrompt]]?</div>
289 <div class="buttons"> 307 <div class="buttons">
290 <paper-button dialog-dismiss autofocus>No</paper-button> 308 <paper-button dialog-dismiss autofocus>No</paper-button>
291 <paper-button dialog-confirm>Yes</paper-button> 309 <paper-button dialog-confirm>Yes</paper-button>
292 </div> 310 </div>
(...skipping 15 matching lines...) Expand all
308 properties: { 326 properties: {
309 bot_id: { 327 bot_id: {
310 type: String, 328 type: String,
311 }, 329 },
312 client_id: { 330 client_id: {
313 type: String, 331 type: String,
314 }, 332 },
315 333
316 _auth_headers: { 334 _auth_headers: {
317 type: Object, 335 type: Object,
336 observer: "_reload",
318 }, 337 },
319 _bot: { 338 _bot: {
320 type: Object, 339 type: Object,
321 }, 340 },
322 _dialogPrompt: { 341 _dialogPrompt: {
323 type: String, 342 type: String,
324 value: "", 343 value: "",
325 }, 344 },
326 _selected: { 345 _selected: {
327 type: Number, 346 type: Number,
328 }, 347 },
329 _show_all: { 348 _show_all: {
330 type: Boolean, 349 type: Boolean,
331 }, 350 },
332 _show_state: { 351 _show_state: {
333 type: Boolean, 352 type: Boolean,
353 },
354
355 _parseEvents: {
stephana 2016/09/28 13:25:23 This don't need to be defined in properties. Why c
kjlubick 2016/09/28 13:50:36 I tried defining the functions below, but Polymer
stephana 2016/09/28 15:45:33 Acknowledged.
356 type: Function,
357 value: function() {
358 return this.$.data.parseEvents.bind(this);
359 }
360 },
361 _parseTasks: {
362 type: Function,
363 value: function() {
364 return this.$.data.parseTasks.bind(this);
365 }
334 } 366 }
335 }, 367 },
336 368
337 _canCancel: function(bot, permissions) { 369 _canCancel: function(bot, permissions) {
338 return bot && bot.task_id && permissions.cancel_task; 370 return bot && bot.task_id && permissions.cancel_task;
339 }, 371 },
340 372
341 _canDelete: function(bot, permissions) { 373 _canDelete: function(bot, permissions) {
342 return bot && bot.is_dead && permissions.delete_bot; 374 return bot && bot.is_dead && permissions.delete_bot;
343 }, 375 },
344 376
345 _canShutdown: function(bot, permissions){ 377 _canShutdown: function(bot, permissions){
346 return bot && !bot.is_dead && permissions.terminate_bot; 378 return bot && !bot.is_dead && permissions.terminate_bot;
347 }, 379 },
348 380
381 _clearAndReload: function(botID) {
382 this.$.page_tasks.clear();
383 this.$.page_events.clear();
384 this._reload();
385 },
386
349 _concat: function(arr) { 387 _concat: function(arr) {
350 if (!arr) { 388 if (!arr) {
351 return ""; 389 return "";
352 } 390 }
353 return arr.join(" | "); 391 return arr.join(" | ");
354 }, 392 },
355 393
356 _deleteBot: function() { 394 _deleteBot: function() {
357 swarming.postWithToast("/_ah/api/swarming/v1/bot/"+this.bot_id+"/delete" , 395 swarming.postWithToast("/_ah/api/swarming/v1/bot/"+this.bot_id+"/delete" ,
358 "Deleting "+this.bot_id, this._auth_headers); 396 "Deleting "+this.bot_id, this._auth_headers);
359 }, 397 },
360 398
361 _eventList(events, showAll) { 399 _eventList(showAll) {
362 if (!events) { 400 if (!this._events) {
363 return []; 401 return [];
364 } 402 }
365 return events.filter(function(e){ 403 return this._events.filter(function(e){
366 return showAll || e.message; 404 return showAll || e.message;
367 }); 405 });
368 }, 406 },
369 407
370 _isDead(bot){ 408 _isDead(bot){
371 if (bot && bot.is_dead) { 409 if (bot && bot.is_dead) {
372 return "dead"; 410 return "dead";
373 } 411 }
374 return ""; 412 return "";
375 }, 413 },
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 462 }
425 return msg || "True"; 463 return msg || "True";
426 } 464 }
427 return ""; 465 return "";
428 }, 466 },
429 467
430 _refresh: function() { 468 _refresh: function() {
431 this.$.data.request(); 469 this.$.data.request();
432 }, 470 },
433 471
472 _reload: function() {
473 if (!this._auth_headers) {
474 return;
475 }
476 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id;
477 // We limit the fields on these two queries to make them faster.
478 this.$.page_tasks.load(baseUrl + "/tasks?fields=cursor%2Citems(abandoned _ts%2Cbot_version%2Ccompleted_ts%2Cduration%2Cexit_code%2Cfailure%2Cinternal_fai lure%2Cmodified_ts%2Cname%2Cstarted_ts%2Cstate%2Ctask_id%2Ctry_number)",
479 this._auth_headers, 30);
480 this.$.page_events.load(baseUrl + "/events?fields=cursor%2Citems(event_t ype%2Cmessage%2Cquarantined%2Ctask_id%2Cts%2Cversion)",
481 this._auth_headers, 50);
482 },
483
434 _shorten: function(str, length) { 484 _shorten: function(str, length) {
435 if (!str || ! length) { 485 if (!str || ! length) {
436 return ""; 486 return "";
437 } 487 }
438 return str.substring(0, length); 488 return str.substring(0, length);
439 }, 489 },
440 490
441 _shutdownBot: function() { 491 _shutdownBot: function() {
442 swarming.postWithToast("/_ah/api/swarming/v1/bot/"+this.bot_id+"/termina te", 492 swarming.postWithToast("/_ah/api/swarming/v1/bot/"+this.bot_id+"/termina te",
443 "Shutting down "+this.bot_id, this._auth_headers); 493 "Shutting down "+this.bot_id, this._auth_headers);
(...skipping 14 matching lines...) Expand all
458 }, 508 },
459 509
460 _toggleState: function() { 510 _toggleState: function() {
461 this.set("_show_state", !this._show_state); 511 this.set("_show_state", !this._show_state);
462 } 512 }
463 513
464 }); 514 });
465 })(); 515 })();
466 </script> 516 </script>
467 </dom-module> 517 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698