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

Side by Side Diff: appengine/swarming/elements/res/js/alias.js

Issue 2408743002: Move elements/ to ui/ (Closed)
Patch Set: rebase again Created 4 years, 2 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 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 // TODO(kjlubick): add tests for this code
6
7 this.swarming = this.swarming || {};
8 this.swarming.alias = this.swarming.alias || (function(){
9 var ANDROID_ALIASES = {
10 "angler": "Nexus 6p",
11 "bullhead": "Nexus 5X",
12 "flo": "Nexus 7 (2013)",
13 "flounder": "Nexus 9",
14 "foster": "NVIDIA Shield",
15 "fugu": "Nexus Player",
16 "grouper": "Nexus 7 (2012)",
17 "hammerhead": "Nexus 5",
18 "heroqlteatt": "Galaxy S7",
19 "m0": "Galaxy S3",
20 "mako": "Nexus 4",
21 "manta": "Nexus 10",
22 "shamu": "Nexus 6",
23 "sprout": "Android One",
24 };
25
26 var UNKNOWN = "unknown";
27
28 var GPU_ALIASES = {
29 "1002": "AMD",
30 "1002:6779": "AMD Radeon HD 6450/7450/8450",
31 "1002:6821": "AMD Radeon HD 8870M",
32 "1002:683d": "AMD Radeon HD 7770/8760",
33 "1002:9830": "AMD Radeon HD 8400",
34 "102b": "Matrox",
35 "102b:0522": "Matrox MGA G200e",
36 "102b:0532": "Matrox MGA G200eW",
37 "102b:0534": "Matrox G200eR2",
38 "10de": "NVIDIA",
39 "10de:08a4": "NVIDIA GeForce 320M",
40 "10de:08aa": "NVIDIA GeForce 320M",
41 "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition",
42 "10de:104a": "NVIDIA GeForce GT 610",
43 "10de:11c0": "NVIDIA GeForce GTX 660",
44 "10de:1244": "NVIDIA GeForce GTX 550 Ti",
45 "10de:1401": "NVIDIA GeForce GTX 960",
46 "8086": "Intel",
47 "8086:0412": "Intel Haswell Integrated",
48 "8086:041a": "Intel Xeon Integrated",
49 "8086:0a2e": "Intel Haswell Integrated",
50 "8086:0d26": "Intel Crystal Well Integrated",
51 "8086:22b1": "Intel Braswell Integrated",
52 }
53
54 // Taken from http://developer.android.com/reference/android/os/BatteryManager .html
55 var BATTERY_HEALTH_ALIASES = {
56 1: "Unknown",
57 2: "Good",
58 3: "Overheated",
59 4: "Dead",
60 5: "Over Voltage",
61 6: "Unspecified Failure",
62 7: "Too Cold",
63 }
64
65 var BATTERY_STATUS_ALIASES = {
66 1: "Unknown",
67 2: "Charging",
68 3: "Discharging",
69 4: "Not Charging",
70 5: "Full",
71 }
72
73 // For consistency, all aliases are displayed like:
74 // Nexus 5X (bullhead)
75 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
76 var ALIAS_REGEXP = /.+ \((.*)\)/;
77
78 var alias = {};
79
80 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu", "battery_health"];
81
82 alias.android = function(dt) {
83 return ANDROID_ALIASES[dt] || UNKNOWN;
84 };
85
86 alias.battery_health = function(bh) {
87 return BATTERY_HEALTH_ALIASES[bh] || UNKNOWN;
88 };
89
90 alias.battery_status = function(bs) {
91 return BATTERY_STATUS_ALIASES[bs] || UNKNOWN;
92 };
93
94 // alias.apply tries to alias the string "orig" based on what "type" it is.
95 // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu)
96 // is automatically applied. Otherwise, "type" is treated as the alias.
97 // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR)
98 // the original will be returned.
99 alias.apply = function(orig, type) {
100 var aliaser = aliasMap[type];
101 if (!aliaser) {
102 // treat type as the actual alias
103 return type + " ("+orig+")";
104 }
105 var alias = aliaser(orig);
106 if (alias !== UNKNOWN) {
107 return alias + " ("+orig+")";
108 }
109 return orig;
110 };
111
112 alias.has = function(type) {
113 return !!aliasMap[type];
114 };
115
116 alias.gpu = function(gpu) {
117 return GPU_ALIASES[gpu] || UNKNOWN;
118 };
119
120 // alias.unapply will return the base dimension/state with its alias removed
121 // if it had one. This is handy for sorting and filtering.
122 alias.unapply = function(str) {
123 var match = ALIAS_REGEXP.exec(str);
124 if (match) {
125 return match[1];
126 }
127 return str;
128 };
129
130 var aliasMap = {
131 "device_type": alias.android,
132 "gpu": alias.gpu,
133 "battery_health": alias.battery_health,
134 "battery_status": alias.battery_status,
135 }
136
137 return alias;
138 })();
OLDNEW
« no previous file with comments | « appengine/swarming/elements/res/imp/taskpage/task-page-demo.html ('k') | appengine/swarming/elements/res/js/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698