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

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-shared.html

Issue 2241413002: Refactor out reusable pieces from new Botlist (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address comments 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
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/swarming-app.html">
13 <script> 14 <script>
14
15 window.SwarmingBehaviors = window.SwarmingBehaviors || {};
16 (function(){ 15 (function(){
17 var ANDROID_ALIASES = { 16 var ANDROID_ALIASES = {
18 "bullhead": "Nexus 5X", 17 "bullhead": "Nexus 5X",
19 "flo": "Nexus 7 (2013)", 18 "flo": "Nexus 7 (2013)",
20 "flounder": "Nexus 9", 19 "flounder": "Nexus 9",
21 "foster": "NVIDIA Shield", 20 "foster": "NVIDIA Shield",
22 "fugu": "Nexus Player", 21 "fugu": "Nexus Player",
23 "grouper": "Nexus 7 (2012)", 22 "grouper": "Nexus 7 (2012)",
24 "hammerhead": "Nexus 5", 23 "hammerhead": "Nexus 5",
25 "m0": "Galaxy S3", 24 "m0": "Galaxy S3",
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 "8086:0a2e": "Intel Haswell Integrated", 60 "8086:0a2e": "Intel Haswell Integrated",
62 "8086:0d26": "Intel Crystal Well Integrated", 61 "8086:0d26": "Intel Crystal Well Integrated",
63 "8086:22b1": "Intel Braswell Integrated", 62 "8086:22b1": "Intel Braswell Integrated",
64 } 63 }
65 64
66 // For consistency, all aliases are displayed like: 65 // For consistency, all aliases are displayed like:
67 // Nexus 5X (bullhead) 66 // Nexus 5X (bullhead)
68 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1. 67 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
69 var ALIAS_REGEXP = /.+ \((.*)\)/; 68 var ALIAS_REGEXP = /.+ \((.*)\)/;
70 69
71 // This behavior wraps up all the shared bot-list functionality. 70 // This behavior wraps up all the shared bot-list functionality by
72 SwarmingBehaviors.BotListBehavior = { 71 // extending SwarmingBehaviors.SwarmingBehavior
72 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.SwarmingBehavior, {
73 73
74 properties: { 74 properties: {
75 DIMENSIONS_WITH_ALIASES: { 75 DIMENSIONS_WITH_ALIASES: {
76 type: Array, 76 type: Array,
77 value: function(){ 77 value: function(){
78 return ["device_type", "gpu"]; 78 return ["device_type", "gpu"];
79 }, 79 },
80 }, 80 },
81 BOT_PROPERTIES: { 81 BOT_PROPERTIES: {
82 type: Array, 82 type: Array,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return bot.dimensions[i].value; 137 return bot.dimensions[i].value;
138 } 138 }
139 } 139 }
140 return undefined; 140 return undefined;
141 }, 141 },
142 142
143 _gpuAlias: function(gpu) { 143 _gpuAlias: function(gpu) {
144 return GPU_ALIASES[gpu] || UNKNOWN; 144 return GPU_ALIASES[gpu] || UNKNOWN;
145 }, 145 },
146 146
147 _not: function(a) {
148 return !a;
149 },
150
151 _or: function() {
152 var result = false;
153 // can't use .foreach, as arguments isn't really a function.
154 for (var i = 0; i < arguments.length; i++) {
155 result = result || arguments[i];
156 }
157 return result;
158 },
159
160 // _state returns the requested attribute from a bot's state. 147 // _state returns the requested attribute from a bot's state.
161 // For consistency with _dimension, if the attribute is not an array, 148 // For consistency with _dimension, if the attribute is not an array,
162 // it is put as the only element in an array. 149 // it is put as the only element in an array.
163 _state: function(bot, attr) { 150 _state: function(bot, attr) {
164 if (!bot || !bot.state || !bot.state[attr]) { 151 if (!bot || !bot.state || !bot.state[attr]) {
165 return undefined 152 return undefined
166 } 153 }
167 var state = bot.state[attr]; 154 var state = bot.state[attr];
168 if (Array.isArray(state)) { 155 if (Array.isArray(state)) {
169 return state; 156 return state;
(...skipping 10 matching lines...) Expand all
180 167
181 // _unalias will return the base dimension/state with its alias removed 168 // _unalias will return the base dimension/state with its alias removed
182 // if it had one. This is handy for sorting and filtering. 169 // if it had one. This is handy for sorting and filtering.
183 _unalias: function(str) { 170 _unalias: function(str) {
184 var match = ALIAS_REGEXP.exec(str); 171 var match = ALIAS_REGEXP.exec(str);
185 if (match) { 172 if (match) {
186 return match[1]; 173 return match[1];
187 } 174 }
188 return str; 175 return str;
189 }, 176 },
190 } 177 }];
191 })() 178 })()
192 </script> 179 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698