diff --git a/dmp-frontend/src/app/datasets/dataset.component.ts b/dmp-frontend/src/app/datasets/dataset.component.ts index b1d5f3674..56d0a581f 100644 --- a/dmp-frontend/src/app/datasets/dataset.component.ts +++ b/dmp-frontend/src/app/datasets/dataset.component.ts @@ -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; diff --git a/dmp-frontend/src/app/form/dynamic-form.component.ts b/dmp-frontend/src/app/form/dynamic-form.component.ts index ceb8be099..e3142bb60 100644 --- a/dmp-frontend/src/app/form/dynamic-form.component.ts +++ b/dmp-frontend/src/app/form/dynamic-form.component.ts @@ -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 = []; - 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 = []; + 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 diff --git a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.html b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.html index 67f38da5a..cb0700595 100644 --- a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.html +++ b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.html @@ -33,14 +33,14 @@
{{field.description}}
- - diff --git a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts index 5fb1cbbfe..6392360a5 100644 --- a/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts +++ b/dmp-frontend/src/app/form/fields/dynamic-form-field.component.ts @@ -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 diff --git a/dmp-frontend/src/app/services/dataModelBuilder.service.ts b/dmp-frontend/src/app/services/dataModelBuilder.service.ts index e255f8a76..7ef9cf1a1 100644 --- a/dmp-frontend/src/app/services/dataModelBuilder.service.ts +++ b/dmp-frontend/src/app/services/dataModelBuilder.service.ts @@ -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[] = []; 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); diff --git a/dmp-frontend/src/app/services/pagination.service.ts b/dmp-frontend/src/app/services/pagination.service.ts index 349caf6e1..3e36abb98 100644 --- a/dmp-frontend/src/app/services/pagination.service.ts +++ b/dmp-frontend/src/app/services/pagination.service.ts @@ -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;