composite fields
This commit is contained in:
parent
6084125de0
commit
84f8d3de90
|
@ -1,9 +1,23 @@
|
|||
<div [formGroup]="form" [ngStyle] = "customStyle" [class]="classFromJson" >
|
||||
<h4 [id]= "group.key">{{group.title}}</h4>
|
||||
<div *ngFor="let field of group.groupFields" >
|
||||
<div *ngIf ="group.compositeFields == undefined">
|
||||
<df-field [field]="field" [form]="form" [dataModel] = "dataModel"></df-field>
|
||||
</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>
|
||||
<!-- class = "form-group" [class]="customStyle" [ngStyle] = "customStyle"-->
|
|
@ -13,6 +13,7 @@ export class GroupBase<T>{
|
|||
style:string;
|
||||
class: string;
|
||||
page: number;
|
||||
compositeFields: GroupBase<T>;
|
||||
|
||||
constructor(options: {
|
||||
value?: T,
|
||||
|
@ -26,7 +27,8 @@ export class GroupBase<T>{
|
|||
section?: string,
|
||||
style?:string
|
||||
class?:string,
|
||||
page?:number
|
||||
page?:number,
|
||||
compositeFields?:GroupBase<T>
|
||||
} = {}) {
|
||||
this.value = options.value;
|
||||
this.key = options.key || '';
|
||||
|
@ -40,5 +42,6 @@ export class GroupBase<T>{
|
|||
this.style = options.style || '';
|
||||
this.class = options.class || '';
|
||||
this.page = options.page || 1;
|
||||
this.compositeFields = options.compositeFields;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@ export class dataModelBuilder {
|
|||
|
||||
this.dataModel = new DataModel();
|
||||
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 = 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.getDatatypes(data.definition.root);
|
||||
this.dataModel.buildIndex();
|
||||
|
||||
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) {
|
||||
fieldGroups.forEach(fieldGroup => { // each fiedgroup fills with its fields from json
|
||||
let newfldGroup = new GroupBase();
|
||||
let compositeFields = new GroupBase();
|
||||
newfldGroup.groupFields = new Array();
|
||||
compositeFields.groupFields = new Array();
|
||||
fields.forEach(field => {
|
||||
if (fieldGroup._id == field.group) {
|
||||
if (dataValues != "")
|
||||
if (dataValues != "")//--------------------------SET VALUES--------------------------------------------
|
||||
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;
|
||||
newfldGroup.groupFields.push(field);
|
||||
if(field.order.toString().split(",").length > 1){
|
||||
compositeFields.groupFields.push(field);
|
||||
newfldGroup.compositeFields = compositeFields;
|
||||
}else
|
||||
newfldGroup.groupFields.push(field);
|
||||
} else {
|
||||
//this.dataModel.fields.push(field);
|
||||
}
|
||||
|
@ -201,78 +207,109 @@ export class dataModelBuilder {
|
|||
return groups;
|
||||
}
|
||||
|
||||
addAttributesToFields(attr, functions, fields, multiplicity){
|
||||
|
||||
private getFieldsAttributes(attributes: any, functions: any, fields: any[]) {
|
||||
let attribute: Attribute[] = [];
|
||||
attributes.forEach(attr => {
|
||||
let newAttribute = new Attribute();
|
||||
newAttribute.datatype = attr._datatype;
|
||||
newAttribute.defaultValue = attr.defaultValue._value;
|
||||
newAttribute.id = attr._id;
|
||||
newAttribute.multiplicityMax = attr.multiplicity._max;
|
||||
newAttribute.multiplicityMin = attr.multiplicity._min;
|
||||
newAttribute.ordinal = attr._ordinal;
|
||||
newAttribute.sources = new Array();
|
||||
newAttribute.validation = new Array();
|
||||
//newAttribute.validation.push(attr.validation.rule);
|
||||
//-----------------Sources---------------------------------------------------------------
|
||||
if (attr.sources) {
|
||||
newAttribute.sources.push(attr.sources.source);
|
||||
if (attr.sources.source.length != undefined) {
|
||||
for (var i = 0; i < attr.sources.source.length; i++) {
|
||||
if (attr.sources.source[i]._type == "url") {
|
||||
newAttribute.url = attr.sources.source[i].value._value;
|
||||
break;
|
||||
}
|
||||
let newAttribute = new Attribute();
|
||||
newAttribute.datatype = attr._datatype;
|
||||
newAttribute.defaultValue = attr.defaultValue._value;
|
||||
newAttribute.id = attr._id;
|
||||
newAttribute.multiplicityMax = attr.multiplicity._max;
|
||||
newAttribute.multiplicityMin = attr.multiplicity._min;
|
||||
newAttribute.ordinal = attr._ordinal
|
||||
if (multiplicity){
|
||||
fields.find(x => x.key == newAttribute.id).order = fields.find(x => x.key == newAttribute.id).order +','+ newAttribute.ordinal;
|
||||
fields.find(x => x.key == newAttribute.id).multiplicity = true;
|
||||
}
|
||||
newAttribute.ordinal = attr._ordinal;
|
||||
newAttribute.sources = new Array();
|
||||
newAttribute.validation = new Array();
|
||||
//newAttribute.validation.push(attr.validation.rule);
|
||||
//-----------------Sources---------------------------------------------------------------
|
||||
if (attr.sources) {
|
||||
newAttribute.sources.push(attr.sources.source);
|
||||
if (attr.sources.source.length != undefined) {
|
||||
for (var i = 0; i < attr.sources.source.length; i++) {
|
||||
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.validation.rule != undefined)
|
||||
if (attr.validation.rule.length)
|
||||
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;
|
||||
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;
|
||||
functions.forEach(fnc => {
|
||||
if (fnc._id == rule.method)
|
||||
rule.methodJs = fnc.script.__cdata;
|
||||
});
|
||||
}
|
||||
newAttribute.validation.push(rule);
|
||||
if (attr.sources.source._type == "url") {
|
||||
newAttribute.url = attr.sources.source.value._value;
|
||||
}
|
||||
}
|
||||
//-----------Rules------------------------------------------------------------------------
|
||||
if(attr.validation.rule != undefined)
|
||||
if (attr.validation.rule.length)
|
||||
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;
|
||||
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;
|
||||
functions.forEach(fnc => {
|
||||
if (fnc._id == rule.method)
|
||||
rule.methodJs = fnc.script.__cdata;
|
||||
});
|
||||
}
|
||||
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); }
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
private getSections(sections: any, fieldGroups: GroupBase<any>[]) {
|
||||
|
@ -299,16 +336,6 @@ export class dataModelBuilder {
|
|||
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) {
|
||||
let DuplicateArray = [];
|
||||
|
|
|
@ -15,6 +15,8 @@ export class FieldControlService {
|
|||
|
||||
groups.forEach(group => {
|
||||
let subgroup: any = {};
|
||||
let subgroupFieldset: any = {};
|
||||
let fieldset: boolean = false;
|
||||
group.groupFields.forEach(field => {
|
||||
//if(field.attributes.validation != undefined)
|
||||
// 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 || '')
|
||||
|
||||
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
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -18,19 +18,19 @@ export class RestBase {
|
|||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
protocol: string = "http";
|
||||
hostname: string ="dl010.madgik.di.uoa.gr" ;//"localhost";//"dl010.madgik.di.uoa.gr";//
|
||||
port: number = 8080;//8080;//
|
||||
webappname: string = "dmp-backend";//"dmp-backend-new";//
|
||||
*/
|
||||
|
||||
|
||||
|
||||
protocol: string = "http";
|
||||
hostname: string = "dionysus.di.uoa.gr" ;
|
||||
port: number = 7070;
|
||||
webappname: string = "dmp-backend";
|
||||
|
||||
// protocol: string = "http";
|
||||
// hostname: string = "dionysus.di.uoa.gr" ;
|
||||
// port: number = 7070;
|
||||
// webappname: string = "dmp-backend";
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue