Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-data.html

Issue 2247143003: Fix glitch with undefined disks (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 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 This in an HTML Import-able file that contains the definition 6 This in an HTML Import-able file that contains the definition
7 of the following elements: 7 of the following elements:
8 8
9 <bot-list-data> 9 <bot-list-data>
10 10
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 }, 166 },
167 167
168 _bots: function(){ 168 _bots: function(){
169 if (!this._list || !this._list.items) { 169 if (!this._list || !this._list.items) {
170 return []; 170 return [];
171 } 171 }
172 // Do any preprocessing here 172 // Do any preprocessing here
173 this._list.items.forEach(function(bot){ 173 this._list.items.forEach(function(bot){
174 // Parse the state, which is a JSON string. This contains a lot of 174 // Parse the state, which is a JSON string. This contains a lot of
175 // interesting information like details about the devices attached. 175 // interesting information like details about the devices attached.
176 bot.state = bot.state || "{}";
176 bot.state = JSON.parse(bot.state); 177 bot.state = JSON.parse(bot.state);
177 // get the disks in an easier to deal with format, sorted by size. 178 // get the disks in an easier to deal with format, sorted by size.
178 var disks = bot.state["disks"]; 179 var disks = bot.state.disks || {};
179 var keys = Object.keys(disks); 180 var keys = Object.keys(disks);
180 if (!keys || !keys.length) { 181 if (!keys.length) {
181 bot.disks = [{"id": "unknown", "mb": 0}]; 182 bot.disks = [{"id": "unknown", "mb": 0}];
182 } else { 183 } else {
183 bot.disks = []; 184 bot.disks = [];
184 for (var i = 0; i < keys.length; i++) { 185 for (var i = 0; i < keys.length; i++) {
185 bot.disks.push({"id":keys[i], "mb":disks[keys[i]].free_mb}); 186 bot.disks.push({"id":keys[i], "mb":disks[keys[i]].free_mb});
186 } 187 }
187 // Sort these so the biggest disk comes first. 188 // Sort these so the biggest disk comes first.
188 bot.disks.sort(function(a, b) { 189 bot.disks.sort(function(a, b) {
189 return b.mb - a.mb; 190 return b.mb - a.mb;
190 }); 191 });
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 279
279 // No need to sort any of this, bot-filters sorts secondary items 280 // No need to sort any of this, bot-filters sorts secondary items
280 // automatically, especially when the user types a query. 281 // automatically, especially when the user types a query.
281 return pMap; 282 return pMap;
282 }, 283 },
283 284
284 }); 285 });
285 })(); 286 })();
286 </script> 287 </script>
287 </dom-module> 288 </dom-module>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698