1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-02-01 02:39:26 +00:00

68 lines
1.6 KiB
Svelte
Raw Normal View History

2023-01-10 17:28:27 +01:00
<script>
import ObjectViewer from '../../../components/objectviewer.svelte';
2023-01-17 09:44:21 +01:00
import ObjectGrid from '../../../components/objectgrid.svelte';
2023-01-17 20:49:07 +01:00
import { DropIndex, GetIndexes } from '../../../../wailsjs/go/app/App';
2023-01-17 09:44:21 +01:00
2023-01-10 17:28:27 +01:00
export let collection;
2023-01-17 09:44:21 +01:00
let indexes = [];
let activePath = [];
let objectViewerData = '';
2023-01-17 09:44:21 +01:00
async function getIndexes() {
const result = await GetIndexes(collection.hostKey, collection.dbKey, collection.key);
if (result) {
indexes = result;
}
}
2023-01-10 17:28:27 +01:00
2023-01-18 13:59:32 +01:00
async function drop(key) {
if (typeof key !== 'string') {
key = activePath[0];
2023-01-17 20:49:07 +01:00
}
2023-01-17 21:03:01 +01:00
const success = await DropIndex(collection.hostKey, collection.dbKey, collection.key, key);
2023-01-17 20:49:07 +01:00
if (success) {
await getIndexes();
activePath[0] = '';
2023-01-17 20:49:07 +01:00
}
}
function openJson(indexId) {
2023-01-19 08:59:57 +01:00
const item = indexes?.find(i => i.name == indexId);
objectViewerData = item;
2023-01-17 09:44:21 +01:00
}
2023-01-10 17:28:27 +01:00
</script>
2023-01-17 09:44:21 +01:00
<div class="indexes">
<div class="actions">
<button class="btn" on:click={getIndexes}>Get indexes</button>
<button class="btn danger" on:click={drop} disabled={!indexes?.length || !activePath[0]}>
2023-01-17 20:49:07 +01:00
Drop selected
</button>
2023-01-17 21:03:01 +01:00
<button class="btn">Create…</button>
2023-01-17 09:44:21 +01:00
</div>
2023-01-17 16:22:49 +01:00
<div class="grid">
2023-01-17 21:03:01 +01:00
<ObjectGrid key="name" data={indexes.map(idx => ({
...idx,
2023-01-18 13:59:32 +01:00
menu: [ { label: 'Drop this index', fn: () => drop(idx.name) } ],
}))} bind:activePath on:trigger={e => openJson(e.detail.itemKey)} />
2023-01-17 16:22:49 +01:00
</div>
2023-01-10 17:28:27 +01:00
</div>
2023-01-17 09:44:21 +01:00
<ObjectViewer bind:data={objectViewerData} />
2023-01-17 09:44:21 +01:00
<style>
.indexes {
display: grid;
gap: 0.5rem;
grid-template: auto 1fr / 1fr;
}
2023-01-17 16:22:49 +01:00
.indexes .grid {
min-height: 0;
min-width: 0;
border: 1px solid #ccc;
}
2023-01-17 09:44:21 +01:00
</style>