fixes and improvements

This commit is contained in:
annampak 2017-11-09 18:43:01 +02:00
parent 95bace54c8
commit ff45be8005
4 changed files with 17 additions and 118 deletions

View File

@ -87,13 +87,8 @@ export class DynamicFormComponent implements OnInit {
if (data.properties) {
console.log("Found already submitted form, loading that one!");
//console.log(data.properties)
//console.log(JSON.parse(data.properties))
formValues = JSON.parse(data.properties);
flatList = flatten(formValues);
//this.patchForm(flatList);
}
@ -122,7 +117,7 @@ export class DynamicFormComponent implements OnInit {
this.dataModel = new DataModel();
this.dataModel = this.dataModelService.getDataModel(data, formValues);
this.dataModel = this.dataModelService.getDataModel(data, formValues); //get formvalues and acossiate them with fields
this.form = this.qcs.toFormGroup(this.dataModel.fields, this.dataModel.groups);
@ -144,14 +139,15 @@ export class DynamicFormComponent implements OnInit {
//count++;
Object.keys(this.form.value[c]).forEach((item) => {
let value = this.form.value[c][item]
if (value != undefined && value != "" && value != " ") countDirtyValues++; //TODO REMOVE SPACES FROM EMPTY STRING
if (typeof(value) == "string") value.trim();
if(typeof(value)== "boolean") value.toString();
if (value != undefined && value != "")
countDirtyValues++; //TODO REMOVE SPACES FROM EMPTY STRING
});
});
this.dataModel.groups.forEach(grp => {
grp.groupFields.forEach((fld) => {
if (fld.visible == true || fld.visible == "true")
@ -183,18 +179,13 @@ export class DynamicFormComponent implements OnInit {
console.log(err);
}
);
//end- klhsh gia to dataset profiel
},
(err) => {
});
}
scrollToElemID(elemID) {
scroll("#" + elemID);
}
@ -213,9 +204,6 @@ export class DynamicFormComponent implements OnInit {
//this.form.get("namingConventionGroup.nonamingConventionA213").setValue("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
}
ngAfterViewChecked(): void { //navigate to certain section of the page
try {
document.querySelector('#' + this.fragment).scrollIntoView();
@ -264,21 +252,6 @@ export class DynamicFormComponent implements OnInit {
else
return false;
// if (i > this.pagination.startIndex && this.pagination.endIndex) {
// return true;
// }
// return false;
}
buildForm(): void {
//this.form = this.qcs.toFormGroup(this.fields.
this.form.valueChanges
.subscribe(data => this.onValueChanged(data));
this.onValueChanged(); // (re)set validation messages now
}
setPage(page: number) {
@ -290,7 +263,6 @@ export class DynamicFormComponent implements OnInit {
// get pagination object from service
this.pagination = this.pagerService.getPagination(this.dataModel.groups, this.dataModel.groups.length, page, pagesize);
//get current page of items
// this.dataModel.sections.forEach(section => {
// if (section.groupFields.length > 0) {
@ -309,38 +281,4 @@ export class DynamicFormComponent implements OnInit {
this.tokenService.setToken(null); //kanonika prepei na mpei mesa sthn function.....
}
onValueChanged(data?: any) {
if (!this.form) { return; }
const form = this.form;
for (const field in this.formErrors) {
// clear previous error message (if any)
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.dirty && !control.valid) {
const messages = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] + ' ';
}
}
}
}
formErrors = {
'name': '',
'power': ''
};
validationMessages = {
'name': {
'required': 'Name is required.',
'minlength': 'Name must be at least 4 characters long.',
'maxlength': 'Name cannot be more than 24 characters long.',
'forbiddenName': 'Someone named "Bob" cannot be a hero.'
},
'power': {
'required': 'Power is required.'
}
};
}

View File

@ -37,10 +37,9 @@
on change event the listener is triggered on blur -->
<div *ngSwitchCase="'dropdown'">
{{field.url}}
<autocomplete-remote *ngIf="field.url" [form]="form" [formCtrlName]="field.key" [label]="'Please select a datarepo'" [url]="field.url" ></autocomplete-remote>
<autocomplete-remote *ngIf="field.url" [form]="form" [formCtrlName]="field.key" [url]="field.url" ></autocomplete-remote>
<select *ngIf="!field.url" class="form-control" [id]="field.key" [formControlName]="field.key" [required]="field.required" (change)="toggleVisibility($event, field, false)">
<option *ngFor="let opt of field.options" [value]="opt.key" >{{opt.value}}</option>
<option *ngFor="let opt of field.options" [value]="opt._value" >{{opt._label}}</option>
</select>
</div>

View File

@ -47,7 +47,7 @@ export class DynamicFormFieldComponent {
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;
dropdownField.options = dropdownField.attributes.sources[0].value;
}
}

View File

@ -30,13 +30,13 @@ 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.checkDuplicateInObject('order', this.dataModel.groups[13].groupFields);
this.dataModel.semanticAttr = new Array(new Attribute);
//this.dataModel.semanticAttr = data.dataset.profile.definition.root.fields.field;
this.dataModel.semanticAttr = this.getFieldsAttributes(data.definition.root.fields.field, data.ruleset.definition.root.functions.function, this.fields);
this.dataModel.sections = this.getSections(data.viewstyle.definition.root.sections.section, this.dataModel.groups);
this.dataModel.buildIndex();
this.checkDuplicateInObject('order', this.dataModel.groups[13].groupFields); //for future use , for composite field
return this.dataModel;
}
@ -214,7 +214,7 @@ export class dataModelBuilder {
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) {
@ -222,39 +222,14 @@ export class dataModelBuilder {
if (attr.sources.source[i]._type == "url") {
newAttribute.url = attr.sources.source[i].value._value;
break;
} else {
newAttribute.sources.forEach(src => {
src.params = new Array();
for (var i = 0, len = attr.sources.source[i].value.length; i < len; i++) {
let prm = new Param();
prm.key = attr.sources.source[i].value[i]._value;
prm.value = attr.sources.source[i].value[i]._label;
src.params.push(prm);
}
});
}
}
}
if (attr.sources.source._type == "url") {
newAttribute.url = attr.sources.source.value._value;
} 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);
}
});
}
}
//-----------Rules------------------------------------------------------------------------
if(attr.validation.rule != undefined)
if (attr.validation.rule.length)
for (var i = 0, len = attr.validation.rule.length; i < len; i++) {
@ -270,7 +245,6 @@ export class dataModelBuilder {
rule.methodJs = fnc.script.__cdata;
});
}
newAttribute.validation.push(rule);
}
else {
@ -286,11 +260,8 @@ export class dataModelBuilder {
if (fnc._id == rule.method)
rule.methodJs = fnc.__cdata;
});
}
newAttribute.validation.push(rule);
}
newAttribute.validation.push(rule); }
}
attribute.push(newAttribute);
@ -300,7 +271,6 @@ export class dataModelBuilder {
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
});
return attribute;
}
@ -328,14 +298,6 @@ export class dataModelBuilder {
return sects;
}
getValuesFromEestore(url: string, fieldPath: string) {
this.restBase.proxy_get(url).subscribe((data) => {
data.data.forEach(data => {
console.log(data);
});
});
}
checkDuplicateInObject(propertyName, inputArray) {
let DuplicateArray = [];
inputArray.forEach(item => {