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 Resources.ServiceWorkerCacheView = class extends UI.SimpleView { | 7 Resources.ServiceWorkerCacheView = class extends UI.SimpleView { |
8 /** | 8 /** |
9 * @param {!SDK.ServiceWorkerCacheModel} model | 9 * @param {!SDK.ServiceWorkerCacheModel} model |
10 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache | 10 * @param {!SDK.ServiceWorkerCacheModel.Cache} cache |
11 */ | 11 */ |
12 constructor(model, cache) { | 12 constructor(model, cache) { |
13 super(Common.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 UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); | 23 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg
eicon-refresh'); |
24 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re
freshButtonClicked, this); | 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 {!UI.DataGrid} | 34 * @return {!UI.DataGrid} |
35 */ | 35 */ |
36 _createDataGrid() { | 36 _createDataGrid() { |
37 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([ | 37 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([ |
38 {id: 'number', title: Common.UIString('#'), width: '50px'}, {id: 'request'
, title: Common.UIString('Request')}, | 38 {id: 'number', title: Common.UIString('#'), width: '50px'}, {id: 'request'
, title: Common.UIString('Request')}, |
39 {id: 'response', title: Common.UIString('Response')} | 39 {id: 'response', title: Common.UIString('Response')} |
40 ]); | 40 ]); |
41 return new UI.DataGrid(columns, undefined, this._deleteButtonClicked.bind(th
is), this._updateData.bind(this, true)); | 41 return new UI.DataGrid(columns, undefined, this._deleteButtonClicked.bind(th
is), this._updateData.bind(this, true)); |
42 } | 42 } |
43 | 43 |
44 _createEditorToolbar() { | 44 _createEditorToolbar() { |
45 var editorToolbar = new UI.Toolbar('data-view-toolbar', this.element); | 45 var editorToolbar = new UI.Toolbar('data-view-toolbar', this.element); |
46 | 46 |
47 this._pageBackButton = new UI.ToolbarButton(Common.UIString('Show previous p
age'), 'largeicon-play-back'); | 47 this._pageBackButton = new UI.ToolbarButton(Common.UIString('Show previous p
age'), 'largeicon-play-back'); |
48 this._pageBackButton.addEventListener(UI.ToolbarButton.Events.Click, this._p
ageBackButtonClicked, this); | 48 this._pageBackButton.addEventListener('click', this._pageBackButtonClicked,
this); |
49 editorToolbar.appendToolbarItem(this._pageBackButton); | 49 editorToolbar.appendToolbarItem(this._pageBackButton); |
50 | 50 |
51 this._pageForwardButton = new UI.ToolbarButton(Common.UIString('Show next pa
ge'), 'largeicon-play'); | 51 this._pageForwardButton = new UI.ToolbarButton(Common.UIString('Show next pa
ge'), 'largeicon-play'); |
52 this._pageForwardButton.setEnabled(false); | 52 this._pageForwardButton.setEnabled(false); |
53 this._pageForwardButton.addEventListener(UI.ToolbarButton.Events.Click, this
._pageForwardButtonClicked, this); | 53 this._pageForwardButton.addEventListener('click', this._pageForwardButtonCli
cked, this); |
54 editorToolbar.appendToolbarItem(this._pageForwardButton); | 54 editorToolbar.appendToolbarItem(this._pageForwardButton); |
55 } | 55 } |
56 | 56 |
57 /** | 57 _pageBackButtonClicked() { |
58 * @param {!Common.Event} event | |
59 */ | |
60 _pageBackButtonClicked(event) { | |
61 this._skipCount = Math.max(0, this._skipCount - this._pageSize); | 58 this._skipCount = Math.max(0, this._skipCount - this._pageSize); |
62 this._updateData(false); | 59 this._updateData(false); |
63 } | 60 } |
64 | 61 |
65 /** | 62 _pageForwardButtonClicked() { |
66 * @param {!Common.Event} event | |
67 */ | |
68 _pageForwardButtonClicked(event) { | |
69 this._skipCount = this._skipCount + this._pageSize; | 63 this._skipCount = this._skipCount + this._pageSize; |
70 this._updateData(false); | 64 this._updateData(false); |
71 } | 65 } |
72 | 66 |
73 /** | 67 /** |
74 * @param {!UI.DataGridNode} node | 68 * @param {!UI.DataGridNode} node |
75 */ | 69 */ |
76 _deleteButtonClicked(node) { | 70 _deleteButtonClicked(node) { |
77 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.data['
request']), node.remove.bind(node)); | 71 this._model.deleteCacheEntry(this._cache, /** @type {string} */ (node.data['
request']), node.remove.bind(node)); |
78 } | 72 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 121 |
128 if (this._lastPageSize !== pageSize) { | 122 if (this._lastPageSize !== pageSize) { |
129 skipCount = 0; | 123 skipCount = 0; |
130 this._skipCount = 0; | 124 this._skipCount = 0; |
131 } | 125 } |
132 this._lastPageSize = pageSize; | 126 this._lastPageSize = pageSize; |
133 this._lastSkipCount = skipCount; | 127 this._lastSkipCount = skipCount; |
134 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateData
Callback.bind(this, skipCount)); | 128 this._model.loadCacheData(this._cache, skipCount, pageSize, this._updateData
Callback.bind(this, skipCount)); |
135 } | 129 } |
136 | 130 |
137 /** | |
138 * @param {!Common.Event} event | |
139 */ | |
140 _refreshButtonClicked(event) { | 131 _refreshButtonClicked(event) { |
141 this._updateData(true); | 132 this._updateData(true); |
142 } | 133 } |
143 | 134 |
144 /** | 135 /** |
145 * @override | 136 * @override |
146 * @return {!Array.<!UI.ToolbarItem>} | 137 * @return {!Array.<!UI.ToolbarItem>} |
147 */ | 138 */ |
148 syncToolbarItems() { | 139 syncToolbarItems() { |
149 return [this._refreshButton]; | 140 return [this._refreshButton]; |
150 } | 141 } |
151 | 142 |
152 clear() { | 143 clear() { |
153 this._dataGrid.rootNode().removeChildren(); | 144 this._dataGrid.rootNode().removeChildren(); |
154 this._entries = []; | 145 this._entries = []; |
155 } | 146 } |
156 }; | 147 }; |
OLD | NEW |