Chromium Code Reviews| 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 "> | |
| 12 <link rel="import" href="../../bower_components/paper-styles/shadow.html"> | |
| 11 <link rel="import" href="../../bower_components/polymer/polymer.html"> | 13 <link rel="import" href="../../bower_components/polymer/polymer.html"> |
| 12 | 14 |
| 13 <link rel="import" href="config-set-card.html"> | 15 <link rel="import" href="config-set-card.html"> |
| 14 | 16 |
| 15 <dom-module id="front-page"> | 17 <dom-module id="front-page"> |
| 16 <template> | 18 <template> |
| 17 <style> | 19 <style> |
| 18 .center { | 20 .center { |
| 19 width: 50%; | 21 width: 25%; |
| 20 margin: auto; | 22 margin: auto; |
| 21 text-align: center; | |
| 22 } | 23 } |
| 23 | 24 |
| 25 .config-card { | |
| 26 padding-bottom: 1%; | |
| 27 animation: fadein 1.5s; | |
| 28 } | |
| 29 | |
| 30 @keyframes fadein { | |
| 31 from {opacity: 0} | |
| 32 to {opacity: 1} | |
| 33 } | |
| 34 | |
| 35 .loading { text-align: center; } | |
| 36 | |
| 24 .search-bar { | 37 .search-bar { |
| 25 padding-top: 7%; | 38 padding-top: 7%; |
| 26 padding-bottom: 2%; | 39 padding-bottom: 2%; |
| 27 } | 40 } |
| 28 | 41 |
| 29 paper-search-bar { | 42 paper-search-bar { |
| 30 border-style: solid; | 43 @apply --shadow-elevation-4dp; |
| 31 border-width: 2px; | |
| 32 width: 40%; | 44 width: 40%; |
| 33 height: 100%; | 45 height: 100%; |
| 34 margin: auto; | 46 margin: auto; |
| 35 } | 47 } |
| 36 </style> | 48 </style> |
| 37 | 49 |
| 38 <iron-ajax | 50 <iron-ajax |
| 39 auto | 51 auto |
| 40 id="requestConfigs" | 52 id="requestConfigs" |
| 41 url="/_ah/api/config/v1/config-sets?include_last_import_attempt=true" | 53 url="/_ah/api/config/v1/config-sets?include_last_import_attempt=true" |
| 42 handle-as="json" | 54 handle-as="json" |
| 43 on-response="_onGotConfigSets" | 55 on-response="_onGotConfigSets" |
| 44 headers="[[auth_headers]]"> | 56 headers="[[auth_headers]]"> |
| 45 </iron-ajax> | 57 </iron-ajax> |
| 46 | 58 |
| 47 <div class="search-bar"> | 59 <div class="search-bar"> |
| 48 <paper-search-bar query="{{query}}"></paper-search-bar> | 60 <paper-search-bar |
| 61 query="{{query}}" | |
| 62 hide-filter-button="true"></paper-search-bar> | |
| 49 </div> | 63 </div> |
| 50 | 64 |
| 51 <div class="config-list"> | 65 <div class="config-list"> |
| 52 <template is="dom-if" if="[[isLoading]]"> | 66 <template is="dom-if" if="[[isLoading]]"> |
| 53 <div class="center">Fetching config sets...</div> | 67 <div class="center loading"> |
| 68 <paper-spinner active></paper-spinner> | |
| 69 </div> | |
| 54 </template> | 70 </template> |
| 55 <template is="dom-if" if="[[_not(isLoading)]]"> | 71 <template is="dom-if" if="[[_not(isLoading)]]"> |
| 56 <template is="dom-if" if="[[_isEmpty(searchResults)]]"> | 72 <template is="dom-if" if="[[_isEmpty(searchResults)]]"> |
| 57 <div class="center">No config sets found.</div> | 73 <div class="center">No config sets found.</div> |
| 58 </template> | 74 </template> |
| 59 <template is="dom-if" if="[[_not(_isEmpty(searchResults))]]"> | 75 <template is="dom-if" if="[[_not(_isEmpty(searchResults))]]"> |
| 60 <template is="dom-repeat" items="[[searchResults]]" as="config"> | 76 <template is="dom-repeat" items="[[searchResults]]" as="config"> |
| 61 <config-set-card | 77 <div class="center config-card"> |
| 62 name="[[config.config_set]]" | 78 <config-set-card |
| 63 last-import-attempt="[[_getLastImportAttempt(config.last_import_ attempt)]]" | 79 name="[[config.config_set]]" |
| 64 on-tap="_handleClick"> | 80 last-import-attempt="[[_getLastImportAttempt(config.last_impor t_attempt)]]"> |
| 65 </config-set-card> | 81 </config-set-card> |
| 82 </div> | |
| 66 </template> | 83 </template> |
| 67 </template> | 84 </template> |
| 68 </template> | 85 </template> |
| 69 </div> | 86 </div> |
| 70 </template> | 87 </template> |
| 71 | |
| 72 <script> | 88 <script> |
| 73 Polymer({ | 89 Polymer({ |
| 74 is: 'front-page', | 90 is: 'front-page', |
| 75 | 91 |
| 76 properties: { | 92 properties: { |
| 77 configSetList: { | 93 configSetList: { |
| 78 type: Array, | 94 type: Array, |
| 79 value: () => [] | 95 value: () => [] |
| 80 }, | 96 }, |
| 81 | 97 |
| 82 isLoading: { | 98 isLoading: { |
| 83 type: Boolean, | 99 type: Boolean, |
| 84 value: true | 100 value: true |
| 85 }, | 101 }, |
| 86 | 102 |
| 87 query: { | 103 query: { |
| 88 type: String, | 104 type: String, |
| 89 observer: '_updateSearchResults' | 105 observer: '_updateSearchResults' |
| 90 }, | 106 }, |
| 91 | 107 |
| 92 searchResults: { | 108 searchResults: { |
| 93 type: Array, | 109 type: Array, |
| 94 value: () => [] | 110 value: () => [] |
| 95 } | 111 } |
| 96 }, | 112 }, |
| 97 | 113 |
| 114 _formatName: function(name) { | |
| 115 var tempName = name.substring(name.indexOf("/") + 1); | |
| 116 return tempName.includes("/") ? | |
| 117 tempName.substring(0, tempName.indexOf("/")) : tempName; | |
| 118 }, | |
| 119 | |
| 98 _getLastImportAttempt: function(lastImportAttempt) { | 120 _getLastImportAttempt: function(lastImportAttempt) { |
| 99 if (lastImportAttempt) { | 121 if (lastImportAttempt) { |
| 100 return lastImportAttempt; | 122 return lastImportAttempt; |
| 101 } else { | 123 } else { |
| 102 return null; | 124 return null; |
| 103 } | 125 } |
| 104 }, | 126 }, |
| 105 | 127 |
| 106 _isEmpty: function(array) { | 128 _isEmpty: function(array) { |
| 107 return array.length === 0; | 129 return array.length === 0; |
| 108 }, | 130 }, |
| 109 | 131 |
| 110 _onGotConfigSets: function(event) { | 132 _onGotConfigSets: function(event) { |
| 111 this.configSetList = event.detail.response.config_sets; | 133 this.configSetList = event.detail.response.config_sets; |
| 112 this._updateSearchResults(); | 134 this._updateSearchResults(); |
| 113 this.isLoading = false; | 135 this.isLoading = false; |
| 114 }, | 136 }, |
| 115 | 137 |
| 116 _not: function(b) { | 138 _not: function(b) { |
| 117 return !b; | 139 return !b; |
| 118 }, | 140 }, |
| 119 | 141 |
| 120 _updateSearchResults: function() { | 142 _updateSearchResults: function() { |
| 121 this.searchResults = this.configSetList.filter(e => e.config_set.include s(this.query)); | 143 // this method sorts search results by the name of the config set, that way |
|
Sergey Berezin
2017/07/13 02:59:31
nit: s/this/This/ (capitalize the first word).
| |
| 122 }, | 144 // the list doesn't consist of all projects followed by all services due to |
| 123 | 145 // the path beginning with "projects/" or "services/" |
| 124 _handleClick: function(event) { | 146 var tempResults = this.configSetList.filter(e => e.config_set.includes(t his.query)); |
| 125 window.location = window.location.href + event.model.config.config_set; | 147 tempResults.sort(function(a, b) { |
| 148 return this._formatName(a.config_set).localeCompare(this._formatName(b .config_set)); | |
| 149 }.bind(this)); | |
| 150 this.searchResults = tempResults; | |
| 126 }, | 151 }, |
| 127 | 152 |
| 128 }); | 153 }); |
| 129 </script> | 154 </script> |
| 130 </dom-module> | 155 </dom-module> |
| OLD | NEW |