2023-01-28 13:25:14 +01:00
|
|
|
<script>
|
2023-08-07 16:59:22 +02:00
|
|
|
import DirectoryChooser from '$components/editors/directorychooser.svelte';
|
|
|
|
import Grid from '$components/grid/grid.svelte';
|
2023-02-15 19:27:51 +01:00
|
|
|
import Modal from '$components/modal.svelte';
|
2023-08-07 18:21:45 +02:00
|
|
|
import hostTree from '$lib/stores/hosttree.js';
|
|
|
|
import applicationSettings from '$lib/stores/settings.js';
|
|
|
|
import { OpenConnection, OpenDatabase } from '$wails/go/app/App.js';
|
2023-06-18 21:31:55 +02:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
2023-01-28 13:25:14 +01:00
|
|
|
|
2023-06-18 21:31:55 +02:00
|
|
|
export let info = {};
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2023-01-28 13:25:14 +01:00
|
|
|
|
2023-02-11 11:22:02 +01:00
|
|
|
$: if (info) {
|
|
|
|
info.outdir = info.outdir || $applicationSettings.defaultExportDirectory;
|
2023-02-21 20:26:46 +01:00
|
|
|
info.filename = info.filename || `Dump ${new Date().getTime()}`;
|
2023-02-11 11:22:02 +01:00
|
|
|
}
|
|
|
|
|
2023-01-28 13:25:14 +01:00
|
|
|
async function selectHost(hostKey) {
|
|
|
|
info.hostKey = hostKey;
|
|
|
|
info.dbKey = undefined;
|
|
|
|
info.collKeys = [];
|
|
|
|
|
|
|
|
if (hostKey) {
|
|
|
|
const databases = await OpenConnection(hostKey);
|
|
|
|
|
2023-06-18 21:31:55 +02:00
|
|
|
if (databases && !$hostTree[hostKey]) {
|
|
|
|
$hostTree[hostKey] = { databases: {} };
|
2023-01-28 13:25:14 +01:00
|
|
|
databases.sort().forEach(dbKey => {
|
2023-06-18 21:31:55 +02:00
|
|
|
$hostTree[hostKey].databases[dbKey] = $hostTree[hostKey].databases[dbKey] || { collections: {} };
|
2023-01-28 13:25:14 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function selectDatabase(dbKey) {
|
|
|
|
info.collKeys = [];
|
|
|
|
info.dbKey = dbKey;
|
|
|
|
|
|
|
|
if (dbKey) {
|
|
|
|
const collections = await OpenDatabase(info.hostKey, dbKey);
|
|
|
|
|
|
|
|
for (const collKey of collections?.sort() || []) {
|
2023-06-18 21:31:55 +02:00
|
|
|
$hostTree[info.hostKey].databases[dbKey].collections[collKey] = {};
|
2023-01-28 13:25:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectCollection(collKey) {
|
|
|
|
info.collKeys = [ collKey ];
|
|
|
|
}
|
2023-06-18 21:31:55 +02:00
|
|
|
|
|
|
|
function performDump() {
|
|
|
|
dispatch('dump', { info });
|
|
|
|
}
|
2023-01-28 13:25:14 +01:00
|
|
|
</script>
|
|
|
|
|
2023-06-18 21:31:55 +02:00
|
|
|
<Modal title="Perform dump" on:close>
|
2023-02-21 20:26:46 +01:00
|
|
|
<form on:submit|preventDefault={performDump}>
|
2023-02-16 20:19:04 +01:00
|
|
|
<label class="field">
|
|
|
|
<span class="label">Output destination:</span>
|
|
|
|
<DirectoryChooser bind:value={info.outdir} />
|
|
|
|
<span class="label">/</span>
|
|
|
|
<input type="text" bind:value={info.filename} />
|
|
|
|
</label>
|
|
|
|
|
2023-01-28 13:25:14 +01:00
|
|
|
<div class="location">
|
|
|
|
<div class="grid">
|
|
|
|
<Grid
|
|
|
|
key="id"
|
|
|
|
columns={[ { title: 'Host', key: 'name' } ]}
|
|
|
|
activePath={info ? [ info.hostKey ] : []}
|
|
|
|
showHeaders
|
|
|
|
hideChildrenToggles
|
|
|
|
items={[
|
|
|
|
{ id: undefined, name: '(localhost)' },
|
2023-06-18 21:31:55 +02:00
|
|
|
...Object.keys($hostTree).map(id => {
|
|
|
|
return { id, name: $hostTree[id]?.name };
|
2023-06-11 09:34:00 +02:00
|
|
|
}),
|
2023-01-28 13:25:14 +01:00
|
|
|
]}
|
|
|
|
on:select={e => selectHost(e.detail?.itemKey)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="grid">
|
|
|
|
<Grid
|
|
|
|
key="id"
|
|
|
|
columns={[ { title: 'Database', key: 'name' } ]}
|
|
|
|
activePath={info ? [ info.dbKey ] : []}
|
|
|
|
showHeaders
|
|
|
|
hideChildrenToggles
|
|
|
|
items={[
|
|
|
|
{ id: undefined, name: '(all databases)' },
|
2023-06-18 21:31:55 +02:00
|
|
|
...($hostTree[info.hostKey]?.databases ? Object.keys($hostTree[info.hostKey].databases).map(id => {
|
2023-06-11 09:34:00 +02:00
|
|
|
return { id, name: id };
|
|
|
|
}) : []
|
2023-01-28 13:25:14 +01:00
|
|
|
),
|
|
|
|
]}
|
|
|
|
on:select={e => selectDatabase(e.detail?.itemKey)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="grid">
|
|
|
|
<Grid
|
|
|
|
key="id"
|
|
|
|
columns={[ { title: 'Collection', key: 'name' } ]}
|
|
|
|
activePath={info?.collKeys ? [ info.collKeys[0] ] : []}
|
|
|
|
showHeaders
|
|
|
|
hideChildrenToggles
|
|
|
|
items={[
|
|
|
|
{ id: undefined, name: '(all collections)' },
|
2023-06-18 21:31:55 +02:00
|
|
|
...($hostTree[info.hostKey]?.databases[info.dbKey]?.collections ? Object.keys($hostTree[info.hostKey].databases[info.dbKey].collections).map(id => {
|
2023-06-11 09:34:00 +02:00
|
|
|
return { id, name: id };
|
|
|
|
}) : []
|
2023-01-28 13:25:14 +01:00
|
|
|
),
|
|
|
|
]}
|
|
|
|
on:select={e => selectCollection(e.detail?.itemKey)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-11 11:22:02 +01:00
|
|
|
</form>
|
2023-05-31 20:20:39 +02:00
|
|
|
|
|
|
|
<svelte:fragment slot="footer">
|
2023-06-27 17:21:54 +02:00
|
|
|
<button class="button" on:click={performDump}>Perform dump</button>
|
2023-05-31 20:20:39 +02:00
|
|
|
</svelte:fragment>
|
2023-01-28 13:25:14 +01:00
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<style>
|
2023-02-11 11:22:02 +01:00
|
|
|
form {
|
2023-01-28 13:25:14 +01:00
|
|
|
display: grid;
|
2023-02-21 20:26:46 +01:00
|
|
|
grid-template: auto 1fr auto / 1fr;
|
2023-02-16 20:19:04 +01:00
|
|
|
gap: 0.5rem;
|
2023-01-28 13:25:14 +01:00
|
|
|
}
|
|
|
|
.location {
|
|
|
|
display: grid;
|
|
|
|
grid-template: 1fr / repeat(3, 1fr);
|
|
|
|
gap: 1rem;
|
|
|
|
}
|
|
|
|
.location .grid {
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
</style>
|