1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-19 05:27:57 +00:00
rolens/frontend/src/organisms/connection/index.svelte

97 lines
2.9 KiB
Svelte
Raw Normal View History

2023-01-16 19:03:56 +00:00
<script>
import Icon from '$components/icon.svelte';
import hostTree from '$lib/stores/hosttree';
import sharedState from '$lib/stores/sharedstate';
2023-06-26 19:05:05 +00:00
import { EventsOn } from '$wails/runtime/runtime';
import CollectionView from './collection/index.svelte';
import DatabaseView from './database/index.svelte';
import HostView from './host/index.svelte';
2023-02-15 18:27:51 +00:00
import HostTree from './hosttree.svelte';
2023-01-16 19:03:56 +00:00
let path = [];
let prevPath = '';
2023-06-26 19:05:05 +00:00
let hostTab = '';
let dbTab = '';
let collTab = '';
2023-01-16 19:03:56 +00:00
$: if (path.join('.') !== prevPath) {
hostTab = 'status';
dbTab = 'stats';
2023-07-24 18:07:29 +00:00
collTab = 'find';
prevPath = path.join('.');
}
$: activeHostKey = path[0];
$: activeDbKey = path[1];
$: activeCollKey = path[2];
2023-01-28 12:25:14 +00:00
2023-05-27 19:18:47 +00:00
$: sharedState.currentHost.set(activeHostKey);
$: sharedState.currentDb.set(activeDbKey);
$: sharedState.currentColl.set(activeCollKey);
2023-06-26 19:05:05 +00:00
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());
2023-06-29 07:50:18 +00:00
EventsOn('ui.coll.export', () => $hostTree[activeHostKey]?.databases[activeDbKey]?.collections[activeCollKey]?.export());
2023-06-26 19:05:05 +00:00
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);
2023-01-16 19:03:56 +00:00
</script>
2023-01-23 12:17:07 +00:00
<div class="tree">
<div class="tree-buttons">
<button class="button-small" on:click={hostTree.newHost}>
<Icon name="+" /> New host
</button>
</div>
<HostTree bind:path />
2023-01-23 12:17:07 +00:00
</div>
2023-01-16 19:03:56 +00:00
{#if activeCollKey}
{#key activeCollKey}
<CollectionView
host={$hostTree[activeHostKey]}
database={$hostTree[activeHostKey]?.databases[activeDbKey]}
collection={$hostTree[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]}
bind:tab={collTab}
/>
{/key}
{:else if activeDbKey}
{#key activeDbKey}
<DatabaseView
host={$hostTree[activeHostKey]}
database={$hostTree[activeHostKey]?.databases[activeDbKey]}
bind:tab={dbTab}
/>
{/key}
2023-06-07 19:52:43 +00:00
{:else if activeHostKey}
{#key activeHostKey}
<HostView host={$hostTree[activeHostKey]} bind:tab={hostTab} />
{/key}
{/if}
2023-01-16 19:03:56 +00:00
<style>
2023-01-23 12:17:07 +00:00
.tree {
padding: 0.5rem;
background-color: #fff;
}
.tree-buttons {
margin-bottom: 1rem;
}
</style>