Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/DOMStorageItemsView.js

Issue 2649923006: [DevTools] Add filtering to DOM storages (Closed)
Patch Set: [DevTools] Add filtering to DOM storages Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Nokia Inc. All rights reserved. 2 * Copyright (C) 2008 Nokia Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 /** 27 Resources.DOMStorageItemsView = class extends Resources.StorageItemsView {
28 * @unrestricted 28 /**
29 */ 29 * @param {!Resources.DOMStorage} domStorage
30 Resources.DOMStorageItemsView = class extends UI.SimpleView { 30 */
31 constructor(domStorage) { 31 constructor(domStorage) {
32 super(Common.UIString('DOM Storage')); 32 super(Common.UIString('DOM Storage'), 'domStoragePanel');
33 33
34 this.domStorage = domStorage; 34 this._domStorage = domStorage;
35 35
36 this.element.classList.add('storage-view', 'table'); 36 this.element.classList.add('storage-view', 'table');
37 37
38 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largei con-delete'); 38 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([
39 this._deleteButton.setEnabled(false); 39 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50},
40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this); 40 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50}
41 41 ]);
42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear'); 42 this._dataGrid = new DataGrid.DataGrid(columns, this._editingCallback.bind(t his), this._deleteCallback.bind(this));
43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, () => this .domStorage.clear(), this); 43 this._dataGrid.setName('DOMStorageItemsView');
44 44 this._dataGrid.asWidget().show(this.element);
45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh'); 45 this._domStorage.addEventListener(
46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this);
47
48 this.domStorage.addEventListener(
49 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this); 46 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this);
50 this.domStorage.addEventListener( 47 this._domStorage.addEventListener(
51 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); 48 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this);
52 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this); 49 this._domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItem Added, this._domStorageItemAdded, this);
53 this.domStorage.addEventListener( 50 this._domStorage.addEventListener(
54 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); 51 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this);
55 } 52 }
56 53
57 /** 54 /**
58 * @override
59 * @return {!Array.<!UI.ToolbarItem>}
60 */
61 syncToolbarItems() {
62 return [this._refreshButton, this._clearButton, this._deleteButton];
63 }
64
65 /**
66 * @override
67 */
68 wasShown() {
69 this._update();
70 }
71
72 /**
73 * @override
74 */
75 willHide() {
76 this._deleteButton.setEnabled(false);
77 }
78
79 /**
80 * @param {!Common.Event} event 55 * @param {!Common.Event} event
81 */ 56 */
82 _domStorageItemsCleared(event) { 57 _domStorageItemsCleared(event) {
83 if (!this.isShowing() || !this._dataGrid) 58 if (!this.isShowing() || !this._dataGrid)
84 return; 59 return;
85 60
86 this._dataGrid.rootNode().removeChildren(); 61 this._dataGrid.rootNode().removeChildren();
87 this._dataGrid.addCreationNode(false); 62 this._dataGrid.addCreationNode(false);
88 this._deleteButton.setEnabled(false); 63 this.setCanDeleteSelected(false);
89 } 64 }
90 65
91 /** 66 /**
92 * @param {!Common.Event} event 67 * @param {!Common.Event} event
93 */ 68 */
94 _domStorageItemRemoved(event) { 69 _domStorageItemRemoved(event) {
95 if (!this.isShowing() || !this._dataGrid) 70 if (!this.isShowing() || !this._dataGrid)
96 return; 71 return;
97 72
98 var storageData = event.data; 73 var storageData = event.data;
99 var rootNode = this._dataGrid.rootNode(); 74 var rootNode = this._dataGrid.rootNode();
100 var children = rootNode.children; 75 var children = rootNode.children;
101 76
102 for (var i = 0; i < children.length; ++i) { 77 for (var i = 0; i < children.length; ++i) {
103 var childNode = children[i]; 78 var childNode = children[i];
104 if (childNode.data.key === storageData.key) { 79 if (childNode.data.key === storageData.key) {
105 rootNode.removeChild(childNode); 80 rootNode.removeChild(childNode);
106 this._deleteButton.setEnabled(children.length > 1); 81 this.setCanDeleteSelected(children.length > 1);
107 return; 82 return;
108 } 83 }
109 } 84 }
110 } 85 }
111 86
112 /** 87 /**
113 * @param {!Common.Event} event 88 * @param {!Common.Event} event
114 */ 89 */
115 _domStorageItemAdded(event) { 90 _domStorageItemAdded(event) {
116 if (!this.isShowing() || !this._dataGrid) 91 if (!this.isShowing() || !this._dataGrid)
117 return; 92 return;
118 93
119 var storageData = event.data; 94 var storageData = event.data;
120 var rootNode = this._dataGrid.rootNode(); 95 var rootNode = this._dataGrid.rootNode();
121 var children = rootNode.children; 96 var children = rootNode.children;
122 97
123 this._deleteButton.setEnabled(true); 98 this.setCanDeleteSelected(true);
124 99
125 for (var i = 0; i < children.length; ++i) { 100 for (var i = 0; i < children.length; ++i) {
126 if (children[i].data.key === storageData.key) 101 if (children[i].data.key === storageData.key)
127 return; 102 return;
128 } 103 }
129 104
130 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); 105 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false);
131 rootNode.insertChild(childNode, children.length - 1); 106 rootNode.insertChild(childNode, children.length - 1);
132 } 107 }
133 108
(...skipping 16 matching lines...) Expand all
150 rootNode.removeChild(childNode); 125 rootNode.removeChild(childNode);
151 return; 126 return;
152 } 127 }
153 keyFound = true; 128 keyFound = true;
154 if (childNode.data.value !== storageData.value) { 129 if (childNode.data.value !== storageData.value) {
155 childNode.data.value = storageData.value; 130 childNode.data.value = storageData.value;
156 childNode.refresh(); 131 childNode.refresh();
157 childNode.select(); 132 childNode.select();
158 childNode.reveal(); 133 childNode.reveal();
159 } 134 }
160 this._deleteButton.setEnabled(true); 135 this.setCanDeleteSelected(true);
161 } 136 }
162 } 137 }
163 } 138 }
164 139
165 _update() { 140 /**
166 this.detachChildWidgets(); 141 * @param {?string} error
167 this.domStorage.getItems(this._showDOMStorageItems.bind(this)); 142 * @param {!Array<!Array<string>>} items
168 } 143 */
169
170 _showDOMStorageItems(error, items) { 144 _showDOMStorageItems(error, items) {
171 if (error) 145 if (error)
172 return; 146 return;
173 147 var rootNode = this._dataGrid.rootNode();
174 this._dataGrid = this._dataGridForDOMStorageItems(items); 148 var selectedKey = null;
175 this._dataGrid.asWidget().show(this.element); 149 for (var node of rootNode.children) {
176 this._deleteButton.setEnabled(this._dataGrid.rootNode().children.length > 1) ; 150 if (!node.selected)
177 } 151 continue;
178 152 selectedKey = node.data.key;
179 _dataGridForDOMStorageItems(items) { 153 break;
180 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ 154 }
181 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, 155 rootNode.removeChildren();
182 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50} 156 var selectedNode = null;
183 ]); 157 var filteredItems = item => `${item[0]} ${item[1]}`;
184 158 for (var item of this.filter(items, filteredItems)) {
185 var nodes = []; 159 var key = item[0];
186 160 var value = item[1];
187 var keys = [];
188 var length = items.length;
189 for (var i = 0; i < items.length; i++) {
190 var key = items[i][0];
191 var value = items[i][1];
192 var node = new DataGrid.DataGridNode({key: key, value: value}, false); 161 var node = new DataGrid.DataGridNode({key: key, value: value}, false);
193 node.selectable = true; 162 node.selectable = true;
194 nodes.push(node); 163 rootNode.appendChild(node);
195 keys.push(key); 164 if (!selectedNode || key === selectedKey)
165 selectedNode = node;
196 } 166 }
197 167 if (selectedNode)
198 var dataGrid = new DataGrid.DataGrid(columns, this._editingCallback.bind(thi s), this._deleteCallback.bind(this)); 168 selectedNode.selected = true;
199 dataGrid.setName('DOMStorageItemsView'); 169 this._dataGrid.addCreationNode(false);
200 length = nodes.length; 170 this.setCanDeleteSelected(!!selectedNode);
201 for (var i = 0; i < length; ++i)
202 dataGrid.rootNode().appendChild(nodes[i]);
203 dataGrid.addCreationNode(false);
204 if (length > 0)
205 nodes[0].selected = true;
206 return dataGrid;
207 } 171 }
208 172
209 /** 173 /**
210 * @param {!Common.Event} event 174 * @override
211 */ 175 */
212 _deleteButtonClicked(event) { 176 deleteSelectedItem() {
213 if (!this._dataGrid || !this._dataGrid.selectedNode) 177 if (!this._dataGrid || !this._dataGrid.selectedNode)
214 return; 178 return;
215 179
216 this._deleteCallback(this._dataGrid.selectedNode); 180 this._deleteCallback(this._dataGrid.selectedNode);
217 } 181 }
218 182
219 /** 183 /**
220 * @param {!Common.Event} event 184 * @override
221 */ 185 */
222 _refreshButtonClicked(event) { 186 refreshItems() {
223 this._update(); 187 this._domStorage.getItems((error, items) => this._showDOMStorageItems(error, items));
188 }
189
190 /**
191 * @override
192 */
193 deleteAllItems() {
194 this._domStorage.clear();
224 } 195 }
225 196
226 _editingCallback(editingNode, columnIdentifier, oldText, newText) { 197 _editingCallback(editingNode, columnIdentifier, oldText, newText) {
227 var domStorage = this.domStorage; 198 var domStorage = this._domStorage;
228 if (columnIdentifier === 'key') { 199 if (columnIdentifier === 'key') {
229 if (typeof oldText === 'string') 200 if (typeof oldText === 'string')
230 domStorage.removeItem(oldText); 201 domStorage.removeItem(oldText);
231 domStorage.setItem(newText, editingNode.data.value || ''); 202 domStorage.setItem(newText, editingNode.data.value || '');
232 this._removeDupes(editingNode); 203 this._removeDupes(editingNode);
233 } else { 204 } else {
234 domStorage.setItem(editingNode.data.key || '', newText); 205 domStorage.setItem(editingNode.data.key || '', newText);
235 } 206 }
236 } 207 }
237 208
238 /** 209 /**
239 * @param {!DataGrid.DataGridNode} masterNode 210 * @param {!DataGrid.DataGridNode} masterNode
240 */ 211 */
241 _removeDupes(masterNode) { 212 _removeDupes(masterNode) {
242 var rootNode = this._dataGrid.rootNode(); 213 var rootNode = this._dataGrid.rootNode();
243 var children = rootNode.children; 214 var children = rootNode.children;
244 for (var i = children.length - 1; i >= 0; --i) { 215 for (var i = children.length - 1; i >= 0; --i) {
245 var childNode = children[i]; 216 var childNode = children[i];
246 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode)) 217 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode))
247 rootNode.removeChild(childNode); 218 rootNode.removeChild(childNode);
248 } 219 }
249 } 220 }
250 221
251 _deleteCallback(node) { 222 _deleteCallback(node) {
252 if (!node || node.isCreationNode) 223 if (!node || node.isCreationNode)
253 return; 224 return;
254 225
255 if (this.domStorage) 226 if (this._domStorage)
256 this.domStorage.removeItem(node.data.key); 227 this._domStorage.removeItem(node.data.key);
257 } 228 }
258 }; 229 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698