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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/elements/res/imp/botlist/bot-list-shared.html
diff --git a/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html b/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html
deleted file mode 100644
index 5a4bb89cc0a718e30ecb8f4b82f470f0850f5097..0000000000000000000000000000000000000000
--- a/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html
+++ /dev/null
@@ -1,179 +0,0 @@
-<!--
- 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/swarming-app.html">
-<script>
- (function(){
- var ANDROID_ALIASES = {
- "bullhead": "Nexus 5X",
- "flo": "Nexus 7 (2013)",
- "flounder": "Nexus 9",
- "foster": "NVIDIA Shield",
- "fugu": "Nexus Player",
- "grouper": "Nexus 7 (2012)",
- "hammerhead": "Nexus 5",
- "m0": "Galaxy S3",
- "mako": "Nexus 4",
- "manta": "Nexus 10",
- "shamu": "Nexus 6",
- "sprout": "Android One",
- };
- // 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";
-
- var GPU_ALIASES = {
- "1002": "AMD",
- "1002:6779": "AMD Radeon HD 6450/7450/8450",
- "1002:6821": "AMD Radeon HD 8870M",
- "1002:683d": "AMD Radeon HD 7770/8760",
- "1002:9830": "AMD Radeon HD 8400",
- "102b": "Matrox",
- "102b:0522": "Matrox MGA G200e",
- "102b:0532": "Matrox MGA G200eW",
- "102b:0534": "Matrox G200eR2",
- "10de": "NVIDIA",
- "10de:08a4": "NVIDIA GeForce 320M",
- "10de:08aa": "NVIDIA GeForce 320M",
- "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition",
- "10de:104a": "NVIDIA GeForce GT 610",
- "10de:11c0": "NVIDIA GeForce GTX 660",
- "10de:1244": "NVIDIA GeForce GTX 550 Ti",
- "10de:1401": "NVIDIA GeForce GTX 960",
- "8086": "Intel",
- "8086:0412": "Intel Haswell Integrated",
- "8086:041a": "Intel Xeon Integrated",
- "8086:0a2e": "Intel Haswell Integrated",
- "8086:0d26": "Intel Crystal Well Integrated",
- "8086:22b1": "Intel Braswell Integrated",
- }
-
- // For consistency, all aliases are displayed like:
- // Nexus 5X (bullhead)
- // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
- var ALIAS_REGEXP = /.+ \((.*)\)/;
-
- // This behavior wraps up all the shared bot-list functionality by
- // extending SwarmingBehaviors.SwarmingBehavior
- SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.SwarmingBehavior, {
-
- properties: {
- DIMENSIONS_WITH_ALIASES: {
- type: Array,
- value: function(){
- return ["device_type", "gpu"];
- },
- },
- 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"];
- }
- },
- },
-
- _androidAlias: function(dt) {
- return ANDROID_ALIASES[dt] || UNKNOWN;
- },
-
- // _applyAlias is the consistent way to modify a string to show its alias.
- _applyAlias: function(orig, alias) {
- return alias +" ("+orig+")";
- },
-
- // _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;
- },
-
- _gpuAlias: function(gpu) {
- return GPU_ALIASES[gpu] || UNKNOWN;
- },
-
- // _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";
- },
-
- // _unalias will return the base dimension/state with its alias removed
- // if it had one. This is handy for sorting and filtering.
- _unalias: function(str) {
- var match = ALIAS_REGEXP.exec(str);
- if (match) {
- return match[1];
- }
- return str;
- },
- }];
- })()
-</script>

Powered by Google App Engine
This is Rietveld 408576698