1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Improved the app menu

This commit is contained in:
Romein van Buren 2023-06-26 21:05:05 +02:00
parent 5191086d74
commit 9acb89205d
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
7 changed files with 82 additions and 42 deletions

View File

@ -5,6 +5,7 @@
* Improved error logging and dialogs.
* Fixed host editing bug.
* Made table headers stick to the top.
* Improved the application menu.
## [v0.2.1]

View File

@ -150,21 +150,15 @@ async function refresh() {
};
collection.truncate = async function() {
const progress = startProgress(`Truncating collection "${collKey}"…`);
await TruncateCollection(hostKey, dbKey, collKey);
await refresh();
progress.end();
};
collection.drop = async function() {
const progress = startProgress(`Dropping collection "${collKey}"…`);
const success = await DropCollection(hostKey, dbKey, collKey);
if (success) {
await refresh();
}
progress.end();
};
collection.getIndexes = async function() {
@ -187,9 +181,7 @@ async function refresh() {
};
index.drop = async function() {
const progress = startProgress(`Dropping index ${index.name}`);
const hasBeenDropped = await DropIndex(hostKey, dbKey, collKey, index.name);
progress.end();
return hasBeenDropped;
};
@ -208,14 +200,10 @@ async function refresh() {
return new Promise(resolve => {
dialog.$on('create', async event => {
const progress = startProgress('Creating index…');
const newIndexName = await CreateIndex(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(event.detail.index));
if (newIndexName) {
dialog.$close();
}
progress.end();
resolve(newIndexName);
});
});

View File

@ -16,8 +16,8 @@
export let hostKey;
export let dbKey;
export let collKey;
export let tab = 'find';
let tab = 'find';
let find;
$: if (collection) {

View File

@ -7,8 +7,7 @@
export let database;
export let hostKey;
export let dbKey;
let tab = 'stats';
export let tab = 'stats';
$: if (database) {
database.hostKey = hostKey;

View File

@ -7,8 +7,7 @@
export let host;
export let hostKey;
let tab = 'status';
export let tab = 'status';
$: if (host) {
host.hostKey = hostKey;

View File

@ -2,12 +2,16 @@
import Icon from '$components/icon.svelte';
import hostTree from '$lib/stores/hosttree';
import sharedState from '$lib/stores/sharedstate';
import { EventsOn } from '$wails/runtime/runtime';
import CollectionView from './collection/index.svelte';
import DatabaseView from './database/index.svelte';
import HostView from './host/index.svelte';
import HostTree from './hosttree.svelte';
let path = [];
let hostTab = '';
let dbTab = '';
let collTab = '';
$: activeHostKey = path[0];
$: activeDbKey = path[1];
@ -16,6 +20,28 @@
$: sharedState.currentHost.set(activeHostKey);
$: sharedState.currentDb.set(activeDbKey);
$: sharedState.currentColl.set(activeCollKey);
EventsOn('ui.host.new', () => hostTree.newHost());
EventsOn('ui.host.edit', () => $hostTree[activeHostKey]?.edit());
EventsOn('ui.host.remove', () => $hostTree[activeHostKey]?.remove());
EventsOn('ui.host.tab', tab => {
path = path.slice(0, 1);
hostTab = tab;
});
EventsOn('ui.db.new', () => $hostTree[activeHostKey]?.newDatabase());
EventsOn('ui.db.dump', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.dump());
EventsOn('ui.db.drop', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.drop());
EventsOn('ui.db.tab', tab => {
path = path.slice(0, 2);
dbTab = tab;
});
EventsOn('ui.coll.new', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.newCollection());
EventsOn('ui.coll.truncate', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.collections[activeCollKey]?.truncate());
EventsOn('ui.coll.drop', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.collections[activeCollKey]?.drop());
EventsOn('ui.coll.tab', tab => collTab = tab);
</script>
<div class="tree">
@ -34,17 +60,20 @@
hostKey={activeHostKey}
dbKey={activeDbKey}
collKey={activeCollKey}
bind:tab={collTab}
/>
{:else if activeDbKey}
<DatabaseView
database={$hostTree[activeHostKey]?.databases[activeDbKey]}
hostKey={activeHostKey}
dbKey={activeDbKey}
bind:tab={dbTab}
/>
{:else if activeHostKey}
<HostView
host={$hostTree[activeHostKey]}
hostKey={activeHostKey}
bind:tab={hostTab}
/>
{/if}

View File

@ -14,7 +14,7 @@ func menuCallbackEmit(a *App, eventName string, data ...interface{}) func(cd *me
}
}
func menuCallbackURL(a *App, url string) func(cd *menu.CallbackData) {
func menuCallbackOpenURL(a *App, url string) func(cd *menu.CallbackData) {
return func(cd *menu.CallbackData) {
wailsRuntime.BrowserOpenURL(a.ctx, url)
}
@ -32,38 +32,62 @@ func (a *App) Menu() *menu.Menu {
aboutMenu.AddText("Open log directory…", nil, func(cd *menu.CallbackData) { a.ui.Reveal(a.Env.LogDirectory) })
aboutMenu.AddText("Purge logs…", nil, func(cd *menu.CallbackData) { a.PurgeLogDirectory() })
aboutMenu.AddSeparator()
aboutMenu.AddText("Quit Rolens", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
fileMenu := appMenu.AddSubmenu("File")
fileMenu.AddText("New host…", keys.CmdOrCtrl("y"), menuCallbackEmit(a, "CreateHost"))
fileMenu.AddSeparator()
fileMenu.AddText("Stats", keys.Combo("h", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "stats"))
fileMenu.AddText("Find", keys.Combo("f", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "find"))
fileMenu.AddText("Insert", keys.Combo("i", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "insert"))
fileMenu.AddText("Update", keys.Combo("u", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "update"))
fileMenu.AddText("Remove", keys.Combo("r", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "remove"))
fileMenu.AddText("Indexes", keys.Combo("x", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "indexes"))
fileMenu.AddText("Aggregate", keys.Combo("a", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "aggregate"))
if runtime.GOOS == "darwin" {
appMenu.Append(menu.EditMenu())
aboutMenu.AddText("Minimize", keys.CmdOrCtrl("M"), func(cd *menu.CallbackData) { wailsRuntime.WindowMinimise(a.ctx) })
aboutMenu.AddText("Hide Rolens", keys.CmdOrCtrl("H"), func(cd *menu.CallbackData) { wailsRuntime.WindowHide(a.ctx) })
aboutMenu.AddSeparator()
windowMenu := appMenu.AddSubmenu("Window")
windowMenu.AddText("Minimize", keys.CmdOrCtrl("M"), func(cd *menu.CallbackData) { wailsRuntime.WindowMinimise(a.ctx) })
windowMenu.AddText("Hide", keys.CmdOrCtrl("H"), func(cd *menu.CallbackData) { wailsRuntime.WindowMinimise(a.ctx) })
appMenu.Append(menu.EditMenu())
}
aboutMenu.AddText("Quit Rolens", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
hostMenu := appMenu.AddSubmenu("Host")
hostMenu.AddText("New…", nil, menuCallbackEmit(a, "ui.host.new"))
hostMenu.AddText("Edit host…", nil, menuCallbackEmit(a, "ui.host.edit"))
hostMenu.AddSeparator()
hostMenu.AddText("Server status", nil, menuCallbackEmit(a, "ui.host.tab", "status"))
hostMenu.AddText("System info", nil, menuCallbackEmit(a, "ui.host.tab", "systemInfo"))
hostMenu.AddText("Shell", nil, menuCallbackEmit(a, "ui.host.tab", "shell"))
hostMenu.AddSeparator()
hostMenu.AddText("Remove host…", nil, menuCallbackEmit(a, "ui.host.remove"))
dbMenu := appMenu.AddSubmenu("Database")
dbMenu.AddText("New…", nil, menuCallbackEmit(a, "ui.db.new"))
dbMenu.AddSeparator()
dbMenu.AddText("Database statistics", nil, menuCallbackEmit(a, "ui.db.tab", "stats"))
dbMenu.AddText("Shell", nil, menuCallbackEmit(a, "ui.db.tab", "shell"))
dbMenu.AddSeparator()
dbMenu.AddText("Dump…", nil, menuCallbackEmit(a, "ui.db.dump"))
dbMenu.AddText("Drop…", nil, menuCallbackEmit(a, "ui.db.drop"))
collMenu := appMenu.AddSubmenu("Collection")
collMenu.AddText("New…", nil, menuCallbackEmit(a, "ui.coll.new"))
collMenu.AddSeparator()
collMenu.AddText("Collection statistics", nil, menuCallbackEmit(a, "ui.coll.tab", "stats"))
collMenu.AddText("Find", nil, menuCallbackEmit(a, "ui.coll.tab", "find"))
collMenu.AddText("Insert", nil, menuCallbackEmit(a, "ui.coll.tab", "insert"))
collMenu.AddText("Update", nil, menuCallbackEmit(a, "ui.coll.tab", "update"))
collMenu.AddText("Remove", nil, menuCallbackEmit(a, "ui.coll.tab", "remove"))
collMenu.AddText("Indexes", nil, menuCallbackEmit(a, "ui.coll.tab", "indexes"))
collMenu.AddText("Aggregate", nil, menuCallbackEmit(a, "ui.coll.tab", "aggregate"))
collMenu.AddText("Shell", nil, menuCallbackEmit(a, "ui.coll.tab", "shell"))
collMenu.AddSeparator()
collMenu.AddText("Truncate…", nil, menuCallbackEmit(a, "ui.coll.truncate"))
collMenu.AddText("Drop…", nil, menuCallbackEmit(a, "ui.coll.drop"))
helpMenu := appMenu.AddSubmenu("Help")
helpMenu.AddText("User guide", nil, menuCallbackURL(a, "https://garraflavatra.github.io/rolens/user-guide/"))
helpMenu.AddText("Website", nil, menuCallbackURL(a, "https://garraflavatra.github.io/rolens/"))
helpMenu.AddText("Discussion board", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/discussions"))
helpMenu.AddText("User guide", nil, menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/user-guide/"))
helpMenu.AddText("Website", nil, menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/"))
helpMenu.AddText("Discussion board", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/discussions"))
helpMenu.AddSeparator()
helpMenu.AddText("Report a problem", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/issues/new"))
helpMenu.AddText("Ask a question", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/discussions/new?category=questions"))
helpMenu.AddText("Report a problem", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/issues/new"))
helpMenu.AddText("Ask a question", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/discussions/new?category=questions"))
helpMenu.AddSeparator()
helpMenu.AddText("Star Rolens on GitHub", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens"))
helpMenu.AddText("Changelog", nil, menuCallbackURL(a, "https://garraflavatra.github.io/rolens/development/changelog/"))
helpMenu.AddText("License", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/blob/main/LICENSE"))
helpMenu.AddText("Star Rolens on GitHub", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens"))
helpMenu.AddText("Changelog", nil, menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/development/changelog/"))
helpMenu.AddText("License", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/blob/main/LICENSE"))
return appMenu
}