dropdown lists connected with sources
This commit is contained in:
parent
2e3b3cb1ad
commit
9a545bcf24
|
@ -19,14 +19,10 @@ export class DataModel {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public buildIndex(){
|
||||
|
||||
|
||||
this.fIndex = new Map<string, FieldBase<any>>();
|
||||
this.fIndSources = new Map<string, Source>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
@Injectable()
|
||||
export class Param {
|
||||
id: string;
|
||||
key: string;
|
||||
value: string;
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
}
|
|
@ -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; i<len; i++){
|
||||
let dropdownField:any;
|
||||
dropdownField = this.dataModel.groups[i].groupFields.find(x=>x.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 => {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { Rule } from '../../entities/common/rule';
|
||||
import { Attribute } from '../../entities/model/attribute';
|
||||
|
||||
export class FieldBase<T>{
|
||||
value: T;
|
||||
key: string;
|
||||
|
@ -10,6 +12,7 @@ export class FieldBase<T>{
|
|||
controlType:string;
|
||||
group:string;
|
||||
description:string;
|
||||
attributes: Attribute;
|
||||
|
||||
constructor(options: {
|
||||
value?: T,
|
||||
|
@ -22,6 +25,7 @@ export class FieldBase<T>{
|
|||
controlType?: string
|
||||
group?: string
|
||||
description?: string,
|
||||
attributes?: Attribute
|
||||
} = {}) {
|
||||
this.value = options.value;
|
||||
this.key = options.key || '';
|
||||
|
@ -33,5 +37,6 @@ export class FieldBase<T>{
|
|||
this.controlType = options.controlType || '';
|
||||
this.group = options.group || '';
|
||||
this.description = options.description || '';
|
||||
this.attributes = options.attributes || new Attribute();
|
||||
}
|
||||
}
|
|
@ -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<len; i++){
|
||||
let prm = new Param();
|
||||
prm.key= attr.sources.source.value[i]._value;
|
||||
prm.value= attr.sources.source.value[i]._label;
|
||||
src.params.push(prm);
|
||||
}
|
||||
|
||||
});
|
||||
newAttribute.validation = attr.validation;
|
||||
|
||||
|
||||
console.log(newAttribute);
|
||||
attribute.push(newAttribute);
|
||||
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue