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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/elements/res/js/alias.js
diff --git a/appengine/swarming/elements/res/js/alias.js b/appengine/swarming/elements/res/js/alias.js
index f07faaa79ee013779b63ccdaa14a338061064196..dbe48cb19196dbb3512b3d2c34896f127b860aab 100644
--- a/appengine/swarming/elements/res/js/alias.js
+++ b/appengine/swarming/elements/res/js/alias.js
@@ -2,6 +2,8 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
+// TODO(kjlubick): add tests for this code
+
this.swarming = this.swarming || {};
this.swarming.alias = this.swarming.alias || (function(){
var ANDROID_ALIASES = {
@@ -60,9 +62,22 @@ this.swarming.alias = this.swarming.alias || (function(){
return ANDROID_ALIASES[dt] || UNKNOWN;
};
- // alias.apply is the consistent way to modify a string to show its alias.
- alias.apply = function(orig, alias) {
- return alias +" ("+orig+")";
+ // alias.apply tries to alias the string "orig" based on what "type" it is.
+ // If type is in DIMENSIONS_WITH_ALIASES, the appropriate alias (e.g. gpu)
+ // is automatically applied. Otherwise, "type" is treated as the alias.
+ // If type is known, but there is no matching alias (e.g. for gpu: FOOBAR)
+ // the original will be returned.
+ alias.apply = function(orig, type) {
+ var aliaser = aliasMap[type];
+ if (!aliaser) {
+ // treat type as the actual alias
+ return type + " ("+orig+")";
+ }
+ var alias = aliaser(orig);
+ if (alias !== "unknown") {
+ return alias + " ("+orig+")";
+ }
+ return orig;
};
alias.gpu = function(gpu) {
@@ -79,5 +94,10 @@ this.swarming.alias = this.swarming.alias || (function(){
return str;
};
+ var aliasMap = {
+ "device_type": alias.android,
+ "gpu": alias.gpu,
+ }
+
return alias;
})();
« 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