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

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

Issue 2306103002: Add aliases to bot-page and refactor duplicated code (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@fix-buttons
Patch Set: rebase again Created 4 years, 3 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 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // TODO(kjlubick): add tests for this code
6
5 this.swarming = this.swarming || {}; 7 this.swarming = this.swarming || {};
6 this.swarming.alias = this.swarming.alias || (function(){ 8 this.swarming.alias = this.swarming.alias || (function(){
7 var ANDROID_ALIASES = { 9 var ANDROID_ALIASES = {
8 "bullhead": "Nexus 5X", 10 "bullhead": "Nexus 5X",
9 "flo": "Nexus 7 (2013)", 11 "flo": "Nexus 7 (2013)",
10 "flounder": "Nexus 9", 12 "flounder": "Nexus 9",
11 "foster": "NVIDIA Shield", 13 "foster": "NVIDIA Shield",
12 "fugu": "Nexus Player", 14 "fugu": "Nexus Player",
13 "grouper": "Nexus 7 (2012)", 15 "grouper": "Nexus 7 (2012)",
14 "hammerhead": "Nexus 5", 16 "hammerhead": "Nexus 5",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 var ALIAS_REGEXP = /.+ \((.*)\)/; 55 var ALIAS_REGEXP = /.+ \((.*)\)/;
54 56
55 var alias = {}; 57 var alias = {};
56 58
57 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu"]; 59 alias.DIMENSIONS_WITH_ALIASES = ["device_type", "gpu"];
58 60
59 alias.android = function(dt) { 61 alias.android = function(dt) {
60 return ANDROID_ALIASES[dt] || UNKNOWN; 62 return ANDROID_ALIASES[dt] || UNKNOWN;
61 }; 63 };
62 64
63 // alias.apply is the consistent way to modify a string to show its alias. 65 // alias.apply tries to alias the string "orig" based on what "type" it is.
64 alias.apply = function(orig, alias) { 66 // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu)
65 return alias +" ("+orig+")"; 67 // is automatically applied. Otherwise, "type" is treated as the alias.
68 // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR)
69 // the original will be returned.
70 alias.apply = function(orig, type) {
71 var aliaser = aliasMap[type];
72 if (!aliaser) {
73 // treat type as the actual alias
74 return type + " ("+orig+")";
75 }
76 var alias = aliaser(orig);
77 if (alias !== "unknown") {
78 return alias + " ("+orig+")";
79 }
80 return orig;
66 }; 81 };
67 82
68 alias.gpu = function(gpu) { 83 alias.gpu = function(gpu) {
69 return GPU_ALIASES[gpu] || UNKNOWN; 84 return GPU_ALIASES[gpu] || UNKNOWN;
70 }; 85 };
71 86
72 // alias.unapply will return the base dimension/state with its alias removed 87 // alias.unapply will return the base dimension/state with its alias removed
73 // if it had one. This is handy for sorting and filtering. 88 // if it had one. This is handy for sorting and filtering.
74 alias.unapply = function(str) { 89 alias.unapply = function(str) {
75 var match = ALIAS_REGEXP.exec(str); 90 var match = ALIAS_REGEXP.exec(str);
76 if (match) { 91 if (match) {
77 return match[1]; 92 return match[1];
78 } 93 }
79 return str; 94 return str;
80 }; 95 };
81 96
97 var aliasMap = {
98 "device_type": alias.android,
99 "gpu": alias.gpu,
100 }
101
82 return alias; 102 return alias;
83 })(); 103 })();
OLDNEW
« no previous file with comments | « appengine/swarming/elements/res/imp/tasklist/task-list-data.html ('k') | appengine/swarming/elements/res/js/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698