From faeb7e0d62ea4d76100fdd6ce3979fa4a6b2b5df Mon Sep 17 00:00:00 2001 From: Kristan Ntavidi Date: Mon, 27 Sep 2021 16:25:17 +0300 Subject: [PATCH] improvement on computing ordinal on mutliplicity fields --- .../components/form-section/form-section.component.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts index a07ea16ca..18a75fe08 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts @@ -74,8 +74,17 @@ export class FormSectionComponent implements OnInit, OnChanges { addMultipleField(fieldsetIndex: number) { const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue(); const multiplicityItemsArray = ((this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))); + + const ordinal = multiplicityItemsArray.length? multiplicityItemsArray.controls.reduce((ordinal, currentControl)=>{ + const currentOrdinal = currentControl.get('ordinal').value as number; + + if(currentOrdinal>= ordinal){ + return currentOrdinal +1; + } + return ordinal as number; + },0) : 0; const idMappings = [] as {old: string, new: string}[]; - const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, multiplicityItemsArray.length,idMappings); + const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, ordinal ,idMappings);