drop down list from servicve

This commit is contained in:
annampak 2017-10-18 23:36:33 +03:00
parent 54a1796725
commit e4f302fd62
2 changed files with 248 additions and 204 deletions

View File

@ -14,6 +14,7 @@ export class FieldBase<T>{
description:string;
attributes: Attribute;
regex:string;
url: any;
constructor(options: {
value?: T,
@ -27,7 +28,8 @@ export class FieldBase<T>{
group?: string
description?: string,
attributes?: Attribute,
regex?:string
regex?:string,
url?: any
} = {}) {
this.value = options.value;
this.key = options.key || '';
@ -41,5 +43,6 @@ export class FieldBase<T>{
this.description = options.description || '';
this.attributes = options.attributes || new Attribute();
this.regex = options.regex || '';
this.url = options.url || {"url":null, "fieldpath":null, "data":null};
}
}

View File

@ -5,21 +5,24 @@ import { TextboxField } from '../../app/form/fields/textbox/field-textbox';
import { CheckBoxField } from '../../app/form/fields/checkbox/field-checkbox';
import { RadioBoxField } from '../../app/form/fields/radiobox/field-radiobox';
import { DataModel } from '../entities/DataModel';
import {Rule} from '../entities/common/rule';
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';
import { Section } from '../entities/model/section';
import { RestBase } from '../services/rest-base';
@Injectable()
export class dataModelBuilder {
private dataModel : DataModel;
private fields : FieldBase<any>[];
private dataModel: DataModel;
private fields: FieldBase<any>[];
public getDataModel(data){
constructor(private restBase: RestBase) { }
if(this.dataModel != null)
public getDataModel(data) {
if (this.dataModel != null)
return this.dataModel;
this.dataModel = new DataModel();
@ -27,75 +30,75 @@ export class dataModelBuilder {
this.dataModel.groups = this.getGroups(data.dataset.profile.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields);
this.dataModel.semanticAttr = new Array(new Attribute);
//this.dataModel.semanticAttr = data.dataset.profile.definition.root.fields.field;
this.dataModel.semanticAttr = this.getFieldsAttributes(data.dataset.profile.definition.root.fields.field, data.dataset.profile.ruleset.definition.root.functions.function, this.fields) ;
this.dataModel.sections = this.getSections(data.dataset.profile.viewstyle.definition.root.sections.section, this.dataModel.groups) ;
this.dataModel.semanticAttr = this.getFieldsAttributes(data.dataset.profile.definition.root.fields.field, data.dataset.profile.ruleset.definition.root.functions.function, this.fields);
this.dataModel.sections = this.getSections(data.dataset.profile.viewstyle.definition.root.sections.section, this.dataModel.groups);
this.dataModel.buildIndex();
return this.dataModel;
}
private buildFields(fields:any[]) {
let fieldsVisible :FieldBase<any>[] =[];
private buildFields(fields: any[]) {
let fieldsVisible: FieldBase<any>[] = [];
fields.forEach(element => {
if (element.viewStyle._renderstyle == "freetext"){
let newfield:FieldBase <any>;
if (element.viewStyle._renderstyle == "freetext") {
let newfield: FieldBase<any>;
let rule = new Rule();
newfield = new TextboxField({
label: element.title.__cdata,
key:element._id,
key: element._id,
value: element.value,
order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule,
order: element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule : rule,
visible: element._defaultVisibility,
group : element._group,
group: element._group,
description: element.description.__cdata
});
fieldsVisible.push(newfield);
}
else if (element.viewStyle._renderstyle == "dropdown" ||element.viewStyle._renderstyle == "combobox"){//to choose one of these in xml
let newfield:DropdownField;
else if (element.viewStyle._renderstyle == "dropdown" || element.viewStyle._renderstyle == "combobox") {//to choose one of these in xml
let newfield: DropdownField;
let rule = new Rule();
newfield = new DropdownField({
label: element.title.__cdata,
key:element._id,
key: element._id,
value: element.value,
order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule,
order: element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule : rule,
visible: element._defaultVisibility,
description: element.description.__cdata,
group : element._group
group: element._group
});
fieldsVisible.push(newfield);
}
else if (element.viewStyle._renderstyle == "checkbox"||element.viewStyle._renderstyle == "checkBox"){
let newfield:CheckBoxField;
else if (element.viewStyle._renderstyle == "checkbox" || element.viewStyle._renderstyle == "checkBox") {
let newfield: CheckBoxField;
let rule = new Array<Rule>();
newfield = new CheckBoxField({
label: element.title.__cdata,
key:element._id,
key: element._id,
value: element.value,
order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule,
order: element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule : rule,
visible: element._defaultVisibility,
group : element._group,
group: element._group,
description: element.description.__cdata,
type: "checkbox"
});
fieldsVisible.push(newfield);
}
else if (element.viewStyle._renderstyle == "booleanDesicion"){
let newfield:RadioBoxField;
else if (element.viewStyle._renderstyle == "booleanDesicion") {
let newfield: RadioBoxField;
let rule = new Array<Rule>();
newfield = new RadioBoxField({
label: element.title.__cdata,
key:element._id,
key: element._id,
value: element.value,
order:element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule: rule,
order: element._ordinal,
rules: element.visible.rule != undefined ? element.visible.rule : rule,
visible: element._defaultVisibility,
group : element._group,
group: element._group,
type: "radio",
description: element.description.__cdata,
answers: [
@ -107,7 +110,7 @@ export class dataModelBuilder {
{
id: 2,
answer: "No",
value:false
value: false
}]
});
fieldsVisible.push(newfield);
@ -117,17 +120,17 @@ export class dataModelBuilder {
return fieldsVisible;
}
private getGroups(fieldGroups:any, fields:any[]){
let groups :GroupBase<any>[] =[];
private getGroups(fieldGroups: any, fields: any[]) {
let groups: GroupBase<any>[] = [];
if(fieldGroups.length>1){
fieldGroups.forEach(fieldGroup =>{ // each fiedgroup fills with its fields from json
if (fieldGroups.length > 1) {
fieldGroups.forEach(fieldGroup => { // each fiedgroup fills with its fields from json
let newfldGroup = new GroupBase();
newfldGroup.groupFields = new Array();
fields.forEach(field => {
if(fieldGroup._id == field.group){
if (fieldGroup._id == field.group) {
newfldGroup.groupFields.push(field);
}else{
} else {
//this.dataModel.fields.push(field);
}
@ -141,13 +144,13 @@ export class dataModelBuilder {
});
}
else{
else {
let newfldGroup = new GroupBase();
newfldGroup.groupFields = new Array();
fields.forEach(field => { //for one fieldgroup, because xml to json transformation doesn't create array of one fieldfroup
if(fieldGroups._id == field.group){
if (fieldGroups._id == field.group) {
newfldGroup.groupFields.push(field);
}else
} else
this.dataModel.fields.push(field);
});
newfldGroup.title = fieldGroups.title.__cdata;
@ -159,9 +162,9 @@ export class dataModelBuilder {
}
private getDummyGroups(){
private getDummyGroups() {
let groups :GroupBase<any>[] =[];
let groups: GroupBase<any>[] = [];
let group: GroupBase<any>;
@ -178,23 +181,23 @@ export class dataModelBuilder {
});
let newfield1:FieldBase <any>;
let newfield1: FieldBase<any>;
newfield1 = new TextboxField({
key:"tf1-455",
key: "tf1-455",
label: "Field from group1",
value: 'this is a groupfield',
required: true,
ordinal:1
ordinal: 1
});
group.groupFields.push(newfield1);
let newfield2:FieldBase <any>;
let newfield2: FieldBase<any>;
newfield2 = new TextboxField({
key:"tf1-443",
key: "tf1-443",
label: "Another field from group1",
value: 'this is a groupfield',
required: true,
ordinal:2
ordinal: 2
});
group.groupFields.push(newfield2);
@ -205,8 +208,8 @@ export class dataModelBuilder {
}
private getFieldsAttributes(attributes:any, functions:any, fields:any[]){
let attribute:Attribute[]=[];
private getFieldsAttributes(attributes: any, functions: any, fields: any[]) {
let attribute: Attribute[] = [];
attributes.forEach(attr => {
let newAttribute = new Attribute();
newAttribute.datatype = attr._datatype;
@ -219,32 +222,62 @@ export class dataModelBuilder {
newAttribute.validation = new Array();
//newAttribute.validation.push(attr.validation.rule);
if(attr.sources){
if (attr.sources) {
newAttribute.sources.push(attr.sources.source);
if (attr.sources.source.url !== undefined) {
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source.url._value;
this.restBase.proxy_get(attr.sources.source.url._value).subscribe((data) => {
console.log(data);
newAttribute.sources.forEach(src => {
src.params=new Array();
for (var i=0, len=attr.sources.source.value.length; i<len; i++){
src.params = new Array();
data.data.forEach(data => {
let prm = new Param();
prm.key= attr.sources.source.value[i]._value;
prm.value= attr.sources.source.value[i]._label;
prm.key = data.id;
prm.value = data.attributes.name;
src.params.push(prm);
});
});
});
} else {
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);
}
});
}
}
if (attr.validation.rule.length)
for (var i=0, len=attr.validation.rule.length; i<len; i++){
for (var i = 0, len = attr.validation.rule.length; i < len; i++) {
let rule = new Rule();
rule.ruleStyle= attr.validation.rule[i]._ruleStyle;
rule.ruleType= attr.validation.rule[i]._type;
rule.ruleStyle = attr.validation.rule[i]._ruleStyle;
rule.ruleType = attr.validation.rule[i]._type;
if (attr.validation.rule[i]._ruleStyle == "regex")
rule.regex= attr.validation.rule[i].__cdata;
if (attr.validation.rule[i]._ruleStyle == "customValidation"){
rule.method= attr.validation.rule[i]._method;
rule.regex = attr.validation.rule[i].__cdata;
if (attr.validation.rule[i]._ruleStyle == "customValidation") {
rule.method = attr.validation.rule[i]._method;
functions.forEach(fnc => {
if(fnc._id == rule.method)
if (fnc._id == rule.method)
rule.methodJs = fnc.script.__cdata;
});
}
@ -252,17 +285,17 @@ export class dataModelBuilder {
newAttribute.validation.push(rule);
}
else{
if(attr.validation.rule){
else {
if (attr.validation.rule) {
let rule = new Rule();
rule.ruleStyle= attr.validation.rule._ruleStyle;
rule.ruleType= attr.validation.rule._type;
rule.ruleStyle = attr.validation.rule._ruleStyle;
rule.ruleType = attr.validation.rule._type;
if (attr.validation.rule._ruleStyle == "regex")
rule.regex= attr.validation.rule.__cdata;
if (attr.validation.rule._ruleStyle == "customValidation"){
rule.method= attr.validation.rule._method;
rule.regex = attr.validation.rule.__cdata;
if (attr.validation.rule._ruleStyle == "customValidation") {
rule.method = attr.validation.rule._method;
functions.forEach(fnc => {
if(fnc._id == rule.method)
if (fnc._id == rule.method)
rule.methodJs = fnc.__cdata;
});
@ -273,6 +306,7 @@ export class dataModelBuilder {
}
attribute.push(newAttribute);
//if (fields.find(x => x.key == newAttribute.id).url.url == null)
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
});
@ -281,10 +315,10 @@ export class dataModelBuilder {
return attribute;
}
private getSections(sections:any, fieldGroups:GroupBase<any>[]){
let sects: Section[]= [];
private getSections(sections: any, fieldGroups: GroupBase<any>[]) {
let sects: Section[] = [];
if(sections.length){
if (sections.length) {
sections.forEach(section => {
let newSection = new Section();
newSection.defaultVisibility = section.defaultVisibility;
@ -294,7 +328,7 @@ export class dataModelBuilder {
newSection.ordinal = section._ordinal;
newSection.groupFields = new Array();
fieldGroups.forEach(fldgroup => {
if(fldgroup.section == newSection.id)
if (fldgroup.section == newSection.id)
newSection.groupFields.push(fldgroup);
})
sects.push(newSection);
@ -304,4 +338,11 @@ export class dataModelBuilder {
return sects;
}
getValuesFromEestore(url: string, fieldPath: string) {
this.restBase.proxy_get(url).subscribe((data) => {
data.data.forEach(data => {
console.log(data);
});
});
}
}