| 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-page-data> | 9 <bot-page-data> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 (function(){ | 51 (function(){ |
| 52 // Time to wait before requesting a new bot. This is to allow a user to | 52 // Time to wait before requesting a new bot. This is to allow a user to |
| 53 // type in a name and not have it make one set of requests for each | 53 // type in a name and not have it make one set of requests for each |
| 54 // keystroke. | 54 // keystroke. |
| 55 var BOT_ID_DEBOUNCE_MS = 400; | 55 var BOT_ID_DEBOUNCE_MS = 400; |
| 56 var lastRequest; | 56 var lastRequest; |
| 57 | 57 |
| 58 var BOT_TIMES = ["first_seen_ts", "last_seen_ts", "lease_expiration_ts"]; | 58 var BOT_TIMES = ["first_seen_ts", "last_seen_ts", "lease_expiration_ts"]; |
| 59 var TASK_TIMES = ["started_ts", "completed_ts", "abandoned_ts", "modified_ts
"]; | 59 var TASK_TIMES = ["started_ts", "completed_ts", "abandoned_ts", "modified_ts
"]; |
| 60 | 60 |
| 61 var timezone; | |
| 62 function formatDate(date) { | |
| 63 if (!timezone) { | |
| 64 // Date.toString() looks like "Mon Aug 29 2016 09:03:41 GMT-0400 (EDT)" | |
| 65 // we want to extract the time zone part and append it to the | |
| 66 // locale time. | |
| 67 var str = date.toString(); | |
| 68 timezone = str.substring(str.indexOf("(")); | |
| 69 } | |
| 70 return date.toLocaleString() + " " + timezone; | |
| 71 } | |
| 72 | |
| 73 Polymer({ | 61 Polymer({ |
| 74 is: 'bot-page-data', | 62 is: 'bot-page-data', |
| 75 | 63 |
| 76 behaviors: [ | 64 behaviors: [ |
| 77 SwarmingBehaviors.BotPageBehavior, | 65 SwarmingBehaviors.BotPageBehavior, |
| 78 ], | 66 ], |
| 79 | 67 |
| 80 properties: { | 68 properties: { |
| 81 // inputs | 69 // inputs |
| 82 auth_headers: { | 70 auth_headers: { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 bot.dimensions = bot.dimensions || []; | 165 bot.dimensions = bot.dimensions || []; |
| 178 bot.dimensions.forEach(function(dim) { | 166 bot.dimensions.forEach(function(dim) { |
| 179 if (swarming.alias.DIMENSIONS_WITH_ALIASES.indexOf(dim.key) !== -1) { | 167 if (swarming.alias.DIMENSIONS_WITH_ALIASES.indexOf(dim.key) !== -1) { |
| 180 dim.value.forEach(function(value, i){ | 168 dim.value.forEach(function(value, i){ |
| 181 dim.value[i] = swarming.alias.apply(value, dim.key); | 169 dim.value[i] = swarming.alias.apply(value, dim.key); |
| 182 }); | 170 }); |
| 183 } | 171 } |
| 184 }); | 172 }); |
| 185 | 173 |
| 186 BOT_TIMES.forEach(function(time) { | 174 BOT_TIMES.forEach(function(time) { |
| 187 if (bot[time]) { | 175 swarming.sanitizeAndHumanizeTime(bot, time); |
| 188 bot[time] = new Date(bot[time]); | |
| 189 bot["human_"+time] = formatDate(bot[time]); | |
| 190 } | |
| 191 }); | 176 }); |
| 192 return bot; | 177 return bot; |
| 193 }, | 178 }, |
| 194 | 179 |
| 195 parseEvents: function(events) { | 180 parseEvents: function(events) { |
| 196 if (!events || !events.items) { | 181 if (!events || !events.items) { |
| 197 return []; | 182 return []; |
| 198 } | 183 } |
| 199 var events = events.items; | 184 var events = events.items; |
| 200 events.forEach(function(event){ | 185 events.forEach(function(event){ |
| 201 // Do any preprocessing here | 186 // Do any preprocessing here |
| 202 if (event.ts) { | 187 swarming.sanitizeAndHumanizeTime(event, "ts"); |
| 203 event.ts = new Date(event.ts); | |
| 204 event.human_ts = formatDate(event.ts); | |
| 205 } | |
| 206 }); | 188 }); |
| 207 | 189 |
| 208 // Sort the most recent events first. | 190 // Sort the most recent events first. |
| 209 events.sort(function(a,b) { | 191 events.sort(function(a,b) { |
| 210 return b.ts - a.ts; | 192 return b.ts - a.ts; |
| 211 }); | 193 }); |
| 212 | 194 |
| 213 return events; | 195 return events; |
| 214 }, | 196 }, |
| 215 | 197 |
| 216 parseTasks: function(tasks) { | 198 parseTasks: function(tasks) { |
| 217 if (!tasks || !tasks.items) { | 199 if (!tasks || !tasks.items) { |
| 218 return []; | 200 return []; |
| 219 } | 201 } |
| 220 var tasks = tasks.items; | 202 var tasks = tasks.items; |
| 221 | 203 |
| 222 tasks.forEach(function(task){ | 204 tasks.forEach(function(task){ |
| 223 // Do any preprocessing here | 205 // Do any preprocessing here |
| 224 TASK_TIMES.forEach(function(time) { | 206 TASK_TIMES.forEach(function(time) { |
| 225 if (task[time]) { | 207 swarming.sanitizeAndHumanizeTime(task, time); |
| 226 task[time] = new Date(task[time]); | |
| 227 task["human_"+time] = formatDate(task[time]); | |
| 228 } | |
| 229 }); | 208 }); |
| 230 | 209 |
| 231 if (task.duration) { | 210 if (task.duration) { |
| 232 task.human_duration = this._humanDuration(task.duration); | 211 task.human_duration = this._humanDuration(task.duration); |
| 233 } else { | 212 } else { |
| 234 var end = task.completed_ts || task.abandoned_ts || task.modified_ts
|| new Date(); | 213 var end = task.completed_ts || task.abandoned_ts || task.modified_ts
|| new Date(); |
| 235 task.human_duration = this._timeDiffExact(task.started_ts, end); | 214 task.human_duration = this._timeDiffExact(task.started_ts, end); |
| 236 task.duration = (end.getTime() - task.started_ts) / 1000; | 215 task.duration = (end.getTime() - task.started_ts) / 1000; |
| 237 } | 216 } |
| 238 | 217 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 252 return b.started_ts - a.started_ts; | 231 return b.started_ts - a.started_ts; |
| 253 }); | 232 }); |
| 254 | 233 |
| 255 return tasks; | 234 return tasks; |
| 256 } | 235 } |
| 257 | 236 |
| 258 }); | 237 }); |
| 259 })(); | 238 })(); |
| 260 </script> | 239 </script> |
| 261 </dom-module> | 240 </dom-module> |
| OLD | NEW |