diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts index 8379c4873e..11a93f1060 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/existing-metadata-list-element/existing-metadata-list-element.component.ts @@ -68,9 +68,11 @@ export class ReorderableFormFieldMetadataValue extends Reorderable { } update(): Observable { - this.metadataValue.place = this.newIndex; - this.model.valueUpdates.next(this.metadataValue as any); - console.log('this.control.value', this.control.value); + // this.metadataValue.place = this.newIndex; + // this.model.valueUpdates.next(this.metadataValue.value); + // console.log('this.model', this.model); + // this.control.markAsDirty(); + // console.log('this.control.value', this.control.value); this.oldIndex = this.newIndex; return observableOf(this.metadataValue); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts index 8a2cb8093d..27849f8de9 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts @@ -70,6 +70,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple } ngOnInit(): void { + console.log('this.model', this.model); this.submissionObjectService .findById(this.model.submissionId).pipe( getSucceededRemoteData(), @@ -89,7 +90,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple this.zone.runOutsideAngular(() => { const reorderable$arr: Array> = this.model.groups .map((group, index) => [group, (this.control as any).controls[index]]) - .slice(1) // disregard the first group, it is always empty to ensure the first field remains empty + //.slice(1) // disregard the first group, it is always empty to ensure the first field remains empty .map(([group, control]: [DynamicFormArrayGroupModel, AbstractControl], index: number) => { const model = group.group[0] as DynamicConcatModel; let formFieldMetadataValue: FormFieldMetadataValueObject = model.value as FormFieldMetadataValueObject; @@ -158,6 +159,7 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent imple if (reorderable.hasMoved) { console.log('reorderable moved', reorderable, reorderable.getPlace()); reorderable.update().pipe(take(1)).subscribe((v) => { + this.change.emit(undefined); console.log('reorderable updated', reorderable, reorderable.getPlace()); }); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts index 3827df7be6..24145bb023 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model.ts @@ -11,6 +11,7 @@ export interface DsDynamicInputModelConfig extends DynamicInputModelConfig { authorityOptions?: AuthorityOptions; languageCodes?: LanguageCode[]; language?: string; + place?: number; value?: any; relationship?: RelationshipOptions; repeatable: boolean; diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-array-model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-array-model.ts index 1a20453248..831b04d258 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-array-model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-row-array-model.ts @@ -5,6 +5,7 @@ export interface DynamicRowArrayModelConfig extends DynamicFormArrayModelConfig required: boolean; submissionId: string; hasRelationship: boolean; + metadataKey: string; } export class DynamicRowArrayModel extends DynamicFormArrayModel { @@ -12,6 +13,7 @@ export class DynamicRowArrayModel extends DynamicFormArrayModel { @serializable() required = false; @serializable() submissionId: string; @serializable() hasRelationship: boolean; + @serializable() metadataKey: string; isRowArray = true; constructor(config: DynamicRowArrayModelConfig, layout?: DynamicFormControlLayout) { @@ -20,5 +22,6 @@ export class DynamicRowArrayModel extends DynamicFormArrayModel { this.required = config.required; this.submissionId = config.submissionId; this.hasRelationship = config.hasRelationship; + this.metadataKey = config.metadataKey; } } diff --git a/src/app/shared/form/builder/form-builder.service.ts b/src/app/shared/form/builder/form-builder.service.ts index dcc9403d9b..1b1ff81423 100644 --- a/src/app/shared/form/builder/form-builder.service.ts +++ b/src/app/shared/form/builder/form-builder.service.ts @@ -228,7 +228,7 @@ export class FormBuilderService extends DynamicFormService { } hasArrayGroupValue(model: DynamicFormControlModel): boolean { - return model && (this.isListGroup(model) || model.type === DYNAMIC_FORM_CONTROL_TYPE_TAG); + return model && (this.isListGroup(model) || model.type === DYNAMIC_FORM_CONTROL_TYPE_TAG || model.type === DYNAMIC_FORM_CONTROL_TYPE_ARRAY); } hasMappedGroupValue(model: DynamicFormControlModel): boolean { @@ -285,11 +285,16 @@ export class FormBuilderService extends DynamicFormService { return isNotEmpty(fieldModel) ? formGroup.get(this.getPath(fieldModel)) : null; } + /** + * Note (discovered while debugging) this is not the ID as used in the form, + * but the first part of the path needed in a patch operation: + * e.g. add foo/0 -> the id is 'foo' + */ getId(model: DynamicPathable): string { let tempModel: DynamicFormControlModel; if (this.isArrayGroup(model as DynamicFormControlModel)) { - return model.index.toString(); + return hasValue((model as any).metadataKey) ? (model as any).metadataKey : model.index.toString(); } else if (this.isModelInCustomGroup(model as DynamicFormControlModel)) { tempModel = (model as any).parent; } else { diff --git a/src/app/shared/form/builder/parsers/field-parser.ts b/src/app/shared/form/builder/parsers/field-parser.ts index 5cacbe962c..a4575087d1 100644 --- a/src/app/shared/form/builder/parsers/field-parser.ts +++ b/src/app/shared/form/builder/parsers/field-parser.ts @@ -44,6 +44,12 @@ export abstract class FieldParser { let arrayCounter = 0; let fieldArrayCounter = 0; + let metadataKey; + + if (Array.isArray(this.configData.selectableMetadata) && this.configData.selectableMetadata.length === 1) { + metadataKey = this.configData.selectableMetadata[0].metadata; + }; + const config = { id: uniqueId() + '_array', label: this.configData.label, @@ -52,6 +58,7 @@ export abstract class FieldParser { hasRelationship: isNotEmpty(this.configData.selectableRelationship), required: isNotEmpty(this.configData.mandatory), submissionId: this.submissionId, + metadataKey, groupFactory: () => { let model; let isFirstModelInArray = true; @@ -314,6 +321,7 @@ export abstract class FieldParser { if (typeof fieldValue === 'object') { modelConfig.language = fieldValue.language; + modelConfig.place = fieldValue.place; if (forceValueAsObj) { modelConfig.value = fieldValue; } else { diff --git a/src/app/shared/mocks/mock-form-models.ts b/src/app/shared/mocks/mock-form-models.ts index a98a950527..f81e7f6545 100644 --- a/src/app/shared/mocks/mock-form-models.ts +++ b/src/app/shared/mocks/mock-form-models.ts @@ -81,7 +81,8 @@ const rowArrayQualdropConfig = { return [MockQualdropModel]; }, required: false, - submissionId: '1234' + submissionId: '1234', + metadataKey: 'dc.some.key' } as DynamicRowArrayModelConfig; export const MockRowArrayQualdropModel: DynamicRowArrayModel = new DynamicRowArrayModel(rowArrayQualdropConfig);