From b7365b739ccc3ad67f01e466ef7071fc605dc65b Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sat, 14 Jan 2023 20:38:39 +0100 Subject: [PATCH] Context menu + database dropping --- frontend/src/app.svelte | 31 ++++++++-- frontend/src/components/contextmenu.svelte | 58 +++++++++++++++++++ frontend/src/components/grid.svelte | 45 ++++++++++++-- frontend/src/components/icon.svelte | 6 +- .../organisms/collection-detail/find.svelte | 11 +--- .../organisms/collection-detail/index.svelte | 1 - frontend/src/stores.js | 12 ++++ frontend/wailsjs/go/main/App.d.ts | 2 + frontend/wailsjs/go/main/App.js | 4 ++ main.go | 31 ++++++++++ 10 files changed, 182 insertions(+), 19 deletions(-) create mode 100644 frontend/src/components/contextmenu.svelte diff --git a/frontend/src/app.svelte b/frontend/src/app.svelte index 3e5a450..5e75190 100644 --- a/frontend/src/app.svelte +++ b/frontend/src/app.svelte @@ -1,10 +1,11 @@ + +{#if items && position} +
+ +{/if} + + diff --git a/frontend/src/components/grid.svelte b/frontend/src/components/grid.svelte index 655e259..a49381c 100644 --- a/frontend/src/components/grid.svelte +++ b/frontend/src/components/grid.svelte @@ -1,9 +1,11 @@
0} class:contained> + {#if actions?.length} +
+ {#each actions as action} + + {/each} +
+ {/if} + {#if showHeaders && columns.some(col => col.title)} @@ -63,10 +85,15 @@ {#each _items as item (item[key])} - select(item[key])} class:selected={activeKey === item[key] && !activeChildKey}> + select(item[key])} + on:dblclick={() => toggleChildren(item[key])} + on:contextmenu|preventDefault={evt => showContextMenu(evt, item)} + class:selected={activeKey === item[key] && !activeChildKey} + > @@ -116,6 +144,15 @@ width: 100%; } + .actions { + margin-bottom: 0.5rem; + padding: 0.5rem; + border-bottom: 1px solid #ccc; + } + .actions button { + margin-right: 0.2rem; + } + table { border-collapse: collapse; width: 100%; diff --git a/frontend/src/components/icon.svelte b/frontend/src/components/icon.svelte index 4f97436..bbb3c14 100644 --- a/frontend/src/components/icon.svelte +++ b/frontend/src/components/icon.svelte @@ -1,5 +1,5 @@ {#if name === 'radio'} @@ -14,6 +14,10 @@ {:else if name === 'x'} +{:else if name === '+'} + {:else if name === '-'} +{:else if name === 'reload'} + {/if} diff --git a/frontend/src/organisms/collection-detail/find.svelte b/frontend/src/organisms/collection-detail/find.svelte index 94df674..848cfec 100644 --- a/frontend/src/organisms/collection-detail/find.svelte +++ b/frontend/src/organisms/collection-detail/find.svelte @@ -13,17 +13,10 @@ sort: '{ "_id": 1 }', fields: '{}', skip: 0, - limit: 30, - }; - - let form = { - query: '{}', - sort: '{ "_id": 1 }', - fields: '{}', - skip: 0, - limit: 30, + limit: 15, }; + let form = { ...defaults }; let result = {}; let submittedForm = {}; let queryField; diff --git a/frontend/src/organisms/collection-detail/index.svelte b/frontend/src/organisms/collection-detail/index.svelte index b806935..70247d9 100644 --- a/frontend/src/organisms/collection-detail/index.svelte +++ b/frontend/src/organisms/collection-detail/index.svelte @@ -24,7 +24,6 @@ async function catchQuery(event) { tab = 'find'; await tick(); - console.log(event, find); find.performQuery(event.detail); } diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 7a5b02f..d0c9ff6 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -9,3 +9,15 @@ busy.subscribe(isBusy => { document.body.classList.remove('busy'); } }); + +export const contextMenu = (() => { + const { set, subscribe } = writable(); + return { + show: (evt, menu) => set(menu ? { + position: [ evt.clientX, evt.clientY ], + items: menu, + } : undefined), + hide: () => set(undefined), + subscribe, + }; +})(); diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index e0bbea2..9240a72 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -4,6 +4,8 @@ import {map[string]main} from '../models'; import {primitive} from '../models'; import {main} from '../models'; +export function DropDatabase(arg1:string,arg2:string):Promise; + export function Hosts():Promise; export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 7def657..ff1b889 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -2,6 +2,10 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function DropDatabase(arg1, arg2) { + return window['go']['main']['App']['DropDatabase'](arg1, arg2); +} + export function Hosts() { return window['go']['main']['App']['Hosts'](); } diff --git a/main.go b/main.go index 37071d1..8c75935 100644 --- a/main.go +++ b/main.go @@ -120,6 +120,37 @@ func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) { return collections } +func (a *App) DropDatabase(hostKey, dbKey string) bool { + sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Title: "Confirm", + Message: "Are you sure you want to drop " + dbKey + "?", + 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).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 +} + func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) { client, ctx, close, err := a.connectToHost(hostKey) if err != nil {
{#if item.children?.length} - {/if} @@ -94,6 +121,7 @@ items={item.children} level={level + 1} on:select={e => selectChild(item[key], e.detail)} + on:closeAll={() => (childrenOpen = {})} />