| 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 window.SwarmingBehaviors.BotListBehavior contains any shared functions and | 6 window.SwarmingBehaviors.BotListBehavior contains any shared functions and |
| 7 constants used by the bot-list and its sub-elements. | 7 constants used by the bot-list and its sub-elements. |
| 8 | 8 |
| 9 To use it, include | 9 To use it, include |
| 10 behaviors: [SwarmingBehaviors.BotListBehavior] | 10 behaviors: [SwarmingBehaviors.BotListBehavior] |
| 11 in the creation of your Polymer element. | 11 in the creation of your Polymer element. |
| 12 --> | 12 --> |
| 13 <link rel="import" href="/res/imp/common/common-behavior.html"> | 13 <link rel="import" href="/res/imp/common/common-behavior.html"> |
| 14 <script> | 14 <script> |
| 15 (function(){ | 15 (function(){ |
| 16 // Taken from http://developer.android.com/reference/android/os/BatteryManag
er.html | |
| 17 var BATTERY_HEALTH_UNKNOWN = 1; | |
| 18 var BATTERY_HEALTH_GOOD = 2; | |
| 19 var BATTERY_STATUS_CHARGING = 2; | |
| 20 | |
| 21 var UNAUTHENTICATED = "unauthenticated"; | |
| 22 var AVAILABLE = "available"; | |
| 23 var UNKNOWN = "unknown"; | 16 var UNKNOWN = "unknown"; |
| 24 | 17 |
| 25 // This behavior wraps up all the shared bot-list functionality by | 18 // This behavior wraps up all the shared bot-list functionality by |
| 26 // extending SwarmingBehaviors.CommonBehavior | 19 // extending SwarmingBehaviors.CommonBehavior |
| 27 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.CommonBehavior, { | 20 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.CommonBehavior, { |
| 28 | 21 |
| 29 properties: { | 22 properties: { |
| 30 BOT_PROPERTIES: { | 23 BOT_PROPERTIES: { |
| 31 type: Array, | 24 type: Array, |
| 32 value: function() { | 25 value: function() { |
| 33 // TODO(kjlubick): Add more of these things from state, as they | 26 // TODO(kjlubick): Add more of these things from state, as they |
| 34 // needed/useful/requested. | 27 // needed/useful/requested. |
| 35 return ["disk_space", "task", "status"]; | 28 return ["disk_space", "task", "status", "version", "external_ip", "l
ast_seen", "first_seen", "battery_level", "battery_voltage", "battery_temperatur
e", "battery_status", "battery_health", "bot_temperature", "device_temperature"]
; |
| 36 } | 29 } |
| 37 }, | 30 }, |
| 38 }, | 31 }, |
| 39 | 32 |
| 40 // _attribute looks first in dimension and then in state for the | 33 // _attribute looks first in dimension and then in state for the |
| 41 // specified attribute. This will always return an array. If there is | 34 // specified attribute. This will always return an array. If there is |
| 42 // no matching attribute, ["unknown"] will be returned. | 35 // no matching attribute, ["unknown"] will be returned. |
| 43 _attribute: function(bot, attr, none) { | 36 _attribute: function(bot, attr, none) { |
| 44 none = none || UNKNOWN; | 37 none = none || UNKNOWN; |
| 45 return this._dimension(bot, attr) || this._state(bot, attr) || [none]; | 38 return this._dimension(bot, attr) || this._state(bot, attr) || [none]; |
| 46 }, | 39 }, |
| 47 | 40 |
| 48 _devices: function(bot) { | 41 _devices: function(bot) { |
| 49 var devices = []; | 42 return bot.state.devices; |
| 50 var d = (bot && bot.state && bot.state.devices) || {}; | |
| 51 // state.devices is like {Serial:Object}, so we need to keep the serial | |
| 52 for (key in d) { | |
| 53 var o = d[key]; | |
| 54 o.serial = key; | |
| 55 o.okay = (o.state === AVAILABLE); | |
| 56 // It is easier to assume all devices on a bot are of the same type | |
| 57 // than to pick through the (incomplete) device state and find it. | |
| 58 o.device_type = this._attribute(bot, "device_type")[0]; | |
| 59 devices.push(o); | |
| 60 } | |
| 61 return devices; | |
| 62 }, | 43 }, |
| 63 | 44 |
| 64 // _deviceType returns the codename of a given Android device. | 45 // _deviceType returns the codename of a given Android device. |
| 65 _deviceType: function(device) { | 46 _deviceType: function(device) { |
| 66 return device.device_type.toLowerCase(); | 47 return device.device_type.toLowerCase(); |
| 67 }, | 48 }, |
| 68 | 49 |
| 69 // _dimension returns the given dimension of a bot. If it is defined, it | 50 // _dimension returns the given dimension of a bot. If it is defined, it |
| 70 // is an array of strings. | 51 // is an array of strings. |
| 71 _dimension: function(bot, dim) { | 52 _dimension: function(bot, dim) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 97 _taskId: function(bot) { | 78 _taskId: function(bot) { |
| 98 if (bot && bot.task_id) { | 79 if (bot && bot.task_id) { |
| 99 return bot.task_id; | 80 return bot.task_id; |
| 100 } | 81 } |
| 101 return "idle"; | 82 return "idle"; |
| 102 }, | 83 }, |
| 103 | 84 |
| 104 }]; | 85 }]; |
| 105 })() | 86 })() |
| 106 </script> | 87 </script> |
| OLD | NEW |