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({});