| 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 <template is="dom-if" if="[[auth_headers]]"> |
| 65 <iron-icon icon="icons:refresh" on-tap="_forceRefresh"></iron-icon> |
| 66 <span id="refreshStatus">[[refreshMessage]]</span> |
| 67 </template> |
| 68 </div> |
| 48 <div class="category">[[_formatCategory(category)]]</div> | 69 <div class="category">[[_formatCategory(category)]]</div> |
| 49 </div> | 70 </div> |
| 50 | 71 <template is="dom-if" if="[[isRefreshing]]"> |
| 51 <template is="dom-if" if="[[isLoading]]"> | 72 <div class="center">Refreshing config files...</div> |
| 52 <div class="center">Fetching config files...</div> | |
| 53 </template> | 73 </template> |
| 54 <template is="dom-if" if="[[!isLoading]]"> | 74 <template is="dom-if" if="[[!isRefreshing]]"> |
| 55 <template is="dom-repeat" items="[[files]]" as="file"> | 75 <template is="dom-if" if="[[isLoading]]"> |
| 56 <config-file-card | 76 <div class="center">Fetching config files...</div> |
| 57 name="[[file.path]]" link="[[location]]/[[file.path]]"> | 77 </template> |
| 58 </config-file-card> | 78 <template is="dom-if" if="[[!isLoading]]"> |
| 79 <template is="dom-repeat" items="[[files]]" as="file"> |
| 80 <config-file-card |
| 81 name="[[file.path]]" link="[[location]]/[[file.path]]"> |
| 82 </config-file-card> |
| 83 </template> |
| 59 </template> | 84 </template> |
| 60 </template> | 85 </template> |
| 61 </template> | 86 </template> |
| 62 <script> | 87 <script> |
| 63 Polymer({ | 88 Polymer({ |
| 64 is: "config-set", | 89 is: "config-set", |
| 65 | 90 |
| 66 properties: { | 91 properties: { |
| 67 category: { | 92 category: { |
| 68 type: String | 93 type: String |
| 69 }, | 94 }, |
| 70 | 95 |
| 71 files: { | 96 files: { |
| 72 type: Array | 97 type: Array |
| 73 }, | 98 }, |
| 74 | 99 |
| 75 isLoading: { | 100 isLoading: { |
| 76 type: Boolean, | 101 type: Boolean, |
| 77 value: true | 102 value: true |
| 78 }, | 103 }, |
| 79 | 104 |
| 105 isRefreshing: { |
| 106 type: Boolean, |
| 107 value: false |
| 108 }, |
| 109 |
| 80 location: { | 110 location: { |
| 81 type: String | 111 type: String |
| 82 }, | 112 }, |
| 83 | 113 |
| 84 name: { | 114 name: { |
| 85 type: String | 115 type: String |
| 116 }, |
| 117 |
| 118 refreshMessage: { |
| 119 type: String, |
| 120 value: null |
| 86 } | 121 } |
| 87 }, | 122 }, |
| 88 | 123 |
| 124 _forceRefresh: function() { |
| 125 this.refreshMessage = null; |
| 126 this.$.refreshConfigs.generateRequest(); |
| 127 this.isRefreshing = true; |
| 128 }, |
| 129 |
| 89 _formatCategory: function(category) { | 130 _formatCategory: function(category) { |
| 90 if (category === "projects") return "Project"; | 131 if (category === "projects") return "Project"; |
| 91 if (category === "services") return "Service"; | 132 if (category === "services") return "Service"; |
| 92 }, | 133 }, |
| 93 | 134 |
| 135 _onCompleteRefresh: function() { |
| 136 this.isRefreshing = false; |
| 137 this.refreshMessage = "Refresh successful."; |
| 138 }, |
| 139 |
| 94 _onGotConfigFiles: function(event) { | 140 _onGotConfigFiles: function(event) { |
| 95 this.files = event.detail.response.config_sets[0].files; | 141 this.files = event.detail.response.config_sets[0].files; |
| 96 this.location = event.detail.response.config_sets[0].location; | 142 this.location = event.detail.response.config_sets[0].location; |
| 97 this.isLoading = false; | 143 this.isLoading = false; |
| 144 }, |
| 145 |
| 146 _onRefreshError: function() { |
| 147 this.isRefreshing = false; |
| 148 this.refreshMessage = "Error: Files could not be refreshed."; |
| 98 } | 149 } |
| 99 }); | 150 }); |
| 100 </script> | 151 </script> |
| 101 </dom-module> | 152 </dom-module> |
| OLD | NEW |