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 | |
5 /** | 4 /** |
6 * @constructor | 5 * @unrestricted |
7 * @extends {WebInspector.SimpleView} | |
8 * @param {!WebInspector.ServiceWorkerCacheModel} model | |
9 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
10 */ | 6 */ |
11 WebInspector.ServiceWorkerCacheView = function(model, cache) | 7 WebInspector.ServiceWorkerCacheView = class extends WebInspector.SimpleView { |
12 { | 8 /** |
13 WebInspector.SimpleView.call(this, WebInspector.UIString("Cache")); | 9 * @param {!WebInspector.ServiceWorkerCacheModel} model |
14 this.registerRequiredCSS("resources/serviceWorkerCacheViews.css"); | 10 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 11 */ |
| 12 constructor(model, cache) { |
| 13 super(WebInspector.UIString('Cache')); |
| 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"), "refresh-toolbar-item"); | 23 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString('
Refresh'), 'refresh-toolbar-item'); |
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 } |
| 32 |
| 33 /** |
| 34 * @return {!WebInspector.DataGrid} |
| 35 */ |
| 36 _createDataGrid() { |
| 37 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */
([ |
| 38 {id: 'number', title: WebInspector.UIString('#'), width: '50px'}, |
| 39 {id: 'request', title: WebInspector.UIString('Request')}, |
| 40 {id: 'response', title: WebInspector.UIString('Response')} |
| 41 ]); |
| 42 return new WebInspector.DataGrid( |
| 43 columns, undefined, this._deleteButtonClicked.bind(this), this._updateDa
ta.bind(this, true)); |
| 44 } |
| 45 |
| 46 _createEditorToolbar() { |
| 47 var editorToolbar = new WebInspector.Toolbar('data-view-toolbar', this.eleme
nt); |
| 48 |
| 49 this._pageBackButton = |
| 50 new WebInspector.ToolbarButton(WebInspector.UIString('Show previous page
'), 'play-backwards-toolbar-item'); |
| 51 this._pageBackButton.addEventListener('click', this._pageBackButtonClicked,
this); |
| 52 editorToolbar.appendToolbarItem(this._pageBackButton); |
| 53 |
| 54 this._pageForwardButton = |
| 55 new WebInspector.ToolbarButton(WebInspector.UIString('Show next page'),
'play-toolbar-item'); |
| 56 this._pageForwardButton.setEnabled(false); |
| 57 this._pageForwardButton.addEventListener('click', this._pageForwardButtonCli
cked, this); |
| 58 editorToolbar.appendToolbarItem(this._pageForwardButton); |
| 59 } |
| 60 |
| 61 _pageBackButtonClicked() { |
| 62 this._skipCount = Math.max(0, this._skipCount - this._pageSize); |
| 63 this._updateData(false); |
| 64 } |
| 65 |
| 66 _pageForwardButtonClicked() { |
| 67 this._skipCount = this._skipCount + this._pageSize; |
| 68 this._updateData(false); |
| 69 } |
| 70 |
| 71 /** |
| 72 * @param {!WebInspector.DataGridNode} node |
| 73 */ |
| 74 _deleteButtonClicked(node) { |
| 75 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.data['
request']), node.remove.bind(node)); |
| 76 } |
| 77 |
| 78 /** |
| 79 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache |
| 80 */ |
| 81 update(cache) { |
| 82 this._cache = cache; |
| 83 |
| 84 if (this._dataGrid) |
| 85 this._dataGrid.asWidget().detach(); |
| 86 this._dataGrid = this._createDataGrid(); |
| 87 this._dataGrid.asWidget().show(this.element); |
| 88 this._skipCount = 0; |
| 89 this._updateData(true); |
| 90 } |
| 91 |
| 92 /** |
| 93 * @param {number} skipCount |
| 94 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} entries |
| 95 * @param {boolean} hasMore |
| 96 * @this {WebInspector.ServiceWorkerCacheView} |
| 97 */ |
| 98 _updateDataCallback(skipCount, entries, hasMore) { |
| 99 this._refreshButton.setEnabled(true); |
| 100 this.clear(); |
| 101 this._entries = entries; |
| 102 for (var i = 0; i < entries.length; ++i) { |
| 103 var data = {}; |
| 104 data['number'] = i + skipCount; |
| 105 data['request'] = entries[i].request; |
| 106 data['response'] = entries[i].response; |
| 107 var node = new WebInspector.DataGridNode(data); |
| 108 node.selectable = true; |
| 109 this._dataGrid.rootNode().appendChild(node); |
| 110 } |
| 111 this._pageBackButton.setEnabled(!!skipCount); |
| 112 this._pageForwardButton.setEnabled(hasMore); |
| 113 } |
| 114 |
| 115 /** |
| 116 * @param {boolean} force |
| 117 */ |
| 118 _updateData(force) { |
| 119 var pageSize = this._pageSize; |
| 120 var skipCount = this._skipCount; |
| 121 this._refreshButton.setEnabled(false); |
| 122 |
| 123 if (!force && this._lastPageSize === pageSize && this._lastSkipCount === ski
pCount) |
| 124 return; |
| 125 |
| 126 if (this._lastPageSize !== pageSize) { |
| 127 skipCount = 0; |
| 128 this._skipCount = 0; |
| 129 } |
| 130 this._lastPageSize = pageSize; |
| 131 this._lastSkipCount = skipCount; |
| 132 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateData
Callback.bind(this, skipCount)); |
| 133 } |
| 134 |
| 135 _refreshButtonClicked(event) { |
| 136 this._updateData(true); |
| 137 } |
| 138 |
| 139 /** |
| 140 * @override |
| 141 * @return {!Array.<!WebInspector.ToolbarItem>} |
| 142 */ |
| 143 syncToolbarItems() { |
| 144 return [this._refreshButton]; |
| 145 } |
| 146 |
| 147 clear() { |
| 148 this._dataGrid.rootNode().removeChildren(); |
| 149 this._entries = []; |
| 150 } |
31 }; | 151 }; |
32 | |
33 WebInspector.ServiceWorkerCacheView.prototype = { | |
34 /** | |
35 * @return {!WebInspector.DataGrid} | |
36 */ | |
37 _createDataGrid: function() | |
38 { | |
39 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>
} */ ([ | |
40 {id: "number", title: WebInspector.UIString("#"), width: "50px"}, | |
41 {id: "request", title: WebInspector.UIString("Request")}, | |
42 {id: "response", title: WebInspector.UIString("Response")} | |
43 ]); | |
44 return new WebInspector.DataGrid(columns, undefined, this._deleteButtonC
licked.bind(this), this._updateData.bind(this, true)); | |
45 }, | |
46 | |
47 _createEditorToolbar: function() | |
48 { | |
49 var editorToolbar = new WebInspector.Toolbar("data-view-toolbar", this.e
lement); | |
50 | |
51 this._pageBackButton = new WebInspector.ToolbarButton(WebInspector.UIStr
ing("Show previous page"), "play-backwards-toolbar-item"); | |
52 this._pageBackButton.addEventListener("click", this._pageBackButtonClick
ed, this); | |
53 editorToolbar.appendToolbarItem(this._pageBackButton); | |
54 | |
55 this._pageForwardButton = new WebInspector.ToolbarButton(WebInspector.UI
String("Show next page"), "play-toolbar-item"); | |
56 this._pageForwardButton.setEnabled(false); | |
57 this._pageForwardButton.addEventListener("click", this._pageForwardButto
nClicked, this); | |
58 editorToolbar.appendToolbarItem(this._pageForwardButton); | |
59 }, | |
60 | |
61 _pageBackButtonClicked: function() | |
62 { | |
63 this._skipCount = Math.max(0, this._skipCount - this._pageSize); | |
64 this._updateData(false); | |
65 }, | |
66 | |
67 _pageForwardButtonClicked: function() | |
68 { | |
69 this._skipCount = this._skipCount + this._pageSize; | |
70 this._updateData(false); | |
71 }, | |
72 | |
73 /** | |
74 * @param {!WebInspector.DataGridNode} node | |
75 */ | |
76 _deleteButtonClicked: function(node) | |
77 { | |
78 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.da
ta["request"]), node.remove.bind(node)); | |
79 }, | |
80 | |
81 /** | |
82 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache | |
83 */ | |
84 update: function(cache) | |
85 { | |
86 this._cache = cache; | |
87 | |
88 if (this._dataGrid) | |
89 this._dataGrid.asWidget().detach(); | |
90 this._dataGrid = this._createDataGrid(); | |
91 this._dataGrid.asWidget().show(this.element); | |
92 this._skipCount = 0; | |
93 this._updateData(true); | |
94 }, | |
95 | |
96 /** | |
97 * @param {number} skipCount | |
98 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} entries | |
99 * @param {boolean} hasMore | |
100 * @this {WebInspector.ServiceWorkerCacheView} | |
101 */ | |
102 _updateDataCallback(skipCount, entries, hasMore) | |
103 { | |
104 this._refreshButton.setEnabled(true); | |
105 this.clear(); | |
106 this._entries = entries; | |
107 for (var i = 0; i < entries.length; ++i) { | |
108 var data = {}; | |
109 data["number"] = i + skipCount; | |
110 data["request"] = entries[i].request; | |
111 data["response"] = entries[i].response; | |
112 var node = new WebInspector.DataGridNode(data); | |
113 node.selectable = true; | |
114 this._dataGrid.rootNode().appendChild(node); | |
115 } | |
116 this._pageBackButton.setEnabled(!!skipCount); | |
117 this._pageForwardButton.setEnabled(hasMore); | |
118 }, | |
119 | |
120 /** | |
121 * @param {boolean} force | |
122 */ | |
123 _updateData: function(force) | |
124 { | |
125 var pageSize = this._pageSize; | |
126 var skipCount = this._skipCount; | |
127 this._refreshButton.setEnabled(false); | |
128 | |
129 if (!force && this._lastPageSize === pageSize && this._lastSkipCount ===
skipCount) | |
130 return; | |
131 | |
132 if (this._lastPageSize !== pageSize) { | |
133 skipCount = 0; | |
134 this._skipCount = 0; | |
135 } | |
136 this._lastPageSize = pageSize; | |
137 this._lastSkipCount = skipCount; | |
138 this._model.loadCacheData(this._cache, skipCount, pageSize, this._update
DataCallback.bind(this, skipCount)); | |
139 }, | |
140 | |
141 _refreshButtonClicked: function(event) | |
142 { | |
143 this._updateData(true); | |
144 }, | |
145 | |
146 /** | |
147 * @override | |
148 * @return {!Array.<!WebInspector.ToolbarItem>} | |
149 */ | |
150 syncToolbarItems: function() | |
151 { | |
152 return [this._refreshButton]; | |
153 }, | |
154 | |
155 clear: function() | |
156 { | |
157 this._dataGrid.rootNode().removeChildren(); | |
158 this._entries = []; | |
159 }, | |
160 | |
161 __proto__: WebInspector.SimpleView.prototype | |
162 }; | |
OLD | NEW |