ui: Don't automaticaly create objects for inner objects

This commit is contained in:
nemunaire 2024-01-17 17:39:41 +01:00
parent 909ef75b16
commit e1e75cbc73
3 changed files with 31 additions and 18 deletions

View file

@ -50,14 +50,12 @@
export let value: any; export let value: any;
let innerSpecs: Array<Field> | undefined = undefined; let innerSpecs: Array<Field> | undefined = undefined;
$: { $: getServiceSpec(type).then((ss) => {
getServiceSpec(type).then((ss) => {
innerSpecs = ss.fields; innerSpecs = ss.fields;
}); });
}
// Initialize unexistant objects and arrays, except standard types. // Initialize unexistant objects and arrays, except standard types.
$: if (innerSpecs) { $: if (innerSpecs && !(specs && specs.tabs)) {
for (const spec of innerSpecs) { for (const spec of innerSpecs) {
fillUndefinedValues(value, spec); fillUndefinedValues(value, spec);
} }
@ -97,6 +95,18 @@
tab={spec.label} tab={spec.label}
active={i == 0} active={i == 0}
> >
{#if innerSpecs && value[spec.id] === undefined}
<div class="my-3 d-flex justify-content-center">
<Button
color="primary"
type="button"
on:click={() => { fillUndefinedValues(value, spec); value = value; }}
>
<Icon name="plus" />
{$t('common.add-object', {thing: spec.label})}
</Button>
</div>
{:else}
<ResourceInput <ResourceInput
{edit} {edit}
{editToolbar} {editToolbar}
@ -109,6 +119,7 @@
on:delete-this-service={() => deleteSubObject(spec.id)} on:delete-this-service={() => deleteSubObject(spec.id)}
on:update-this-service={(event) => dispatch("update-this-service", event.detail)} on:update-this-service={(event) => dispatch("update-this-service", event.detail)}
/> />
{/if}
</TabPane> </TabPane>
{/each} {/each}
</TabContent> </TabContent>

View file

@ -28,6 +28,7 @@
"common": { "common": {
"add": "Add", "add": "Add",
"add-new-thing": "Add new {{thing}}", "add-new-thing": "Add new {{thing}}",
"add-object": "Add a {{thing}} object to this service",
"cancel": "Cancel", "cancel": "Cancel",
"cancel-edit": "Cancel edit", "cancel-edit": "Cancel edit",
"continue": "Continue", "continue": "Continue",

View file

@ -28,6 +28,7 @@
"common": { "common": {
"add": "Ajouter", "add": "Ajouter",
"add-new-thing": "Ajouter {{thing}}", "add-new-thing": "Ajouter {{thing}}",
"add-object": "Add un objet {{thing}} à ce service",
"cancel": "Annuler", "cancel": "Annuler",
"cancel-edit": "Abandonner", "cancel-edit": "Abandonner",
"continue": "Continuer", "continue": "Continuer",