2023-01-16 20:03:56 +01:00
|
|
|
<script>
|
2023-02-15 19:27:51 +01:00
|
|
|
import Grid from '$components/grid.svelte';
|
2023-06-18 21:31:55 +02:00
|
|
|
import hostTree from '$lib/stores/hosttree';
|
2023-01-16 20:03:56 +01:00
|
|
|
|
2023-06-18 21:31:55 +02:00
|
|
|
export let path = [];
|
2023-01-16 20:03:56 +01:00
|
|
|
</script>
|
|
|
|
|
2023-01-22 21:12:56 +01:00
|
|
|
<Grid
|
|
|
|
striped={false}
|
|
|
|
columns={[ { key: 'name' }, { key: 'count', right: true } ]}
|
2023-06-18 21:31:55 +02:00
|
|
|
items={Object.values($hostTree || {}).map(host => {
|
2023-06-11 09:34:00 +02:00
|
|
|
return {
|
2023-06-18 21:31:55 +02:00
|
|
|
id: host.key,
|
|
|
|
name: host.name,
|
2023-06-11 09:34:00 +02:00
|
|
|
icon: 'server',
|
2023-06-18 21:31:55 +02:00
|
|
|
children: Object.values(host.databases || {})
|
|
|
|
.sort((a, b) => a.key.localeCompare(b))
|
|
|
|
.map(database => {
|
|
|
|
return {
|
|
|
|
id: database.key,
|
|
|
|
name: database.key,
|
|
|
|
icon: 'db',
|
|
|
|
count: Object.keys(database.collections || {}).length || '',
|
|
|
|
children: Object.values(database.collections)
|
|
|
|
.sort((a, b) => a.key.localeCompare(b))
|
|
|
|
.map(collection => {
|
|
|
|
return {
|
|
|
|
id: collection.key,
|
|
|
|
name: collection.key,
|
|
|
|
icon: 'list',
|
|
|
|
menu: [
|
|
|
|
{ label: 'Export collection…', fn: collection.export },
|
|
|
|
{ label: 'Dump collection (BSON via mongodump)…', fn: collection.dump },
|
|
|
|
{ separator: true },
|
|
|
|
{ label: 'Rename collection…', fn: collection.rename },
|
|
|
|
{ label: 'Truncate collection…', fn: collection.truncate },
|
|
|
|
{ label: 'Drop collection…', fn: collection.drop },
|
|
|
|
{ separator: true },
|
|
|
|
{ label: 'New collection…', fn: database.newCollection },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}) || [],
|
|
|
|
menu: [
|
|
|
|
{ label: 'Dump database (BSON via mongodump)…', fn: database.dump },
|
|
|
|
{ label: 'Drop database…', fn: database.drop },
|
|
|
|
{ separator: true },
|
|
|
|
{ label: 'New database…', fn: host.newDatabase },
|
|
|
|
{ label: 'New collection…', fn: database.newCollection },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}),
|
2023-01-23 13:17:07 +01:00
|
|
|
menu: [
|
2023-06-18 21:31:55 +02:00
|
|
|
{ label: 'New database…', fn: host.newDatabase },
|
2023-06-11 09:34:00 +02:00
|
|
|
{ separator: true },
|
2023-06-18 21:31:55 +02:00
|
|
|
{ label: `Edit host ${host.name}…`, fn: host.edit },
|
|
|
|
{ label: 'Remove host…', fn: host.remove },
|
2023-01-23 13:17:07 +01:00
|
|
|
],
|
2023-06-11 09:34:00 +02:00
|
|
|
};
|
|
|
|
})}
|
2023-01-22 21:12:56 +01:00
|
|
|
on:select={e => {
|
2023-06-18 21:31:55 +02:00
|
|
|
let level;
|
|
|
|
({ path, level } = e.detail);
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case 0: return $hostTree[path[0]].open();
|
|
|
|
case 1: return $hostTree[path[0]].databases[path[1]].open();
|
|
|
|
case 2: return $hostTree[path[0]].databases[path[1]].collections[path[2]].open();
|
2023-01-22 21:12:56 +01:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
2023-01-23 13:17:07 +01:00
|
|
|
|
|
|
|
<!--
|
|
|
|
actions={[
|
|
|
|
{ icon: 'reload', fn: reload },
|
|
|
|
{ icon: '+', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'new')) },
|
|
|
|
{ icon: 'edit', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'edit')), disabled: !activeHostKey },
|
|
|
|
{ icon: '-', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'drop')), disabled: !activeDbKey },
|
|
|
|
]}
|
|
|
|
-->
|