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

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-shared.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/swarming-app.html">
14 <script>
15 (function(){
16 var ANDROID_ALIASES = {
17 "bullhead": "Nexus 5X",
18 "flo": "Nexus 7 (2013)",
19 "flounder": "Nexus 9",
20 "foster": "NVIDIA Shield",
21 "fugu": "Nexus Player",
22 "grouper": "Nexus 7 (2012)",
23 "hammerhead": "Nexus 5",
24 "m0": "Galaxy S3",
25 "mako": "Nexus 4",
26 "manta": "Nexus 10",
27 "shamu": "Nexus 6",
28 "sprout": "Android One",
29 };
30 // Taken from http://developer.android.com/reference/android/os/BatteryManag er.html
31 var BATTERY_HEALTH_UNKNOWN = 1;
32 var BATTERY_HEALTH_GOOD = 2;
33 var BATTERY_STATUS_CHARGING = 2;
34
35 var UNAUTHENTICATED = "unauthenticated";
36 var AVAILABLE = "available";
37 var UNKNOWN = "unknown";
38
39 var GPU_ALIASES = {
40 "1002": "AMD",
41 "1002:6779": "AMD Radeon HD 6450/7450/8450",
42 "1002:6821": "AMD Radeon HD 8870M",
43 "1002:683d": "AMD Radeon HD 7770/8760",
44 "1002:9830": "AMD Radeon HD 8400",
45 "102b": "Matrox",
46 "102b:0522": "Matrox MGA G200e",
47 "102b:0532": "Matrox MGA G200eW",
48 "102b:0534": "Matrox G200eR2",
49 "10de": "NVIDIA",
50 "10de:08a4": "NVIDIA GeForce 320M",
51 "10de:08aa": "NVIDIA GeForce 320M",
52 "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition",
53 "10de:104a": "NVIDIA GeForce GT 610",
54 "10de:11c0": "NVIDIA GeForce GTX 660",
55 "10de:1244": "NVIDIA GeForce GTX 550 Ti",
56 "10de:1401": "NVIDIA GeForce GTX 960",
57 "8086": "Intel",
58 "8086:0412": "Intel Haswell Integrated",
59 "8086:041a": "Intel Xeon Integrated",
60 "8086:0a2e": "Intel Haswell Integrated",
61 "8086:0d26": "Intel Crystal Well Integrated",
62 "8086:22b1": "Intel Braswell Integrated",
63 }
64
65 // For consistency, all aliases are displayed like:
66 // Nexus 5X (bullhead)
67 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
68 var ALIAS_REGEXP = /.+ \((.*)\)/;
69
70 // This behavior wraps up all the shared bot-list functionality by
71 // extending SwarmingBehaviors.SwarmingBehavior
72 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.SwarmingBehavior, {
73
74 properties: {
75 DIMENSIONS_WITH_ALIASES: {
76 type: Array,
77 value: function(){
78 return ["device_type", "gpu"];
79 },
80 },
81 BOT_PROPERTIES: {
82 type: Array,
83 value: function() {
84 // TODO(kjlubick): Add more of these things from state, as they
85 // needed/useful/requested.
86 return ["disk_space", "task", "status"];
87 }
88 },
89 },
90
91 _androidAlias: function(dt) {
92 return ANDROID_ALIASES[dt] || UNKNOWN;
93 },
94
95 // _applyAlias is the consistent way to modify a string to show its alias.
96 _applyAlias: function(orig, alias) {
97 return alias +" ("+orig+")";
98 },
99
100 // _attribute looks first in dimension and then in state for the
101 // specified attribute. This will always return an array. If there is
102 // no matching attribute, ["unknown"] will be returned.
103 _attribute: function(bot, attr, none) {
104 none = none || UNKNOWN;
105 return this._dimension(bot, attr) || this._state(bot, attr) || [none];
106 },
107
108 _devices: function(bot) {
109 var devices = [];
110 var d = (bot && bot.state && bot.state.devices) || {};
111 // state.devices is like {Serial:Object}, so we need to keep the serial
112 for (key in d) {
113 var o = d[key];
114 o.serial = key;
115 o.okay = (o.state === AVAILABLE);
116 // It is easier to assume all devices on a bot are of the same type
117 // than to pick through the (incomplete) device state and find it.
118 o.device_type = this._attribute(bot, "device_type")[0];
119 devices.push(o);
120 }
121 return devices;
122 },
123
124 // _deviceType returns the codename of a given Android device.
125 _deviceType: function(device) {
126 return device.device_type.toLowerCase();
127 },
128
129 // _dimension returns the given dimension of a bot. If it is defined, it
130 // is an array of strings.
131 _dimension: function(bot, dim) {
132 if (!bot || !bot.dimensions || !dim) {
133 return undefined;
134 }
135 for (var i = 0; i < bot.dimensions.length; i++) {
136 if (bot.dimensions[i].key === dim) {
137 return bot.dimensions[i].value;
138 }
139 }
140 return undefined;
141 },
142
143 _gpuAlias: function(gpu) {
144 return GPU_ALIASES[gpu] || UNKNOWN;
145 },
146
147 // _state returns the requested attribute from a bot's state.
148 // For consistency with _dimension, if the attribute is not an array,
149 // it is put as the only element in an array.
150 _state: function(bot, attr) {
151 if (!bot || !bot.state || !bot.state[attr]) {
152 return undefined
153 }
154 var state = bot.state[attr];
155 if (Array.isArray(state)) {
156 return state;
157 }
158 return [state];
159 },
160
161 _taskId: function(bot) {
162 if (bot && bot.task_id) {
163 return bot.task_id;
164 }
165 return "idle";
166 },
167
168 // _unalias will return the base dimension/state with its alias removed
169 // if it had one. This is handy for sorting and filtering.
170 _unalias: function(str) {
171 var match = ALIAS_REGEXP.exec(str);
172 if (match) {
173 return match[1];
174 }
175 return str;
176 },
177 }];
178 })()
179 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698