From 67007c8d3d9ce510de36f087817e57a5f5c8b5bc Mon Sep 17 00:00:00 2001 From: Diamadis Tziotzios Date: Mon, 11 Dec 2017 17:35:51 +0200 Subject: [PATCH] no message --- .../dynamic-form-composite-field.html | 14 +++++- .../dynamic-form-composite-field.ts | 43 +++++++++++-------- .../dynamic-form-group.component.ts | 2 +- .../src/app/form/dynamic-form.component.html | 4 +- dmp-frontend/src/app/models/CompositeField.ts | 7 +-- dmp-frontend/src/app/models/Field.ts | 18 ++++++-- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.html b/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.html index a033f0711..22b0cce68 100644 --- a/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.html +++ b/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.html @@ -1,7 +1,8 @@
- +

{{compositeField.title}}

@@ -11,7 +12,16 @@ {{compositeField.extendedDescription}}
- +
+ + Add one more field + + +
+ +
+ +
diff --git a/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.ts b/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.ts index 7e4c3885a..0b405c712 100644 --- a/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.ts +++ b/dmp-frontend/src/app/form/dynamic-form-composite-field/dynamic-form-composite-field.ts @@ -1,26 +1,33 @@ import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service'; import { CompositeField } from '../../models/CompositeField'; -import { FormGroup } from '@angular/forms'; +import { FormGroup, FormArray } from '@angular/forms'; import { Section } from '../../entities/model/section'; import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; +import { Field } from '../../models/Field'; @Component({ - selector: 'df-composite-field', - templateUrl: './dynamic-form-composite-field.html', - styleUrls: [ - './dynamic-form-composite-field.css' - ], - encapsulation: ViewEncapsulation.None, - }) - export class DynamicFormCompositeFieldComponent implements OnInit{ + selector: 'df-composite-field', + templateUrl: './dynamic-form-composite-field.html', + styleUrls: [ + './dynamic-form-composite-field.css' + ], + encapsulation: ViewEncapsulation.None, +}) +export class DynamicFormCompositeFieldComponent implements OnInit { - @Input() compositeField: CompositeField - @Input() form: FormGroup; - @Input() pathName:string; - @Input() path:string; - - constructor(private visibilityRulesService:VisibilityRulesService){} + @Input() compositeField: CompositeField + @Input() form: FormGroup; + @Input() pathName: string; + @Input() path: string; - ngOnInit(){ + constructor(private visibilityRulesService: VisibilityRulesService) { } - } - } \ No newline at end of file + ngOnInit() { + + } + + addMultipleField(fieldIndex: number) { + let field: Field = this.compositeField.fields[fieldIndex].cloneForMultiplicity(fieldIndex); + this.compositeField.fields[fieldIndex].multiplicityItems.push(field); + ((this.form.get("fields").get('' + fieldIndex).get('multiplicityItems'))).push(field.buildForm()); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/form/dynamic-form-group/dynamic-form-group.component.ts b/dmp-frontend/src/app/form/dynamic-form-group/dynamic-form-group.component.ts index 510785611..e7e0b1331 100644 --- a/dmp-frontend/src/app/form/dynamic-form-group/dynamic-form-group.component.ts +++ b/dmp-frontend/src/app/form/dynamic-form-group/dynamic-form-group.component.ts @@ -45,7 +45,7 @@ export class DynamicFormGroupComponent implements OnInit { addMultipleField(fieldsetIndex: number) { - let compositeField: CompositeField = this.group.compositeFields[fieldsetIndex].cloneForMultiplicity(); + let compositeField: CompositeField = this.group.compositeFields[fieldsetIndex].cloneForMultiplicity(fieldsetIndex); this.group.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField); ((this.form.get("compositeFields").get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm()); } diff --git a/dmp-frontend/src/app/form/dynamic-form.component.html b/dmp-frontend/src/app/form/dynamic-form.component.html index 0335ab0a6..56c5ca811 100644 --- a/dmp-frontend/src/app/form/dynamic-form.component.html +++ b/dmp-frontend/src/app/form/dynamic-form.component.html @@ -5,8 +5,8 @@
- - + +
diff --git a/dmp-frontend/src/app/models/CompositeField.ts b/dmp-frontend/src/app/models/CompositeField.ts index 46c2629d4..78f3cae71 100644 --- a/dmp-frontend/src/app/models/CompositeField.ts +++ b/dmp-frontend/src/app/models/CompositeField.ts @@ -7,7 +7,7 @@ import { Multiplicity } from './Multiplicity'; export class CompositeField extends BaseModel implements Serializable { public fields: Array = new Array(); public ordinal: number - public id: number + public id: string public multiplicity: Multiplicity; public multiplicityItems: Array = new Array(); @@ -45,10 +45,11 @@ export class CompositeField extends BaseModel implements Serializable { - newItem.fields.push(field.cloneForMultiplicity()); + newItem.fields.push(field.cloneForMultiplicity(this.fields.indexOf(field))); }); newItem.ordinal = this.ordinal; diff --git a/dmp-frontend/src/app/models/Field.ts b/dmp-frontend/src/app/models/Field.ts index d12c22a50..12f41af5c 100644 --- a/dmp-frontend/src/app/models/Field.ts +++ b/dmp-frontend/src/app/models/Field.ts @@ -15,6 +15,7 @@ export class Field extends BaseModel implements Serializable, FormGenerat public defaultVisibility: boolean; public page: number; public multiplicity: Multiplicity; + public multiplicityItems: Array = new Array(); public data: any; fromJSONObject(item: any): Field { this.id = item.id; @@ -25,7 +26,10 @@ export class Field extends BaseModel implements Serializable, FormGenerat this.viewStyle = item.viewStyle; this.defaultVisibility = item.defaultVisibility; this.page = item.page; - this.multiplicity = new JsonSerializer().fromJSONObject(item.multiplicity, Multiplicity); + //this.multiplicity = new JsonSerializer().fromJSONObject(item.multiplicity, Multiplicity); + this.multiplicity = new Multiplicity(); + this.multiplicity.max = 2; + this.multiplicityItems = new JsonSerializer().fromJSONArray(item.multiplicityItems, Field); this.data = item.data; return this; } @@ -42,13 +46,21 @@ export class Field extends BaseModel implements Serializable, FormGenerat page:[this.page], data:[this.data] */ }); + + let multiplicityItemsFormArray = new Array(); + this.multiplicityItems.forEach(item => { + let form: FormGroup = item.buildForm(); + multiplicityItemsFormArray.push(form) + }) + formGroup.addControl('multiplicityItems', this.formBuilder.array(multiplicityItemsFormArray)); + return formGroup; } - cloneForMultiplicity(): Field { + cloneForMultiplicity(index: number): Field { let newItem: Field = new Field(); - newItem.id = this.id; + newItem.id = 'multiple_' + this.id + '_' + index; newItem.title = this.title; newItem.description = this.description; newItem.extendedDescription = this.extendedDescription;