Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** |
| 28 * @unrestricted | 28 * @unrestricted |
| 29 */ | 29 */ |
| 30 Resources.DOMStorageItemsView = class extends UI.SimpleView { | 30 Resources.DOMStorageItemsView = class extends Resources.ItemsView { |
| 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; |
|
dgozman
2017/01/26 22:21:09
While you are here, mind renaming to _domStorage?
eostroukhov
2017/01/26 23:35:46
Done.
| |
| 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 ]); | |
| 42 var dataGrid = new DataGrid.DataGrid(columns, this._editingCallback.bind(thi s), this._deleteCallback.bind(this)); | |
|
dgozman
2017/01/26 22:21:09
this._dataGrid
eostroukhov
2017/01/26 23:35:45
Done.
| |
| 43 dataGrid.setName('DOMStorageItemsView'); | |
| 41 | 44 |
| 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear'); | 45 this._dataGrid = dataGrid; |
| 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, () => this .domStorage.clear(), this); | 46 this.showFilterBar(); |
|
dgozman
2017/01/26 22:21:09
Why show filter by default?
eostroukhov
2017/01/26 23:35:46
I will rename to "showFilterUI" - what it does is
| |
| 44 | 47 this._dataGrid.asWidget().show(this.element); |
| 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh'); | |
| 46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this); | |
| 47 | 48 |
| 48 this.domStorage.addEventListener( | 49 this.domStorage.addEventListener( |
| 49 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this); | 50 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this); |
| 50 this.domStorage.addEventListener( | 51 this.domStorage.addEventListener( |
| 51 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); | 52 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); |
| 52 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this); | 53 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this); |
| 53 this.domStorage.addEventListener( | 54 this.domStorage.addEventListener( |
| 54 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); | 55 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); |
| 55 } | 56 } |
| 56 | 57 |
| 57 /** | 58 /** |
| 58 * @override | 59 * @override |
| 59 * @return {!Array.<!UI.ToolbarItem>} | |
| 60 */ | |
| 61 syncToolbarItems() { | |
| 62 return [this._refreshButton, this._clearButton, this._deleteButton]; | |
| 63 } | |
| 64 | |
| 65 /** | |
| 66 * @override | |
| 67 */ | 60 */ |
| 68 wasShown() { | 61 wasShown() { |
| 69 this._update(); | 62 this.onRefresh(); |
| 70 } | 63 } |
| 71 | 64 |
| 72 /** | 65 /** |
| 73 * @override | 66 * @override |
| 74 */ | 67 */ |
| 75 willHide() { | 68 willHide() { |
| 76 this._deleteButton.setEnabled(false); | 69 this._setDeleteEnabled(false); |
| 77 } | 70 } |
| 78 | 71 |
| 79 /** | 72 /** |
| 80 * @param {!Common.Event} event | 73 * @param {!Common.Event} event |
| 81 */ | 74 */ |
| 82 _domStorageItemsCleared(event) { | 75 _domStorageItemsCleared(event) { |
| 83 if (!this.isShowing() || !this._dataGrid) | 76 if (!this.isShowing() || !this._dataGrid) |
| 84 return; | 77 return; |
| 85 | 78 |
| 86 this._dataGrid.rootNode().removeChildren(); | 79 this._dataGrid.rootNode().removeChildren(); |
| 87 this._dataGrid.addCreationNode(false); | 80 this._dataGrid.addCreationNode(false); |
| 88 this._deleteButton.setEnabled(false); | 81 this._setDeleteEnabled(false); |
| 89 } | 82 } |
| 90 | 83 |
| 91 /** | 84 /** |
| 92 * @param {!Common.Event} event | 85 * @param {!Common.Event} event |
| 93 */ | 86 */ |
| 94 _domStorageItemRemoved(event) { | 87 _domStorageItemRemoved(event) { |
| 95 if (!this.isShowing() || !this._dataGrid) | 88 if (!this.isShowing() || !this._dataGrid) |
| 96 return; | 89 return; |
| 97 | 90 |
| 98 var storageData = event.data; | 91 var storageData = event.data; |
| 99 var rootNode = this._dataGrid.rootNode(); | 92 var rootNode = this._dataGrid.rootNode(); |
| 100 var children = rootNode.children; | 93 var children = rootNode.children; |
| 101 | 94 |
| 102 for (var i = 0; i < children.length; ++i) { | 95 for (var i = 0; i < children.length; ++i) { |
| 103 var childNode = children[i]; | 96 var childNode = children[i]; |
| 104 if (childNode.data.key === storageData.key) { | 97 if (childNode.data.key === storageData.key) { |
| 105 rootNode.removeChild(childNode); | 98 rootNode.removeChild(childNode); |
| 106 this._deleteButton.setEnabled(children.length > 1); | 99 this._setDeleteEnabled(children.length > 1); |
| 107 return; | 100 return; |
| 108 } | 101 } |
| 109 } | 102 } |
| 110 } | 103 } |
| 111 | 104 |
| 112 /** | 105 /** |
| 113 * @param {!Common.Event} event | 106 * @param {!Common.Event} event |
| 114 */ | 107 */ |
| 115 _domStorageItemAdded(event) { | 108 _domStorageItemAdded(event) { |
| 116 if (!this.isShowing() || !this._dataGrid) | 109 if (!this.isShowing() || !this._dataGrid) |
| 117 return; | 110 return; |
| 118 | 111 |
| 119 var storageData = event.data; | 112 var storageData = event.data; |
| 120 var rootNode = this._dataGrid.rootNode(); | 113 var rootNode = this._dataGrid.rootNode(); |
| 121 var children = rootNode.children; | 114 var children = rootNode.children; |
| 122 | 115 |
| 123 this._deleteButton.setEnabled(true); | 116 this._setDeleteEnabled(true); |
| 124 | 117 |
| 125 for (var i = 0; i < children.length; ++i) { | 118 for (var i = 0; i < children.length; ++i) { |
| 126 if (children[i].data.key === storageData.key) | 119 if (children[i].data.key === storageData.key) |
| 127 return; | 120 return; |
| 128 } | 121 } |
| 129 | 122 |
| 130 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); | 123 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); |
| 131 rootNode.insertChild(childNode, children.length - 1); | 124 rootNode.insertChild(childNode, children.length - 1); |
| 132 } | 125 } |
| 133 | 126 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 150 rootNode.removeChild(childNode); | 143 rootNode.removeChild(childNode); |
| 151 return; | 144 return; |
| 152 } | 145 } |
| 153 keyFound = true; | 146 keyFound = true; |
| 154 if (childNode.data.value !== storageData.value) { | 147 if (childNode.data.value !== storageData.value) { |
| 155 childNode.data.value = storageData.value; | 148 childNode.data.value = storageData.value; |
| 156 childNode.refresh(); | 149 childNode.refresh(); |
| 157 childNode.select(); | 150 childNode.select(); |
| 158 childNode.reveal(); | 151 childNode.reveal(); |
| 159 } | 152 } |
| 160 this._deleteButton.setEnabled(true); | 153 this._setDeleteEnabled(true); |
| 161 } | 154 } |
| 162 } | 155 } |
| 163 } | 156 } |
| 164 | 157 |
| 165 _update() { | 158 /** |
| 166 this.detachChildWidgets(); | 159 * @param {?Object} error |
| 167 this.domStorage.getItems(this._showDOMStorageItems.bind(this)); | 160 * @param {!Array<!Array<string>>} items |
| 168 } | 161 */ |
| 169 | |
| 170 _showDOMStorageItems(error, items) { | 162 _showDOMStorageItems(error, items) { |
| 171 if (error) | 163 if (error) |
| 172 return; | 164 return; |
| 173 | 165 var rootNode = this._dataGrid.rootNode(); |
| 174 this._dataGrid = this._dataGridForDOMStorageItems(items); | 166 var selectedKey = null; |
| 175 this._dataGrid.asWidget().show(this.element); | 167 for (var node of rootNode.children) { |
| 176 this._deleteButton.setEnabled(this._dataGrid.rootNode().children.length > 1) ; | 168 if (!node.selected) |
| 169 continue; | |
| 170 selectedKey = node.data.key; | |
| 171 break; | |
| 172 } | |
| 173 rootNode.removeChildren(); | |
| 174 var selectedNode = null; | |
| 175 for (var item of this.filter(items, item => `${item[0]} ${item[1]}`)) { | |
|
dgozman
2017/01/26 22:21:09
Mind extracting |filteredItems| variable?
eostroukhov
2017/01/26 23:35:46
Done.
| |
| 176 var key = item[0]; | |
| 177 var value = item[1]; | |
| 178 var node = new DataGrid.DataGridNode({key, value}, false); | |
|
dgozman
2017/01/26 22:21:09
Don't use new language features without discussion
eostroukhov
2017/01/26 23:35:45
Assumed it was ok to use ES6 - I removed this feat
| |
| 179 node.selectable = true; | |
| 180 rootNode.appendChild(node); | |
| 181 if (!selectedNode || key === selectedKey) { | |
|
dgozman
2017/01/26 22:21:09
if (key === selectedKey)
selectedNode = node;
eostroukhov
2017/01/26 23:35:46
Done. Note that I kept "!selectedNode" to select t
| |
| 182 if (selectedNode) | |
| 183 selectedNode.selected = false; | |
| 184 selectedNode = node; | |
| 185 node.selected = true; | |
| 186 } | |
| 187 } | |
| 188 this._dataGrid.addCreationNode(false); | |
| 189 this._setDeleteEnabled(!!selectedNode); | |
| 177 } | 190 } |
| 178 | 191 |
| 179 _dataGridForDOMStorageItems(items) { | 192 _setDeleteEnabled(enabled) { |
| 180 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ | 193 this.deleteButton.setEnabled(enabled); |
|
dgozman
2017/01/26 22:21:09
Inline this.
eostroukhov
2017/01/26 23:35:45
Done.
| |
| 181 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, | |
| 182 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50} | |
| 183 ]); | |
| 184 | |
| 185 var nodes = []; | |
| 186 | |
| 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); | |
| 193 node.selectable = true; | |
| 194 nodes.push(node); | |
| 195 keys.push(key); | |
| 196 } | |
| 197 | |
| 198 var dataGrid = new DataGrid.DataGrid(columns, this._editingCallback.bind(thi s), this._deleteCallback.bind(this)); | |
| 199 dataGrid.setName('DOMStorageItemsView'); | |
| 200 length = nodes.length; | |
| 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 } | 194 } |
| 208 | 195 |
| 209 /** | 196 /** |
| 210 * @param {!Common.Event} event | 197 * @override |
| 211 */ | 198 */ |
| 212 _deleteButtonClicked(event) { | 199 onDelete() { |
| 213 if (!this._dataGrid || !this._dataGrid.selectedNode) | 200 if (!this._dataGrid || !this._dataGrid.selectedNode) |
| 214 return; | 201 return; |
| 215 | 202 |
| 216 this._deleteCallback(this._dataGrid.selectedNode); | 203 this._deleteCallback(this._dataGrid.selectedNode); |
| 217 } | 204 } |
| 218 | 205 |
| 219 /** | 206 /** |
| 220 * @param {!Common.Event} event | 207 * @override |
| 221 */ | 208 */ |
| 222 _refreshButtonClicked(event) { | 209 onRefresh() { |
| 223 this._update(); | 210 this.domStorage.getItems((error, items) => this._showDOMStorageItems(error, items)); |
| 211 } | |
| 212 | |
| 213 /** | |
| 214 * @override | |
| 215 */ | |
| 216 onClearAll() { | |
| 217 this.domStorage.clear(); | |
| 224 } | 218 } |
| 225 | 219 |
| 226 _editingCallback(editingNode, columnIdentifier, oldText, newText) { | 220 _editingCallback(editingNode, columnIdentifier, oldText, newText) { |
| 227 var domStorage = this.domStorage; | 221 var domStorage = this.domStorage; |
| 228 if (columnIdentifier === 'key') { | 222 if (columnIdentifier === 'key') { |
| 229 if (typeof oldText === 'string') | 223 if (typeof oldText === 'string') |
| 230 domStorage.removeItem(oldText); | 224 domStorage.removeItem(oldText); |
| 231 domStorage.setItem(newText, editingNode.data.value || ''); | 225 domStorage.setItem(newText, editingNode.data.value || ''); |
| 232 this._removeDupes(editingNode); | 226 this._removeDupes(editingNode); |
| 233 } else { | 227 } else { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 249 } | 243 } |
| 250 | 244 |
| 251 _deleteCallback(node) { | 245 _deleteCallback(node) { |
| 252 if (!node || node.isCreationNode) | 246 if (!node || node.isCreationNode) |
| 253 return; | 247 return; |
| 254 | 248 |
| 255 if (this.domStorage) | 249 if (this.domStorage) |
| 256 this.domStorage.removeItem(node.data.key); | 250 this.domStorage.removeItem(node.data.key); |
| 257 } | 251 } |
| 258 }; | 252 }; |
| OLD | NEW |