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

Side by Side Diff: appengine/swarming/elements/res/imp/taskpage/task-page-data.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 unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file.
5
6 This in an HTML Import-able file that contains the definition
7 of the following elements:
8
9 <task-page-data>
10
11 This makes calls authenticated with Oauth 2 to the swarming apis. It parses
12 that data into usable data structures.
13
14 Properties:
15 // input
16 auth_headers: Object, the OAuth2 header to include in the request. This
17 should come from swarming-app.
18 task_id: String, the id of the task to fetch data on.
19 // output
20 busy: Boolean, if we are fetching any data from the server.
21 request: Object, the task request. This contains information such as the
22 name, id, created_ts, tags, and dimensions. See the sample data in
23 task-request-demo.json for a full rundown.
24 result: Object, the result or progress of the task. This contains informatio n such as the
25 modified_ts, duration, exit_code, information about the bot that picked
26 up the task, etc. See the sample data in task-result-demo.json for a
27 full rundown.
28 stdout: String, the raw output of the task, if any. See
29 task-stdout-demo.json for a full rundown.
30
31 Methods:
32 reload(): Force a fetch of the data. This happens automatically when
33 auth_headers is set or task_id is changed.
34 reloadStdout(): Force a fetch of just the stdout
35
36 Events:
37 None.
38 -->
39
40
41 <link rel="import" href="/res/imp/common/common-behavior.html">
42 <link rel="import" href="/res/imp/common/task-behavior.html">
43
44 <dom-module id="task-page-data">
45 <script>
46 (function(){
47 // Time to wait before requesting a new task. This is to allow a user to
48 // type in a name and not have it make one set of requests for each
49 // keystroke.
50 var TASK_ID_DEBOUNCE_MS = 400;
51 var lastRequest;
52
53 var TIMES = ["abandoned_ts", "completed_ts", "created_ts", "modified_ts", "s tarted_ts"];
54
55 Polymer({
56 is: 'task-page-data',
57
58 behaviors: [
59 SwarmingBehaviors.CommonBehavior,
60 SwarmingBehaviors.TaskBehavior,
61 ],
62
63 properties: {
64 // inputs
65 auth_headers: {
66 type: Object,
67 },
68
69 task_id: {
70 type: String,
71 },
72
73 // outputs
74 busy: {
75 type: Boolean,
76 computed: "_or(_busy1,_busy2,_busy3)",
77 notify: true,
78 },
79 request: {
80 type: Object,
81 computed: "_parseRequest(_request)",
82 notify: true,
83 },
84 result: {
85 type: Object,
86 computed: "_parseResult(_result)",
87 notify: true,
88 },
89 stdout: {
90 type: String,
91 computed: "_parseStdout(_stdout)",
92 notify: true,
93 },
94
95 // private
96 _busy1: {
97 type: Boolean,
98 value: false
99 },
100 _busy2: {
101 type: Boolean,
102 value: false
103 },
104 _busy3: {
105 type: Boolean,
106 value: false
107 },
108 _request: {
109 type: Object,
110 },
111 _result: {
112 type: Object,
113 },
114 _stdout: {
115 type: Object,
116 },
117 },
118
119 observers: [
120 "reload(auth_headers,task_id)",
121 ],
122
123 reload: function(){
124 if (!this.task_id || !this.auth_headers) {
125 console.log("task_id and auth_headers can't be empty");
126 return;
127 }
128 if (lastRequest) {
129 this.cancelAsync(lastRequest);
130 }
131
132 var baseUrl = "/_ah/api/swarming/v1/task/" + this.task_id;
133 lastRequest = this.async(function(){
134 lastRequest = undefined;
135 this._getJsonAsync("_request", baseUrl + "/request",
136 "_busy1", this.auth_headers);
137 this._getJsonAsync("_result",
138 baseUrl + "/result?include_performance_stats=true",
139 "_busy2", this.auth_headers);
140 this.reloadStdout();
141 }, TASK_ID_DEBOUNCE_MS);
142 },
143
144 _parseRequest: function(request) {
145 if (!request) {
146 return {};
147 }
148 request.tagMap = {};
149 request.tags = request.tags || [];
150 request.tags.forEach(function(tag) {
151 var split = tag.split(":", 1)
152 var key = split[0];
153 var rest = tag.substring(key.length + 1);
154 request.tagMap[key] = rest;
155 });
156
157 TIMES.forEach(function(time) {
158 if (request[time]) {
159 request[time] = new Date(request[time]);
160 request["human_"+time] = sk.human.localeTime(request[time]);
161 }
162 });
163 return request;
164 },
165
166 _parseResult: function(result) {
167 if (!result) {
168 return {};
169 }
170 var now = new Date();
171 TIMES.forEach(function(time) {
172 if (result[time]) {
173 result[time] = new Date(result[time]);
174 result["human_"+time] = sk.human.localeTime(result[time]);
175 }
176 });
177 // Running tasks have no duration set, so we can figure it out.
178 if (!result.duration && result.state === this.RUNNING && result.started_ ts){
179 result.duration = (now - result.started_ts) / 1000;
180 }
181 // Make the duration human readable
182 if (result.duration){
183 result.human_duration = this._humanDuration(result.duration);
184 }
185 return result;
186 },
187
188 _parseStdout: function(stdout) {
189 if (!stdout || !stdout.output) {
190 return "[No output yet]";
191 }
192 return stdout.output;
193 },
194
195 reloadStdout: function() {
196 this._getJsonAsync("_stdout", "/_ah/api/swarming/v1/task/" +
197 this.task_id + "/stdout", "_busy3", this.auth_headers);
198 },
199
200 });
201 })();
202 </script>
203 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698