| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // require cr.js | 5 // require cr.js |
| 6 // require cr/event_target.js | 6 // require cr/event_target.js |
| 7 // require cr/ui.js | 7 // require cr/ui.js |
| 8 // require cr/ui/tabs.js | 8 // require cr/ui/tabs.js |
| 9 // require cr/ui/tree.js | 9 // require cr/ui/tree.js |
| 10 // require cr/util.js | 10 // require cr/util.js |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 var result = checkIfAvailable_(value); | 99 var result = checkIfAvailable_(value); |
| 100 if (result) | 100 if (result) |
| 101 return result; | 101 return result; |
| 102 | 102 |
| 103 var segments = separateBackward_(value.toString(), 3); | 103 var segments = separateBackward_(value.toString(), 3); |
| 104 result = segments.join(',') + ' B'; | 104 result = segments.join(',') + ' B'; |
| 105 | 105 |
| 106 if (segments.length > 1) { | 106 if (segments.length > 1) { |
| 107 var UNIT = [' B', ' KB', ' MB', ' GB', ' TB', ' PB']; | 107 var UNIT = [' B', ' KB', ' MB', ' GB', ' TB', ' PB']; |
| 108 result = segments[0] + '.' + segments[1].slice(0, 2) + | 108 result = segments[0] + '.' + segments[1].slice(0, 2) + |
| 109 UNIT[Math.min(segments.length, UNIT.length) - 1] + | 109 UNIT[Math.min(segments.length, UNIT.length) - 1] + ' (' + result + ')'; |
| 110 ' (' + result + ')'; | |
| 111 } | 110 } |
| 112 | 111 |
| 113 return result; | 112 return result; |
| 114 } | 113 } |
| 115 | 114 |
| 116 /** | 115 /** |
| 117 * Return formatted date |value| if |value| is not undefined. | 116 * Return formatted date |value| if |value| is not undefined. |
| 118 * If |value| is undefined, this function returns 'N/A'. | 117 * If |value| is undefined, this function returns 'N/A'. |
| 119 * @param {?number} value Number of milliseconds since | 118 * @param {?number} value Number of milliseconds since |
| 120 * UNIX epoch time (0:00, Jan 1, 1970, UTC). | 119 * UNIX epoch time (0:00, Jan 1, 1970, UTC). |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 194 |
| 196 /** | 195 /** |
| 197 * Initialize and return a tree item, that represents specified storage type. | 196 * Initialize and return a tree item, that represents specified storage type. |
| 198 * @param {!string} type Storage type. | 197 * @param {!string} type Storage type. |
| 199 * @return {cr.ui.TreeItem} Initialized |storageObject|. | 198 * @return {cr.ui.TreeItem} Initialized |storageObject|. |
| 200 */ | 199 */ |
| 201 function getStorageObject(type) { | 200 function getStorageObject(type) { |
| 202 var treeViewObject = getTreeViewObject(); | 201 var treeViewObject = getTreeViewObject(); |
| 203 var storageObject = treeViewObject.detail.children[type]; | 202 var storageObject = treeViewObject.detail.children[type]; |
| 204 if (!storageObject) { | 203 if (!storageObject) { |
| 205 storageObject = new cr.ui.TreeItem({ | 204 storageObject = |
| 206 label: type, | 205 new cr.ui.TreeItem({label: type, detail: {payload: {}, children: {}}}); |
| 207 detail: {payload: {}, children: {}} | |
| 208 }); | |
| 209 storageObject.mayHaveChildren_ = true; | 206 storageObject.mayHaveChildren_ = true; |
| 210 treeViewObject.detail.children[type] = storageObject; | 207 treeViewObject.detail.children[type] = storageObject; |
| 211 treeViewObject.add(storageObject); | 208 treeViewObject.add(storageObject); |
| 212 } | 209 } |
| 213 return storageObject; | 210 return storageObject; |
| 214 } | 211 } |
| 215 | 212 |
| 216 /** | 213 /** |
| 217 * Initialize and return a tree item, that represents specified | 214 * Initialize and return a tree item, that represents specified |
| 218 * storage type and hostname. | 215 * storage type and hostname. |
| 219 * @param {!string} type Storage type. | 216 * @param {!string} type Storage type. |
| 220 * @param {!string} host Hostname. | 217 * @param {!string} host Hostname. |
| 221 * @return {cr.ui.TreeItem} Initialized |hostObject|. | 218 * @return {cr.ui.TreeItem} Initialized |hostObject|. |
| 222 */ | 219 */ |
| 223 function getHostObject(type, host) { | 220 function getHostObject(type, host) { |
| 224 var storageObject = getStorageObject(type); | 221 var storageObject = getStorageObject(type); |
| 225 var hostObject = storageObject.detail.children[host]; | 222 var hostObject = storageObject.detail.children[host]; |
| 226 if (!hostObject) { | 223 if (!hostObject) { |
| 227 hostObject = new cr.ui.TreeItem({ | 224 hostObject = |
| 228 label: host, | 225 new cr.ui.TreeItem({label: host, detail: {payload: {}, children: {}}}); |
| 229 detail: {payload: {}, children: {}} | |
| 230 }); | |
| 231 hostObject.mayHaveChildren_ = true; | 226 hostObject.mayHaveChildren_ = true; |
| 232 storageObject.detail.children[host] = hostObject; | 227 storageObject.detail.children[host] = hostObject; |
| 233 storageObject.add(hostObject); | 228 storageObject.add(hostObject); |
| 234 } | 229 } |
| 235 return hostObject; | 230 return hostObject; |
| 236 } | 231 } |
| 237 | 232 |
| 238 /** | 233 /** |
| 239 * Initialize and return a tree item, that represents specified | 234 * Initialize and return a tree item, that represents specified |
| 240 * storage type, hostname and origin url. | 235 * storage type, hostname and origin url. |
| 241 * @param {!string} type Storage type. | 236 * @param {!string} type Storage type. |
| 242 * @param {!string} host Hostname. | 237 * @param {!string} host Hostname. |
| 243 * @param {!string} origin Origin URL. | 238 * @param {!string} origin Origin URL. |
| 244 * @return {cr.ui.TreeItem} Initialized |originObject|. | 239 * @return {cr.ui.TreeItem} Initialized |originObject|. |
| 245 */ | 240 */ |
| 246 function getOriginObject(type, host, origin) { | 241 function getOriginObject(type, host, origin) { |
| 247 var hostObject = getHostObject(type, host); | 242 var hostObject = getHostObject(type, host); |
| 248 var originObject = hostObject.detail.children[origin]; | 243 var originObject = hostObject.detail.children[origin]; |
| 249 if (!originObject) { | 244 if (!originObject) { |
| 250 originObject = new cr.ui.TreeItem({ | 245 originObject = new cr.ui.TreeItem( |
| 251 label: origin, | 246 {label: origin, detail: {payload: {}, children: {}}}); |
| 252 detail: {payload: {}, children: {}} | |
| 253 }); | |
| 254 originObject.mayHaveChildren_ = false; | 247 originObject.mayHaveChildren_ = false; |
| 255 hostObject.detail.children[origin] = originObject; | 248 hostObject.detail.children[origin] = originObject; |
| 256 hostObject.add(originObject); | 249 hostObject.add(originObject); |
| 257 } | 250 } |
| 258 return originObject; | 251 return originObject; |
| 259 } | 252 } |
| 260 | 253 |
| 261 /** | 254 /** |
| 262 * Event Handler for |cr.quota.onAvailableSpaceUpdated|. | 255 * Event Handler for |cr.quota.onAvailableSpaceUpdated|. |
| 263 * |event.detail| contains |availableSpace|. | 256 * |event.detail| contains |availableSpace|. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 * unlimitedUsage: {?number} | 289 * unlimitedUsage: {?number} |
| 297 * quota: {?string} | 290 * quota: {?string} |
| 298 * }} | 291 * }} |
| 299 */ | 292 */ |
| 300 var data = event.detail; | 293 var data = event.detail; |
| 301 var storageObject = getStorageObject(data.type); | 294 var storageObject = getStorageObject(data.type); |
| 302 copyAttributes_(data, storageObject.detail.payload); | 295 copyAttributes_(data, storageObject.detail.payload); |
| 303 storageObject.reveal(); | 296 storageObject.reveal(); |
| 304 if (getTreeViewObject().selectedItem == storageObject) | 297 if (getTreeViewObject().selectedItem == storageObject) |
| 305 updateDescription(); | 298 updateDescription(); |
| 306 | |
| 307 } | 299 } |
| 308 | 300 |
| 309 /** | 301 /** |
| 310 * Event Handler for |cr.quota.onPerHostInfoUpdated|. | 302 * Event Handler for |cr.quota.onPerHostInfoUpdated|. |
| 311 * |event.detail| contains records which have: | 303 * |event.detail| contains records which have: |
| 312 * |host|: | 304 * |host|: |
| 313 * Hostname of the entry. (e.g. 'example.com') | 305 * Hostname of the entry. (e.g. 'example.com') |
| 314 * |type|: | 306 * |type|: |
| 315 * Storage type. 'temporary' or 'persistent' | 307 * Storage type. 'temporary' or 'persistent' |
| 316 * |usage|: | 308 * |usage|: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 333 */ | 325 */ |
| 334 var dataArray = event.detail; | 326 var dataArray = event.detail; |
| 335 | 327 |
| 336 for (var i = 0; i < dataArray.length; ++i) { | 328 for (var i = 0; i < dataArray.length; ++i) { |
| 337 var data = dataArray[i]; | 329 var data = dataArray[i]; |
| 338 var hostObject = getHostObject(data.type, data.host); | 330 var hostObject = getHostObject(data.type, data.host); |
| 339 copyAttributes_(data, hostObject.detail.payload); | 331 copyAttributes_(data, hostObject.detail.payload); |
| 340 hostObject.reveal(); | 332 hostObject.reveal(); |
| 341 if (getTreeViewObject().selectedItem == hostObject) | 333 if (getTreeViewObject().selectedItem == hostObject) |
| 342 updateDescription(); | 334 updateDescription(); |
| 343 | |
| 344 } | 335 } |
| 345 } | 336 } |
| 346 | 337 |
| 347 /** | 338 /** |
| 348 * Event Handler for |cr.quota.onPerOriginInfoUpdated|. | 339 * Event Handler for |cr.quota.onPerOriginInfoUpdated|. |
| 349 * |event.detail| contains records which have: | 340 * |event.detail| contains records which have: |
| 350 * |origin|: | 341 * |origin|: |
| 351 * Origin URL of the entry. | 342 * Origin URL of the entry. |
| 352 * |type|: | 343 * |type|: |
| 353 * Storage type of the entry. 'temporary' or 'persistent'. | 344 * Storage type of the entry. 'temporary' or 'persistent'. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 */ | 394 */ |
| 404 var data = event.detail; | 395 var data = event.detail; |
| 405 for (var key in data) { | 396 for (var key in data) { |
| 406 var entry = statistics[key]; | 397 var entry = statistics[key]; |
| 407 if (!entry) { | 398 if (!entry) { |
| 408 entry = cr.doc.createElement('tr'); | 399 entry = cr.doc.createElement('tr'); |
| 409 $('stat-entries').appendChild(entry); | 400 $('stat-entries').appendChild(entry); |
| 410 statistics[key] = entry; | 401 statistics[key] = entry; |
| 411 } | 402 } |
| 412 entry.detail = data[key]; | 403 entry.detail = data[key]; |
| 413 entry.innerHTML = | 404 entry.innerHTML = '<td>' + stringToText_(key) + '</td>' + |
| 414 '<td>' + stringToText_(key) + '</td>' + | |
| 415 '<td>' + stringToText_(entry.detail) + '</td>'; | 405 '<td>' + stringToText_(entry.detail) + '</td>'; |
| 416 localize_(entry); | 406 localize_(entry); |
| 417 } | 407 } |
| 418 } | 408 } |
| 419 | 409 |
| 420 /** | 410 /** |
| 421 * Update description on 'tree-item-description' field with | 411 * Update description on 'tree-item-description' field with |
| 422 * selected item in tree view. | 412 * selected item in tree view. |
| 423 */ | 413 */ |
| 424 function updateDescription() { | 414 function updateDescription() { |
| 425 var item = getTreeViewObject().selectedItem; | 415 var item = getTreeViewObject().selectedItem; |
| 426 var tbody = $('tree-item-description'); | 416 var tbody = $('tree-item-description'); |
| 427 tbody.innerHTML = ''; | 417 tbody.innerHTML = ''; |
| 428 | 418 |
| 429 if (item) { | 419 if (item) { |
| 430 var keyAndLabel = [['type', 'Storage Type'], | 420 var keyAndLabel = [ |
| 431 ['host', 'Host Name'], | 421 ['type', 'Storage Type'], ['host', 'Host Name'], ['origin', 'Origin URL'], |
| 432 ['origin', 'Origin URL'], | 422 ['usage', 'Total Storage Usage', numBytesToText_], |
| 433 ['usage', 'Total Storage Usage', numBytesToText_], | 423 ['unlimitedUsage', 'Usage of Unlimited Origins', numBytesToText_], |
| 434 ['unlimitedUsage', 'Usage of Unlimited Origins', | 424 ['quota', 'Quota', numBytesToText_], ['inUse', 'Origin is in use?'], |
| 435 numBytesToText_], | 425 ['usedCount', 'Used count'], |
| 436 ['quota', 'Quota', numBytesToText_], | 426 ['lastAccessTime', 'Last Access Time', dateToText], |
| 437 ['inUse', 'Origin is in use?'], | 427 ['lastModifiedTime', 'Last Modified Time', dateToText] |
| 438 ['usedCount', 'Used count'], | 428 ]; |
| 439 ['lastAccessTime', 'Last Access Time', | |
| 440 dateToText], | |
| 441 ['lastModifiedTime', 'Last Modified Time', | |
| 442 dateToText] | |
| 443 ]; | |
| 444 for (var i = 0; i < keyAndLabel.length; ++i) { | 429 for (var i = 0; i < keyAndLabel.length; ++i) { |
| 445 var key = keyAndLabel[i][0]; | 430 var key = keyAndLabel[i][0]; |
| 446 var label = keyAndLabel[i][1]; | 431 var label = keyAndLabel[i][1]; |
| 447 var entry = item.detail.payload[key]; | 432 var entry = item.detail.payload[key]; |
| 448 if (entry === undefined) | 433 if (entry === undefined) |
| 449 continue; | 434 continue; |
| 450 | 435 |
| 451 var normalize = keyAndLabel[i][2] || stringToText_; | 436 var normalize = keyAndLabel[i][2] || stringToText_; |
| 452 | 437 |
| 453 var row = cr.doc.createElement('tr'); | 438 var row = cr.doc.createElement('tr'); |
| 454 row.innerHTML = | 439 row.innerHTML = '<td>' + label + '</td>' + |
| 455 '<td>' + label + '</td>' + | |
| 456 '<td>' + normalize(entry) + '</td>'; | 440 '<td>' + normalize(entry) + '</td>'; |
| 457 localize_(row); | 441 localize_(row); |
| 458 tbody.appendChild(row); | 442 tbody.appendChild(row); |
| 459 } | 443 } |
| 460 } | 444 } |
| 461 } | 445 } |
| 462 | 446 |
| 463 /** | 447 /** |
| 464 * Dump |treeViewObject| or subtree to a object. | 448 * Dump |treeViewObject| or subtree to a object. |
| 465 * @param {?{cr.ui.Tree|cr.ui.TreeItem}} opt_treeitem | 449 * @param {?{cr.ui.Tree|cr.ui.TreeItem}} opt_treeitem |
| (...skipping 28 matching lines...) Expand all Loading... |
| 494 return result; | 478 return result; |
| 495 } | 479 } |
| 496 | 480 |
| 497 /** | 481 /** |
| 498 * Event handler for 'dump-button' 'click'ed. | 482 * Event handler for 'dump-button' 'click'ed. |
| 499 * Dump and show all data from WebUI page to 'dump-field' element. | 483 * Dump and show all data from WebUI page to 'dump-field' element. |
| 500 */ | 484 */ |
| 501 function dump() { | 485 function dump() { |
| 502 var separator = '========\n'; | 486 var separator = '========\n'; |
| 503 | 487 |
| 504 $('dump-field').textContent = | 488 $('dump-field').textContent = separator + 'Summary\n' + separator + |
| 505 separator + | |
| 506 'Summary\n' + | |
| 507 separator + | |
| 508 JSON.stringify({availableSpace: availableSpace}, null, 2) + '\n' + | 489 JSON.stringify({availableSpace: availableSpace}, null, 2) + '\n' + |
| 509 separator + | 490 separator + 'Usage And Quota\n' + separator + |
| 510 'Usage And Quota\n' + | 491 JSON.stringify(dumpTreeToObj(), null, 2) + '\n' + separator + |
| 511 separator + | 492 'Misc Statistics\n' + separator + |
| 512 JSON.stringify(dumpTreeToObj(), null, 2) + '\n' + | |
| 513 separator + | |
| 514 'Misc Statistics\n' + | |
| 515 separator + | |
| 516 JSON.stringify(dumpStatisticsToObj(), null, 2); | 493 JSON.stringify(dumpStatisticsToObj(), null, 2); |
| 517 } | 494 } |
| 518 | 495 |
| 519 function onLoad() { | 496 function onLoad() { |
| 520 cr.ui.decorate('tabbox', cr.ui.TabBox); | 497 cr.ui.decorate('tabbox', cr.ui.TabBox); |
| 521 | 498 |
| 522 cr.quota.onAvailableSpaceUpdated.addEventListener('update', | 499 cr.quota.onAvailableSpaceUpdated.addEventListener( |
| 523 handleAvailableSpace); | 500 'update', handleAvailableSpace); |
| 524 cr.quota.onGlobalInfoUpdated.addEventListener('update', handleGlobalInfo); | 501 cr.quota.onGlobalInfoUpdated.addEventListener('update', handleGlobalInfo); |
| 525 cr.quota.onPerHostInfoUpdated.addEventListener('update', handlePerHostInfo); | 502 cr.quota.onPerHostInfoUpdated.addEventListener('update', handlePerHostInfo); |
| 526 cr.quota.onPerOriginInfoUpdated.addEventListener('update', | 503 cr.quota.onPerOriginInfoUpdated.addEventListener( |
| 527 handlePerOriginInfo); | 504 'update', handlePerOriginInfo); |
| 528 cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics); | 505 cr.quota.onStatisticsUpdated.addEventListener('update', handleStatistics); |
| 529 cr.quota.requestInfo(); | 506 cr.quota.requestInfo(); |
| 530 | 507 |
| 531 $('refresh-button').addEventListener('click', cr.quota.requestInfo, false); | 508 $('refresh-button').addEventListener('click', cr.quota.requestInfo, false); |
| 532 $('dump-button').addEventListener('click', dump, false); | 509 $('dump-button').addEventListener('click', dump, false); |
| 533 } | 510 } |
| 534 | 511 |
| 535 cr.doc.addEventListener('DOMContentLoaded', onLoad, false); | 512 cr.doc.addEventListener('DOMContentLoaded', onLoad, false); |
| 536 })(); | 513 })(); |
| OLD | NEW |