summaryrefslogtreecommitdiff
path: root/Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js')
-rw-r--r--Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js174
1 files changed, 174 insertions, 0 deletions
diff --git a/Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js b/Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js
new file mode 100644
index 000000000..8cc45f66a
--- /dev/null
+++ b/Source/WebInspectorUI/UserInterface/Views/IndexedDatabaseObjectStoreContentView.js
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.IndexedDatabaseObjectStoreContentView = class IndexedDatabaseObjectStoreContentView extends WebInspector.ContentView
+{
+ constructor(objectStoreOrIndex)
+ {
+ super(objectStoreOrIndex);
+
+ this.element.classList.add("indexed-database-object-store");
+
+ if (objectStoreOrIndex instanceof WebInspector.IndexedDatabaseObjectStore) {
+ this._objectStore = objectStoreOrIndex;
+ this._objectStoreIndex = null;
+ } else if (objectStoreOrIndex instanceof WebInspector.IndexedDatabaseObjectStoreIndex) {
+ this._objectStore = objectStoreOrIndex.parentObjectStore;
+ this._objectStoreIndex = objectStoreOrIndex;
+ }
+
+ function displayKeyPath(keyPath)
+ {
+ if (!keyPath)
+ return "";
+ if (keyPath instanceof Array)
+ return keyPath.join(WebInspector.UIString(", "));
+ console.assert(keyPath instanceof String || typeof keyPath === "string");
+ return keyPath;
+ }
+
+ var displayPrimaryKeyPath = displayKeyPath(this._objectStore.keyPath);
+
+ var columnInfo = {
+ primaryKey: {title: displayPrimaryKeyPath ? WebInspector.UIString("Primary Key \u2014 %s").format(displayPrimaryKeyPath) : WebInspector.UIString("Primary Key")},
+ key: {},
+ value: {title: WebInspector.UIString("Value")}
+ };
+
+ if (this._objectStoreIndex) {
+ // When there is an index, show the key path in the Key column.
+ var displayIndexKeyPath = displayKeyPath(this._objectStoreIndex.keyPath);
+ columnInfo.key.title = WebInspector.UIString("Index Key \u2014 %s").format(displayIndexKeyPath);
+ } else {
+ // Only need to show Key for indexes -- it is the same as Primary Key
+ // when there is no index being used.
+ delete columnInfo.key;
+ }
+
+ this._dataGrid = new WebInspector.DataGrid(columnInfo);
+ this._dataGrid.variableHeightRows = true;
+ this._dataGrid.scrollContainer.addEventListener("scroll", this._dataGridScrolled.bind(this));
+ this.addSubview(this._dataGrid);
+
+ this._entries = [];
+
+ this._fetchingMoreData = false;
+ this._fetchMoreData();
+
+ this._refreshButtonNavigationItem = new WebInspector.ButtonNavigationItem("indexed-database-object-store-refresh", WebInspector.UIString("Refresh"), "Images/ReloadFull.svg", 13, 13);
+ this._refreshButtonNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._refreshButtonClicked, this);
+
+ this._clearButtonNavigationItem = new WebInspector.ButtonNavigationItem("indexed-database-object-store-clear", WebInspector.UIString("Clear object store"), "Images/NavigationItemTrash.svg", 15, 15);
+ this._clearButtonNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._clearButtonClicked, this);
+ }
+
+ // Public
+
+ get navigationItems()
+ {
+ return [this._refreshButtonNavigationItem, this._clearButtonNavigationItem];
+ }
+
+ closed()
+ {
+ super.closed();
+
+ this._reset();
+ }
+
+ saveToCookie(cookie)
+ {
+ cookie.type = WebInspector.ContentViewCookieType.IndexedDatabaseObjectStore;
+ cookie.securityOrigin = this._objectStore.parentDatabase.securityOrigin;
+ cookie.databaseName = this._objectStore.parentDatabase.name;
+ cookie.objectStoreName = this._objectStore.name;
+ cookie.objectStoreIndexName = this._objectStoreIndex && this._objectStoreIndex.name;
+ }
+
+ get scrollableElements()
+ {
+ return [this._dataGrid.scrollContainer];
+ }
+
+ // Private
+
+ _reset()
+ {
+ for (var entry of this._entries) {
+ entry.primaryKey.release();
+ entry.key.release();
+ entry.value.release();
+ }
+
+ this._entries = [];
+ this._dataGrid.removeChildren();
+ }
+
+ _dataGridScrolled()
+ {
+ if (!this._moreEntriesAvailable || !this._dataGrid.isScrolledToLastRow())
+ return;
+
+ this._fetchMoreData();
+ }
+
+ _fetchMoreData()
+ {
+ if (this._fetchingMoreData)
+ return;
+
+ function processEntries(entries, moreAvailable)
+ {
+ this._entries = this._entries.concat(entries);
+ this._moreEntriesAvailable = moreAvailable;
+
+ for (var entry of entries) {
+ var dataGridNode = new WebInspector.IndexedDatabaseEntryDataGridNode(entry);
+ this._dataGrid.appendChild(dataGridNode);
+ }
+
+ this._fetchingMoreData = false;
+
+ if (moreAvailable && this._dataGrid.isScrolledToLastRow())
+ this._fetchMoreData();
+ }
+
+ this._fetchingMoreData = true;
+
+ WebInspector.storageManager.requestIndexedDatabaseData(this._objectStore, this._objectStoreIndex, this._entries.length, 25, processEntries.bind(this));
+ }
+
+ _refreshButtonClicked()
+ {
+ this._reset();
+ this._fetchMoreData();
+ }
+
+ _clearButtonClicked()
+ {
+ WebInspector.storageManager.clearObjectStore(this._objectStore);
+ this._reset();
+ }
+};