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="config-file-card.html"> | 7 <link rel="import" href="config-file-card.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/iron-icons/iron-icons.html"> | |
| 9 <link rel="import" href="../../bower_components/paper-item/paper-item.html"> | 10 <link rel="import" href="../../bower_components/paper-item/paper-item.html"> |
| 10 <link rel="import" href="../../bower_components/polymer/polymer.html"> | 11 <link rel="import" href="../../bower_components/polymer/polymer.html"> |
| 11 | 12 |
| 12 <dom-module id="config-set"> | 13 <dom-module id="config-set"> |
| 13 <template> | 14 <template> |
| 14 <style> | 15 <style> |
| 15 .category { | 16 .category { |
| 16 font-size: 100%; | 17 font-size: 100%; |
| 17 font-family: sans-serif; | 18 font-family: sans-serif; |
| 18 } | 19 } |
| 19 | 20 |
| 20 .center { | 21 .center { |
| 21 width: 27%; | 22 width: 27%; |
| 22 margin: auto; | 23 margin: auto; |
| 23 text-align: left; | 24 text-align: left; |
| 24 } | 25 } |
| 25 | 26 |
| 26 .name { | 27 .name { |
| 27 font-size: 200%; | 28 font-size: 200%; |
| 28 font-family: sans-serif; | 29 font-family: sans-serif; |
| 29 } | 30 } |
| 30 | 31 |
| 32 #refreshStatus { | |
| 33 font-size: 35%; | |
| 34 } | |
| 35 | |
| 31 .title { | 36 .title { |
| 32 padding-bottom: 1%; | 37 padding-bottom: 1%; |
| 33 padding-top: 5%; | 38 padding-top: 5%; |
| 34 } | 39 } |
| 35 </style> | 40 </style> |
| 36 | 41 |
| 37 <iron-ajax | 42 <iron-ajax |
| 38 auto | 43 auto |
| 39 id="requestConfigs" | 44 id="requestConfigs" |
| 40 url="/_ah/api/config/v1/config-sets?config_set=[[category]]/[[name]][[ro ute.path]]&include_files=true" | 45 url="/_ah/api/config/v1/config-sets?config_set=[[category]]/[[name]][[ro ute.path]]&include_files=true" |
| 41 handle-as="json" | 46 handle-as="json" |
| 42 on-response="_onGotConfigFiles" | 47 on-response="_onGotConfigFiles" |
| 43 headers="[[auth_headers]]"> | 48 headers="[[auth_headers]]"> |
| 44 </iron-ajax> | 49 </iron-ajax> |
| 45 | 50 |
| 51 <iron-ajax | |
| 52 id="refreshConfigs" | |
| 53 url="/_ah/api/config/v1/reimport?config_set=[[category]]/[[name]][[route .path]]" | |
| 54 method="POST" | |
| 55 handle-as="json" | |
| 56 on-error="_onRefreshError" | |
| 57 on-response="_onCompleteRefresh" | |
| 58 headers="[[auth_headers]]"> | |
| 59 </iron-ajax> | |
| 60 | |
| 46 <div class="center title"> | 61 <div class="center title"> |
| 47 <div class="name">[[name]][[route.path]]</div> | 62 <div class="name"> |
| 63 [[name]][[route.path]] | |
| 64 <iron-icon icon="icons:refresh" on-tap="_forceRefresh"></iron-icon> | |
|
Ryan Tseng
2017/07/06 18:27:11
Show this only if the user is logged in
| |
| 65 <span id="refreshStatus">[[refreshMessage]]</span> | |
| 66 </div> | |
| 48 <div class="category">[[_formatCategory(category)]]</div> | 67 <div class="category">[[_formatCategory(category)]]</div> |
| 49 </div> | 68 </div> |
| 50 | 69 <template is="dom-if" if="[[isRefreshing]]"> |
| 51 <template is="dom-if" if="[[isLoading]]"> | 70 <div class="center">Refreshing config files...</div> |
| 52 <div class="center">Fetching config files...</div> | |
| 53 </template> | 71 </template> |
| 54 <template is="dom-if" if="[[!isLoading]]"> | 72 <template is="dom-if" if="[[!isRefreshing]]"> |
| 55 <template is="dom-repeat" items="[[files]]" as="file"> | 73 <template is="dom-if" if="[[isLoading]]"> |
| 56 <config-file-card | 74 <div class="center">Fetching config files...</div> |
| 57 name="[[file.path]]" link="[[location]]/[[file.path]]"> | 75 </template> |
| 58 </config-file-card> | 76 <template is="dom-if" if="[[!isLoading]]"> |
| 77 <template is="dom-repeat" items="[[files]]" as="file"> | |
| 78 <config-file-card | |
| 79 name="[[file.path]]" link="[[location]]/[[file.path]]"> | |
| 80 </config-file-card> | |
| 81 </template> | |
| 59 </template> | 82 </template> |
| 60 </template> | 83 </template> |
| 61 </template> | 84 </template> |
| 62 <script> | 85 <script> |
| 63 Polymer({ | 86 Polymer({ |
| 64 is: "config-set", | 87 is: "config-set", |
| 65 | 88 |
| 66 properties: { | 89 properties: { |
| 67 category: { | 90 category: { |
| 68 type: String | 91 type: String |
| 69 }, | 92 }, |
| 70 | 93 |
| 71 files: { | 94 files: { |
| 72 type: Array | 95 type: Array |
| 73 }, | 96 }, |
| 74 | 97 |
| 75 isLoading: { | 98 isLoading: { |
| 76 type: Boolean, | 99 type: Boolean, |
| 77 value: true | 100 value: true |
| 78 }, | 101 }, |
| 79 | 102 |
| 103 isRefreshing: { | |
| 104 type: Boolean, | |
| 105 value: false | |
| 106 }, | |
| 107 | |
| 80 location: { | 108 location: { |
| 81 type: String | 109 type: String |
| 82 }, | 110 }, |
| 83 | 111 |
| 84 name: { | 112 name: { |
| 85 type: String | 113 type: String |
| 114 }, | |
| 115 | |
| 116 refreshMessage: { | |
| 117 type: String, | |
| 118 value: null | |
| 86 } | 119 } |
| 87 }, | 120 }, |
| 88 | 121 |
| 122 _forceRefresh: function() { | |
| 123 this.refreshMessage = null; | |
| 124 this.$.refreshConfigs.generateRequest(); | |
| 125 this.isRefreshing = true; | |
| 126 }, | |
| 127 | |
| 89 _formatCategory: function(category) { | 128 _formatCategory: function(category) { |
| 90 if (category === "projects") return "Project"; | 129 if (category === "projects") return "Project"; |
| 91 if (category === "services") return "Service"; | 130 if (category === "services") return "Service"; |
| 92 }, | 131 }, |
| 93 | 132 |
| 133 _onCompleteRefresh: function() { | |
| 134 this.isRefreshing = false; | |
| 135 this.refreshMessage = "Refresh successful."; | |
| 136 }, | |
| 137 | |
| 94 _onGotConfigFiles: function(event) { | 138 _onGotConfigFiles: function(event) { |
| 95 this.files = event.detail.response.config_sets[0].files; | 139 this.files = event.detail.response.config_sets[0].files; |
| 96 this.location = event.detail.response.config_sets[0].location; | 140 this.location = event.detail.response.config_sets[0].location; |
| 97 this.isLoading = false; | 141 this.isLoading = false; |
| 142 }, | |
| 143 | |
| 144 _onRefreshError: function() { | |
| 145 this.isRefreshing = false; | |
| 146 this.refreshMessage = "Error: Files could not be refreshed."; | |
| 98 } | 147 } |
| 99 }); | 148 }); |
| 100 </script> | 149 </script> |
| 101 </dom-module> | 150 </dom-module> |
| OLD | NEW |