From bd18b548425db945350904d55be2360c989b26ca Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Mon, 20 Feb 2023 21:04:01 +0100 Subject: [PATCH] Zenity dialogs --- .../src/organisms/connection/index.svelte | 69 ++++--------------- frontend/wailsjs/go/app/App.d.ts | 2 + frontend/wailsjs/go/app/App.js | 4 ++ go.mod | 13 +++- go.sum | 35 +++++++++- internal/app/app.go | 49 ++++++------- internal/app/app_settings.go | 25 ++----- internal/app/collection.go | 47 +++---------- internal/app/collection_aggregate.go | 25 ++----- internal/app/collection_find.go | 49 +++---------- internal/app/collection_find_queries.go | 26 ++----- internal/app/collection_indexes.go | 31 ++------- internal/app/collection_insert.go | 13 +--- internal/app/collection_remove.go | 31 ++------- internal/app/collection_update.go | 25 ++----- internal/app/connection.go | 24 ++----- internal/app/database.go | 24 ++----- internal/app/database_export.go | 24 ++----- internal/app/hosts.go | 57 ++++----------- internal/app/views.go | 32 ++------- 20 files changed, 176 insertions(+), 429 deletions(-) diff --git a/frontend/src/organisms/connection/index.svelte b/frontend/src/organisms/connection/index.svelte index 1354877..3d1438b 100644 --- a/frontend/src/organisms/connection/index.svelte +++ b/frontend/src/organisms/connection/index.svelte @@ -5,7 +5,7 @@ import input from '$lib/actions/input'; import busy from '$lib/stores/busy'; import { connections } from '$lib/stores/connections'; - import { Hosts, RenameCollection } from '$wails/go/app/App'; + import { EnterText, Hosts, RenameCollection } from '$wails/go/app/App'; import { EventsOn } from '$wails/runtime/runtime'; import { onMount } from 'svelte'; import CollectionDetail from './collection/index.svelte'; @@ -19,8 +19,6 @@ export let activeCollKey = ''; let hostTree; - let newDb; - let newColl; let showHostDetail = false; let hostDetailKey = ''; @@ -44,9 +42,11 @@ showHostDetail = true; } - function createDatabase() { - $connections[activeHostKey].databases[newDb.name] = { collections: {} }; - newDb = undefined; + async function createDatabase() { + const name = await EnterText('Create a database', 'Enter the database name. 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 (name) { + $connections[activeHostKey].databases[name] = { collections: {} }; + } } function openEditCollModal(collKey) { @@ -66,9 +66,11 @@ busy.end(); } - function createCollection() { - $connections[activeHostKey].databases[activeDbKey].collections[newColl.name] = {}; - newColl = undefined; + async function createCollection() { + const name = await EnterText('Create a collection', '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 (name) { + $connections[activeHostKey].databases[activeDbKey].collections[name] = {}; + } } function exportCollection(collKey) { @@ -92,8 +94,8 @@ } EventsOn('CreateHost', createHost); - EventsOn('CreateDatabase', () => newDb = {}); - EventsOn('CreateCollection', () => newColl = {}); + EventsOn('CreateDatabase', createDatabase); + EventsOn('CreateCollection', createCollection); onMount(getHosts); @@ -105,8 +107,8 @@ bind:activeDbKey bind:this={hostTree} on:newHost={createHost} - on:newDatabase={() => newDb = {}} - on:newCollection={() => newColl = {}} + on:newDatabase={createDatabase} + on:newCollection={createCollection} on:editHost={e => editHost(e.detail)} on:renameCollection={e => openEditCollModal(e.detail)} on:exportCollection={e => exportCollection(e.detail)} @@ -131,42 +133,6 @@ -{#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 collection

- - 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} - {#if collToRename}
@@ -184,11 +150,6 @@ {/if}