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 Resources.DOMStorageItemsView = class extends Resources.ItemsView { | |
| 27 constructor(domStorage) { | |
|
dgozman
2017/01/27 22:48:45
JSDoc please.
eostroukhov
2017/01/28 00:03:29
Done.
| |
| 28 super(Common.UIString('DOM Storage'), 'domStoragePanel'); | |
| 26 | 29 |
| 27 /** | 30 this._domStorage = domStorage; |
| 28 * @unrestricted | |
| 29 */ | |
| 30 Resources.DOMStorageItemsView = class extends UI.SimpleView { | |
| 31 constructor(domStorage) { | |
| 32 super(Common.UIString('DOM Storage')); | |
| 33 | |
| 34 this.domStorage = domStorage; | |
| 35 | 31 |
| 36 this.element.classList.add('storage-view', 'table'); | 32 this.element.classList.add('storage-view', 'table'); |
| 37 | 33 |
| 38 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largei con-delete'); | 34 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ |
| 39 this._deleteButton.setEnabled(false); | 35 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, |
| 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this); | 36 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50} |
| 41 | 37 ]); |
| 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear'); | 38 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); | 39 this._dataGrid.setName('DOMStorageItemsView'); |
| 44 | 40 this._dataGrid.asWidget().show(this.element); |
| 45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh'); | 41 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); | 42 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this); |
| 50 this.domStorage.addEventListener( | 43 this._domStorage.addEventListener( |
| 51 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); | 44 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); |
| 52 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this); | 45 this._domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItem Added, this._domStorageItemAdded, this); |
| 53 this.domStorage.addEventListener( | 46 this._domStorage.addEventListener( |
| 54 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); | 47 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); |
| 55 } | 48 } |
| 56 | 49 |
| 57 /** | 50 /** |
| 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 | 51 * @param {!Common.Event} event |
| 81 */ | 52 */ |
| 82 _domStorageItemsCleared(event) { | 53 _domStorageItemsCleared(event) { |
| 83 if (!this.isShowing() || !this._dataGrid) | 54 if (!this.isShowing() || !this._dataGrid) |
| 84 return; | 55 return; |
| 85 | 56 |
| 86 this._dataGrid.rootNode().removeChildren(); | 57 this._dataGrid.rootNode().removeChildren(); |
| 87 this._dataGrid.addCreationNode(false); | 58 this._dataGrid.addCreationNode(false); |
| 88 this._deleteButton.setEnabled(false); | 59 this.setCanDeleteSelected(false); |
| 89 } | 60 } |
| 90 | 61 |
| 91 /** | 62 /** |
| 92 * @param {!Common.Event} event | 63 * @param {!Common.Event} event |
| 93 */ | 64 */ |
| 94 _domStorageItemRemoved(event) { | 65 _domStorageItemRemoved(event) { |
| 95 if (!this.isShowing() || !this._dataGrid) | 66 if (!this.isShowing() || !this._dataGrid) |
| 96 return; | 67 return; |
| 97 | 68 |
| 98 var storageData = event.data; | 69 var storageData = event.data; |
| 99 var rootNode = this._dataGrid.rootNode(); | 70 var rootNode = this._dataGrid.rootNode(); |
| 100 var children = rootNode.children; | 71 var children = rootNode.children; |
| 101 | 72 |
| 102 for (var i = 0; i < children.length; ++i) { | 73 for (var i = 0; i < children.length; ++i) { |
| 103 var childNode = children[i]; | 74 var childNode = children[i]; |
| 104 if (childNode.data.key === storageData.key) { | 75 if (childNode.data.key === storageData.key) { |
| 105 rootNode.removeChild(childNode); | 76 rootNode.removeChild(childNode); |
| 106 this._deleteButton.setEnabled(children.length > 1); | 77 this.setCanDeleteSelected(children.length > 1); |
| 107 return; | 78 return; |
| 108 } | 79 } |
| 109 } | 80 } |
| 110 } | 81 } |
| 111 | 82 |
| 112 /** | 83 /** |
| 113 * @param {!Common.Event} event | 84 * @param {!Common.Event} event |
| 114 */ | 85 */ |
| 115 _domStorageItemAdded(event) { | 86 _domStorageItemAdded(event) { |
| 116 if (!this.isShowing() || !this._dataGrid) | 87 if (!this.isShowing() || !this._dataGrid) |
| 117 return; | 88 return; |
| 118 | 89 |
| 119 var storageData = event.data; | 90 var storageData = event.data; |
| 120 var rootNode = this._dataGrid.rootNode(); | 91 var rootNode = this._dataGrid.rootNode(); |
| 121 var children = rootNode.children; | 92 var children = rootNode.children; |
| 122 | 93 |
| 123 this._deleteButton.setEnabled(true); | 94 this.setCanDeleteSelected(true); |
| 124 | 95 |
| 125 for (var i = 0; i < children.length; ++i) { | 96 for (var i = 0; i < children.length; ++i) { |
| 126 if (children[i].data.key === storageData.key) | 97 if (children[i].data.key === storageData.key) |
| 127 return; | 98 return; |
| 128 } | 99 } |
| 129 | 100 |
| 130 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); | 101 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); |
| 131 rootNode.insertChild(childNode, children.length - 1); | 102 rootNode.insertChild(childNode, children.length - 1); |
| 132 } | 103 } |
| 133 | 104 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 150 rootNode.removeChild(childNode); | 121 rootNode.removeChild(childNode); |
| 151 return; | 122 return; |
| 152 } | 123 } |
| 153 keyFound = true; | 124 keyFound = true; |
| 154 if (childNode.data.value !== storageData.value) { | 125 if (childNode.data.value !== storageData.value) { |
| 155 childNode.data.value = storageData.value; | 126 childNode.data.value = storageData.value; |
| 156 childNode.refresh(); | 127 childNode.refresh(); |
| 157 childNode.select(); | 128 childNode.select(); |
| 158 childNode.reveal(); | 129 childNode.reveal(); |
| 159 } | 130 } |
| 160 this._deleteButton.setEnabled(true); | 131 this.setCanDeleteSelected(true); |
| 161 } | 132 } |
| 162 } | 133 } |
| 163 } | 134 } |
| 164 | 135 |
| 165 _update() { | 136 /** |
| 166 this.detachChildWidgets(); | 137 * @param {?Object} error |
| 167 this.domStorage.getItems(this._showDOMStorageItems.bind(this)); | 138 * @param {!Array<!Array<string>>} items |
| 168 } | 139 */ |
| 169 | |
| 170 _showDOMStorageItems(error, items) { | 140 _showDOMStorageItems(error, items) { |
| 171 if (error) | 141 if (error) |
| 172 return; | 142 return; |
| 173 | 143 var rootNode = this._dataGrid.rootNode(); |
| 174 this._dataGrid = this._dataGridForDOMStorageItems(items); | 144 var selectedKey = null; |
| 175 this._dataGrid.asWidget().show(this.element); | 145 for (var node of rootNode.children) { |
| 176 this._deleteButton.setEnabled(this._dataGrid.rootNode().children.length > 1) ; | 146 if (!node.selected) |
| 177 } | 147 continue; |
| 178 | 148 selectedKey = node.data.key; |
| 179 _dataGridForDOMStorageItems(items) { | 149 break; |
| 180 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ | 150 } |
| 181 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, | 151 rootNode.removeChildren(); |
| 182 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50} | 152 var selectedNode = null; |
| 183 ]); | 153 var filteredItems = item => `${item[0]} ${item[1]}`; |
| 184 | 154 for (var item of this.filter(items, filteredItems)) { |
| 185 var nodes = []; | 155 var key = item[0]; |
| 186 | 156 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); | 157 var node = new DataGrid.DataGridNode({key: key, value: value}, false); |
| 193 node.selectable = true; | 158 node.selectable = true; |
| 194 nodes.push(node); | 159 rootNode.appendChild(node); |
| 195 keys.push(key); | 160 if (!selectedNode || key === selectedKey) |
| 161 selectedNode = node; | |
| 196 } | 162 } |
| 197 | 163 if (selectedNode) |
| 198 var dataGrid = new DataGrid.DataGrid(columns, this._editingCallback.bind(thi s), this._deleteCallback.bind(this)); | 164 selectedNode.selected = true; |
| 199 dataGrid.setName('DOMStorageItemsView'); | 165 this._dataGrid.addCreationNode(false); |
| 200 length = nodes.length; | 166 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 } | 167 } |
| 208 | 168 |
| 209 /** | 169 /** |
| 210 * @param {!Common.Event} event | 170 * @override |
| 211 */ | 171 */ |
| 212 _deleteButtonClicked(event) { | 172 deleteSelected() { |
| 213 if (!this._dataGrid || !this._dataGrid.selectedNode) | 173 if (!this._dataGrid || !this._dataGrid.selectedNode) |
| 214 return; | 174 return; |
| 215 | 175 |
| 216 this._deleteCallback(this._dataGrid.selectedNode); | 176 this._deleteCallback(this._dataGrid.selectedNode); |
| 217 } | 177 } |
| 218 | 178 |
| 219 /** | 179 /** |
| 220 * @param {!Common.Event} event | 180 * @override |
| 221 */ | 181 */ |
| 222 _refreshButtonClicked(event) { | 182 refresh() { |
| 223 this._update(); | 183 this._domStorage.getItems((error, items) => this._showDOMStorageItems(error, items)); |
| 184 } | |
| 185 | |
| 186 /** | |
| 187 * @override | |
| 188 */ | |
| 189 deleteAll() { | |
| 190 this._domStorage.clear(); | |
| 224 } | 191 } |
| 225 | 192 |
| 226 _editingCallback(editingNode, columnIdentifier, oldText, newText) { | 193 _editingCallback(editingNode, columnIdentifier, oldText, newText) { |
| 227 var domStorage = this.domStorage; | 194 var domStorage = this._domStorage; |
| 228 if (columnIdentifier === 'key') { | 195 if (columnIdentifier === 'key') { |
| 229 if (typeof oldText === 'string') | 196 if (typeof oldText === 'string') |
| 230 domStorage.removeItem(oldText); | 197 domStorage.removeItem(oldText); |
| 231 domStorage.setItem(newText, editingNode.data.value || ''); | 198 domStorage.setItem(newText, editingNode.data.value || ''); |
| 232 this._removeDupes(editingNode); | 199 this._removeDupes(editingNode); |
| 233 } else { | 200 } else { |
| 234 domStorage.setItem(editingNode.data.key || '', newText); | 201 domStorage.setItem(editingNode.data.key || '', newText); |
| 235 } | 202 } |
| 236 } | 203 } |
| 237 | 204 |
| 238 /** | 205 /** |
| 239 * @param {!DataGrid.DataGridNode} masterNode | 206 * @param {!DataGrid.DataGridNode} masterNode |
| 240 */ | 207 */ |
| 241 _removeDupes(masterNode) { | 208 _removeDupes(masterNode) { |
| 242 var rootNode = this._dataGrid.rootNode(); | 209 var rootNode = this._dataGrid.rootNode(); |
| 243 var children = rootNode.children; | 210 var children = rootNode.children; |
| 244 for (var i = children.length - 1; i >= 0; --i) { | 211 for (var i = children.length - 1; i >= 0; --i) { |
| 245 var childNode = children[i]; | 212 var childNode = children[i]; |
| 246 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode)) | 213 if ((childNode.data.key === masterNode.data.key) && (masterNode !== childN ode)) |
| 247 rootNode.removeChild(childNode); | 214 rootNode.removeChild(childNode); |
| 248 } | 215 } |
| 249 } | 216 } |
| 250 | 217 |
| 251 _deleteCallback(node) { | 218 _deleteCallback(node) { |
| 252 if (!node || node.isCreationNode) | 219 if (!node || node.isCreationNode) |
| 253 return; | 220 return; |
| 254 | 221 |
| 255 if (this.domStorage) | 222 if (this._domStorage) |
| 256 this.domStorage.removeItem(node.data.key); | 223 this._domStorage.removeItem(node.data.key); |
| 257 } | 224 } |
| 258 }; | 225 }; |
| OLD | NEW |