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

Unified Diff: appengine/swarming/elements/res/imp/common/common-behavior.html

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 side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/elements/res/imp/common/common-behavior.html
diff --git a/appengine/swarming/elements/res/imp/common/common-behavior.html b/appengine/swarming/elements/res/imp/common/common-behavior.html
deleted file mode 100644
index 1a7e506fb4b8e57566214d62f985af438e13d6e1..0000000000000000000000000000000000000000
--- a/appengine/swarming/elements/res/imp/common/common-behavior.html
+++ /dev/null
@@ -1,160 +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.
-
- It contains the definition of the following Behaviors:
-
- SwarmingBehaviors.CommonBehavior
-
- To use it, include
- behaviors: [SwarmingBehaviors.CommonBehavior]
- in the creation of any Polymer element.
-
- SwarmingBehaviors.CommonBehavior contains shared methods to ease
- templating, such as _or() and _not() as well as general utility methods
- such as _getJsonAsync.
- -->
-
-<script>
- window.SwarmingBehaviors = window.SwarmingBehaviors || {};
- (function(){
- // This behavior wraps up all the shared swarming functionality.
- SwarmingBehaviors.CommonBehavior = {
-
- _botLink: function(bot_id) {
- if (!bot_id) {
- return undefined;
- }
- return "/newui/bot?id=" + bot_id;
- },
-
- // Create a link to a bot list with the preloaded filters and columns.
- // filters should be an array of {key:String, value:String} and
- // columns should be an array of Strings.
- _botListLink: function(filters, columns) {
- filters = filters || [];
- columns = columns || [];
- var fArr = [];
- filters.forEach(function(f){
- fArr.push(f.key + ":" + f.value);
- });
- var obj = {
- f: fArr,
- c: columns,
- }
- return "/newui/botlist?" + sk.query.fromParamSet(obj);
- },
-
- // Create a link to a bot in Google Cloud Console. Cloud console will try
- // to find the bot in the last project the user was logged in as, which
- // is the best we can do atm.
- _cloudConsoleLink: function(zone, bot_id) {
- return `http://console.cloud.google.com/compute/instancesDetail/zones/${zone}/instances/${bot_id}`
- },
-
- // _getJsonAsync makes an XHR to a url, parses the response as JSON
- // and sticks the resulting object into the property with the name given
- // by "bindTo". If busy is defined, the property with that name will be
- // set to true while the request is in flight and false afterwards.
- // request headers (e.g. authentication) and query params will be used if
- // provided. Query params is an object like {String:Array<String>}. On
- // error, bindTo will be set to false. It is not set to undefined
- // because computed values in Polymer don't fire if a property is
- // undefined. Clients should check that bindTo is not falsey.
- // To avoid multiple requests clobering one another, an object _jsonAsync
- // is created on "this" to debounce requests - the most recent request
- // will win out.
- _getJsonAsync: function(bindTo, url, busy, headers, params) {
- if (!bindTo || !url || !busy) {
- console.log("Need at least a polymer element to bind to, a busy element, and a url");
- return;
- }
- this.set(busy, true);
- var now = new Date();
- this._jsonAsync = this._jsonAsync || {};
- this._jsonAsync[bindTo] = now;
- if (params) {
- url = url + "?" + sk.query.fromParamSet(params);
- }
- sk.request("GET", url, "", headers).then(JSON.parse).then(function(json){
- if (this._jsonAsync[bindTo] !== now) {
- console.log("ignoring result because a second request happened.");
- this.set(busy, false);
- return;
- }
- this.set(bindTo, json);
- this.set(busy, false);
- }.bind(this)).catch(function(reason){
- console.log("Reason for failure of request to " + url, reason);
-
- if (this._jsonAsync[bindTo] !== now) {
- console.log("ignoring failure because a second request happened.");
- this.set(busy, false);
- return;
- }
- this.set(bindTo, false);
- this.set(busy, false);
- }.bind(this));
- },
-
- _humanDuration: function(timeInSecs) {
- return sk.human.strDuration(timeInSecs) || "0s";
- },
-
- _not: function(a) {
- return !a;
- },
-
- _or: function() {
- var result = false;
- // can't use .foreach, as arguments isn't really an Array.
- for (var i = 0; i < arguments.length; i++) {
- result = result || arguments[i];
- }
- return result;
- },
-
- _taskLink: function(taskId, disableCanonicalID) {
- if (!taskId) {
- return undefined;
- }
- if (!disableCanonicalID) {
- // task abcefgh0 is the "canonical" task id. The first try has the id
- // abcefgh1. If there is a second (transparent retry), it will be
- // abcefgh2. We almost always want to link to the canonical one,
- // because the milo output (if any) will only be generated for
- // abcefgh0, not abcefgh1 or abcefgh2.
- taskId = taskId.substring(0, taskId.length - 1) + "0";
- }
- return "/newui/task?id=" + taskId;
- },
-
- // _timeDiffApprox returns the approximate difference between now and
- // the specified date.
- _timeDiffApprox: function(date){
- if (!date) {
- return "eons";
- }
- return sk.human.diffDate(date.getTime());
- },
-
- // timeDiffExact returns the exact difference between the two specified
- // dates. E.g. 2d 22h 22m 28s ago If a second date is not provided,
- // now is used.
- _timeDiffExact: function(first, second){
- if (!first) {
- return "eons";
- }
- if (!second) {
- second = new Date();
- }
- return this._humanDuration((second.getTime() - first.getTime())/1000);
- },
-
- _truthy: function(a){
- return !!a;
- }
- };
- })();
-</script>

Powered by Google App Engine
This is Rietveld 408576698