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

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

Issue 2338383002: Refactor prior to adding task-page (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: Tweak docs 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 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 It contains the definition of the following Behaviors: 6 It contains the definition of the following Behaviors:
7 7
8 SwarmingBehaviors.CommonBehavior 8 SwarmingBehaviors.CommonBehavior
9 9
10 To use it, include 10 To use it, include
11 behaviors: [SwarmingBehaviors.CommonBehavior] 11 behaviors: [SwarmingBehaviors.CommonBehavior]
12 in the creation of any Polymer element. 12 in the creation of any Polymer element.
13 13
14 SwarmingBehaviors.CommonBehavior contains shared methods to ease 14 SwarmingBehaviors.CommonBehavior contains shared methods to ease
15 templating, such as _or() and _not() as well as general utility methods 15 templating, such as _or() and _not() as well as general utility methods
16 such as _getJsonAsync. 16 such as _getJsonAsync.
17 --> 17 -->
18 18
19 <script> 19 <script>
20 window.SwarmingBehaviors = window.SwarmingBehaviors || {}; 20 window.SwarmingBehaviors = window.SwarmingBehaviors || {};
21 (function(){ 21 (function(){
22 // This behavior wraps up all the shared swarming functionality. 22 // This behavior wraps up all the shared swarming functionality.
23 SwarmingBehaviors.CommonBehavior = { 23 SwarmingBehaviors.CommonBehavior = {
24 24
25 _botLink: function(bot_id) {
26 if (!bot_id) {
27 return undefined;
28 }
29 return "/newui/bot?id=" + bot_id;
30 },
31
25 // _getJsonAsync makes an XHR to a url, parses the response as JSON 32 // _getJsonAsync makes an XHR to a url, parses the response as JSON
26 // and sticks the resulting object into the property with the name given 33 // and sticks the resulting object into the property with the name given
27 // by "bindTo". If busy is defined, the property with that name will be 34 // by "bindTo". If busy is defined, the property with that name will be
28 // set to true while the request is in flight and false afterwards. 35 // set to true while the request is in flight and false afterwards.
29 // request headers (e.g. authentication) and query params will be used if 36 // request headers (e.g. authentication) and query params will be used if
30 // provided. Query params is an object like {String:Array<String>}. On 37 // provided. Query params is an object like {String:Array<String>}. On
31 // error, bindTo will be set to false. It is not set to undefined 38 // error, bindTo will be set to false. It is not set to undefined
32 // because computed values in Polymer don't fire if a property is 39 // because computed values in Polymer don't fire if a property is
33 // undefined. Clients should check that bindTo is not falsey. 40 // undefined. Clients should check that bindTo is not falsey.
34 _getJsonAsync: function(bindTo, url, busy, headers, params) { 41 _getJsonAsync: function(bindTo, url, busy, headers, params) {
(...skipping 14 matching lines...) Expand all
49 } 56 }
50 }.bind(this)).catch(function(reason){ 57 }.bind(this)).catch(function(reason){
51 console.log("Reason for failure of request to " + url, reason); 58 console.log("Reason for failure of request to " + url, reason);
52 this.set(bindTo, false); 59 this.set(bindTo, false);
53 if (busy) { 60 if (busy) {
54 this.set(busy, false); 61 this.set(busy, false);
55 } 62 }
56 }.bind(this)); 63 }.bind(this));
57 }, 64 },
58 65
66 _humanDuration: function(timeInSecs) {
67 return sk.human.strDuration(timeInSecs) || "0s";
68 },
69
59 _not: function(a) { 70 _not: function(a) {
60 return !a; 71 return !a;
61 }, 72 },
62 73
63 _or: function() { 74 _or: function() {
64 var result = false; 75 var result = false;
65 // can't use .foreach, as arguments isn't really an Array. 76 // can't use .foreach, as arguments isn't really an Array.
66 for (var i = 0; i < arguments.length; i++) { 77 for (var i = 0; i < arguments.length; i++) {
67 result = result || arguments[i]; 78 result = result || arguments[i];
68 } 79 }
69 return result; 80 return result;
70 }, 81 },
82
83 _taskLink: function(task_id) {
84 if (!task_id) {
85 return undefined;
86 }
87 return "/newui/task?id=" + task_id;
88 },
89
90 // timeDiffApprox returns the approximate difference between now and
stephana 2016/09/15 16:33:52 nit: should be _timeDiffApprox
kjlubick 2016/09/15 16:59:32 Done.
91 // the specified date.
92 _timeDiffApprox: function(date){
93 if (!date) {
94 return "eons";
95 }
96 return sk.human.diffDate(date.getTime());
97 },
98
99 // timeDiffExact returns the exact difference between the two specified
100 // dates. E.g. 2d 22h 22m 28s ago If a second date is not provided,
101 // now is used.
102 _timeDiffExact: function(first, second){
103 if (!first) {
104 return "eons";
105 }
106 if (!second) {
107 second = new Date();
108 }
109 return this._humanDuration((second.getTime() - first.getTime())/1000);
110 },
71 }; 111 };
72 })(); 112 })();
73 </script> 113 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698