mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Drop collections
This commit is contained in:
parent
9662d46957
commit
c81c5c9c73
@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { DropDatabase, Hosts, OpenCollection, OpenConnection, OpenDatabase } from '../wailsjs/go/app/App';
|
||||
import { DropCollection, DropDatabase, Hosts, OpenCollection, OpenConnection, OpenDatabase } from '../wailsjs/go/app/App';
|
||||
import AddressBar from './organisms/addressbar/index.svelte';
|
||||
import Grid from './components/grid.svelte';
|
||||
import CollectionDetail from './organisms/collection-detail/index.svelte';
|
||||
@ -19,8 +19,10 @@
|
||||
$: database = connection?.databases[activeDbKey];
|
||||
$: collection = database?.collections?.[activeCollKey];
|
||||
|
||||
$: console.log(connection?.databases);
|
||||
|
||||
async function openConnection(hostKey) {
|
||||
$busy = true;
|
||||
busy.start();
|
||||
const databases = await OpenConnection(hostKey);
|
||||
|
||||
if (databases) {
|
||||
@ -33,32 +35,40 @@
|
||||
window.runtime.WindowSetTitle(`${host.name} - Mongodup`);
|
||||
}
|
||||
|
||||
$busy = false;
|
||||
busy.end();
|
||||
}
|
||||
|
||||
async function openDatabase(dbKey) {
|
||||
$busy = true;
|
||||
busy.start();
|
||||
const collections = await OpenDatabase(activeHostKey, dbKey);
|
||||
|
||||
for (const collKey of collections || []) {
|
||||
connections[activeHostKey].databases[dbKey].collections[collKey] = {};
|
||||
}
|
||||
|
||||
$busy = false;
|
||||
busy.end();
|
||||
}
|
||||
|
||||
async function dropDatabase(dbKey) {
|
||||
$busy = true;
|
||||
busy.start();
|
||||
await DropDatabase(activeHostKey, dbKey);
|
||||
await openConnection(activeHostKey);
|
||||
$busy = false();
|
||||
busy.end();
|
||||
}
|
||||
|
||||
async function openCollection(collKey) {
|
||||
$busy = true;
|
||||
busy.start();
|
||||
const stats = await OpenCollection(activeHostKey, activeDbKey, collKey);
|
||||
connections[activeHostKey].databases[activeDbKey].collections[collKey].stats = stats;
|
||||
$busy = false;
|
||||
busy.end();
|
||||
}
|
||||
|
||||
async function dropCollection(dbKey, collKey) {
|
||||
busy.start();
|
||||
await DropCollection(activeHostKey, dbKey, collKey);
|
||||
await openConnection(activeHostKey);
|
||||
await openCollection(collKey);
|
||||
busy.end();
|
||||
}
|
||||
|
||||
async function reload() {
|
||||
@ -78,11 +88,14 @@
|
||||
<div class="databaselist">
|
||||
<Grid
|
||||
columns={[ { key: 'id' }, { key: 'collCount', right: true } ]}
|
||||
items={Object.keys(connection.databases).map(id => ({
|
||||
id,
|
||||
collCount: Object.keys(connection.databases[id].collections || {}).length,
|
||||
children: connection.databases[id].collections || [],
|
||||
menu: [ { label: `Drop ${id}`, fn: () => dropDatabase(id) } ],
|
||||
items={Object.keys(connection.databases).map(dbKey => ({
|
||||
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) } ],
|
||||
})) || [],
|
||||
menu: [ { label: `Drop ${dbKey}`, fn: () => dropDatabase(dbKey) } ],
|
||||
}))}
|
||||
actions={[
|
||||
{ icon: 'reload', fn: reload },
|
||||
|
@ -1,7 +1,6 @@
|
||||
<script>
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
|
||||
export let items = undefined;
|
||||
export let position = undefined;
|
||||
|
||||
@ -10,6 +9,11 @@
|
||||
function close() {
|
||||
dispatch('close');
|
||||
}
|
||||
|
||||
function click(fn) {
|
||||
fn();
|
||||
close();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if items && position}
|
||||
@ -20,7 +24,7 @@
|
||||
<hr />
|
||||
{:else}
|
||||
<li>
|
||||
<button class="item" on:click={item.fn}>
|
||||
<button class="item" on:click={() => click(item.fn)}>
|
||||
{item.label}
|
||||
</button>
|
||||
</li>
|
||||
|
@ -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();
|
||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -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<boolean>;
|
||||
|
||||
export function DropDatabase(arg1:string,arg2:string):Promise<boolean>;
|
||||
|
||||
export function Hosts():Promise<map[string]app.Host>;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user