get describe form

This commit is contained in:
annampak 2017-11-02 18:39:05 +02:00
parent ec3ae4c441
commit 04994e9743
6 changed files with 86 additions and 83 deletions

View File

@ -164,7 +164,7 @@ export class DatasetsComponent implements OnInit {
);
}
editRow(item, event) { debugger;
editRow(item, event) {
if (event.toElement.id == "editDataset"){
this.dataset.label = item.label;
this.dataset.uri = item.uri;

View File

@ -75,96 +75,97 @@ export class DynamicFormComponent implements OnInit {
this.datasetId = params.datasetId;
//this.datasetProperties = params.datasetProperties
});
this.serverService.getDatasetProfileByID(this.id).subscribe(
response => {
console.log("response");
console.log(response);
const data = response;
//replace the xmls {model,view,rule} definitions with json -- https://github.com/abdmob/x2js library
data.definition = this.xml2jsonOBJ.xml_str2json(data.definition);
data.ruleset.definition = this.xml2jsonOBJ.xml_str2json(data.ruleset.definition);
data.viewstyle.definition = this.xml2jsonOBJ.xml_str2json(data.viewstyle.definition);
//can be converted back to xml (which shouldn't be needed) with this.xml2jsonOBJ.json2xml_str
console.log("this.serverService.getFields");
console.log("data.dataset")
console.log(data.definition)
console.log(data.ruleset.definition)
console.log(data.viewstyle.definition)
this.dataModel = new DataModel();
this.dataModel = this.dataModelService.getDataModel(data);debugger;
this.form = this.qcs.toFormGroup(this.dataModel.fields, this.dataModel.groups);
this.form.valueChanges.subscribe(data => {
// console.log('Form changes', data);
let dirtyValuesArray: Array<any> = [];
let count = 0;
let countDirtyValues = 0;
Object.keys(this.form.controls).forEach((c) => {
//count++;
let currentControl = this.form.controls[c];
if (currentControl.dirty)
dirtyValuesArray.push(currentControl.value);
});
this.dataModel.groups.forEach(grp => {
grp.groupFields.forEach((fld) => {
if (fld.visible == true || fld.visible == "true")
count++;
if (fld.value != undefined && fld.value !=" ")
countDirtyValues++;
});
});
//console.log(count);
// var percentage = Math.floor(dirtyValuesArray.length * 100 / count);
var percentage = Math.floor(countDirtyValues * 100 / count);
this.dirtyValues = percentage;
})
//this.form = this.qcs.toFormGroup(this.fields);
console.log("SUMMARY: ======>");
console.log(this.dataModel);
console.log(this.form);
this.route.paramMap //this is how i get the projects's id
// initialize to page 1
this.setPage(1);
},
err => {
console.log("There was an error fetching the data from server");
console.log(err);
}
);
this.serverService.getDatasetByID(this.datasetId).subscribe(
(data) => {
var flatList;
var formValues;
if(data.properties){
console.log("Found already submitted form, loading that one!");
//console.log(data.properties)
//console.log(JSON.parse(data.properties))
let formValues = JSON.parse(data.properties);
formValues = JSON.parse(data.properties);
flatList = flatten(formValues);
this.patchForm(flatList);
//this.patchForm(flatList);
}
//η κληση για το dataset profile pou htan prin pio panw anexarthth
this.serverService.getDatasetProfileByID(this.id).subscribe(
response => {
console.log("response");
console.log(response);
const data = response;
//replace the xmls {model,view,rule} definitions with json -- https://github.com/abdmob/x2js library
data.definition = this.xml2jsonOBJ.xml_str2json(data.definition);
data.ruleset.definition = this.xml2jsonOBJ.xml_str2json(data.ruleset.definition);
data.viewstyle.definition = this.xml2jsonOBJ.xml_str2json(data.viewstyle.definition);
//can be converted back to xml (which shouldn't be needed) with this.xml2jsonOBJ.json2xml_str
console.log("this.serverService.getFields");
console.log("data.dataset")
console.log(data.definition)
console.log(data.ruleset.definition)
console.log(data.viewstyle.definition)
this.dataModel = new DataModel();
this.dataModel = this.dataModelService.getDataModel(data, formValues);debugger;
this.form = this.qcs.toFormGroup(this.dataModel.fields, this.dataModel.groups);
this.form.valueChanges.subscribe(data => {
// console.log('Form changes', data);
let dirtyValuesArray: Array<any> = [];
let count = 0;
let countDirtyValues = 0;
Object.keys(this.form.controls).forEach((c) => {
//count++;
let currentControl = this.form.controls[c];
if (currentControl.dirty)
dirtyValuesArray.push(currentControl.value);
});
this.dataModel.groups.forEach(grp => {
grp.groupFields.forEach((fld) => {
if (fld.visible == true || fld.visible == "true")
count++;
if (fld.value != undefined && fld.value !=" ")
countDirtyValues++;
});
});
//console.log(count);
// var percentage = Math.floor(dirtyValuesArray.length * 100 / count);
var percentage = Math.floor(countDirtyValues * 100 / count);
this.dirtyValues = percentage;
})
//this.form = this.qcs.toFormGroup(this.fields);
console.log("SUMMARY: ======>");
console.log(this.dataModel);
console.log(this.form);
this.route.paramMap //this is how i get the projects's id
// initialize to page 1
this.setPage(1);
},
err => {
console.log("There was an error fetching the data from server");
console.log(err);
}
);
//end- klhsh gia to dataset profiel

View File

@ -33,14 +33,14 @@
<div>{{field.description}}</div>
<input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type"
[(ngModel)]="field.value" [required]="field.required" [pattern] = "field.regex" (ngModelChange) = "toggleVisibility($event, field)"> <!--input or change event
[required]="field.required" [pattern] = "field.regex" (ngModelChange) = "toggleVisibility($event, field)"> <!--input or change event
on change event the listener is triggered on blur -->
<select *ngSwitchCase="'dropdown'" class="form-control" [id]="field.key" [formControlName]="field.key" [(ngModel)]="field.value" [required]="field.required">
<select *ngSwitchCase="'dropdown'" class="form-control" [id]="field.key" [formControlName]="field.key" [required]="field.required">
<option *ngFor="let opt of field.options" [value]="opt.key">{{opt.value}}</option>
</select>
<input *ngSwitchCase="'checkbox'" class="form-check" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type"
<input *ngSwitchCase="'checkbox'" class="form-check" [formControlName]="field.key" [id]="field.key" [type]="field.type"
(change)="toggleVisibility($event, field, ckb)" #ckb [required]="field.required" [checked] = "field.value"> <!--(change)="field.value = ckb.checked" has moved into the toggleVisibility
// without property [checked] as pages change the checkboxes of the previous pages lose the checked pro -->

View File

@ -48,7 +48,7 @@ export class DynamicFormFieldComponent {
if (dropdownField.attributes.sources != undefined)
dropdownField.options = dropdownField.attributes.sources[0].params;
}
// this.toggleVisibility(null,this.field, null) to do
}
this.route.fragment.subscribe(fragment => { this.fragment = fragment; }); //navigate to certain section of the page

View File

@ -20,14 +20,14 @@ export class dataModelBuilder {
constructor(private restBase: RestBase) { }
public getDataModel(data) {
public getDataModel(data, dataValues) {
if (this.dataModel != null)
return this.dataModel;
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);
this.dataModel.groups = this.getGroups(data.viewstyle.definition.root.fieldGroups.fieldGroup, this.fields, dataValues);
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);
@ -120,7 +120,7 @@ export class dataModelBuilder {
return fieldsVisible;
}
private getGroups(fieldGroups: any, fields: any[]) {
private getGroups(fieldGroups: any, fields: any[] , dataValues) {
let groups: GroupBase<any>[] = [];
if (fieldGroups.length > 1) {
@ -129,6 +129,8 @@ export class dataModelBuilder {
newfldGroup.groupFields = new Array();
fields.forEach(field => {
if (fieldGroup._id == field.group) {
if(dataValues[fieldGroup._id][field.key] != undefined)
field.value = dataValues[fieldGroup._id][field.key].value == undefined ? dataValues[fieldGroup._id][field.key] : dataValues[fieldGroup._id][field.key].value;
newfldGroup.groupFields.push(field);
} else {
//this.dataModel.fields.push(field);

View File

@ -4,7 +4,7 @@ export class PaginationService {
let totalPages = Math.ceil(totalGroups / pageSize);
//each group get the number of its page for toc linking
for (var x = 0; x < totalPages ; x++) {debugger;
for (var x = 0; x < totalPages ; x++) {
for (var i = 0; i < pageSize; i++) {
if (x==0)
groups[i].page = x+1;