From c81c5c9c735cd09b0ecfae8259cf9bf094f0d24f Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sat, 14 Jan 2023 21:09:21 +0100 Subject: [PATCH] Drop collections --- frontend/src/app.svelte | 41 ++++++++++++++-------- frontend/src/components/contextmenu.svelte | 8 +++-- frontend/src/stores.js | 27 +++++++++----- frontend/wailsjs/go/app/App.d.ts | 2 ++ frontend/wailsjs/go/app/App.js | 4 +++ internal/app/collection.go | 31 ++++++++++++++++ 6 files changed, 88 insertions(+), 25 deletions(-) diff --git a/frontend/src/app.svelte b/frontend/src/app.svelte index 39bc4b2..a8fbc2e 100644 --- a/frontend/src/app.svelte +++ b/frontend/src/app.svelte @@ -1,6 +1,6 @@ {#if items && position} @@ -20,7 +24,7 @@
{:else}
  • -
  • diff --git a/frontend/src/stores.js b/frontend/src/stores.js index d0c9ff6..34e4566 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -1,14 +1,23 @@ import { writable } from 'svelte/store'; -export const busy = writable(false); -busy.subscribe(isBusy => { - if (isBusy) { - document.body.classList.add('busy'); - } - else { - document.body.classList.remove('busy'); - } -}); +export const busy = (() => { + const { update, subscribe } = writable(0); + + subscribe(isBusy => { + if (isBusy) { + document.body.classList.add('busy'); + } + else { + document.body.classList.remove('busy'); + } + }); + + return { + start: () => update(v => ++v), + end: () => update(v => --v), + subscribe, + }; +})(); export const contextMenu = (() => { const { set, subscribe } = writable(); diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index cddb339..71e23bb 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -4,6 +4,8 @@ import {map[string]app} from '../models'; import {primitive} from '../models'; import {app} from '../models'; +export function DropCollection(arg1:string,arg2:string,arg3:string):Promise; + export function DropDatabase(arg1:string,arg2:string):Promise; export function Hosts():Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 71cddef..83ba49d 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -2,6 +2,10 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function DropCollection(arg1, arg2, arg3) { + return window['go']['app']['App']['DropCollection'](arg1, arg2, arg3); +} + export function DropDatabase(arg1, arg2) { return window['go']['app']['App']['DropDatabase'](arg1, arg2); } diff --git a/internal/app/collection.go b/internal/app/collection.go index 392f963..e84551e 100644 --- a/internal/app/collection.go +++ b/internal/app/collection.go @@ -27,3 +27,34 @@ func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) { defer close() return result } + +func (a *App) DropCollection(hostKey, dbKey, collKey string) bool { + sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Title: "Confirm", + Message: "Are you sure you want to drop " + collKey + "?", + Buttons: []string{"Yes", "No"}, + DefaultButton: "Yes", + CancelButton: "No", + }) + if sure != "Yes" { + return false + } + + client, ctx, close, err := a.connectToHost(hostKey) + if err != nil { + fmt.Println(err.Error()) + return false + } + err = client.Database(dbKey).Collection(collKey).Drop(ctx) + if err != nil { + fmt.Println(err.Error()) + runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Type: runtime.ErrorDialog, + Title: "Could not drop " + dbKey, + Message: err.Error(), + }) + return false + } + defer close() + return true +}