From 9a545bcf249cbdc49021ad4c125d98ab47653a3c Mon Sep 17 00:00:00 2001 From: annampak Date: Fri, 22 Sep 2017 14:38:53 +0300 Subject: [PATCH] dropdown lists connected with sources --- dmp-frontend/src/app/entities/DataModel.ts | 16 ---------------- dmp-frontend/src/app/entities/model/param.ts | 6 +++++- .../form/fields/dynamic-form-field.component.ts | 15 +++++++++++++-- dmp-frontend/src/app/form/fields/field-base.ts | 5 +++++ .../app/services/dataModelBuilder.service.ts | 17 +++++++++++++++-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/dmp-frontend/src/app/entities/DataModel.ts b/dmp-frontend/src/app/entities/DataModel.ts index dd4da1c93..f6e823937 100644 --- a/dmp-frontend/src/app/entities/DataModel.ts +++ b/dmp-frontend/src/app/entities/DataModel.ts @@ -19,14 +19,10 @@ export class DataModel { } - - - public buildIndex(){ this.fIndex = new Map>(); - this.fIndSources = new Map(); this.fields.forEach((field) => { console.log("fieldid:" +field.key); @@ -40,24 +36,12 @@ export class DataModel { }); }); - this.semanticAttr.forEach((attr) => { - attr.sources.forEach(src => { - this.fIndSources.set(attr.id, src); - console.log("fieldid: "+attr.id + "attr:" +src); - }); - - }); - } public getFieldByKey(key){ return this.fIndex.get(key); } - public getFieldSourceByKey(key){ - return this.fIndSources.get(key); - } - diff --git a/dmp-frontend/src/app/entities/model/param.ts b/dmp-frontend/src/app/entities/model/param.ts index fdabf4446..7ebecb455 100644 --- a/dmp-frontend/src/app/entities/model/param.ts +++ b/dmp-frontend/src/app/entities/model/param.ts @@ -2,6 +2,10 @@ import { Injectable } from '@angular/core'; @Injectable() export class Param { - id: string; + key: string; value: string; + + constructor(){ + + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts index dd2dce4ba..196ff589e 100644 --- a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts +++ b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts @@ -1,9 +1,10 @@ import { DataModel } from '../../entities/DataModel'; -import { Component, Input } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { FieldBase } from './field-base'; import { GroupBase } from '../../form/dynamic-form-group/group-base'; +import { DropdownField } from '../../form/fields/dropdown/field-dropdown'; @Component({ @@ -20,7 +21,17 @@ export class DynamicFormFieldComponent { return true; //return this.form.controls[this.field.key].valid; } - + public ngOnInit() { //dropdown lists take only one of the available sources + for (var i=0, len = this.dataModel.groups.length; ix.controlType == "dropdown"); + if(dropdownField != undefined){ + if(dropdownField.attributes.sources != undefined) + dropdownField.options = dropdownField.attributes.sources[0].params; + } + + } + } ruleVisibleMethod(field, rule, dataModel){ //visibility rule -- checks if target field is visible dataModel.fields.forEach(fld => { diff --git a/dmp-frontend/src/app/form/fields/field-base.ts b/dmp-frontend/src/app/form/fields/field-base.ts index bdead23b9..da2c6f79b 100644 --- a/dmp-frontend/src/app/form/fields/field-base.ts +++ b/dmp-frontend/src/app/form/fields/field-base.ts @@ -1,4 +1,6 @@ import { Rule } from '../../entities/common/rule'; +import { Attribute } from '../../entities/model/attribute'; + export class FieldBase{ value: T; key: string; @@ -10,6 +12,7 @@ export class FieldBase{ controlType:string; group:string; description:string; + attributes: Attribute; constructor(options: { value?: T, @@ -22,6 +25,7 @@ export class FieldBase{ controlType?: string group?: string description?: string, + attributes?: Attribute } = {}) { this.value = options.value; this.key = options.key || ''; @@ -33,5 +37,6 @@ export class FieldBase{ this.controlType = options.controlType || ''; this.group = options.group || ''; this.description = options.description || ''; + this.attributes = options.attributes || new Attribute(); } } \ No newline at end of file diff --git a/dmp-frontend/src/app/services/dataModelBuilder.service.ts b/dmp-frontend/src/app/services/dataModelBuilder.service.ts index de78b37e9..643cd89b3 100644 --- a/dmp-frontend/src/app/services/dataModelBuilder.service.ts +++ b/dmp-frontend/src/app/services/dataModelBuilder.service.ts @@ -8,6 +8,7 @@ import { DataModel } from '../entities/DataModel'; import {Rule} from '../entities/common/rule'; import { GroupBase } from '../form/dynamic-form-group/group-base'; import { Attribute } from '../entities/model/attribute'; +import { Param } from '../entities/model/param'; @Injectable() export class dataModelBuilder { @@ -213,11 +214,23 @@ export class dataModelBuilder { newAttribute.multiplicityMin = attr.multiplicity._min; newAttribute.ordinal = attr._ordinal; newAttribute.sources = new Array(); - newAttribute.sources.push(attr.sources.source) + newAttribute.sources.push(attr.sources.source); + + newAttribute.sources.forEach(src => { + src.params=new Array(); + for (var i=0, len=attr.sources.source.value.length; i x.key == newAttribute.id).attributes.sources = newAttribute.sources; });