From a583a5fdde3d46d9dfd9723638404096b25365db Mon Sep 17 00:00:00 2001 From: annampak Date: Mon, 27 Nov 2017 15:35:00 +0200 Subject: [PATCH] Dataset Profile Form --- dmp-admin/src/app/app.component.html | 3 +- dmp-admin/src/app/app.module.ts | 13 + .../compositefield-form.component.html | 12 + .../compositefield-form.component.ts | 29 ++ .../app/field-form/field-form.component.html | 62 +++++ .../app/field-form/field-form.component.ts | 29 ++ .../src/app/formBuilder/form.component.html | 15 ++ .../src/app/formBuilder/form.component.ts | 39 +++ .../groupfield-form.component.html | 38 +++ .../groupfield-form.component.ts | 29 ++ dmp-admin/src/app/models/BaseModel.ts | 4 + dmp-admin/src/app/models/CompositeField.ts | 27 ++ .../src/app/models/DatasetProfileModel.ts | 27 ++ dmp-admin/src/app/models/Field.ts | 57 ++++ dmp-admin/src/app/models/FieldGroup.ts | 58 ++++ dmp-admin/src/app/models/Rule.ts | 29 ++ dmp-admin/src/app/models/Section.ts | 55 ++++ dmp-admin/src/app/models/Validation.ts | 21 ++ .../app/models/interfaces/FormGenerator.ts | 4 + .../src/app/models/interfaces/Serializable.ts | 3 + .../app/rule-component/rule.component.html | 34 +++ .../src/app/rule-component/rule.component.ts | 15 ++ .../section-form/section-form.component.html | 27 ++ .../section-form/section-form.component.ts | 30 +++ dmp-admin/src/app/testModel/testModel.ts | 251 ++++++++++++++++++ dmp-admin/src/app/utilities/JsonSerializer.ts | 17 ++ 26 files changed, 927 insertions(+), 1 deletion(-) create mode 100644 dmp-admin/src/app/compositefield-form/compositefield-form.component.html create mode 100644 dmp-admin/src/app/compositefield-form/compositefield-form.component.ts create mode 100644 dmp-admin/src/app/field-form/field-form.component.html create mode 100644 dmp-admin/src/app/field-form/field-form.component.ts create mode 100644 dmp-admin/src/app/formBuilder/form.component.html create mode 100644 dmp-admin/src/app/formBuilder/form.component.ts create mode 100644 dmp-admin/src/app/groupfield-form/groupfield-form.component.html create mode 100644 dmp-admin/src/app/groupfield-form/groupfield-form.component.ts create mode 100644 dmp-admin/src/app/models/BaseModel.ts create mode 100644 dmp-admin/src/app/models/CompositeField.ts create mode 100644 dmp-admin/src/app/models/DatasetProfileModel.ts create mode 100644 dmp-admin/src/app/models/Field.ts create mode 100644 dmp-admin/src/app/models/FieldGroup.ts create mode 100644 dmp-admin/src/app/models/Rule.ts create mode 100644 dmp-admin/src/app/models/Section.ts create mode 100644 dmp-admin/src/app/models/Validation.ts create mode 100644 dmp-admin/src/app/models/interfaces/FormGenerator.ts create mode 100644 dmp-admin/src/app/models/interfaces/Serializable.ts create mode 100644 dmp-admin/src/app/rule-component/rule.component.html create mode 100644 dmp-admin/src/app/rule-component/rule.component.ts create mode 100644 dmp-admin/src/app/section-form/section-form.component.html create mode 100644 dmp-admin/src/app/section-form/section-form.component.ts create mode 100644 dmp-admin/src/app/testModel/testModel.ts create mode 100644 dmp-admin/src/app/utilities/JsonSerializer.ts diff --git a/dmp-admin/src/app/app.component.html b/dmp-admin/src/app/app.component.html index 503b172b9..8eda0142b 100644 --- a/dmp-admin/src/app/app.component.html +++ b/dmp-admin/src/app/app.component.html @@ -39,7 +39,8 @@ - + + diff --git a/dmp-admin/src/app/app.module.ts b/dmp-admin/src/app/app.module.ts index 035f88606..8417c6461 100644 --- a/dmp-admin/src/app/app.module.ts +++ b/dmp-admin/src/app/app.module.ts @@ -61,6 +61,13 @@ import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos- import { DatasetprofileEditorComponent } from './managers/datasetprofile-editor/datasetprofile-editor.component'; import { DatasetProfileGUIEditorComponent } from './dataset-profile-gui-editor/dataset-profile-gui-editor.component'; +import { FieldFormComponent } from './field-form/field-form.component'; +import { FormComponent } from './formBuilder/form.component'; +import { GroupFieldFormComponent } from './groupfield-form/groupfield-form.component'; +import { RuleFormComponent } from './rule-component/rule.component'; +import { SectionFormComponent } from './section-form/section-form.component'; +import { CompositeFieldFormComponent } from './compositefield-form/compositefield-form.component'; + @NgModule({ @@ -78,6 +85,12 @@ import { DatasetProfileGUIEditorComponent } from './dataset-profile-gui-editor/d AppComponent, GooggleSignInComponent, + FieldFormComponent, + FormComponent, + GroupFieldFormComponent, + RuleFormComponent, + SectionFormComponent, + CompositeFieldFormComponent, DatasetsViewerComponent, ProfileEditorComponent, PropertiesEditorComponent, diff --git a/dmp-admin/src/app/compositefield-form/compositefield-form.component.html b/dmp-admin/src/app/compositefield-form/compositefield-form.component.html new file mode 100644 index 000000000..6f44aa2d4 --- /dev/null +++ b/dmp-admin/src/app/compositefield-form/compositefield-form.component.html @@ -0,0 +1,12 @@ +
+

FieldSet

+
+ +
+ +
+ + Add another field + + +
+
diff --git a/dmp-admin/src/app/compositefield-form/compositefield-form.component.ts b/dmp-admin/src/app/compositefield-form/compositefield-form.component.ts new file mode 100644 index 000000000..5ecadd491 --- /dev/null +++ b/dmp-admin/src/app/compositefield-form/compositefield-form.component.ts @@ -0,0 +1,29 @@ +import { Component, Input } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { CompositeField } from '../models/CompositeField'; +import { Field } from '../models/Field'; +import { FormArray } from '@angular/forms/src/model'; + +@Component({ + selector: 'compositefield-form', + templateUrl: './compositefield-form.component.html', + styleUrls: [] +}) + +export class CompositeFieldFormComponent { +@Input() form: FormGroup; +@Input() dataModel: CompositeField; + +constructon(){} + +ngOnInit(){ + this.addNewField(); +} + +addNewField(){ + let field: Field = new Field(); + this.dataModel.fields.push(field); + (this.form.get("fields")).push(field.buildForm()); +} + +} \ No newline at end of file diff --git a/dmp-admin/src/app/field-form/field-form.component.html b/dmp-admin/src/app/field-form/field-form.component.html new file mode 100644 index 000000000..1fea8d714 --- /dev/null +++ b/dmp-admin/src/app/field-form/field-form.component.html @@ -0,0 +1,62 @@ +
+

Fields

+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + +
+
+ +
+
+ +
+
+ + Add another rule + + +
+
\ No newline at end of file diff --git a/dmp-admin/src/app/field-form/field-form.component.ts b/dmp-admin/src/app/field-form/field-form.component.ts new file mode 100644 index 000000000..700f04509 --- /dev/null +++ b/dmp-admin/src/app/field-form/field-form.component.ts @@ -0,0 +1,29 @@ +import { Component, Input } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { Field } from '../models/Field'; +import { Rule } from '../models/Rule'; +import { FormArray } from '@angular/forms/src/model'; + +@Component({ + selector: 'field-form', + templateUrl: './field-form.component.html', + styleUrls: [] +}) + +export class FieldFormComponent { +@Input() form: FormGroup; +@Input() dataModel: Field; + +constructon(){} + +ngOnInit(){ + this.addNewRule(); +} + +addNewRule(){ + let rule: Rule = new Rule(); + this.dataModel.rules.push(rule); + (this.form.get("rules")).push(rule.buildForm()); +} + +} \ No newline at end of file diff --git a/dmp-admin/src/app/formBuilder/form.component.html b/dmp-admin/src/app/formBuilder/form.component.html new file mode 100644 index 000000000..c946f3734 --- /dev/null +++ b/dmp-admin/src/app/formBuilder/form.component.html @@ -0,0 +1,15 @@ +
+
+
+ +
+ + + +

Form value: {{ form.value | json }}

+
+
\ No newline at end of file diff --git a/dmp-admin/src/app/formBuilder/form.component.ts b/dmp-admin/src/app/formBuilder/form.component.ts new file mode 100644 index 000000000..e40c50dd3 --- /dev/null +++ b/dmp-admin/src/app/formBuilder/form.component.ts @@ -0,0 +1,39 @@ +import { Component, OnInit } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { SectionFormComponent } from '../section-form/section-form.component'; +import { Section } from '../models/Section'; +import { FieldGroup } from '../models/FieldGroup'; +import { DatasetProfileModel } from '../models/DatasetProfileModel'; +import { TestModel } from '../testModel/testModel'; +import { FormArray } from '@angular/forms/src/model'; + + +@Component({ + selector: 'form-comp', + templateUrl: './form.component.html', + styleUrls: [] +}) + +export class FormComponent { + + dataModel: DatasetProfileModel ; + form: FormGroup; + + constructor(){ + } + + ngOnInit(){ + this.dataModel = new DatasetProfileModel(); + this.dataModel = new JsonSerializer().fromJSONObject(TestModel,DatasetProfileModel); + this.form = this.dataModel.buildForm(); + this.addSection(); + } + + addSection(){ + let section:Section = new Section(); + this.dataModel.sections.push(section); + (this.form.get("sections")).push(section.buildForm()); + } + +} \ No newline at end of file diff --git a/dmp-admin/src/app/groupfield-form/groupfield-form.component.html b/dmp-admin/src/app/groupfield-form/groupfield-form.component.html new file mode 100644 index 000000000..d22e9f3c6 --- /dev/null +++ b/dmp-admin/src/app/groupfield-form/groupfield-form.component.html @@ -0,0 +1,38 @@ +
+

GroupFields

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ +
+ + +
\ No newline at end of file diff --git a/dmp-admin/src/app/groupfield-form/groupfield-form.component.ts b/dmp-admin/src/app/groupfield-form/groupfield-form.component.ts new file mode 100644 index 000000000..f06ab74cf --- /dev/null +++ b/dmp-admin/src/app/groupfield-form/groupfield-form.component.ts @@ -0,0 +1,29 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { FieldGroup } from '../models/FieldGroup'; +import { CompositeField } from '../models/CompositeField'; +import { FormArray } from '@angular/forms/src/model'; + +@Component({ + selector: 'groupfield-form', + templateUrl: './groupfield-form.component.html', + styleUrls: [] +}) + +export class GroupFieldFormComponent { + @Input() form: FormGroup; + @Input() dataModel: FieldGroup; + + constructor(){} + + ngOnInit(){ + this.addNewField(); + } + + addNewField(){ + let compositeField: CompositeField = new CompositeField(); + this.dataModel.compositeFields.push(compositeField); + (this.form.get("compositeFields")).push(compositeField.buildForm()); + } + +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/BaseModel.ts b/dmp-admin/src/app/models/BaseModel.ts new file mode 100644 index 000000000..c4cfd9e90 --- /dev/null +++ b/dmp-admin/src/app/models/BaseModel.ts @@ -0,0 +1,4 @@ +import { FormBuilder } from '@angular/forms'; +export abstract class BaseModel{ + public formBuilder:FormBuilder = new FormBuilder(); +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/CompositeField.ts b/dmp-admin/src/app/models/CompositeField.ts new file mode 100644 index 000000000..4de8a6122 --- /dev/null +++ b/dmp-admin/src/app/models/CompositeField.ts @@ -0,0 +1,27 @@ +import { FormGroup } from '@angular/forms'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { Serializable } from './interfaces/Serializable'; +import { BaseModel } from './BaseModel'; +import {Field} from './Field' +export class CompositeField extends BaseModel implements Serializable { + public fields:Array = new Array(); + + + fromJSONObject(item:any):CompositeField{ + + this.fields = new JsonSerializer().fromJSONArray(item.fields,Field); + return this; + } + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({}); + + let fieldsFormArray = new Array(); + this.fields.forEach(item => { + let form: FormGroup = item.buildForm(); + fieldsFormArray.push(form) + }) + formGroup.addControl('fields', this.formBuilder.array(fieldsFormArray)); + return formGroup; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/DatasetProfileModel.ts b/dmp-admin/src/app/models/DatasetProfileModel.ts new file mode 100644 index 000000000..9d86174c1 --- /dev/null +++ b/dmp-admin/src/app/models/DatasetProfileModel.ts @@ -0,0 +1,27 @@ +import { BaseModel } from './BaseModel'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { Section } from './Section'; +import { Serializable } from './interfaces/Serializable'; +export class DatasetProfileModel extends BaseModel implements Serializable,FormGenerator{ + + public sections:Array
= new Array
(); + + fromJSONObject(item:any):DatasetProfileModel{ + this.sections = new JsonSerializer
().fromJSONArray(item.sections,Section); + return this; + } + + buildForm():FormGroup{ + let formGroup:FormGroup = new FormBuilder().group({}); + let sectionsFormArray = new Array(); + this.sections.forEach(item => { + let form: FormGroup = item.buildForm(); + sectionsFormArray.push(form) + }) + formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray)); + return formGroup; + } + +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/Field.ts b/dmp-admin/src/app/models/Field.ts new file mode 100644 index 000000000..e512ddfee --- /dev/null +++ b/dmp-admin/src/app/models/Field.ts @@ -0,0 +1,57 @@ +import { BaseModel } from './BaseModel'; +import { FormGroup } from '@angular/forms'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { Serializable } from './interfaces/Serializable'; +import {Rule} from './Rule' + +export class Field extends BaseModel implements Serializable,FormGenerator{ + + public id:string; + public title:string; + public value:string; + public description:string; + public extendedDescription:string; + public viewStyle:string; + public defaultVisibility:boolean; + public page:number; + public rules: Array = new Array(); + + fromJSONObject(item:any):Field{ + this.id = item.id; + this.title = item.title; + this.value = item.value; + this.description = item.description; + this.extendedDescription = item.extendedDescription; + this.viewStyle = item.viewStyle; + this.defaultVisibility = item.defaultVisibility; + this.page = item.page; + this.rules = new JsonSerializer().fromJSONArray(item.rule, Rule); + return this; + } + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + id: [this.id], + title: [this.title], + value: [this.value], + description: [this.description], + extendedDescription:[this.extendedDescription], + viewStyle: [this.viewStyle], + defaultVisibility:[this.defaultVisibility], + page:[this.page] + }); + + let rulesFormArray = new Array(); + if (this.rules){ + this.rules.forEach(rule =>{ + let form:FormGroup = rule.buildForm(); + rulesFormArray.push(form); + }); + } + + formGroup.addControl("rules", this.formBuilder.array(rulesFormArray)) + + return formGroup; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/FieldGroup.ts b/dmp-admin/src/app/models/FieldGroup.ts new file mode 100644 index 000000000..2f7acac08 --- /dev/null +++ b/dmp-admin/src/app/models/FieldGroup.ts @@ -0,0 +1,58 @@ +import { CompositeField } from './CompositeField'; +import { BaseModel } from './BaseModel'; +import { FormGroup } from '@angular/forms'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { Validation } from './Validation'; +import { Rule } from './Rule'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { Serializable } from './interfaces/Serializable'; +import { Field } from './Field'; + +export class FieldGroup extends BaseModel implements Serializable, FormGenerator{ + public id: string; + public title: string; + public section: string; + public value: string; + public description: string; + public extendedDescription: string; + public defaultVisibility: boolean; + public page: number; + public ordinal: number; + public compositeFields: Array = new Array(); + + fromJSONObject(item: any): FieldGroup { + this.id = item.id; + this.title = item.title; + this.value = item.value; + this.description = item.description; + this.extendedDescription = item.extendedDescription; + this.defaultVisibility = item.defaultVisibility; + this.page = item.page; + this.ordinal = item.ordinal; + this.compositeFields = new JsonSerializer().fromJSONArray(item.compositeFields, CompositeField); + return this; + } + + buildForm(): FormGroup { + let formGroup: FormGroup = this.formBuilder.group({ + id: [this.id], + title: [this.title], + value: [this.value], + description: [this.description], + extendedDescription: [this.extendedDescription], + defaultVisibility: [this.defaultVisibility], + page: [this.page], + ordinal: [this.ordinal] + }); + let compositeFieldsFormArray = new Array(); + if (this.compositeFields) { + this.compositeFields.forEach(item => { + let form: FormGroup = item.buildForm(); + compositeFieldsFormArray.push(form) + }) + } + formGroup.addControl('compositeFields', this.formBuilder.array(compositeFieldsFormArray)); + + return formGroup; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/Rule.ts b/dmp-admin/src/app/models/Rule.ts new file mode 100644 index 000000000..d54d39098 --- /dev/null +++ b/dmp-admin/src/app/models/Rule.ts @@ -0,0 +1,29 @@ +import { BaseModel } from './BaseModel'; +import { FormGroup } from '@angular/forms'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { Serializable } from './interfaces/Serializable'; +export class Rule extends BaseModel implements Serializable,FormGenerator{ + public sourceField:string; + public targetField:string; + public requiredValue; + public type: string; + + fromJSONObject(item:any):Rule{ + this.sourceField = item.sourceField; + this.targetField = item.targetField; + this.requiredValue = item.requiredValue; + this.type = item.type; + return this; + } + + buildForm():FormGroup{ + let formGroup = this.formBuilder.group({ + sourceField: [this.sourceField], + targetField: [this.targetField], + requiredValue: [this.requiredValue], + type: [this.type] + + }); + return formGroup; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/Section.ts b/dmp-admin/src/app/models/Section.ts new file mode 100644 index 000000000..789e9f63d --- /dev/null +++ b/dmp-admin/src/app/models/Section.ts @@ -0,0 +1,55 @@ +import { BaseModel } from './BaseModel'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; +import { JsonSerializer } from '../utilities/JsonSerializer'; +import { Serializable } from './interfaces/Serializable'; +import { FieldGroup } from './FieldGroup'; +export class Section extends BaseModel implements Serializable
, FormGenerator{ + public sections: Array
= new Array
(); + public fieldGroups: Array = new Array(); + public defaultVisibility: boolean; + public page: number; + public id: string + public title: string + public description: string; + public ordinal: number; + + fromJSONObject(item: any): Section { + this.sections = new JsonSerializer
().fromJSONArray(item.sections, Section); + this.fieldGroups = new JsonSerializer().fromJSONArray(item.fieldGroups, FieldGroup); + this.page = item.page; + this.defaultVisibility = item.defaultVisibility; + this.id = item.id; + this.title = item.title; + this.description = item.description; + this.ordinal = item.ordinal; + return this; + } + + buildForm(): FormGroup { + let formGroup: FormGroup = new FormBuilder().group({}); + let sectionsFormArray = new Array(); + if (this.sections) { + this.sections.forEach(item => { + let form: FormGroup = item.buildForm(); + sectionsFormArray.push(form) + }) + } + let fieldGroupsFormArray = new Array(); + if (this.fieldGroups) { + this.fieldGroups.forEach(item => { + let form: FormGroup = item.buildForm(); + fieldGroupsFormArray.push(form) + }) + } + formGroup.addControl('sections', this.formBuilder.array(sectionsFormArray)); + formGroup.addControl('fieldGroups', this.formBuilder.array(fieldGroupsFormArray)); + formGroup.addControl('defaultVisibility', new FormControl(this.defaultVisibility)); + formGroup.addControl('page', new FormControl(this.page)); + formGroup.addControl('id', new FormControl(this.id)); + formGroup.addControl('title', new FormControl(this.title)); + formGroup.addControl('description', new FormControl(this.description)); + formGroup.addControl('ordinal', new FormControl(this.ordinal)); + return formGroup; + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/Validation.ts b/dmp-admin/src/app/models/Validation.ts new file mode 100644 index 000000000..fc0ec9367 --- /dev/null +++ b/dmp-admin/src/app/models/Validation.ts @@ -0,0 +1,21 @@ +import { BaseModel } from './BaseModel'; +import { FormGroup } from '@angular/forms'; +import { FormGenerator } from './interfaces/FormGenerator'; +import { Serializable } from './interfaces/Serializable'; +export class Validation extends BaseModel implements Serializable,FormGenerator{ + public type:string; + public value:string; + + fromJSONObject(item:any):Validation{ + this.type = item.type; + this.value = item.value; + return this; + } + + buildForm():FormGroup{ + return this.formBuilder.group({ + type: [this.type], + value: [this.value], + }); + } +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/interfaces/FormGenerator.ts b/dmp-admin/src/app/models/interfaces/FormGenerator.ts new file mode 100644 index 000000000..05cc5c8ff --- /dev/null +++ b/dmp-admin/src/app/models/interfaces/FormGenerator.ts @@ -0,0 +1,4 @@ +import { AbstractControl } from '@angular/forms'; +export interface FormGenerator{ + buildForm():T +} \ No newline at end of file diff --git a/dmp-admin/src/app/models/interfaces/Serializable.ts b/dmp-admin/src/app/models/interfaces/Serializable.ts new file mode 100644 index 000000000..26bc7c1bc --- /dev/null +++ b/dmp-admin/src/app/models/interfaces/Serializable.ts @@ -0,0 +1,3 @@ +export interface Serializable { + fromJSONObject(item: Object): T; +} \ No newline at end of file diff --git a/dmp-admin/src/app/rule-component/rule.component.html b/dmp-admin/src/app/rule-component/rule.component.html new file mode 100644 index 000000000..22aac2be5 --- /dev/null +++ b/dmp-admin/src/app/rule-component/rule.component.html @@ -0,0 +1,34 @@ +
+

Rules

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
\ No newline at end of file diff --git a/dmp-admin/src/app/rule-component/rule.component.ts b/dmp-admin/src/app/rule-component/rule.component.ts new file mode 100644 index 000000000..57ae4ee8f --- /dev/null +++ b/dmp-admin/src/app/rule-component/rule.component.ts @@ -0,0 +1,15 @@ +import { Component, Input } from '@angular/core'; +import { FormGroup } from '@angular/forms' +import { Rule } from '../models/Rule' + +@Component({ + selector: 'rule-form', + templateUrl: './rule.component.html', + styleUrls: [] +}) + +export class RuleFormComponent { +@Input() form: FormGroup; +@Input() dataModel: FormGroup; + +} \ No newline at end of file diff --git a/dmp-admin/src/app/section-form/section-form.component.html b/dmp-admin/src/app/section-form/section-form.component.html new file mode 100644 index 000000000..5aa4df0c2 --- /dev/null +++ b/dmp-admin/src/app/section-form/section-form.component.html @@ -0,0 +1,27 @@ +
+

Section

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
\ No newline at end of file diff --git a/dmp-admin/src/app/section-form/section-form.component.ts b/dmp-admin/src/app/section-form/section-form.component.ts new file mode 100644 index 000000000..eb610bc2a --- /dev/null +++ b/dmp-admin/src/app/section-form/section-form.component.ts @@ -0,0 +1,30 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup } from '@angular/forms'; +import { Section } from '../models/Section'; +import { FieldGroup } from '../models/FieldGroup'; +import { FormArray } from '@angular/forms/src/model'; + + + +@Component({ + selector: 'section-form', + templateUrl: './section-form.component.html', + styleUrls: [] +}) + +export class SectionFormComponent { + @Input() form: FormGroup; + @Input() dataModel:Section; + constructor(){ } + + ngOnInit(){ + this.addGroupField(); + } + + addGroupField(){ + let fieldGroup:FieldGroup = new FieldGroup(); + this.dataModel.fieldGroups.push(fieldGroup); + (this.form.get("fieldGroups")).push(fieldGroup.buildForm()); + } + +} \ No newline at end of file diff --git a/dmp-admin/src/app/testModel/testModel.ts b/dmp-admin/src/app/testModel/testModel.ts new file mode 100644 index 000000000..9f520ca77 --- /dev/null +++ b/dmp-admin/src/app/testModel/testModel.ts @@ -0,0 +1,251 @@ +export const TestModel = { + "sections": [ + { + "id": "sumData", + "defaultVisibility": "true", + "page": "1", + "title": "1 Data Summary", + "description": " Fill in the fields to describe your data model ", + "sections": [], + "fieldGroups": + [ + { + "id": "dataSummaryGroup", + "defaultVisibility": "true", + "page": "1", + "title": "Data Summary", + "description": "", + "extendedDescription": "", + "compositeFields": [ + { + "fields": + [ + { + "id": "dataSummary", + "defaultVisibility": "true", + "title": "", + "description": "", + "extendedDescription": "", + "viewStyle": "checkBox" + } + ] + } + ] + } + ] + }, + { + "id": "fairData", + "ordinal": "2", + "defaultVisibility": "true", + "page": "1", + "title": "2 Fair Data", + "sections": [ + { + "id": "dataMetadata", + "defaultVisibility": "true", + "page": "1", + "title": "2.1 Making data findable, including provisions for metadata", + "sections": [], + "fieldGroups": [ + { + "id": "FindDataMetadataGroup", + "section": "dataMetadata", + "defaultVisibility": "true", + "page": "1", + "title": "Making data findable, including provisions for metadata", + "description": "Making data findable, including provisions for metadata", + "extendedDescription": "FieldGroup Description", + "compositeFields": [ + { + "fields": + [ + { + "id": "useMetadataQ211", + "defaultVisibility": "true", + "title": "Q2.1.1 Will you use metadata to describe the data?", + "description": "User can select from a list of metadata standards. If they cannot find the standard in the list provided then they should choose \"not listed\". Selecting this will result in a field in which the user can insert the URL to the description of the metadata scheme used. A \"comments\" box should exist to allow users to add comments. They may select more than one metadata standard. They may specify more than one URL when selecting \"not listed\". They are also presented with a field in which to specify the location of the metadata service. Users can select the \"no metadata\" button to specify no metadata will be used to describe the data.", + "extendedDescription": "FieldGroup Description", + "viewStyle": "booleanDesicion" + } + ] + }, + { + "fields": + [ + { + "id": "metadataStandarsA211", + "defaultVisibility": "false", + "title": "Metadata standards", + "description": "The data will be described by metadata that follows the metadata standards described in , , ? The data will be described by metadata that follows the metadata schema described in , . The metadata will be stored in the service located at ", + "extendedDescription": "", + "viewStyle": "combobox" + }] + }, + { + "fields": + [ + { + "id": "notlistedA211", + "defaultVisibility": "false", + "title": "Not listed", + "description": "", + "extendedDescription": "", + "viewStyle": "checkBox" + }] + }, + { + "fields": + [ + { + "id": "notlistedUrlA211", + "defaultVisibility": "false", + "title": "Url", + "description": "URL to the description of the metadata scheme used", + "extendedDescription": "", + "viewStyle": "freetext" + }] + }, + { + "fields": + [ + { + "id": "notlistedCommentA211", + "defaultVisibility": "false", + "title": "Comments", + "description": "", + "extendedDescription": "", + "viewStyle": "freetext" + }] + }, + { + "fields": + [ + { + "id": "noMetadata", + "defaultVisibility": "false", + "title": "The data will not be described by any metadata.", + "description": "", + "extendedDescription": "", + "viewStyle": "checkBox" + } + ] + } + ] + }, + { + "id": "VocabulariesGroup", + "defaultVisibility": "true", + "page": "1", + "title": "Vocabularies", + "description": "Vocabularies", + "extendedDescription": "FieldGroup Description", + "compositeFields": [ + { + "fields": [ + { + "id": "useVocabulariesQ212", + "defaultVisibility": "true", + "title": "Q2.1.2 Will your metadata use standardised vocabularies?", + "description": "User selects from a drop-down list of existing standardised vocabularies or \"not listed\" or \"none\". There should be a \"comments\" fields for additional information. If \"not listed\" is selected the user is presented with two additional fields in which the user can put the URL to the new vocabulary along with a short description. The user should be allowed to select more than one option.", + "extendedDescription": "FieldGroup Description", + "viewStyle": "booleanDesicion" + }] + }, + { + "fields": [ + { + "id": "standardisedVocabulariesA212", + "defaultVisibility": "false", + "title": "Existing standardised vocabularies", + "description": "The metadata will make use of the standardised vocabulary ", + "extendedDescription": "", + "viewStyle": "combobox" + }] + }, + { + "fields": [ + { + "id": "notlistedVocabularyA212", + "defaultVisibility": "false", + "title": "Not listed vocabulary", + "description": "", + "extendedDescription": "", + "viewStyle": "checkBox" + }] + }, + { + "fields": [ + { + "id": "notlistedVocUrlA212", + "defaultVisibility": "false", + "title": "Vocabulary Url", + "description": "The user can put the URL to the new vocabulary", + "extendedDescription": "", + "viewStyle": "freetext" + }] + }, + { + "fields": [ + { + "id": "notlistedVocCommentA212", + "defaultVisibility": "false", + "title": "Comments", + "description": "Vocabulary short description", + "extendedDescription": "", + "viewStyle": "freetext" + }] + }, + { + "fields": [ + { + "id": "noMetadataVocabularyA212", + "defaultVisibility": "false", + "title": "The metadata will not make use of any vocabulary", + "description": "", + "extendedDescription": "", + "viewStyle": "checkBox" + } + ] + } + ] + }, + { + "id": "FreeOfChargeGroup", + "defaultVisibility": "true", + "page": "1", + "title": "Metadata Available", + "description": "Metadata Available", + "extendedDescription": "FieldGroup Description", + "compositeFields": [ + { + "fields": [ + { + "id": "freeOfChargeGroupQ213", + "defaultVisibility": "true", + "title": "Q2.1.3 Will you use standardised formats for some or all of your data.", + "description": "User is presented with a choice of ?yes?, ?no?. There should be a ?comments? field for additional information.", + "extendedDescription": "Field Description", + "viewStyle": "booleanDesicion" + }] + }, + { + "fields": [ + { + "id": "freeOfChargeGroupCommentA213", + "defaultVisibility": "true", + "title": "Comments", + "description": "", + "extendedDescription": "", + "viewStyle": "freetext" + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/dmp-admin/src/app/utilities/JsonSerializer.ts b/dmp-admin/src/app/utilities/JsonSerializer.ts new file mode 100644 index 000000000..4222500ef --- /dev/null +++ b/dmp-admin/src/app/utilities/JsonSerializer.ts @@ -0,0 +1,17 @@ +import { Serializable } from '../models/interfaces/Serializable'; +export class JsonSerializer>{ + + public fromJSONArray(items: any[], type: { new(): T; }): T[] { + if(!items)return null; + const objectList: T[] = new Array(); + for (let i = 0; i < items.length; i++) { + objectList.push(new type().fromJSONObject(items[i])) + } + return objectList; + } + + public fromJSONObject(item: any, type: { new(): T; }): T { + if(!item)return null; + return new type().fromJSONObject(item); + } +} \ No newline at end of file