| OLD | NEW |
| 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-data> | 9 <bot-list-data> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ], | 56 ], |
| 57 | 57 |
| 58 properties: { | 58 properties: { |
| 59 // inputs | 59 // inputs |
| 60 auth_headers: { | 60 auth_headers: { |
| 61 type: Object, | 61 type: Object, |
| 62 observer: "signIn", | 62 observer: "signIn", |
| 63 }, | 63 }, |
| 64 query_params: { | 64 query_params: { |
| 65 type: Object, | 65 type: Object, |
| 66 observer: "_request", | 66 }, |
| 67 tasks: { |
| 68 type: Array, |
| 67 }, | 69 }, |
| 68 | 70 |
| 69 // outputs | 71 // outputs |
| 70 busy: { | 72 busy: { |
| 71 type: Boolean, | 73 type: Boolean, |
| 72 computed: "_or(_busy1,_busy2,_busy3)", | 74 computed: "_or(_busy2,_busy1)", |
| 73 notify: true, | 75 notify: true, |
| 74 }, | 76 }, |
| 75 primary_map: { | 77 primary_map: { |
| 76 type: Object, | 78 type: Object, |
| 77 computed: "_primaryMap(_tags,_dimensions,tasks)", | 79 computed: "_primaryMap(_tags,_dimensions,tasks.*)", |
| 78 notify: true, | 80 notify: true, |
| 79 }, | 81 }, |
| 80 primary_arr: { | 82 primary_arr: { |
| 81 type: Array, | 83 type: Array, |
| 82 computed: "_primaryArr(primary_map)", | 84 computed: "_primaryArr(primary_map)", |
| 83 notify: true, | 85 notify: true, |
| 84 }, | 86 }, |
| 85 tasks: { | 87 |
| 86 type: Array, | |
| 87 computed: "_tasks(_list)", | |
| 88 notify: true, | |
| 89 }, | |
| 90 | 88 |
| 91 // private | 89 // private |
| 92 _busy1: { | |
| 93 type: Boolean, | |
| 94 value: false | |
| 95 }, | |
| 96 _busy2: { | 90 _busy2: { |
| 97 type: Boolean, | 91 type: Boolean, |
| 98 value: false | 92 value: false |
| 99 }, | 93 }, |
| 100 _busy3: { | 94 _busy1: { |
| 101 type: Boolean, | 95 type: Boolean, |
| 102 value: false | 96 value: false |
| 103 }, | 97 }, |
| 104 _dimensions: { | 98 _dimensions: { |
| 105 type: Object, | 99 type: Object, |
| 106 }, | 100 }, |
| 107 _list: { | 101 _list: { |
| 108 type: Object, | 102 type: Object, |
| 109 }, | 103 }, |
| 110 _tags: { | 104 _tags: { |
| 111 type: Object, | 105 type: Object, |
| 112 }, | 106 }, |
| 113 }, | 107 }, |
| 114 | 108 |
| 115 signIn: function(){ | 109 signIn: function(){ |
| 116 this._getJsonAsync("_tags", "/_ah/api/swarming/v1/tasks/tags", | 110 this._getJsonAsync("_tags", "/_ah/api/swarming/v1/tasks/tags", |
| 117 "_busy2", this.auth_headers); | 111 "_busy2", this.auth_headers); |
| 118 this._getJsonAsync("_dimensions","/_ah/api/swarming/v1/bots/dimensions", | 112 this._getJsonAsync("_dimensions","/_ah/api/swarming/v1/bots/dimensions", |
| 119 "_busy3", this.auth_headers); | 113 "_busy1", this.auth_headers); |
| 120 | |
| 121 this._request(); | |
| 122 }, | 114 }, |
| 123 | 115 |
| 124 _primaryArr: function(map) { | 116 _primaryArr: function(map) { |
| 125 var arr = Object.keys(map); | 117 var arr = Object.keys(map); |
| 126 arr.sort(); | 118 arr.sort(); |
| 127 return arr; | 119 return arr; |
| 128 }, | 120 }, |
| 129 | 121 |
| 130 _primaryMap: function(tags, dims, tasks) { | 122 _primaryMap: function(tags, dims) { |
| 131 tags = (tags && tags.tasks_tags) || []; | 123 tags = (tags && tags.tasks_tags) || []; |
| 132 dims = (dims && dims.bots_dimensions) || []; | 124 dims = (dims && dims.bots_dimensions) || []; |
| 133 tasks = tasks || []; | 125 tasks = this.tasks || []; |
| 134 var map = {}; | 126 var map = {}; |
| 135 // We combine all the tags reported by the tags endpoint, all known | 127 // We combine all the tags reported by the tags endpoint, all known |
| 136 // dimensions from the dimensions endpoint, and the tags seen in the | 128 // dimensions from the dimensions endpoint, and the tags seen in the |
| 137 // returned tasks, just in case they didn't show up in the first two. | 129 // returned tasks, just in case they didn't show up in the first two. |
| 138 // This way a user can filter by what the data actually has and can | 130 // This way a user can filter by what the data actually has and can |
| 139 // discover new tags to filter by. | 131 // discover new tags to filter by. |
| 140 tags.forEach(function(t) { | 132 tags.forEach(function(t) { |
| 141 if (!map[t.key]) { | 133 if (!map[t.key]) { |
| 142 map[t.key] = {}; | 134 map[t.key] = {}; |
| 143 } | 135 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 193 |
| 202 // TODO(kjlubick): Allow a person to sort on the task list by bot | 194 // TODO(kjlubick): Allow a person to sort on the task list by bot |
| 203 pMap["bot"] = []; | 195 pMap["bot"] = []; |
| 204 TIMES.forEach(function(t) { | 196 TIMES.forEach(function(t) { |
| 205 pMap[t] = []; | 197 pMap[t] = []; |
| 206 }); | 198 }); |
| 207 | 199 |
| 208 return pMap; | 200 return pMap; |
| 209 }, | 201 }, |
| 210 | 202 |
| 211 _request: function() { | 203 parseTasks: function(json) { |
| 212 // wait until the user has logged in and the filters have loaded before
requesting this to avoid double or even triple requests. | 204 console.log("ping", json); |
| 213 if (!this.auth_headers || !this.query_params) { | 205 if (!json|| !json.items) { |
| 214 return; | |
| 215 } | |
| 216 this._getJsonAsync("_list", "/_ah/api/swarming/v1/tasks/list", | |
| 217 "_busy1", this.auth_headers, this.query_params); | |
| 218 }, | |
| 219 | |
| 220 _tasks: function() { | |
| 221 if (!this._list || !this._list.items) { | |
| 222 return []; | 206 return []; |
| 223 } | 207 } |
| 224 var now = new Date(); | 208 var now = new Date(); |
| 225 | 209 |
| 226 // Do any preprocessing here | 210 // Do any preprocessing here |
| 227 this._list.items.forEach(function(t) { | 211 json.items.forEach(function(t) { |
| 228 var tagMap = {}; | 212 var tagMap = {}; |
| 229 t.tags = t.tags || []; | 213 t.tags = t.tags || []; |
| 230 t.tags.forEach(function(tag) { | 214 t.tags.forEach(function(tag) { |
| 231 var split = tag.split(":", 1) | 215 var split = tag.split(":", 1) |
| 232 var key = split[0]; | 216 var key = split[0]; |
| 233 var rest = tag.substring(key.length + 1); | 217 var rest = tag.substring(key.length + 1); |
| 234 tagMap[key] = rest; | 218 tagMap[key] = rest; |
| 235 }); | 219 }); |
| 236 t.tagMap = tagMap; | 220 t.tagMap = tagMap; |
| 237 | 221 |
| 238 TIMES.forEach(function(time) { | 222 TIMES.forEach(function(time) { |
| 239 if (t[time]) { | 223 if (t[time]) { |
| 240 t[time] = new Date(t[time]); | 224 t[time] = new Date(t[time]); |
| 241 t["human_"+time] = sk.human.localeTime(t[time]); | 225 t["human_"+time] = sk.human.localeTime(t[time]); |
| 242 } | 226 } |
| 243 }); | 227 }); |
| 244 // Running tasks have no duration set, so we can figure it out. | 228 // Running tasks have no duration set, so we can figure it out. |
| 245 if (!t.duration && t.state === this.RUNNING && t.started_ts){ | 229 if (!t.duration && t.state === this.RUNNING && t.started_ts){ |
| 246 t.duration = (now - t.started_ts) / 1000; | 230 t.duration = (now - t.started_ts) / 1000; |
| 247 } | 231 } |
| 248 // Make the duration human readable | 232 // Make the duration human readable |
| 249 if (t.duration){ | 233 if (t.duration){ |
| 250 t.human_duration = this._humanDuration(t.duration); | 234 t.human_duration = this._humanDuration(t.duration); |
| 251 } | 235 } |
| 252 }.bind(this)); | 236 }.bind(this)); |
| 253 return this._list.items; | 237 return json.items; |
| 254 } | 238 } |
| 255 }); | 239 }); |
| 256 })(); | 240 })(); |
| 257 </script> | 241 </script> |
| 258 </dom-module> | 242 </dom-module> |
| OLD | NEW |