| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 This in an HTML Import-able file that contains the definition |
| 3 of the following elements: |
| 4 |
| 5 <bot-mass-delete> |
| 6 |
| 7 Usage: |
| 8 |
| 9 <bot-mass-delete></bot-mass-delete> |
| 10 |
| 11 bot-mass-delete offers an interface for the user to delete multiple bots |
| 12 (and hopefully avoid doing so on accident). Care is taken such that only dead |
| 13 bots are deleted. |
| 14 |
| 15 Properties: |
| 16 // input |
| 17 auth_headers: Object, the OAuth2 header to include in the request. This |
| 18 should come from swarming-app. |
| 19 dimensions: Array<String> the dimensions that match the bots being deleted. |
| 20 |
| 21 // output |
| 22 started_deleting: Boolean, If the user has hit the big red button to start |
| 23 deleting bots. |
| 24 finished_deleting: Boolean, If the dialog has finished canceling all the |
| 25 bots. |
| 26 |
| 27 Methods: |
| 28 prompt() Set up the dialog, resetting started_deleting and |
| 29 finished_deleting to false. |
| 30 |
| 31 Events: |
| 32 None. |
| 33 --> |
| 34 |
| 35 <dom-module id="bot-mass-delete"> |
| 36 <template> |
| 37 <style> |
| 38 .container { |
| 39 padding: 5px; |
| 40 max-width: 800px; |
| 41 } |
| 42 .delete-button { |
| 43 background-color: red; |
| 44 color: white; |
| 45 font-weight: bold; |
| 46 } |
| 47 .delete[disabled] { |
| 48 background-color: grey; |
| 49 } |
| 50 </style> |
| 51 <div class="container"> |
| 52 |
| 53 <div> |
| 54 You are about to delete all DEAD bots with the following dimensions: |
| 55 <ul> |
| 56 <template is="dom-repeat" items="[[dimensions]]" as="dim"> |
| 57 <li>[[dim]]</li> |
| 58 </template> |
| 59 </ul> |
| 60 This is about [[_estimated_count]] bots. [[_note_about_max]] |
| 61 Once you start the process, the only way to partially stop it is to clos
e this |
| 62 browser window. |
| 63 |
| 64 If that sounds good, click the button below. |
| 65 </div> |
| 66 |
| 67 <paper-button |
| 68 class="delete-button" |
| 69 raised |
| 70 disabled$="[[!_ready_to_delete]]" |
| 71 hidden$="[[started_deleting]]" |
| 72 on-tap="_delete"> |
| 73 Delete the bots |
| 74 </paper-button> |
| 75 |
| 76 <div > |
| 77 <div hidden$="[[!started_deleting]]">Progress: [[_deleted_count]] delete
d</div> |
| 78 <div>Note: the bot deletion is being done in browser - closing the windo
w will stop the mass deletion.</div> |
| 79 </div> |
| 80 |
| 81 </div> |
| 82 </template> |
| 83 <script> |
| 84 (function(){ |
| 85 Polymer({ |
| 86 is: "bot-mass-delete", |
| 87 |
| 88 properties: { |
| 89 // input |
| 90 auth_headers: { |
| 91 type: Object, |
| 92 }, |
| 93 dimensions: { |
| 94 type: Array, |
| 95 }, |
| 96 // output |
| 97 finished_deleting: { |
| 98 type: Boolean, |
| 99 value: false, |
| 100 notify: true, |
| 101 }, |
| 102 started_deleting: { |
| 103 type: Boolean, |
| 104 value: false, |
| 105 notify: true, |
| 106 }, |
| 107 |
| 108 |
| 109 _deleted_count: { |
| 110 type : Number, |
| 111 value: 0, |
| 112 }, |
| 113 |
| 114 _estimated_count: { |
| 115 type: String, |
| 116 value: "(counting...please wait)", |
| 117 }, |
| 118 _note_about_max: { |
| 119 type: String, |
| 120 value: "", |
| 121 }, |
| 122 _ready_to_delete: { |
| 123 type: Boolean, |
| 124 value: false, |
| 125 }, |
| 126 _to_delete: { |
| 127 type: Array, |
| 128 } |
| 129 }, |
| 130 |
| 131 _args: function() { |
| 132 var args = "?is_dead=TRUE&dimensions="; |
| 133 var dims = this.dimensions || []; |
| 134 return args + dims.join("&dimensions="); |
| 135 }, |
| 136 |
| 137 _delete: function() { |
| 138 this.started_deleting = true; |
| 139 |
| 140 // get list of bots that match |
| 141 var toDeleteURL = "/api/swarming/v1/bots/list" + this._args(); |
| 142 sk.request("GET", toDeleteURL, null, this.auth_headers) |
| 143 .then(JSON.parse).then(function(json){ |
| 144 this._to_delete = json.items; |
| 145 this._deleted_count = 0; |
| 146 this.async(this._deleteNext); |
| 147 }.bind(this)) |
| 148 .catch(function(e){ |
| 149 console.log(e); |
| 150 sk.errorMessage(e); |
| 151 }); |
| 152 |
| 153 }, |
| 154 |
| 155 _deleteNext: function() { |
| 156 if (!this._to_delete) { |
| 157 return; |
| 158 } |
| 159 if (this._deleted_count >= this._to_delete.length) { |
| 160 this.finished_deleting = true; |
| 161 return; |
| 162 } |
| 163 var id = this._to_delete[this._deleted_count].bot_id; |
| 164 if (!id) { |
| 165 console.log("Skipping empty id in slot ",this._deleted_count); |
| 166 } |
| 167 |
| 168 sk.request("POST", `/api/swarming/v1/bot/${id}/delete`, |
| 169 "", this.auth_headers) |
| 170 .then(function(){ |
| 171 this._deleted_count += 1; |
| 172 this.async(this._deleteNext); |
| 173 }.bind(this)) |
| 174 .catch(function(e){ |
| 175 console.log(e); |
| 176 sk.errorMessage(e); |
| 177 }); |
| 178 |
| 179 }, |
| 180 |
| 181 prompt: function(){ |
| 182 this.started_deleting = false; |
| 183 this.finished_deleting = false; |
| 184 this._ready_to_delete = false; |
| 185 |
| 186 var countUrl = "/api/swarming/v1/bots/count" + this._args(); |
| 187 sk.request("GET", countUrl, null, this.auth_headers) |
| 188 .then(JSON.parse).then(function(json){ |
| 189 this._ready_to_delete = true; |
| 190 this._estimated_count = json.dead; |
| 191 }.bind(this)) |
| 192 .catch(function(e){ |
| 193 console.log(e); |
| 194 sk.errorMessage(e); |
| 195 }); |
| 196 }, |
| 197 }); |
| 198 })() |
| 199 </script> |
| 200 </dom-module> |
| OLD | NEW |