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