2024-01-22 13:12:21 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import api from '$lib/api';
|
|
|
|
import { ATTR_IN } from '@upnd/upend/constants';
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import type { UpObject } from '@upnd/upend';
|
|
|
|
import type { Readable } from 'svelte/store';
|
|
|
|
import EntitySetEditor from './EntitySetEditor.svelte';
|
|
|
|
import { i18n } from '../i18n';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-01-22 20:33:12 +01:00
|
|
|
export let entity: Readable<UpObject | undefined>;
|
2024-01-22 13:12:21 +01:00
|
|
|
|
|
|
|
$: groups = Object.fromEntries(
|
|
|
|
($entity?.attr[ATTR_IN] || []).map((e) => [e.value.c as string, e.address])
|
|
|
|
);
|
|
|
|
|
|
|
|
async function addGroup(address: string) {
|
2024-01-22 20:33:12 +01:00
|
|
|
if (!$entity) return;
|
|
|
|
|
2024-01-22 13:12:21 +01:00
|
|
|
await api.putEntry([
|
|
|
|
{
|
|
|
|
entity: $entity.address,
|
|
|
|
attribute: ATTR_IN,
|
|
|
|
value: {
|
|
|
|
t: 'Address',
|
|
|
|
c: address
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
dispatch('change');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removeGroup(address: string) {
|
|
|
|
await api.deleteEntry(groups[address]);
|
|
|
|
dispatch('change');
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<EntitySetEditor
|
|
|
|
entities={Object.keys(groups)}
|
2024-01-22 20:33:12 +01:00
|
|
|
header={$i18n.t('Groups') || ''}
|
2024-01-22 13:12:21 +01:00
|
|
|
hide={Object.keys(groups).length === 0}
|
|
|
|
on:add={(e) => addGroup(e.detail)}
|
|
|
|
on:remove={(e) => removeGroup(e.detail)}
|
|
|
|
on:highlighted
|
|
|
|
/>
|