 Chromium Code Reviews
 Chromium Code Reviews Issue 2337363003:
  Create boilerplate for task-page  (Closed) 
  Base URL: git@github.com:luci/luci-py@refactor-task
    
  
    Issue 2337363003:
  Create boilerplate for task-page  (Closed) 
  Base URL: git@github.com:luci/luci-py@refactor-task| 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 | |
| 
jcgregorio
2016/09/20 12:35:19
1 blank line.
 
kjlubick
2016/09/20 13:27:32
Done.
 | |
| 42 behaviors: [ | |
| 43 SwarmingBehaviors.CommonBehavior, | |
| 44 ], | |
| 45 | |
| 46 properties: { | |
| 47 // inputs | |
| 48 auth_headers: { | |
| 49 type: Object, | |
| 50 }, | |
| 51 task_id: { | |
| 52 type: String, | |
| 53 }, | |
| 54 | |
| 55 // outputs | |
| 56 busy: { | |
| 57 type: Boolean, | |
| 58 computed: "_or(_busy1,_busy2,_busy3)", | |
| 59 notify: true, | |
| 60 }, | |
| 61 request: { | |
| 62 type: Object, | |
| 63 computed: "_parseRequest(_request)", | |
| 64 notify: true, | |
| 65 }, | |
| 66 result: { | |
| 67 type: Array, | |
| 68 computed: "_parseResult(_result)", | |
| 69 notify: true, | |
| 70 }, | |
| 71 stdout: { | |
| 72 type: String, | |
| 73 computed: "_parseStdout(_stdout)", | |
| 74 notify: true, | |
| 75 }, | |
| 76 | |
| 77 // private | |
| 78 _busy1: { | |
| 79 type: Boolean, | |
| 80 value: false | |
| 81 }, | |
| 82 _busy2: { | |
| 83 type: Boolean, | |
| 84 value: false | |
| 85 }, | |
| 86 _busy3: { | |
| 87 type: Boolean, | |
| 88 value: false | |
| 89 }, | |
| 90 _request: { | |
| 91 type: Object, | |
| 92 }, | |
| 93 _result: { | |
| 94 type: Object, | |
| 95 }, | |
| 96 _stdout: { | |
| 97 type: Object, | |
| 98 }, | |
| 99 }, | |
| 100 | |
| 101 observers: [ | |
| 102 "reload(auth_headers,task_id)", | |
| 103 ], | |
| 104 | |
| 105 reload: function(){ | |
| 106 if (!this.task_id || !this.auth_headers) { | |
| 107 console.log("task_id and auth_headers can't be empty"); | |
| 108 return; | |
| 109 } | |
| 110 if (lastRequest) { | |
| 111 this.cancelAsync(lastRequest); | |
| 112 } | |
| 113 | |
| 114 lastRequest = this.async(function(){ | |
| 115 lastRequest = undefined; | |
| 116 var baseUrl = "/_ah/api/swarming/v1/task/"+this.task_id; | |
| 117 this._getJsonAsync("_request", baseUrl + "/request", | |
| 118 "_busy1", this.auth_headers); | |
| 119 this._getJsonAsync("_result", | |
| 120 baseUrl + "/result?include_performance_stats=true", | |
| 121 "_busy2", this.auth_headers); | |
| 122 this._getJsonAsync("_stdout", baseUrl + "/stdout", | |
| 123 "_busy3", this.auth_headers); | |
| 124 }, TASK_ID_DEBOUNCE_MS); | |
| 125 }, | |
| 126 | |
| 127 _parseRequest: function(request) { | |
| 128 console.log(request); | |
| 129 if (!request) { | |
| 130 return {}; | |
| 131 } | |
| 132 return request; | |
| 133 }, | |
| 134 | |
| 135 _parseResult: function(result) { | |
| 136 console.log(result); | |
| 137 if (!result) { | |
| 138 return {}; | |
| 139 } | |
| 140 return result; | |
| 141 }, | |
| 142 | |
| 143 _parseStdout: function(stdout) { | |
| 144 console.log(stdout); | |
| 145 if (!stdout || !stdout.output) { | |
| 146 return ""; | |
| 147 } | |
| 148 return stdout.output; | |
| 149 } | |
| 150 | |
| 151 }); | |
| 152 })(); | |
| 153 </script> | |
| 154 </dom-module> | |
| OLD | NEW |