| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2017 The LUCI Authors. All rights reserved. | 2 Copyright 2017 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 | 6 |
| 7 <link rel="import" href="../../bower_components/app-layout/app-layout.html"> | 7 <link rel="import" href="../../bower_components/app-layout/app-layout.html"> |
| 8 <link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html"> | 8 <link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html"> |
| 9 <link rel="import" href="../../bower_components/paper-button/paper-button.html"> | 9 <link rel="import" href="../../bower_components/paper-button/paper-button.html"> |
| 10 <link rel="import" href="../../bower_components/paper-search/paper-search-bar.ht
ml"> | 10 <link rel="import" href="../../bower_components/paper-search/paper-search-bar.ht
ml"> |
| 11 <link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html
"> | 11 <link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html
"> |
| 12 <link rel="import" href="../../bower_components/paper-styles/shadow.html"> | 12 <link rel="import" href="../../bower_components/paper-styles/shadow.html"> |
| 13 <link rel="import" href="../../bower_components/polymer/polymer.html"> | 13 <link rel="import" href="../../bower_components/polymer/polymer.html"> |
| 14 <link rel="import" href="../../common/common-behaviors.html"> |
| 14 | 15 |
| 15 <link rel="import" href="config-set-card.html"> | 16 <link rel="import" href="config-set-card.html"> |
| 16 | 17 |
| 17 <dom-module id="front-page"> | 18 <dom-module id="front-page"> |
| 18 <template> | 19 <template> |
| 19 <style> | 20 <style> |
| 20 @media only screen and (min-width: 768px) { | 21 @media only screen and (min-width: 768px) { |
| 21 .center { | 22 .center { |
| 22 width: 550px; | 23 width: 550px; |
| 23 } | 24 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 <template is="dom-if" if="[[_not(isLoading)]]"> | 88 <template is="dom-if" if="[[_not(isLoading)]]"> |
| 88 <template is="dom-if" if="[[_not(errorMessage)]]"> | 89 <template is="dom-if" if="[[_not(errorMessage)]]"> |
| 89 <template is="dom-if" if="[[_isEmpty(searchResults)]]"> | 90 <template is="dom-if" if="[[_isEmpty(searchResults)]]"> |
| 90 <div class="center name">No config sets found.</div> | 91 <div class="center name">No config sets found.</div> |
| 91 </template> | 92 </template> |
| 92 <template is="dom-if" if="[[_not(_isEmpty(searchResults))]]"> | 93 <template is="dom-if" if="[[_not(_isEmpty(searchResults))]]"> |
| 93 <template is="dom-repeat" items="[[searchResults]]" as="config"> | 94 <template is="dom-repeat" items="[[searchResults]]" as="config"> |
| 94 <div class="center config-card"> | 95 <div class="center config-card"> |
| 95 <config-set-card | 96 <config-set-card |
| 96 name="[[config.config_set]]" | 97 name="[[config.config_set]]" |
| 97 last-import-attempt="[[_getLastImportAttempt(config.last_impor
t_attempt)]]"> | 98 last-import-attempt="[[_getLastImportAttempt(config.last_impor
t_attempt)]]" |
| 99 revision="[[_getRevision(config.revision)]]" |
| 100 link="[[_getURL(config)]]" |
| 101 timestamp="[[_getTimestamp(config.last_import_attempt, config.
revision)]]"> |
| 98 </config-set-card> | 102 </config-set-card> |
| 99 </div> | 103 </div> |
| 100 </template> | 104 </template> |
| 101 </template> | 105 </template> |
| 102 </template> | 106 </template> |
| 103 <template is="dom-if" if="[[errorMessage]]"> | 107 <template is="dom-if" if="[[errorMessage]]"> |
| 104 <div class="center name">[[errorMessage]]</div> | 108 <div class="center name">[[errorMessage]]</div> |
| 105 </template> | 109 </template> |
| 106 </template> | 110 </template> |
| 107 </div> | 111 </div> |
| 108 </template> | 112 </template> |
| 109 <script> | 113 <script> |
| 110 Polymer({ | 114 Polymer({ |
| 111 is: 'front-page', | 115 is: 'front-page', |
| 112 | 116 |
| 117 behaviors: [ConfigUIBehaviors.CommonBehavior], |
| 118 |
| 113 properties: { | 119 properties: { |
| 114 configSetList: { | 120 configSetList: { |
| 115 type: Array, | 121 type: Array, |
| 116 value: () => [] | 122 value: () => [] |
| 117 }, | 123 }, |
| 118 | 124 |
| 119 errorMessage: { | 125 errorMessage: { |
| 120 type: String, | 126 type: String, |
| 121 value: null | 127 value: null |
| 122 }, | 128 }, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 168 } |
| 163 }, | 169 }, |
| 164 | 170 |
| 165 _formatName: function(name) { | 171 _formatName: function(name) { |
| 166 var tempName = name.substring(name.indexOf("/") + 1); | 172 var tempName = name.substring(name.indexOf("/") + 1); |
| 167 return tempName.includes("/") ? | 173 return tempName.includes("/") ? |
| 168 tempName.substring(0, tempName.indexOf("/")) : tempName; | 174 tempName.substring(0, tempName.indexOf("/")) : tempName; |
| 169 }, | 175 }, |
| 170 | 176 |
| 171 _getLastImportAttempt: function(lastImportAttempt) { | 177 _getLastImportAttempt: function(lastImportAttempt) { |
| 172 if (lastImportAttempt) { | 178 return lastImportAttempt || null; |
| 173 return lastImportAttempt; | 179 }, |
| 180 |
| 181 _getURL: function(config) { |
| 182 if (config.last_import_attempt && config.last_import_attempt.success) { |
| 183 return config.last_import_attempt.revision.url; |
| 184 } else if (config.revision && config.revision.url) { |
| 185 return config.revision.url; |
| 174 } else { | 186 } else { |
| 175 return null; | 187 return config.location; |
| 176 } | 188 } |
| 177 }, | 189 }, |
| 178 | 190 |
| 179 _isEmpty: function(array) { | |
| 180 return array.length === 0; | |
| 181 }, | |
| 182 | |
| 183 _not: function(b) { | |
| 184 return !b; | |
| 185 }, | |
| 186 | |
| 187 _onGotConfigSets: function(event) { | 191 _onGotConfigSets: function(event) { |
| 188 this.configSetList = event.detail.response.config_sets; | 192 this.configSetList = event.detail.response.config_sets; |
| 189 this._updateSearchResults(); | 193 this._updateSearchResults(); |
| 190 this.isLoading = false; | 194 this.isLoading = false; |
| 191 this.fire('processedConfigSets'); | 195 this.fire('processedConfigSets'); |
| 192 }, | 196 }, |
| 193 | 197 |
| 194 _onRequestError: function(event) { | 198 _onRequestError: function(event) { |
| 195 var error = parseInt(event.detail.error.message.match(/\d+/g)); | 199 var error = parseInt(event.detail.error.message.match(/\d+/g)); |
| 196 if (error === 403) { | 200 if (error === 403) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 var tempResults = this.configSetList.filter(e => e.config_set.includes(t
his.query)); | 215 var tempResults = this.configSetList.filter(e => e.config_set.includes(t
his.query)); |
| 212 tempResults.sort(function(a, b) { | 216 tempResults.sort(function(a, b) { |
| 213 return this._formatName(a.config_set).localeCompare(this._formatName(b
.config_set)); | 217 return this._formatName(a.config_set).localeCompare(this._formatName(b
.config_set)); |
| 214 }.bind(this)); | 218 }.bind(this)); |
| 215 this.searchResults = tempResults; | 219 this.searchResults = tempResults; |
| 216 }, | 220 }, |
| 217 | 221 |
| 218 }); | 222 }); |
| 219 </script> | 223 </script> |
| 220 </dom-module> | 224 </dom-module> |
| OLD | NEW |