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

Side by Side Diff: appengine/swarming/elements/res/imp/tasklist/task-list-data.html

Issue 2266133002: Add filter to task-list (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@extract-filters
Patch Set: Fix default sort Created 4 years, 3 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-data> 9 <bot-list-data>
10 10
(...skipping 26 matching lines...) Expand all
37 automatically when auth_headers is set. 37 automatically when auth_headers is set.
38 38
39 Events: 39 Events:
40 None. 40 None.
41 --> 41 -->
42 42
43 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> 43 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html">
44 <link rel="import" href="/res/imp/common/common-behavior.html"> 44 <link rel="import" href="/res/imp/common/common-behavior.html">
45 45
46 <dom-module id="task-list-data"> 46 <dom-module id="task-list-data">
47 <template>
48 <iron-ajax id="tasklist"
49 url="/_ah/api/swarming/v1/tasks/list"
50 headers="[[auth_headers]]"
51 params="[[query_params]]"
52 handle-as="json"
53 last-response="{{_list}}"
54 loading="{{_busy1}}">
55 </iron-ajax>
56 <!-- TODO(kjlubick): Make more requests (like all tags) -->
57
58 </template>
59 <script> 47 <script>
60 (function(){ 48 (function(){
61 Polymer({ 49 Polymer({
62 is: 'task-list-data', 50 is: 'task-list-data',
63 51
64 behaviors: [SwarmingBehaviors.CommonBehavior], 52 behaviors: [
53 SwarmingBehaviors.CommonBehavior,
54 ],
65 55
66 properties: { 56 properties: {
67 // inputs 57 // inputs
68 auth_headers: { 58 auth_headers: {
69 type: Object, 59 type: Object,
70 observer: "signIn", 60 observer: "signIn",
71 }, 61 },
72 query_params: { 62 query_params: {
73 type: Object, 63 type: Object,
64 observer: "_request",
74 }, 65 },
75 66
76 //outputs 67 // outputs
77 busy: { 68 busy: {
78 type: Boolean, 69 type: Boolean,
79 computed: "_or(_busy1)", 70 computed: "_or(_busy1,_busy2,_busy3)",
71 notify: true,
72 },
73 primary_map: {
74 type: Object,
75 computed: "_primaryMap(_tags,_dimensions,tasks)",
76 notify: true,
77 },
78 primary_arr: {
79 type: Array,
80 computed: "_primaryArr(primary_map)",
80 notify: true, 81 notify: true,
81 }, 82 },
82 tasks: { 83 tasks: {
83 type: Array, 84 type: Array,
84 computed: "_tasks(_list)", 85 computed: "_tasks(_list)",
85 notify: true, 86 notify: true,
87 },
88
89 // private
90 _busy1: {
91 type: Boolean,
92 value: false
93 },
94 _busy2: {
95 type: Boolean,
96 value: false
97 },
98 _busy3: {
99 type: Boolean,
100 value: false
101 },
102 _dimensions: {
103 type: Object,
104 },
105 _list: {
106 type: Object,
107 },
108 _tags: {
109 type: Object,
110 },
111 },
112
113 signIn: function(){
114 this._getJsonAsync("_tags", "/_ah/api/swarming/v1/tasks/tags",
115 "_busy2", this.auth_headers);
116 this._getJsonAsync("_dimensions","/_ah/api/swarming/v1/bots/dimensions",
117 "_busy3", this.auth_headers);
118
119 this._request();
120 },
121
122 _primaryArr: function(map) {
123 var arr = Object.keys(map);
124 arr.sort();
125 return arr;
126 },
127
128 _primaryMap: function(tags, dims, tasks) {
129 tags = (tags && tags.tasks_tags) || [];
130 dims = (dims && dims.bots_dimensions) || [];
131 tasks = tasks || [];
132 var map = {};
133 // We combine all the tags reported by the tags endpoint, all known
134 // dimensions from the dimensions endpoint, and the tags seen in the
135 // returned tasks, just in case they didn't show up in the first two.
136 // This way a user can filter by what the data actually has and can
137 // discover new tags to filter by.
138 tags.forEach(function(t) {
139 if (!map[t.key]) {
140 map[t.key] = {};
141 }
142 var values = t.value || [];
143 values.forEach(function(v) {
144 map[t.key][v] = true;
145 })
146 });
147
148 dims.forEach(function(d) {
149 var vals = d.value;
150 if (!map[d.key]) {
151 map[d.key] = {};
152 }
153 vals.forEach(function(v) {
154 map[d.key][v] = true;
155 })
156 });
157
158 tasks.forEach(function(t) {
159 Object.keys(t.tagMap).forEach(function(k) {
160 var v = t.tagMap[k];
161 if (!map[k]) {
162 map[k] = {};
163 }
164 map[k][v] = true;
165 });
166 });
167
168 // Turn the Map<Object,Map<Boolean>> into a Map<Object,Array<String>>
169 // with all of the aliases applied.
170 var pMap = {};
171 for (key in map) {
172 var values = Object.keys(map[key]);
173 if (swarming.alias.DIMENSIONS_WITH_ALIASES.indexOf(key) === -1) {
174 pMap[key] = values;
175 } else if (key === "gpu") {
176 var gpus = [];
177 values.forEach(function(g){
178 var alias = swarming.alias.gpu(g);
179 if (alias !== "unknown") {
180 gpus.push(swarming.alias.apply(g, alias));
181 } else {
182 gpus.push(g);
183 }
184 }.bind(this));
185 pMap["gpu"] = gpus;
186 } else if (key === "device_type") {
187 var devs = [];
188 values.forEach(function(dt){
189 var alias = swarming.alias.android(dt);
190 if (alias !== "unknown") {
191 devs.push(swarming.alias.apply(dt, alias));
192 } else {
193 devs.push(dt);
194 }
195 }.bind(this));
196 pMap["device_type"] = devs;
197 } else {
198 console.log("Unknown alias type: ", d);
199 }
86 } 200 }
201
202 // Add some options that might not show up.
203 pMap["android_devices"].push("0");
204 pMap["device_os"].push("none");
205 pMap["device_type"].push("none");
206 pMap["user"].push("none");
207
208 // Custom filter options
209 pMap["name"] = [];
210 pMap["state"] = ["PENDING", "RUNNING", "PENDING_RUNNING", "COMPLETED",
211 "COMPLETED_SUCCESS","COMPLETED_FAILURE", "EXPIRED", "TIMED_OUT",
212 "BOT_DIED", "CANCELED", "ALL", "DEDUPED"];
213 pMap["abandoned_ts"] = [];
214 pMap["completed_ts"] = [];
215 pMap["costs_usd"] = [];
216 pMap["created_ts"] = [];
217 pMap["deduped_from"] = [];
218 pMap["duration"] = [];
219 pMap["modified_ts"] = [];
220 pMap["server_versions"] = [];
221 pMap["started_ts"] = [];
222
223 return pMap;
87 }, 224 },
88 signIn: function(){ 225
89 // Auto on iron-ajax means to automatically re-make the request if 226 _request: function() {
90 // the url or the query params change. Auto does not trigger if the 227 // wait until the user has logged in before requesting this.
91 // [auth] headers change, so we wait until the user is signed in 228 if (!this.auth_headers) {
92 // before making any requests. 229 return;
93 this.$.tasklist.auto = true; 230 }
231 this._getJsonAsync("_list", "/_ah/api/swarming/v1/tasks/list",
232 "_busy1", this.auth_headers, this.query_params);
94 }, 233 },
95 234
96 _tasks: function() { 235 _tasks: function() {
97 if (!this._list || !this._list.items) { 236 if (!this._list || !this._list.items) {
98 return []; 237 return [];
99 } 238 }
100 // Do any preprocessing here 239 // Do any preprocessing here
240 this._list.items.forEach(function(t) {
241 var tagMap = {};
242 t.tags.forEach(function(tag) {
243 var split = tag.split(":", 1)
244 var key = split[0];
245 var rest = tag.substring(key.length + 1);
246 tagMap[key] = rest;
247 });
248 t.tagMap = tagMap;
249 });
101 return this._list.items; 250 return this._list.items;
102 } 251 }
103 }); 252 });
104 })(); 253 })();
105 </script> 254 </script>
106 </dom-module> 255 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698