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
3 // found in the LICENSE file.
7 * @extends {WebInspector.VBox}
8 * @param {!WebInspector.ServiceWorkerCacheModel} model
9 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
11 WebInspector
.ServiceWorkerCacheView = function(model
, cache
)
13 WebInspector
.VBox
.call(this);
14 this.registerRequiredCSS("resources/serviceWorkerCacheViews.css");
18 this.element
.classList
.add("service-worker-cache-data-view");
19 this.element
.classList
.add("storage-view");
21 this._createEditorToolbar();
23 this._refreshButton
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Refresh"), "refresh-toolbar-item");
24 this._refreshButton
.addEventListener("click", this._refreshButtonClicked
, this);
33 WebInspector
.ServiceWorkerCacheView
.prototype = {
35 * @return {!WebInspector.DataGrid}
37 _createDataGrid: function()
40 columns
.push({id
: "number", title
: WebInspector
.UIString("#"), width
: "50px"});
41 columns
.push({id
: "request", title
: WebInspector
.UIString("Request")});
42 columns
.push({id
: "response", title
: WebInspector
.UIString("Response")});
44 var dataGrid
= new WebInspector
.DataGrid(columns
, undefined, this._deleteButtonClicked
.bind(this), this._updateData
.bind(this, true));
48 _createEditorToolbar: function()
50 var editorToolbar
= new WebInspector
.Toolbar(this.element
);
51 editorToolbar
.element
.classList
.add("data-view-toolbar");
53 this._pageBackButton
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Show previous page"), "play-backwards-toolbar-item");
54 this._pageBackButton
.addEventListener("click", this._pageBackButtonClicked
, this);
55 editorToolbar
.appendToolbarItem(this._pageBackButton
);
57 this._pageForwardButton
= new WebInspector
.ToolbarButton(WebInspector
.UIString("Show next page"), "play-toolbar-item");
58 this._pageForwardButton
.setEnabled(false);
59 this._pageForwardButton
.addEventListener("click", this._pageForwardButtonClicked
, this);
60 editorToolbar
.appendToolbarItem(this._pageForwardButton
);
63 _pageBackButtonClicked: function()
65 this._skipCount
= Math
.max(0, this._skipCount
- this._pageSize
);
66 this._updateData(false);
69 _pageForwardButtonClicked: function()
71 this._skipCount
= this._skipCount
+ this._pageSize
;
72 this._updateData(false);
76 * @param {!WebInspector.DataGridNode} node
78 _deleteButtonClicked: function(node
)
80 this._model
.deleteCacheEntry(this._cache
, node
.data
["request"], node
.remove
.bind(node
));
84 * @param {!WebInspector.ServiceWorkerCacheModel.Cache} cache
86 update: function(cache
)
91 this._dataGrid
.detach();
92 this._dataGrid
= this._createDataGrid();
93 this._dataGrid
.show(this.element
);
96 this._updateData(true);
100 * @param {number} skipCount
101 * @param {!Array.<!WebInspector.ServiceWorkerCacheModel.Entry>} entries
102 * @param {boolean} hasMore
103 * @this {WebInspector.ServiceWorkerCacheView}
105 _updateDataCallback(skipCount
, entries
, hasMore
)
107 this._refreshButton
.setEnabled(true);
109 this._entries
= entries
;
110 for (var i
= 0; i
< entries
.length
; ++i
) {
112 data
["number"] = i
+ skipCount
;
113 data
["request"] = entries
[i
].request
;
114 data
["response"] = entries
[i
].response
;
115 var node
= new WebInspector
.DataGridNode(data
);
116 node
.selectable
= true;
117 this._dataGrid
.rootNode().appendChild(node
);
119 this._pageBackButton
.setEnabled(!!skipCount
);
120 this._pageForwardButton
.setEnabled(hasMore
);
124 * @param {boolean} force
126 _updateData: function(force
)
128 var pageSize
= this._pageSize
;
129 var skipCount
= this._skipCount
;
130 this._refreshButton
.setEnabled(false);
132 if (!force
&& this._lastPageSize
=== pageSize
&& this._lastSkipCount
=== skipCount
)
135 if (this._lastPageSize
!== pageSize
) {
139 this._lastPageSize
= pageSize
;
140 this._lastSkipCount
= skipCount
;
141 this._model
.loadCacheData(this._cache
, skipCount
, pageSize
, this._updateDataCallback
.bind(this, skipCount
));
144 _refreshButtonClicked: function(event
)
146 this._updateData(true);
150 * @return {!Array.<!WebInspector.ToolbarItem>}
152 toolbarItems: function()
154 return [this._refreshButton
];
159 this._dataGrid
.rootNode().removeChildren();
163 __proto__
: WebInspector
.VBox
.prototype