From 35b7c8190ae3b9f93f88a60393ba6ee95d168213 Mon Sep 17 00:00:00 2001 From: "CITE\\dtziotzios" Date: Thu, 7 Feb 2019 10:26:00 +0200 Subject: [PATCH 1/3] visibillity rules change to evaluate child rules on a change. --- .../visibility-rules/visibility-rules.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts index 25f27bdcd..eba937c59 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts @@ -38,10 +38,13 @@ export class VisibilityRulesService { for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) { if (value != null && (this.parseValue(value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) { this.elementVisibilityMap.set(visibilityRule.targetControlId, false); + this.updateValueAndVisibility(visibilityRule.targetControlId, null); + // this.clearValues(targetPathKey); return; } } this.elementVisibilityMap.set(visibilityRule.targetControlId, true); + this.updateValueAndVisibility(visibilityRule.targetControlId, null); } parseValue(value: any) { From ff437132ed1b0109b4d6ded4bfd93ece2e137217 Mon Sep 17 00:00:00 2001 From: dtziotzios Date: Thu, 7 Feb 2019 17:00:42 +0200 Subject: [PATCH 2/3] Fixes autocomplete for Project endpoint. --- .../eu/eudat/models/data/project/ProjectListingModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/project/ProjectListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/project/ProjectListingModel.java index ae93cb757..4447a04db 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/project/ProjectListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/project/ProjectListingModel.java @@ -102,8 +102,8 @@ public class ProjectListingModel implements DataModel Date: Fri, 8 Feb 2019 10:48:28 +0200 Subject: [PATCH 3/3] visibility service is also using the form group to reset values for hidden fields --- .../dataset-description-form.component.ts | 2 +- .../dataset-description-form.model.ts | 1 + .../visibility-rules.service.ts | 41 +++++++++++++++++-- .../editor/project-editor.component.ts | 2 +- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.component.ts index 0b7410146..0b873b888 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.component.ts @@ -56,7 +56,7 @@ export class DatasetDescriptionFormComponent extends BaseComponent implements On ngOnInit() { // this.visibilityRulesService.formGroup = this.form; - this.visibilityRulesService.buildVisibilityRules(this.visibilityRules); + this.visibilityRulesService.buildVisibilityRules(this.visibilityRules, this.form); // this.datasetProfileDefinitionModel = new DatasetDescriptionFormEditorModel().fromModel(this.dataModel); // this.visibilityRulesService.setModel(this.datasetProfileDefinitionModel); diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts index 823e40d48..49df80bd7 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts @@ -248,6 +248,7 @@ export class DatasetDescriptionFieldEditorModel extends BaseFormModel { description: [{ value: this.description, disabled: true }], extendedDescription: [{ value: this.extendedDescription, disabled: true }], title: [{ value: this.title, disabled: true }], + defaultValue: [{ value: this.defaultValue, disabled: true }], }); const multiplicityItemsFormArray = new Array(); diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts index eba937c59..5db5c4948 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service.ts @@ -1,5 +1,5 @@ import { ApplicationRef, Injectable, NgZone } from '@angular/core'; -import { FormArray, FormGroup } from '@angular/forms'; +import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms'; import { isNumeric } from 'rxjs/internal/util/isNumeric'; import { Rule } from '../../../../core/model/dataset-profile-definition/rule'; import { VisibilityRule } from './models/visibility-rule'; @@ -10,6 +10,7 @@ export class VisibilityRulesService { private visibilityRuleContext: VisibilityRulesContext; + private form: AbstractControl; private elementVisibilityMap = new Map(); constructor( @@ -24,9 +25,10 @@ export class VisibilityRulesService { return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false; } - public buildVisibilityRules(item: Array) { + public buildVisibilityRules(item: Array, form: AbstractControl) { this.visibilityRuleContext = new VisibilityRulesContext(); this.visibilityRuleContext.buildVisibilityRuleContext(item || []); + this.form = form; } public updateValueAndVisibility(id: string, value: any) { @@ -38,13 +40,14 @@ export class VisibilityRulesService { for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) { if (value != null && (this.parseValue(value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) { this.elementVisibilityMap.set(visibilityRule.targetControlId, false); - this.updateValueAndVisibility(visibilityRule.targetControlId, null); + this.resetControlWithId(this.form, visibilityRule.targetControlId); + //this.updateValueAndVisibility(visibilityRule.targetControlId, null); // this.clearValues(targetPathKey); return; } } this.elementVisibilityMap.set(visibilityRule.targetControlId, true); - this.updateValueAndVisibility(visibilityRule.targetControlId, null); + //this.updateValueAndVisibility(visibilityRule.targetControlId, null); } parseValue(value: any) { @@ -93,4 +96,34 @@ export class VisibilityRulesService { return item; } } + + private resetControlWithId(formControl: AbstractControl, id: string) { + if (formControl instanceof FormGroup) { + if ((formControl as FormGroup).contains('id') && (formControl as FormGroup).contains('value') && (formControl as FormGroup).get('id').value === id) { + this.resetFieldFormGroup(formControl); + } if ((formControl as FormGroup).contains('id') && (formControl as FormGroup).contains('fields') && (formControl as FormGroup).get('id').value === id) { + this.resetCompositeFieldFormGroup(formControl); + } else { + Object.keys(formControl.controls).forEach(item => { + const control = formControl.get(item); + this.resetControlWithId(control, id); + }); + } + } else if (formControl instanceof FormArray) { + formControl.controls.forEach(item => { + this.resetControlWithId(item, id); + }); + } + } + + private resetFieldFormGroup(formGroup: FormGroup) { + formGroup.get('value').setValue(formGroup.get('defaultValue').value ? formGroup.get('defaultValue').value.value : undefined); + } + + private resetCompositeFieldFormGroup(formGroup: FormGroup) { + (formGroup.get('fields') as FormArray).controls.forEach((element: FormGroup) => { + this.resetFieldFormGroup(element); + }); + (formGroup.get('multiplicityItems') as FormArray).controls.splice(0); + } } diff --git a/dmp-frontend/src/app/ui/project/editor/project-editor.component.ts b/dmp-frontend/src/app/ui/project/editor/project-editor.component.ts index 8e63e9d9a..d8abb0556 100644 --- a/dmp-frontend/src/app/ui/project/editor/project-editor.component.ts +++ b/dmp-frontend/src/app/ui/project/editor/project-editor.component.ts @@ -40,7 +40,7 @@ export class ProjectEditorComponent extends BaseComponent implements OnInit, IBr public language: TranslateService, private dialog: MatDialog, private projectFileUploadService: ProjectFileUploadService, - private uiNotificationService:UiNotificationService + private uiNotificationService: UiNotificationService ) { super(); }