composite fields
This commit is contained in:
parent
6084125de0
commit
84f8d3de90
|
@ -1,9 +1,23 @@
|
||||||
<div [formGroup]="form" [ngStyle] = "customStyle" [class]="classFromJson" >
|
<div [formGroup]="form" [ngStyle] = "customStyle" [class]="classFromJson" >
|
||||||
<h4 [id]= "group.key">{{group.title}}</h4>
|
<h4 [id]= "group.key">{{group.title}}</h4>
|
||||||
<div *ngFor="let field of group.groupFields" >
|
<div *ngFor="let field of group.groupFields" >
|
||||||
|
<div *ngIf ="group.compositeFields == undefined">
|
||||||
<df-field [field]="field" [form]="form" [dataModel] = "dataModel"></df-field>
|
<df-field [field]="field" [form]="form" [dataModel] = "dataModel"></df-field>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngFor="let field of group.groupFields" > <!--edw akoma den exei oloklirwthei!! -->
|
||||||
|
<div *ngIf ="group.compositeFields != undefined">
|
||||||
|
<div *ngFor="let field of group.compositeFields.groupFields" >
|
||||||
|
<df-field [field]="field" [form]="form" [dataModel] = "dataModel"></df-field>
|
||||||
|
</div>
|
||||||
|
<a (click)="addFieldSet()" style="cursor: default">
|
||||||
|
Add another fieldSet +
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- class = "form-group" [class]="customStyle" [ngStyle] = "customStyle"-->
|
<!-- class = "form-group" [class]="customStyle" [ngStyle] = "customStyle"-->
|
|
@ -13,6 +13,7 @@ export class GroupBase<T>{
|
||||||
style:string;
|
style:string;
|
||||||
class: string;
|
class: string;
|
||||||
page: number;
|
page: number;
|
||||||
|
compositeFields: GroupBase<T>;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
value?: T,
|
value?: T,
|
||||||
|
@ -26,7 +27,8 @@ export class GroupBase<T>{
|
||||||
section?: string,
|
section?: string,
|
||||||
style?:string
|
style?:string
|
||||||
class?:string,
|
class?:string,
|
||||||
page?:number
|
page?:number,
|
||||||
|
compositeFields?:GroupBase<T>
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.value = options.value;
|
this.value = options.value;
|
||||||
this.key = options.key || '';
|
this.key = options.key || '';
|
||||||
|
@ -40,5 +42,6 @@ export class GroupBase<T>{
|
||||||
this.style = options.style || '';
|
this.style = options.style || '';
|
||||||
this.class = options.class || '';
|
this.class = options.class || '';
|
||||||
this.page = options.page || 1;
|
this.page = options.page || 1;
|
||||||
|
this.compositeFields = options.compositeFields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ export class dataModelBuilder {
|
||||||
|
|
||||||
this.dataModel = new DataModel();
|
this.dataModel = new DataModel();
|
||||||
this.fields = this.buildFields(data.viewstyle.definition.root.fields.field);
|
this.fields = this.buildFields(data.viewstyle.definition.root.fields.field);
|
||||||
this.dataModel.groups = this.getGroups(data.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields, dataValues);
|
|
||||||
this.dataModel.semanticAttr = new Array(new Attribute);
|
this.dataModel.semanticAttr = new Array(new Attribute);
|
||||||
this.dataModel.semanticAttr = this.getFieldsAttributes(data.definition.root.fields.field, data.ruleset.definition.root.functions.function, this.fields);
|
this.dataModel.semanticAttr = this.getFieldsAttributes(data.definition.root.fields.fieldset, data.ruleset.definition.root.functions.function, this.fields);
|
||||||
|
this.dataModel.groups = this.getGroups(data.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields, dataValues);
|
||||||
this.dataModel.sections = this.getSections(data.viewstyle.definition.root.sections.section, this.dataModel.groups);
|
this.dataModel.sections = this.getSections(data.viewstyle.definition.root.sections.section, this.dataModel.groups);
|
||||||
//this.getDatatypes(data.definition.root);
|
|
||||||
this.dataModel.buildIndex();
|
this.dataModel.buildIndex();
|
||||||
|
|
||||||
this.checkDuplicateInObject('order', this.dataModel.groups[13].groupFields); //for future use , for composite field
|
this.checkDuplicateInObject('order', this.dataModel.groups[13].groupFields); //for future use , for composite field
|
||||||
|
@ -162,13 +162,19 @@ export class dataModelBuilder {
|
||||||
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();
|
||||||
|
let compositeFields = new GroupBase();
|
||||||
newfldGroup.groupFields = new Array();
|
newfldGroup.groupFields = new Array();
|
||||||
|
compositeFields.groupFields = new Array();
|
||||||
fields.forEach(field => {
|
fields.forEach(field => {
|
||||||
if (fieldGroup._id == field.group) {
|
if (fieldGroup._id == field.group) {
|
||||||
if (dataValues != "")
|
if (dataValues != "")//--------------------------SET VALUES--------------------------------------------
|
||||||
if (dataValues[fieldGroup._id][field.key] != undefined) // to put values in fields
|
if (dataValues[fieldGroup._id][field.key] != undefined) // to put values in fields
|
||||||
field.value = dataValues[fieldGroup._id][field.key].value == undefined ? dataValues[fieldGroup._id][field.key] : dataValues[fieldGroup._id][field.key].value;
|
field.value = dataValues[fieldGroup._id][field.key].value == undefined ? dataValues[fieldGroup._id][field.key] : dataValues[fieldGroup._id][field.key].value;
|
||||||
newfldGroup.groupFields.push(field);
|
if(field.order.toString().split(",").length > 1){
|
||||||
|
compositeFields.groupFields.push(field);
|
||||||
|
newfldGroup.compositeFields = compositeFields;
|
||||||
|
}else
|
||||||
|
newfldGroup.groupFields.push(field);
|
||||||
} else {
|
} else {
|
||||||
//this.dataModel.fields.push(field);
|
//this.dataModel.fields.push(field);
|
||||||
}
|
}
|
||||||
|
@ -201,78 +207,109 @@ export class dataModelBuilder {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAttributesToFields(attr, functions, fields, multiplicity){
|
||||||
|
|
||||||
private getFieldsAttributes(attributes: any, functions: any, fields: any[]) {
|
let newAttribute = new Attribute();
|
||||||
let attribute: Attribute[] = [];
|
newAttribute.datatype = attr._datatype;
|
||||||
attributes.forEach(attr => {
|
newAttribute.defaultValue = attr.defaultValue._value;
|
||||||
let newAttribute = new Attribute();
|
newAttribute.id = attr._id;
|
||||||
newAttribute.datatype = attr._datatype;
|
newAttribute.multiplicityMax = attr.multiplicity._max;
|
||||||
newAttribute.defaultValue = attr.defaultValue._value;
|
newAttribute.multiplicityMin = attr.multiplicity._min;
|
||||||
newAttribute.id = attr._id;
|
newAttribute.ordinal = attr._ordinal
|
||||||
newAttribute.multiplicityMax = attr.multiplicity._max;
|
if (multiplicity){
|
||||||
newAttribute.multiplicityMin = attr.multiplicity._min;
|
fields.find(x => x.key == newAttribute.id).order = fields.find(x => x.key == newAttribute.id).order +','+ newAttribute.ordinal;
|
||||||
newAttribute.ordinal = attr._ordinal;
|
fields.find(x => x.key == newAttribute.id).multiplicity = true;
|
||||||
newAttribute.sources = new Array();
|
}
|
||||||
newAttribute.validation = new Array();
|
newAttribute.ordinal = attr._ordinal;
|
||||||
//newAttribute.validation.push(attr.validation.rule);
|
newAttribute.sources = new Array();
|
||||||
//-----------------Sources---------------------------------------------------------------
|
newAttribute.validation = new Array();
|
||||||
if (attr.sources) {
|
//newAttribute.validation.push(attr.validation.rule);
|
||||||
newAttribute.sources.push(attr.sources.source);
|
//-----------------Sources---------------------------------------------------------------
|
||||||
if (attr.sources.source.length != undefined) {
|
if (attr.sources) {
|
||||||
for (var i = 0; i < attr.sources.source.length; i++) {
|
newAttribute.sources.push(attr.sources.source);
|
||||||
if (attr.sources.source[i]._type == "url") {
|
if (attr.sources.source.length != undefined) {
|
||||||
newAttribute.url = attr.sources.source[i].value._value;
|
for (var i = 0; i < attr.sources.source.length; i++) {
|
||||||
break;
|
if (attr.sources.source[i]._type == "url") {
|
||||||
}
|
newAttribute.url = attr.sources.source[i].value._value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attr.sources.source._type == "url") {
|
|
||||||
newAttribute.url = attr.sources.source.value._value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//-----------Rules------------------------------------------------------------------------
|
if (attr.sources.source._type == "url") {
|
||||||
if(attr.validation.rule != undefined)
|
newAttribute.url = attr.sources.source.value._value;
|
||||||
if (attr.validation.rule.length)
|
}
|
||||||
for (var i = 0, len = attr.validation.rule.length; i < len; i++) {
|
}
|
||||||
let rule = new Rule();
|
//-----------Rules------------------------------------------------------------------------
|
||||||
rule.ruleStyle = attr.validation.rule[i]._ruleStyle;
|
if(attr.validation.rule != undefined)
|
||||||
rule.ruleType = attr.validation.rule[i]._type;
|
if (attr.validation.rule.length)
|
||||||
if (attr.validation.rule[i]._ruleStyle == "regex")
|
for (var i = 0, len = attr.validation.rule.length; i < len; i++) {
|
||||||
rule.regex = attr.validation.rule[i].__cdata;
|
let rule = new Rule();
|
||||||
if (attr.validation.rule[i]._ruleStyle == "customValidation") {
|
rule.ruleStyle = attr.validation.rule[i]._ruleStyle;
|
||||||
rule.method = attr.validation.rule[i]._method;
|
rule.ruleType = attr.validation.rule[i]._type;
|
||||||
functions.forEach(fnc => {
|
if (attr.validation.rule[i]._ruleStyle == "regex")
|
||||||
if (fnc._id == rule.method)
|
rule.regex = attr.validation.rule[i].__cdata;
|
||||||
rule.methodJs = fnc.script.__cdata;
|
if (attr.validation.rule[i]._ruleStyle == "customValidation") {
|
||||||
});
|
rule.method = attr.validation.rule[i]._method;
|
||||||
}
|
functions.forEach(fnc => {
|
||||||
newAttribute.validation.push(rule);
|
if (fnc._id == rule.method)
|
||||||
|
rule.methodJs = fnc.script.__cdata;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
newAttribute.validation.push(rule);
|
||||||
if (attr.validation.rule) {
|
|
||||||
let rule = new Rule();
|
|
||||||
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;
|
|
||||||
functions.forEach(fnc => {
|
|
||||||
if (fnc._id == rule.method)
|
|
||||||
rule.methodJs = fnc.__cdata;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
newAttribute.validation.push(rule); }
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (attr.validation.rule) {
|
||||||
|
let rule = new Rule();
|
||||||
|
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;
|
||||||
|
functions.forEach(fnc => {
|
||||||
|
if (fnc._id == rule.method)
|
||||||
|
rule.methodJs = fnc.__cdata;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
newAttribute.validation.push(rule); }
|
||||||
|
}
|
||||||
|
|
||||||
attribute.push(newAttribute);
|
|
||||||
if (newAttribute.url !== undefined)
|
|
||||||
fields.find(x => x.key == newAttribute.id).url = newAttribute.url;
|
|
||||||
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
|
||||||
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
return newAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getFieldsAttributes(fieldsets: any, functions: any, fields: any[]) {
|
||||||
|
let attribute: Attribute[] = [];
|
||||||
|
let newAttribute = new Attribute();
|
||||||
|
let multiplicityParam = false;
|
||||||
|
fieldsets.forEach(fieldset => {
|
||||||
|
if (fieldset.fields.field.length){
|
||||||
|
if(fieldset.multiplicity._max >1 || fieldset.multiplicity._max == "n")
|
||||||
|
multiplicityParam = true;
|
||||||
|
fieldset.fields.field.forEach(fieldAttribute=>{
|
||||||
|
newAttribute = this.addAttributesToFields(fieldAttribute, functions, fields, multiplicityParam)
|
||||||
|
attribute.push(newAttribute);
|
||||||
|
if (newAttribute.url !== undefined)
|
||||||
|
fields.find(x => x.key == newAttribute.id).url = newAttribute.url;
|
||||||
|
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
||||||
|
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
if(fieldset.multiplicity._max >1 || fieldset.multiplicity._max == "n")
|
||||||
|
multiplicityParam = true;
|
||||||
|
newAttribute = this.addAttributesToFields(fieldset.fields.field, functions, fields, multiplicityParam)
|
||||||
|
attribute.push(newAttribute);
|
||||||
|
if (newAttribute.url !== undefined)
|
||||||
|
fields.find(x => x.key == newAttribute.id).url = newAttribute.url;
|
||||||
|
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
||||||
|
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return attribute;
|
return attribute;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSections(sections: any, fieldGroups: GroupBase<any>[]) {
|
private getSections(sections: any, fieldGroups: GroupBase<any>[]) {
|
||||||
|
@ -299,16 +336,6 @@ export class dataModelBuilder {
|
||||||
return sects;
|
return sects;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDatatypes(dataTypes){
|
|
||||||
if (dataTypes.datatypes.datatype.id == "compositeField"){
|
|
||||||
dataTypes.datatypes.datatype.fields.forEach(field => {
|
|
||||||
this.dataModel.fields.forEach(fieldinModel=>{
|
|
||||||
if (field.id == fieldinModel.key)
|
|
||||||
fieldinModel.datatype = "compositeField";
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkDuplicateInObject(propertyName, inputArray) {
|
checkDuplicateInObject(propertyName, inputArray) {
|
||||||
let DuplicateArray = [];
|
let DuplicateArray = [];
|
||||||
|
|
|
@ -15,6 +15,8 @@ export class FieldControlService {
|
||||||
|
|
||||||
groups.forEach(group => {
|
groups.forEach(group => {
|
||||||
let subgroup: any = {};
|
let subgroup: any = {};
|
||||||
|
let subgroupFieldset: any = {};
|
||||||
|
let fieldset: boolean = false;
|
||||||
group.groupFields.forEach(field => {
|
group.groupFields.forEach(field => {
|
||||||
//if(field.attributes.validation != undefined)
|
//if(field.attributes.validation != undefined)
|
||||||
// field.attributes.validation.forEach(val => {
|
// field.attributes.validation.forEach(val => {
|
||||||
|
@ -26,9 +28,25 @@ export class FieldControlService {
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
subgroup[field.key] = field.required ? new FormControl(field.value || '', Validators.required) : new FormControl(field.value || '')
|
subgroup[field.key] = field.required ? new FormControl(field.value || '', Validators.required) : new FormControl(field.value || '')
|
||||||
|
|
||||||
|
if (group.compositeFields!=undefined){
|
||||||
|
fieldset = true;
|
||||||
|
group.compositeFields.groupFields.forEach(field => {
|
||||||
|
//subgroupFieldset[field.key] = field.required ? new FormControl(field.value || '', Validators.required) : new FormControl(field.value || '')
|
||||||
|
subgroup[field.key] = field.required ? new FormControl(field.value || '', Validators.required) : new FormControl(field.value || '');
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//PLEASE CHANGE THE group.key TO BE SAME AS THE ONE ON THE DYNAMIC-FORM-GROUP-COMPONENT.html
|
//PLEASE CHANGE THE group.key TO BE SAME AS THE ONE ON THE DYNAMIC-FORM-GROUP-COMPONENT.html
|
||||||
form[group.key] = new FormGroup(subgroup);
|
if (fieldset){
|
||||||
|
//subgroup["FieldSet"+ group.key] = form[group.key] = new FormGroup(subgroupFieldset);
|
||||||
|
form[group.key] = new FormGroup(subgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
form[group.key] = new FormGroup(subgroup);
|
||||||
//console.log("FORM_GROUP_GROUP: ");
|
//console.log("FORM_GROUP_GROUP: ");
|
||||||
//console.log(form);
|
//console.log(form);
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,19 +18,19 @@ export class RestBase {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
protocol: string = "http";
|
protocol: string = "http";
|
||||||
hostname: string ="dl010.madgik.di.uoa.gr" ;//"localhost";//"dl010.madgik.di.uoa.gr";//
|
hostname: string ="dl010.madgik.di.uoa.gr" ;//"localhost";//"dl010.madgik.di.uoa.gr";//
|
||||||
port: number = 8080;//8080;//
|
port: number = 8080;//8080;//
|
||||||
webappname: string = "dmp-backend";//"dmp-backend-new";//
|
webappname: string = "dmp-backend";//"dmp-backend-new";//
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protocol: string = "http";
|
|
||||||
hostname: string = "dionysus.di.uoa.gr" ;
|
// protocol: string = "http";
|
||||||
port: number = 7070;
|
// hostname: string = "dionysus.di.uoa.gr" ;
|
||||||
webappname: string = "dmp-backend";
|
// port: number = 7070;
|
||||||
|
// webappname: string = "dmp-backend";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue