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,18 +95,31 @@
tab={spec.label} tab={spec.label}
active={i == 0} active={i == 0}
> >
<ResourceInput {#if innerSpecs && value[spec.id] === undefined}
{edit} <div class="my-3 d-flex justify-content-center">
{editToolbar} <Button
index={index + '_' + spec.id} color="primary"
noDecorate type="button"
{readonly} on:click={() => { fillUndefinedValues(value, spec); value = value; }}
specs={spec} >
type={spec.type} <Icon name="plus" />
bind:value={value[spec.id]} {$t('common.add-object', {thing: spec.label})}
on:delete-this-service={() => deleteSubObject(spec.id)} </Button>
on:update-this-service={(event) => dispatch("update-this-service", event.detail)} </div>
/> {:else}
<ResourceInput
{edit}
{editToolbar}
index={index + '_' + spec.id}
noDecorate
{readonly}
specs={spec}
type={spec.type}
bind:value={value[spec.id]}
on:delete-this-service={() => deleteSubObject(spec.id)}
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",