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

Unified Diff: appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html

Issue 2269643002: Extract shared filters and aliasing code (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address nit Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html
diff --git a/appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html b/appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html
new file mode 100644
index 0000000000000000000000000000000000000000..1de27fc480db92a8a47673005d81840736f3f78b
--- /dev/null
+++ b/appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html
@@ -0,0 +1,106 @@
+<!--
+ Copyright 2016 The LUCI Authors. All rights reserved.
+ Use of this source code is governed under the Apache License, Version 2.0
+ that can be found in the LICENSE file.
+
+ window.SwarmingBehaviors.BotListBehavior contains any shared functions and
+ constants used by the bot-list and its sub-elements.
+
+ To use it, include
+ behaviors: [SwarmingBehaviors.BotListBehavior]
+ in the creation of your Polymer element.
+-->
+<link rel="import" href="/res/imp/common/common-behavior.html">
+<script>
+ (function(){
+ // Taken from http://developer.android.com/reference/android/os/BatteryManager.html
+ var BATTERY_HEALTH_UNKNOWN = 1;
+ var BATTERY_HEALTH_GOOD = 2;
+ var BATTERY_STATUS_CHARGING = 2;
+
+ var UNAUTHENTICATED = "unauthenticated";
+ var AVAILABLE = "available";
+ var UNKNOWN = "unknown";
+
+ // This behavior wraps up all the shared bot-list functionality by
+ // extending SwarmingBehaviors.CommonBehavior
+ SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.CommonBehavior, {
+
+ properties: {
+ BOT_PROPERTIES: {
+ type: Array,
+ value: function() {
+ // TODO(kjlubick): Add more of these things from state, as they
+ // needed/useful/requested.
+ return ["disk_space", "task", "status"];
+ }
+ },
+ },
+
+ // _attribute looks first in dimension and then in state for the
+ // specified attribute. This will always return an array. If there is
+ // no matching attribute, ["unknown"] will be returned.
+ _attribute: function(bot, attr, none) {
+ none = none || UNKNOWN;
+ return this._dimension(bot, attr) || this._state(bot, attr) || [none];
+ },
+
+ _devices: function(bot) {
+ var devices = [];
+ var d = (bot && bot.state && bot.state.devices) || {};
+ // state.devices is like {Serial:Object}, so we need to keep the serial
+ for (key in d) {
+ var o = d[key];
+ o.serial = key;
+ o.okay = (o.state === AVAILABLE);
+ // It is easier to assume all devices on a bot are of the same type
+ // than to pick through the (incomplete) device state and find it.
+ o.device_type = this._attribute(bot, "device_type")[0];
+ devices.push(o);
+ }
+ return devices;
+ },
+
+ // _deviceType returns the codename of a given Android device.
+ _deviceType: function(device) {
+ return device.device_type.toLowerCase();
+ },
+
+ // _dimension returns the given dimension of a bot. If it is defined, it
+ // is an array of strings.
+ _dimension: function(bot, dim) {
+ if (!bot || !bot.dimensions || !dim) {
+ return undefined;
+ }
+ for (var i = 0; i < bot.dimensions.length; i++) {
+ if (bot.dimensions[i].key === dim) {
+ return bot.dimensions[i].value;
+ }
+ }
+ return undefined;
+ },
+
+ // _state returns the requested attribute from a bot's state.
+ // For consistency with _dimension, if the attribute is not an array,
+ // it is put as the only element in an array.
+ _state: function(bot, attr) {
+ if (!bot || !bot.state || !bot.state[attr]) {
+ return undefined
+ }
+ var state = bot.state[attr];
+ if (Array.isArray(state)) {
+ return state;
+ }
+ return [state];
+ },
+
+ _taskId: function(bot) {
+ if (bot && bot.task_id) {
+ return bot.task_id;
+ }
+ return "idle";
+ },
+
+ }];
+ })()
+</script>

Powered by Google App Engine
This is Rietveld 408576698