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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file.
5
6 window.SwarmingBehaviors.BotListBehavior contains any shared functions and
7 constants used by the bot-list and its sub-elements.
8
9 To use it, include
10 behaviors: [SwarmingBehaviors.BotListBehavior]
11 in the creation of your Polymer element.
12 -->
13 <link rel="import" href="/res/imp/common/common-behavior.html">
14 <script>
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";
24
25 // This behavior wraps up all the shared bot-list functionality by
26 // extending SwarmingBehaviors.CommonBehavior
27 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.CommonBehavior, {
28
29 properties: {
30 BOT_PROPERTIES: {
31 type: Array,
32 value: function() {
33 // TODO(kjlubick): Add more of these things from state, as they
34 // needed/useful/requested.
35 return ["disk_space", "task", "status"];
36 }
37 },
38 },
39
40 // _attribute looks first in dimension and then in state for the
41 // specified attribute. This will always return an array. If there is
42 // no matching attribute, ["unknown"] will be returned.
43 _attribute: function(bot, attr, none) {
44 none = none || UNKNOWN;
45 return this._dimension(bot, attr) || this._state(bot, attr) || [none];
46 },
47
48 _devices: function(bot) {
49 var 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 },
63
64 // _deviceType returns the codename of a given Android device.
65 _deviceType: function(device) {
66 return device.device_type.toLowerCase();
67 },
68
69 // _dimension returns the given dimension of a bot. If it is defined, it
70 // is an array of strings.
71 _dimension: function(bot, dim) {
72 if (!bot || !bot.dimensions || !dim) {
73 return undefined;
74 }
75 for (var i = 0; i < bot.dimensions.length; i++) {
76 if (bot.dimensions[i].key === dim) {
77 return bot.dimensions[i].value;
78 }
79 }
80 return undefined;
81 },
82
83 // _state returns the requested attribute from a bot's state.
84 // For consistency with _dimension, if the attribute is not an array,
85 // it is put as the only element in an array.
86 _state: function(bot, attr) {
87 if (!bot || !bot.state || !bot.state[attr]) {
88 return undefined
89 }
90 var state = bot.state[attr];
91 if (Array.isArray(state)) {
92 return state;
93 }
94 return [state];
95 },
96
97 _taskId: function(bot) {
98 if (bot && bot.task_id) {
99 return bot.task_id;
100 }
101 return "idle";
102 },
103
104 }];
105 })()
106 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698