Chromium Code Reviews| 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 It contains the definition of the following Behaviors: | 6 It contains the definition of the following Behaviors: |
| 7 | 7 |
| 8 SwarmingBehaviors.CommonBehavior | 8 SwarmingBehaviors.CommonBehavior |
| 9 | 9 |
| 10 To use it, include | 10 To use it, include |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 SwarmingBehaviors.CommonBehavior = { | 23 SwarmingBehaviors.CommonBehavior = { |
| 24 | 24 |
| 25 _botLink: function(bot_id) { | 25 _botLink: function(bot_id) { |
| 26 if (!bot_id) { | 26 if (!bot_id) { |
| 27 return undefined; | 27 return undefined; |
| 28 } | 28 } |
| 29 return "/bot?id=" + bot_id; | 29 return "/bot?id=" + bot_id; |
| 30 }, | 30 }, |
| 31 | 31 |
| 32 // Create a link to a bot list with the preloaded filters and columns. | 32 // Create a link to a bot list with the preloaded filters and columns. |
| 33 // filters should be an array of {key:String, value:String} and | 33 // filters should be an array of {key:String, value:String} or an array |
|
jcgregorio
2016/12/06 18:51:55
Document arg params like you did in task-list-data
kjlubick
2016/12/06 20:05:27
Done.
| |
| 34 // of {key:String, value:Array<String>} or an array of Strings | |
| 35 // of Strings, where the Strings are valid filters (e.g. "foo:bar") and | |
|
stephana
2016/12/06 18:43:39
typo: "array of Strings of Strings"
kjlubick
2016/12/06 18:50:32
Done.
| |
| 34 // columns should be an array of Strings. | 36 // columns should be an array of Strings. |
| 35 _botListLink: function(filters, columns) { | 37 _botListLink: function(filters, columns) { |
| 36 filters = filters || []; | 38 filters = filters || []; |
| 37 columns = columns || []; | 39 columns = columns || []; |
| 38 var fArr = []; | 40 var fArr = []; |
| 39 filters.forEach(function(f){ | 41 filters.forEach(function(f){ |
| 40 fArr.push(f.key + ":" + f.value); | 42 if (f.key && f.value) { |
| 43 if (Array.isArray(f.value)) { | |
| 44 f.value.forEach(function(v) { | |
| 45 fArr.push(f.key + ":" + v); | |
| 46 }); | |
| 47 } else { | |
| 48 fArr.push(f.key + ":" + f.value); | |
| 49 } | |
| 50 } else { | |
| 51 fArr.push(f); | |
| 52 } | |
| 41 }); | 53 }); |
| 42 var obj = { | 54 var obj = { |
| 43 f: fArr, | 55 f: fArr, |
| 44 c: columns, | 56 c: columns, |
| 45 } | 57 } |
| 46 return "/botlist?" + sk.query.fromParamSet(obj); | 58 return "/botlist?" + sk.query.fromParamSet(obj); |
| 47 }, | 59 }, |
| 48 | 60 |
| 49 // Create a link to a bot in Google Cloud Console. Cloud console will try | 61 // Create a link to a bot in Google Cloud Console. Cloud console will try |
| 50 // to find the bot in the last project the user was logged in as, which | 62 // to find the bot in the last project the user was logged in as, which |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // task abcefgh0 is the "canonical" task id. The first try has the id | 187 // task abcefgh0 is the "canonical" task id. The first try has the id |
| 176 // abcefgh1. If there is a second (transparent retry), it will be | 188 // abcefgh1. If there is a second (transparent retry), it will be |
| 177 // abcefgh2. We almost always want to link to the canonical one, | 189 // abcefgh2. We almost always want to link to the canonical one, |
| 178 // because the milo output (if any) will only be generated for | 190 // because the milo output (if any) will only be generated for |
| 179 // abcefgh0, not abcefgh1 or abcefgh2. | 191 // abcefgh0, not abcefgh1 or abcefgh2. |
| 180 taskId = taskId.substring(0, taskId.length - 1) + "0"; | 192 taskId = taskId.substring(0, taskId.length - 1) + "0"; |
| 181 } | 193 } |
| 182 return "/task?id=" + taskId; | 194 return "/task?id=" + taskId; |
| 183 }, | 195 }, |
| 184 | 196 |
| 197 // Create a link to a task list with the preloaded filters and columns. | |
| 198 // filters should be an array of {key:String, value:String} or an array | |
| 199 // of Strings, where the Strings are valid filters (e.g. "foo:bar") and | |
| 200 // columns should be an array of Strings. | |
| 201 _taskListLink: function(filters, columns) { | |
| 202 filters = filters || []; | |
| 203 columns = columns || []; | |
| 204 var fArr = []; | |
| 205 filters.forEach(function(f){ | |
| 206 if (f.key && f.value) { | |
| 207 fArr.push(f.key + ":" + f.value); | |
| 208 } else { | |
| 209 fArr.push(f); | |
| 210 } | |
| 211 }); | |
| 212 var obj = { | |
| 213 f: fArr, | |
| 214 c: columns, | |
| 215 } | |
| 216 return "/tasklist?" + sk.query.fromParamSet(obj); | |
| 217 }, | |
| 218 | |
| 185 // _timeDiffApprox returns the approximate difference between now and | 219 // _timeDiffApprox returns the approximate difference between now and |
| 186 // the specified date. | 220 // the specified date. |
| 187 _timeDiffApprox: function(date){ | 221 _timeDiffApprox: function(date){ |
| 188 if (!date) { | 222 if (!date) { |
| 189 return "eons"; | 223 return "eons"; |
| 190 } | 224 } |
| 191 return sk.human.diffDate(date.getTime()); | 225 return sk.human.diffDate(date.getTime()); |
| 192 }, | 226 }, |
| 193 | 227 |
| 194 // timeDiffExact returns the exact difference between the two specified | 228 // timeDiffExact returns the exact difference between the two specified |
| 195 // dates. E.g. 2d 22h 22m 28s ago If a second date is not provided, | 229 // dates. E.g. 2d 22h 22m 28s ago If a second date is not provided, |
| 196 // now is used. | 230 // now is used. |
| 197 _timeDiffExact: function(first, second){ | 231 _timeDiffExact: function(first, second){ |
| 198 if (!first) { | 232 if (!first) { |
| 199 return "eons"; | 233 return "eons"; |
| 200 } | 234 } |
| 201 if (!second) { | 235 if (!second) { |
| 202 second = new Date(); | 236 second = new Date(); |
| 203 } | 237 } |
| 204 return this._humanDuration((second.getTime() - first.getTime())/1000); | 238 return this._humanDuration((second.getTime() - first.getTime())/1000); |
| 205 }, | 239 }, |
| 206 | 240 |
| 207 _truthy: function(a){ | 241 _truthy: function(a){ |
| 208 return !!a; | 242 return !!a; |
| 209 } | 243 } |
| 210 }; | 244 }; |
| 211 })(); | 245 })(); |
| 212 </script> | 246 </script> |
| OLD | NEW |