| 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-list> |
| 10 |
| 11 task-list creats a dynamic table for viewing swarming tasks. Columns can be |
| 12 dynamically filtered and it supports client-side filtering. |
| 13 |
| 14 This is a top-level element. |
| 15 |
| 16 Properties: |
| 17 client_id: String, Oauth 2.0 client id. It will be set by server-side |
| 18 template evaluation. |
| 19 |
| 20 Methods: |
| 21 None. |
| 22 |
| 23 Events: |
| 24 None. |
| 25 --> |
| 26 |
| 27 <link rel="import" href="/res/imp/bower_components/iron-flex-layout/iron-flex-la
yout-classes.html"> |
| 28 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html"> |
| 29 |
| 30 <link rel="import" href="/res/imp/common/dynamic-table.html"> |
| 31 <link rel="import" href="/res/imp/common/sort-toggle.html"> |
| 32 <link rel="import" href="/res/imp/common/swarming-app.html"> |
| 33 <link rel="import" href="/res/imp/common/url-param.html"> |
| 34 |
| 35 <link rel="import" href="task-filters.html"> |
| 36 <link rel="import" href="task-list-data.html"> |
| 37 |
| 38 <dom-module id="task-list"> |
| 39 <template> |
| 40 <style include="iron-flex iron-flex-alignment iron-positioning swarming-app-
style dynamic-table-style"> |
| 41 |
| 42 .task-list th > span { |
| 43 /* Leave space for sort-toggle*/ |
| 44 padding-right: 30px; |
| 45 } |
| 46 </style> |
| 47 |
| 48 <url-param name="sort" |
| 49 value="{{_sortstr}}" |
| 50 default_value="id:asc"> |
| 51 </url-param> |
| 52 |
| 53 <swarming-app |
| 54 client_id="[[client_id]]" |
| 55 auth_headers="{{_auth_headers}}" |
| 56 signed_in="{{_signed_in}}" |
| 57 busy="[[_busy]]" |
| 58 name="Swarming Task List"> |
| 59 |
| 60 <h2 hidden$="[[_signed_in]]">You must sign in to see anything useful.</h2> |
| 61 |
| 62 <div hidden$="[[_not(_signed_in)]]"> |
| 63 <task-list-data |
| 64 auth_headers="[[_auth_headers]]" |
| 65 query_params="[[_query_params]]" |
| 66 tasks="{{_items}}" |
| 67 busy="{{_busy}}"> |
| 68 </task-list-data> |
| 69 |
| 70 <div class="horizontal layout"> |
| 71 |
| 72 <task-filters |
| 73 columns="{{_columns}}" |
| 74 query_params="{{_query_params}}" |
| 75 filter="{{_filter}}" |
| 76 verbose="{{_verbose}}"> |
| 77 </task-filters> |
| 78 |
| 79 </div> |
| 80 |
| 81 <table class="task-list"> |
| 82 <thead on-sort_change="_sortChange"> |
| 83 <!-- To allow for dynamic columns without having a lot of copy-pasted |
| 84 code, we break columns up into "special" and "plain" columns. Special |
| 85 columns require some sort of HTML output (e.g. anchor tags) and plain |
| 86 columns just output text. The plain columns use Polymer functions to |
| 87 insert their text [_header(), _column(), _deviceColumn()]. Polymer |
| 88 functions do not allow HTML (to avoid XSS), so special columns, like i
d |
| 89 and task are inserted in a fixed order. |
| 90 --> |
| 91 <tr> |
| 92 <th> |
| 93 <span>Task Name</span> |
| 94 <sort-toggle |
| 95 name="name" |
| 96 current="[[_sort]]"> |
| 97 </sort-toggle> |
| 98 </th> |
| 99 <!-- This wonky syntax is the proper way to listen to changes on a
n |
| 100 array (we are listening to all subproperties). The element returne
d is |
| 101 not of much use, so we'll ignore it in _hide() and use this._colum
ns. |
| 102 --> |
| 103 <th hidden$="[[_hide('state', _columns.*)]]"> |
| 104 <span>Status</span> |
| 105 <sort-toggle |
| 106 name="state" |
| 107 current="[[_sort]]"> |
| 108 </sort-toggle> |
| 109 </th> |
| 110 |
| 111 <template |
| 112 is="dom-repeat" |
| 113 items="[[_plainColumns]]" |
| 114 as="c"> |
| 115 <th hidden$="[[_hide(c)]]"> |
| 116 <span>[[_header(c)]]</span> |
| 117 <sort-toggle |
| 118 name="[[c]]" |
| 119 current="[[_sort]]"> |
| 120 </sort-toggle> |
| 121 </th> |
| 122 </template> |
| 123 </tr> |
| 124 </thead> |
| 125 <tbody> |
| 126 <template |
| 127 id="tasks_table" |
| 128 is="dom-repeat" |
| 129 items="[[_filteredSortedItems]]" |
| 130 as="task" |
| 131 initial-count=50> |
| 132 |
| 133 <tr class$="[[_taskClass(task)]]"> |
| 134 <td> |
| 135 <a |
| 136 class="center" |
| 137 href$="[[_taskLink(task)]]" |
| 138 target="_blank"> |
| 139 [[task.name]] |
| 140 </a> |
| 141 </td> |
| 142 <td hidden$="[[_hide('state', _columns.*)]]"> |
| 143 [[_column('state', task, _verbose)]] |
| 144 <!-- TODO(kjlubick): Add button to stop pending.--> |
| 145 </td> |
| 146 |
| 147 <template |
| 148 is="dom-repeat" |
| 149 items="[[_plainColumns]]" |
| 150 as="c"> |
| 151 <td hidden$="[[_hide(c)]]"> |
| 152 [[_column(c, task, _verbose)]] |
| 153 </td> |
| 154 </template> |
| 155 |
| 156 </tr> |
| 157 </template> <!--tasks_table repeat--> |
| 158 </tbody> |
| 159 </table> |
| 160 </div> |
| 161 |
| 162 </swarming-app> |
| 163 |
| 164 </template> |
| 165 <script> |
| 166 (function(){ |
| 167 var specialColumns = ["name", "state"]; |
| 168 var columnMap = {}; |
| 169 var headerMap = { |
| 170 "user": "Requesting User", |
| 171 }; |
| 172 var specialSort = {}; |
| 173 |
| 174 Polymer({ |
| 175 is: 'task-list', |
| 176 behaviors: [ |
| 177 SwarmingBehaviors.SwarmingBehavior, |
| 178 SwarmingBehaviors.DynamicTableBehavior, |
| 179 ], |
| 180 |
| 181 properties: { |
| 182 client_id: { |
| 183 type: String, |
| 184 }, |
| 185 |
| 186 // For dynamic table. |
| 187 _columnMap: { |
| 188 type: Object, |
| 189 value: columnMap, |
| 190 }, |
| 191 _headerMap: { |
| 192 type: Object, |
| 193 value: headerMap, |
| 194 }, |
| 195 _specialColumns: { |
| 196 type: Array, |
| 197 value: specialColumns, |
| 198 }, |
| 199 _specialSort: { |
| 200 type: Object, |
| 201 value: specialSort, |
| 202 }, |
| 203 }, |
| 204 |
| 205 _attribute: function(task, col, def) { |
| 206 var retVal = task[col] || [def]; |
| 207 if (!Array.isArray(retVal)) { |
| 208 return [retVal]; |
| 209 } |
| 210 return retVal; |
| 211 }, |
| 212 |
| 213 _taskLink: function(task) { |
| 214 // TODO(kjlubick) Make this point to /newui/ when appropriate. |
| 215 return "/restricted/task/"+task.task_id; |
| 216 }, |
| 217 |
| 218 _taskClass: function(task) { |
| 219 // TODO(kjlubick): Color tasks? |
| 220 return ""; |
| 221 } |
| 222 |
| 223 }); |
| 224 })(); |
| 225 </script> |
| 226 </dom-module> |
| OLD | NEW |