2023-01-10 16:28:27 +00:00
|
|
|
<script>
|
2023-01-18 19:59:00 +00:00
|
|
|
import { OpenConnection } from '../wailsjs/go/app/App';
|
2023-01-20 15:27:51 +00:00
|
|
|
import { EventsOn, WindowSetTitle } from '../wailsjs/runtime';
|
2023-01-15 16:10:30 +00:00
|
|
|
import BlankState from './components/blankstate.svelte';
|
2023-01-16 19:03:56 +00:00
|
|
|
import ContextMenu from './components/contextmenu.svelte';
|
2023-01-20 15:27:51 +00:00
|
|
|
import About from './organisms/about/index.svelte';
|
2023-01-16 19:03:56 +00:00
|
|
|
import AddressBar from './organisms/addressbar/index.svelte';
|
|
|
|
import Connection from './organisms/connection/index.svelte';
|
2023-01-20 14:35:16 +00:00
|
|
|
import Settings from './organisms/settings/index.svelte';
|
2023-01-20 15:27:51 +00:00
|
|
|
import { applicationSettings, busy, connections, contextMenu, environment } from './stores';
|
2023-01-10 16:28:27 +00:00
|
|
|
|
|
|
|
let hosts = {};
|
|
|
|
let activeHostKey = '';
|
|
|
|
let activeDbKey = '';
|
|
|
|
let activeCollKey = '';
|
2023-01-11 19:41:15 +00:00
|
|
|
let addressBarModalOpen = true;
|
2023-01-20 14:35:16 +00:00
|
|
|
let settingsModalOpen = false;
|
2023-01-20 15:27:51 +00:00
|
|
|
let aboutModalOpen = false;
|
2023-01-10 16:28:27 +00:00
|
|
|
|
|
|
|
$: host = hosts[activeHostKey];
|
2023-01-16 19:03:56 +00:00
|
|
|
$: connection = $connections[activeHostKey];
|
2023-01-10 16:28:27 +00:00
|
|
|
$: database = connection?.databases[activeDbKey];
|
|
|
|
$: collection = database?.collections?.[activeCollKey];
|
|
|
|
|
2023-01-20 15:27:51 +00:00
|
|
|
EventsOn('OpenPrefrences', () => settingsModalOpen = true);
|
|
|
|
EventsOn('OpenHostsModal', () => addressBarModalOpen = true);
|
|
|
|
EventsOn('OpenAboutModal', () => aboutModalOpen = true);
|
|
|
|
|
2023-01-10 16:28:27 +00:00
|
|
|
async function openConnection(hostKey) {
|
2023-01-14 20:09:21 +00:00
|
|
|
busy.start();
|
2023-01-10 16:28:27 +00:00
|
|
|
const databases = await OpenConnection(hostKey);
|
|
|
|
|
|
|
|
if (databases) {
|
2023-01-16 19:03:56 +00:00
|
|
|
$connections[hostKey] = { databases: {} };
|
2023-01-10 16:28:27 +00:00
|
|
|
databases.forEach(dbKey => {
|
2023-01-16 19:03:56 +00:00
|
|
|
$connections[hostKey].databases[dbKey] = { collections: {} };
|
2023-01-10 16:28:27 +00:00
|
|
|
});
|
|
|
|
activeHostKey = hostKey;
|
|
|
|
addressBarModalOpen = false;
|
2023-01-20 19:46:07 +00:00
|
|
|
WindowSetTitle(`${hosts[activeHostKey].name} - Rolens`);
|
2023-01-10 16:28:27 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 20:09:21 +00:00
|
|
|
busy.end();
|
2023-01-10 16:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
2023-01-20 15:27:51 +00:00
|
|
|
<svelte:window on:contextmenu|preventDefault />
|
2023-01-18 10:22:02 +00:00
|
|
|
|
2023-01-20 14:35:16 +00:00
|
|
|
<div id="root" class="platform-{$environment?.platform}">
|
2023-01-17 08:07:53 +00:00
|
|
|
<div class="titlebar"></div>
|
2023-01-16 15:56:16 +00:00
|
|
|
|
2023-01-20 14:35:16 +00:00
|
|
|
{#if $environment && $applicationSettings}
|
2023-01-16 15:56:16 +00:00
|
|
|
<main class:empty={!host || !connection}>
|
2023-01-18 19:59:00 +00:00
|
|
|
<AddressBar bind:hosts bind:activeHostKey on:select={e => openConnection(e.detail)} bind:modalOpen={addressBarModalOpen} />
|
2023-01-16 15:56:16 +00:00
|
|
|
|
|
|
|
{#if host && connection}
|
2023-01-16 19:03:56 +00:00
|
|
|
<Connection {hosts} bind:activeCollKey bind:activeDbKey {activeHostKey} />
|
2023-01-16 15:56:16 +00:00
|
|
|
{:else}
|
|
|
|
<BlankState label="A database client is nothing without a host" image="/fish.svg" />
|
|
|
|
{/if}
|
|
|
|
</main>
|
|
|
|
|
|
|
|
{#key $contextMenu}
|
|
|
|
<ContextMenu {...$contextMenu} on:close={contextMenu.hide} />
|
|
|
|
{/key}
|
2023-01-20 14:35:16 +00:00
|
|
|
<Settings bind:show={settingsModalOpen} />
|
2023-01-20 15:27:51 +00:00
|
|
|
<About bind:show={aboutModalOpen} />
|
2023-01-11 19:41:15 +00:00
|
|
|
{/if}
|
2023-01-16 15:56:16 +00:00
|
|
|
</div>
|
2023-01-14 19:38:39 +00:00
|
|
|
|
2023-01-10 16:28:27 +00:00
|
|
|
<style>
|
2023-01-16 19:03:56 +00:00
|
|
|
.titlebar {
|
|
|
|
height: 0;
|
|
|
|
background-color: #00002a;
|
2023-01-16 15:56:16 +00:00
|
|
|
--wails-draggable: drag;
|
2023-01-16 19:03:56 +00:00
|
|
|
}
|
2023-01-18 10:26:28 +00:00
|
|
|
#root.platform-darwin .titlebar {
|
2023-01-17 08:07:53 +00:00
|
|
|
height: var(--darwin-titlebar-height);
|
2023-01-16 15:56:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 16:28:27 +00:00
|
|
|
main {
|
|
|
|
height: 100vh;
|
2023-01-11 19:41:15 +00:00
|
|
|
display: grid;
|
|
|
|
grid-template: 3rem auto / 250px 1fr;
|
|
|
|
gap: 0.5rem;
|
|
|
|
padding: 0.5rem;
|
2023-01-10 16:28:27 +00:00
|
|
|
}
|
2023-01-18 10:26:28 +00:00
|
|
|
#root.platform-darwin main {
|
2023-01-17 08:07:53 +00:00
|
|
|
height: calc(100vh - var(--darwin-titlebar-height));
|
2023-01-16 15:56:16 +00:00
|
|
|
}
|
2023-01-15 16:10:30 +00:00
|
|
|
main.empty {
|
|
|
|
grid-template: 3rem auto / 1fr;
|
|
|
|
}
|
|
|
|
|
2023-01-17 15:22:49 +00:00
|
|
|
main > :global(*) {
|
|
|
|
overflow: auto;
|
|
|
|
min-height: 0;
|
|
|
|
min-width: 0;
|
|
|
|
}
|
2023-01-11 19:41:15 +00:00
|
|
|
main > :global(.addressbar) {
|
|
|
|
grid-column: 1 / 3;
|
2023-01-10 16:28:27 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 19:38:39 +00:00
|
|
|
.databaselist {
|
2023-01-10 19:10:39 +00:00
|
|
|
overflow: scroll;
|
2023-01-10 16:28:27 +00:00
|
|
|
}
|
2023-01-15 15:49:08 +00:00
|
|
|
|
|
|
|
.btn.create {
|
|
|
|
margin-top: 0.5rem;
|
|
|
|
}
|
2023-01-10 16:28:27 +00:00
|
|
|
</style>
|