From e0cda5cccb52c35528bc5137a27ba05021ba1dc2 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Mon, 16 Jan 2023 20:03:56 +0100 Subject: [PATCH] Split app.svelte --- frontend/src/app.svelte | 178 ++---------------- frontend/src/components/contextmenu.svelte | 6 + frontend/src/components/modal.svelte | 1 - .../collection}/find.svelte | 12 +- .../collection}/index.svelte | 4 +- .../collection}/indexes.svelte | 0 .../collection}/insert.svelte | 4 +- .../collection}/remove.svelte | 2 +- .../collection}/stats.svelte | 4 +- .../src/organisms/connection/dblist.svelte | 127 +++++++++++++ .../src/organisms/connection/index.svelte | 92 +++++++++ frontend/src/stores.js | 2 + 12 files changed, 258 insertions(+), 174 deletions(-) rename frontend/src/organisms/{collection-detail => connection/collection}/find.svelte (92%) rename frontend/src/organisms/{collection-detail => connection/collection}/index.svelte (93%) rename frontend/src/organisms/{collection-detail => connection/collection}/indexes.svelte (100%) rename frontend/src/organisms/{collection-detail => connection/collection}/insert.svelte (92%) rename frontend/src/organisms/{collection-detail => connection/collection}/remove.svelte (90%) rename frontend/src/organisms/{collection-detail => connection/collection}/stats.svelte (65%) create mode 100644 frontend/src/organisms/connection/dblist.svelte create mode 100644 frontend/src/organisms/connection/index.svelte diff --git a/frontend/src/app.svelte b/frontend/src/app.svelte index 7ab9a58..937766b 100644 --- a/frontend/src/app.svelte +++ b/frontend/src/app.svelte @@ -1,16 +1,12 @@ diff --git a/frontend/src/organisms/connection/dblist.svelte b/frontend/src/organisms/connection/dblist.svelte new file mode 100644 index 0000000..a5cb3ac --- /dev/null +++ b/frontend/src/organisms/connection/dblist.svelte @@ -0,0 +1,127 @@ + + +{#if host && connection} + ({ + id: dbKey, + collCount: Object.keys(connection.databases[dbKey].collections || {}).length || '', + children: Object.keys(connection.databases[dbKey].collections).map(collKey => ({ + id: collKey, + menu: [ + { label: `Drop ${collKey}`, fn: () => dropCollection(dbKey, collKey) }, + { label: `Drop ${dbKey}`, fn: () => dropDatabase(dbKey) }, + { separator: true }, + { label: 'New database', fn: () => dispatch('newDatabase') }, + { label: 'New collection', fn: () => dispatch('newCollection') }, + ], + })).sort((a, b) => a.id.localeCompare(b)) || [], + menu: [ + { label: `Drop ${dbKey}`, fn: () => dropDatabase(dbKey) }, + { separator: true }, + { label: 'New database', fn: () => dispatch('newDatabase') }, + { label: 'New collection', fn: () => dispatch('newCollection') }, + ], + }))} + actions={[ + { icon: 'reload', fn: reload }, + { icon: '+', fn: evt => { + if (activeDbKey) { + contextMenu.show(evt, [ + { label: 'New database', fn: () => dispatch('newDatabase') }, + { label: 'New collection', fn: () => dispatch('newCollection') }, + ]); + } + else { + dispatch('newDatabase'); + } + } }, + { icon: '-', fn: evt => { + if (activeCollKey) { + contextMenu.show(evt, [ + { label: 'Drop database', fn: () => dropDatabase(activeDbKey) }, + { label: 'Drop collection', fn: () => dropCollection(activeDbKey, activeCollKey) }, + ]); + } + else { + dropDatabase(activeDbKey); + } + }, disabled: !activeDbKey }, + ]} + bind:activeKey={activeDbKey} + bind:activeChildKey={activeCollKey} + on:select={e => openDatabase(e.detail)} + on:selectChild={e => openCollection(e.detail)} + /> +{/if} diff --git a/frontend/src/organisms/connection/index.svelte b/frontend/src/organisms/connection/index.svelte new file mode 100644 index 0000000..a3b5b98 --- /dev/null +++ b/frontend/src/organisms/connection/index.svelte @@ -0,0 +1,92 @@ + + + addressBarModalOpen = false} + on:newDatabase={() => newDb = {}} + on:newCollection={() => newColl = {}} +/> + + + +{#if newDb} + +

Create a database

+

Note: databases in MongoDB do not exist until they have a collection and an item. Your new database will not persist on the server; fill it to have it created.

+
+ + +
+
+{/if} + +{#if newColl} + +

Create a collections

+

Note: collections in MongoDB do not exist until they have at least one item. Your new collection will not persist on the server; fill it to have it created.

+
+ + +
+
+{/if} diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 34e4566..e7810c9 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -30,3 +30,5 @@ export const contextMenu = (() => { subscribe, }; })(); + +export const connections = writable({});