| OLD | NEW | 
|---|
| (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     busy: Boolean, if we are fetching any data from the server. | 
|  | 16     TODO(kjlubick) | 
|  | 17 | 
|  | 18   Methods: | 
|  | 19     request(): Force a fetch of the data. This happens automatically when | 
|  | 20         auth_headers is set or task_id is changed. | 
|  | 21 | 
|  | 22   Events: | 
|  | 23     None. | 
|  | 24 --> | 
|  | 25 | 
|  | 26 | 
|  | 27 <link rel="import" href="/res/imp/common/common-behavior.html"> | 
|  | 28 | 
|  | 29 <dom-module id="task-page-data"> | 
|  | 30   <script> | 
|  | 31   (function(){ | 
|  | 32     // Time to wait before requesting a new task. This is to allow a user to | 
|  | 33     // type in a name and not have it make one set of requests for each | 
|  | 34     // keystroke. | 
|  | 35     var TASK_ID_DEBOUNCE_MS = 400; | 
|  | 36     var lastRequest; | 
|  | 37 | 
|  | 38     Polymer({ | 
|  | 39       is: 'task-page-data', | 
|  | 40 | 
|  | 41       behaviors: [ | 
|  | 42           SwarmingBehaviors.CommonBehavior, | 
|  | 43       ], | 
|  | 44 | 
|  | 45       properties: { | 
|  | 46         // inputs | 
|  | 47         auth_headers: { | 
|  | 48           type: Object, | 
|  | 49         }, | 
|  | 50         task_id: { | 
|  | 51           type: String, | 
|  | 52         }, | 
|  | 53 | 
|  | 54         // outputs | 
|  | 55         busy: { | 
|  | 56           type: Boolean, | 
|  | 57           computed: "_or(_busy1,_busy2,_busy3)", | 
|  | 58           notify: true, | 
|  | 59         }, | 
|  | 60         request: { | 
|  | 61           type: Object, | 
|  | 62           computed: "_parseRequest(_request)", | 
|  | 63           notify: true, | 
|  | 64         }, | 
|  | 65         result: { | 
|  | 66           type: Array, | 
|  | 67           computed: "_parseResult(_result)", | 
|  | 68           notify: true, | 
|  | 69         }, | 
|  | 70         stdout: { | 
|  | 71           type: String, | 
|  | 72           computed: "_parseStdout(_stdout)", | 
|  | 73           notify: true, | 
|  | 74         }, | 
|  | 75 | 
|  | 76         // private | 
|  | 77          _busy1: { | 
|  | 78           type: Boolean, | 
|  | 79           value: false | 
|  | 80         }, | 
|  | 81         _busy2: { | 
|  | 82           type: Boolean, | 
|  | 83           value: false | 
|  | 84         }, | 
|  | 85         _busy3: { | 
|  | 86           type: Boolean, | 
|  | 87           value: false | 
|  | 88         }, | 
|  | 89         _request: { | 
|  | 90           type: Object, | 
|  | 91         }, | 
|  | 92         _result: { | 
|  | 93           type: Object, | 
|  | 94         }, | 
|  | 95         _stdout: { | 
|  | 96           type: Object, | 
|  | 97         }, | 
|  | 98       }, | 
|  | 99 | 
|  | 100       observers: [ | 
|  | 101         "reload(auth_headers,task_id)", | 
|  | 102       ], | 
|  | 103 | 
|  | 104       reload: function(){ | 
|  | 105         if (!this.task_id || !this.auth_headers) { | 
|  | 106           console.log("task_id and auth_headers can't be empty"); | 
|  | 107           return; | 
|  | 108         } | 
|  | 109         if (lastRequest) { | 
|  | 110           this.cancelAsync(lastRequest); | 
|  | 111         } | 
|  | 112 | 
|  | 113         lastRequest = this.async(function(){ | 
|  | 114           lastRequest = undefined; | 
|  | 115           var baseUrl = "/_ah/api/swarming/v1/task/"+this.task_id; | 
|  | 116           this._getJsonAsync("_request", baseUrl + "/request", | 
|  | 117             "_busy1", this.auth_headers); | 
|  | 118           this._getJsonAsync("_result", | 
|  | 119             baseUrl + "/result?include_performance_stats=true", | 
|  | 120             "_busy2", this.auth_headers); | 
|  | 121           this._getJsonAsync("_stdout", baseUrl + "/stdout", | 
|  | 122             "_busy3", this.auth_headers); | 
|  | 123         }, TASK_ID_DEBOUNCE_MS); | 
|  | 124       }, | 
|  | 125 | 
|  | 126       _parseRequest: function(request) { | 
|  | 127         console.log(request); | 
|  | 128         if (!request) { | 
|  | 129           return {}; | 
|  | 130         } | 
|  | 131         return request; | 
|  | 132       }, | 
|  | 133 | 
|  | 134       _parseResult: function(result) { | 
|  | 135         console.log(result); | 
|  | 136         if (!result) { | 
|  | 137           return {}; | 
|  | 138         } | 
|  | 139         return result; | 
|  | 140       }, | 
|  | 141 | 
|  | 142       _parseStdout: function(stdout) { | 
|  | 143         console.log(stdout); | 
|  | 144         if (!stdout || !stdout.output) { | 
|  | 145           return ""; | 
|  | 146         } | 
|  | 147         return stdout.output; | 
|  | 148       } | 
|  | 149 | 
|  | 150     }); | 
|  | 151   })(); | 
|  | 152   </script> | 
|  | 153 </dom-module> | 
| OLD | NEW | 
|---|