mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Drop collections
This commit is contained in:
parent
9662d46957
commit
c81c5c9c73
@ -1,6 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
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 AddressBar from './organisms/addressbar/index.svelte';
|
||||||
import Grid from './components/grid.svelte';
|
import Grid from './components/grid.svelte';
|
||||||
import CollectionDetail from './organisms/collection-detail/index.svelte';
|
import CollectionDetail from './organisms/collection-detail/index.svelte';
|
||||||
@ -19,8 +19,10 @@
|
|||||||
$: database = connection?.databases[activeDbKey];
|
$: database = connection?.databases[activeDbKey];
|
||||||
$: collection = database?.collections?.[activeCollKey];
|
$: collection = database?.collections?.[activeCollKey];
|
||||||
|
|
||||||
|
$: console.log(connection?.databases);
|
||||||
|
|
||||||
async function openConnection(hostKey) {
|
async function openConnection(hostKey) {
|
||||||
$busy = true;
|
busy.start();
|
||||||
const databases = await OpenConnection(hostKey);
|
const databases = await OpenConnection(hostKey);
|
||||||
|
|
||||||
if (databases) {
|
if (databases) {
|
||||||
@ -33,32 +35,40 @@
|
|||||||
window.runtime.WindowSetTitle(`${host.name} - Mongodup`);
|
window.runtime.WindowSetTitle(`${host.name} - Mongodup`);
|
||||||
}
|
}
|
||||||
|
|
||||||
$busy = false;
|
busy.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openDatabase(dbKey) {
|
async function openDatabase(dbKey) {
|
||||||
$busy = true;
|
busy.start();
|
||||||
const collections = await OpenDatabase(activeHostKey, dbKey);
|
const collections = await OpenDatabase(activeHostKey, dbKey);
|
||||||
|
|
||||||
for (const collKey of collections || []) {
|
for (const collKey of collections || []) {
|
||||||
connections[activeHostKey].databases[dbKey].collections[collKey] = {};
|
connections[activeHostKey].databases[dbKey].collections[collKey] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
$busy = false;
|
busy.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dropDatabase(dbKey) {
|
async function dropDatabase(dbKey) {
|
||||||
$busy = true;
|
busy.start();
|
||||||
await DropDatabase(activeHostKey, dbKey);
|
await DropDatabase(activeHostKey, dbKey);
|
||||||
await openConnection(activeHostKey);
|
await openConnection(activeHostKey);
|
||||||
$busy = false();
|
busy.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openCollection(collKey) {
|
async function openCollection(collKey) {
|
||||||
$busy = true;
|
busy.start();
|
||||||
const stats = await OpenCollection(activeHostKey, activeDbKey, collKey);
|
const stats = await OpenCollection(activeHostKey, activeDbKey, collKey);
|
||||||
connections[activeHostKey].databases[activeDbKey].collections[collKey].stats = stats;
|
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() {
|
async function reload() {
|
||||||
@ -78,11 +88,14 @@
|
|||||||
<div class="databaselist">
|
<div class="databaselist">
|
||||||
<Grid
|
<Grid
|
||||||
columns={[ { key: 'id' }, { key: 'collCount', right: true } ]}
|
columns={[ { key: 'id' }, { key: 'collCount', right: true } ]}
|
||||||
items={Object.keys(connection.databases).map(id => ({
|
items={Object.keys(connection.databases).map(dbKey => ({
|
||||||
id,
|
id: dbKey,
|
||||||
collCount: Object.keys(connection.databases[id].collections || {}).length,
|
collCount: Object.keys(connection.databases[dbKey].collections || {}).length,
|
||||||
children: connection.databases[id].collections || [],
|
children: Object.keys(connection.databases[dbKey].collections).map(collKey => ({
|
||||||
menu: [ { label: `Drop ${id}`, fn: () => dropDatabase(id) } ],
|
id: collKey,
|
||||||
|
menu: [ { label: `Drop ${collKey}`, fn: () => dropCollection(dbKey, collKey) } ],
|
||||||
|
})) || [],
|
||||||
|
menu: [ { label: `Drop ${dbKey}`, fn: () => dropDatabase(dbKey) } ],
|
||||||
}))}
|
}))}
|
||||||
actions={[
|
actions={[
|
||||||
{ icon: 'reload', fn: reload },
|
{ icon: 'reload', fn: reload },
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
|
||||||
export let items = undefined;
|
export let items = undefined;
|
||||||
export let position = undefined;
|
export let position = undefined;
|
||||||
|
|
||||||
@ -10,6 +9,11 @@
|
|||||||
function close() {
|
function close() {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function click(fn) {
|
||||||
|
fn();
|
||||||
|
close();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if items && position}
|
{#if items && position}
|
||||||
@ -20,7 +24,7 @@
|
|||||||
<hr />
|
<hr />
|
||||||
{:else}
|
{:else}
|
||||||
<li>
|
<li>
|
||||||
<button class="item" on:click={item.fn}>
|
<button class="item" on:click={() => click(item.fn)}>
|
||||||
{item.label}
|
{item.label}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
export const busy = writable(false);
|
export const busy = (() => {
|
||||||
busy.subscribe(isBusy => {
|
const { update, subscribe } = writable(0);
|
||||||
if (isBusy) {
|
|
||||||
document.body.classList.add('busy');
|
subscribe(isBusy => {
|
||||||
}
|
if (isBusy) {
|
||||||
else {
|
document.body.classList.add('busy');
|
||||||
document.body.classList.remove('busy');
|
}
|
||||||
}
|
else {
|
||||||
});
|
document.body.classList.remove('busy');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: () => update(v => ++v),
|
||||||
|
end: () => update(v => --v),
|
||||||
|
subscribe,
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
export const contextMenu = (() => {
|
export const contextMenu = (() => {
|
||||||
const { set, subscribe } = writable();
|
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 {primitive} from '../models';
|
||||||
import {app} 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 DropDatabase(arg1:string,arg2:string):Promise<boolean>;
|
||||||
|
|
||||||
export function Hosts():Promise<map[string]app.Host>;
|
export function Hosts():Promise<map[string]app.Host>;
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// 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) {
|
export function DropDatabase(arg1, arg2) {
|
||||||
return window['go']['app']['App']['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()
|
defer close()
|
||||||
return result
|
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