| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.ServiceWorkerCacheView = class extends WebInspector.SimpleView { | 7 Resources.ServiceWorkerCacheView = class extends UI.SimpleView { |
| 8 /** | 8 /** |
| 9 * @param {!WebInspector.ServiceWorkerCacheModel} model | 9 * @param {!SDK.ServiceWorkerCacheModel} model |
| 10 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | 10 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache |
| 11 */ | 11 */ |
| 12 constructor(model, cache) { | 12 constructor(model, cache) { |
| 13 super(WebInspector.UIString('Cache')); | 13 super(Common.UIString('Cache')); |
| 14 this.registerRequiredCSS('resources/serviceWorkerCacheViews.css'); | 14 this.registerRequiredCSS('resources/serviceWorkerCacheViews.css'); |
| 15 | 15 |
| 16 this._model = model; | 16 this._model = model; |
| 17 | 17 |
| 18 this.element.classList.add('service-worker-cache-data-view'); | 18 this.element.classList.add('service-worker-cache-data-view'); |
| 19 this.element.classList.add('storage-view'); | 19 this.element.classList.add('storage-view'); |
| 20 | 20 |
| 21 this._createEditorToolbar(); | 21 this._createEditorToolbar(); |
| 22 | 22 |
| 23 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString('
Refresh'), 'largeicon-refresh'); | 23 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); |
| 24 this._refreshButton.addEventListener('click', this._refreshButtonClicked, th
is); | 24 this._refreshButton.addEventListener('click', this._refreshButtonClicked, th
is); |
| 25 | 25 |
| 26 this._pageSize = 50; | 26 this._pageSize = 50; |
| 27 this._skipCount = 0; | 27 this._skipCount = 0; |
| 28 | 28 |
| 29 this.update(cache); | 29 this.update(cache); |
| 30 this._entries = []; | 30 this._entries = []; |
| 31 } | 31 } |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * @return {!WebInspector.DataGrid} | 34 * @return {!UI.DataGrid} |
| 35 */ | 35 */ |
| 36 _createDataGrid() { | 36 _createDataGrid() { |
| 37 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */
([ | 37 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([ |
| 38 {id: 'number', title: WebInspector.UIString('#'), width: '50px'}, | 38 {id: 'number', title: Common.UIString('#'), width: '50px'}, |
| 39 {id: 'request', title: WebInspector.UIString('Request')}, | 39 {id: 'request', title: Common.UIString('Request')}, |
| 40 {id: 'response', title: WebInspector.UIString('Response')} | 40 {id: 'response', title: Common.UIString('Response')} |
| 41 ]); | 41 ]); |
| 42 return new WebInspector.DataGrid( | 42 return new UI.DataGrid( |
| 43 columns, undefined, this._deleteButtonClicked.bind(this), this._updateDa
ta.bind(this, true)); | 43 columns, undefined, this._deleteButtonClicked.bind(this), this._updateDa
ta.bind(this, true)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 _createEditorToolbar() { | 46 _createEditorToolbar() { |
| 47 var editorToolbar = new WebInspector.Toolbar('data-view-toolbar', this.eleme
nt); | 47 var editorToolbar = new UI.Toolbar('data-view-toolbar', this.element); |
| 48 | 48 |
| 49 this._pageBackButton = | 49 this._pageBackButton = |
| 50 new WebInspector.ToolbarButton(WebInspector.UIString('Show previous page
'), 'largeicon-play-back'); | 50 new UI.ToolbarButton(Common.UIString('Show previous page'), 'largeicon-p
lay-back'); |
| 51 this._pageBackButton.addEventListener('click', this._pageBackButtonClicked,
this); | 51 this._pageBackButton.addEventListener('click', this._pageBackButtonClicked,
this); |
| 52 editorToolbar.appendToolbarItem(this._pageBackButton); | 52 editorToolbar.appendToolbarItem(this._pageBackButton); |
| 53 | 53 |
| 54 this._pageForwardButton = | 54 this._pageForwardButton = |
| 55 new WebInspector.ToolbarButton(WebInspector.UIString('Show next page'),
'largeicon-play'); | 55 new UI.ToolbarButton(Common.UIString('Show next page'), 'largeicon-play'
); |
| 56 this._pageForwardButton.setEnabled(false); | 56 this._pageForwardButton.setEnabled(false); |
| 57 this._pageForwardButton.addEventListener('click', this._pageForwardButtonCli
cked, this); | 57 this._pageForwardButton.addEventListener('click', this._pageForwardButtonCli
cked, this); |
| 58 editorToolbar.appendToolbarItem(this._pageForwardButton); | 58 editorToolbar.appendToolbarItem(this._pageForwardButton); |
| 59 } | 59 } |
| 60 | 60 |
| 61 _pageBackButtonClicked() { | 61 _pageBackButtonClicked() { |
| 62 this._skipCount = Math.max(0, this._skipCount - this._pageSize); | 62 this._skipCount = Math.max(0, this._skipCount - this._pageSize); |
| 63 this._updateData(false); | 63 this._updateData(false); |
| 64 } | 64 } |
| 65 | 65 |
| 66 _pageForwardButtonClicked() { | 66 _pageForwardButtonClicked() { |
| 67 this._skipCount = this._skipCount + this._pageSize; | 67 this._skipCount = this._skipCount + this._pageSize; |
| 68 this._updateData(false); | 68 this._updateData(false); |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {!WebInspector.DataGridNode} node | 72 * @param {!UI.DataGridNode} node |
| 73 */ | 73 */ |
| 74 _deleteButtonClicked(node) { | 74 _deleteButtonClicked(node) { |
| 75 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.data['
request']), node.remove.bind(node)); | 75 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.data['
request']), node.remove.bind(node)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | 79 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache |
| 80 */ | 80 */ |
| 81 update(cache) { | 81 update(cache) { |
| 82 this._cache = cache; | 82 this._cache = cache; |
| 83 | 83 |
| 84 if (this._dataGrid) | 84 if (this._dataGrid) |
| 85 this._dataGrid.asWidget().detach(); | 85 this._dataGrid.asWidget().detach(); |
| 86 this._dataGrid = this._createDataGrid(); | 86 this._dataGrid = this._createDataGrid(); |
| 87 this._dataGrid.asWidget().show(this.element); | 87 this._dataGrid.asWidget().show(this.element); |
| 88 this._skipCount = 0; | 88 this._skipCount = 0; |
| 89 this._updateData(true); | 89 this._updateData(true); |
| 90 } | 90 } |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * @param {number} skipCount | 93 * @param {number} skipCount |
| 94 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} entries | 94 * @param {!Array.<!SDK.ServiceWorkerCacheModel.Entry>} entries |
| 95 * @param {boolean} hasMore | 95 * @param {boolean} hasMore |
| 96 * @this {WebInspector.ServiceWorkerCacheView} | 96 * @this {Resources.ServiceWorkerCacheView} |
| 97 */ | 97 */ |
| 98 _updateDataCallback(skipCount, entries, hasMore) { | 98 _updateDataCallback(skipCount, entries, hasMore) { |
| 99 this._refreshButton.setEnabled(true); | 99 this._refreshButton.setEnabled(true); |
| 100 this.clear(); | 100 this.clear(); |
| 101 this._entries = entries; | 101 this._entries = entries; |
| 102 for (var i = 0; i < entries.length; ++i) { | 102 for (var i = 0; i < entries.length; ++i) { |
| 103 var data = {}; | 103 var data = {}; |
| 104 data['number'] = i + skipCount; | 104 data['number'] = i + skipCount; |
| 105 data['request'] = entries[i].request; | 105 data['request'] = entries[i].request; |
| 106 data['response'] = entries[i].response; | 106 data['response'] = entries[i].response; |
| 107 var node = new WebInspector.DataGridNode(data); | 107 var node = new UI.DataGridNode(data); |
| 108 node.selectable = true; | 108 node.selectable = true; |
| 109 this._dataGrid.rootNode().appendChild(node); | 109 this._dataGrid.rootNode().appendChild(node); |
| 110 } | 110 } |
| 111 this._pageBackButton.setEnabled(!!skipCount); | 111 this._pageBackButton.setEnabled(!!skipCount); |
| 112 this._pageForwardButton.setEnabled(hasMore); | 112 this._pageForwardButton.setEnabled(hasMore); |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * @param {boolean} force | 116 * @param {boolean} force |
| 117 */ | 117 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 131 this._lastSkipCount = skipCount; | 131 this._lastSkipCount = skipCount; |
| 132 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateData
Callback.bind(this, skipCount)); | 132 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateData
Callback.bind(this, skipCount)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 _refreshButtonClicked(event) { | 135 _refreshButtonClicked(event) { |
| 136 this._updateData(true); | 136 this._updateData(true); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /** | 139 /** |
| 140 * @override | 140 * @override |
| 141 * @return {!Array.<!WebInspector.ToolbarItem>} | 141 * @return {!Array.<!UI.ToolbarItem>} |
| 142 */ | 142 */ |
| 143 syncToolbarItems() { | 143 syncToolbarItems() { |
| 144 return [this._refreshButton]; | 144 return [this._refreshButton]; |
| 145 } | 145 } |
| 146 | 146 |
| 147 clear() { | 147 clear() { |
| 148 this._dataGrid.rootNode().removeChildren(); | 148 this._dataGrid.rootNode().removeChildren(); |
| 149 this._entries = []; | 149 this._entries = []; |
| 150 } | 150 } |
| 151 }; | 151 }; |
| OLD | NEW |