Merge branch 'ui-refactoring' of https://gitlab.eudat.eu/dmp/OpenAIRE-EUDAT-DMP-service-pilot into ui-refactoring
This commit is contained in:
commit
17ce0ef455
|
@ -102,8 +102,8 @@ public class ProjectListingModel implements DataModel<eu.eudat.data.entities.Pro
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getStatus() {
|
public Short getStatus() {
|
||||||
return status.getValue();
|
return status != null ? status.getValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(Short status) {
|
public void setStatus(Short status) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class DatasetDescriptionFormComponent extends BaseComponent implements On
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
// this.visibilityRulesService.formGroup = this.form;
|
// 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.datasetProfileDefinitionModel = new DatasetDescriptionFormEditorModel().fromModel(this.dataModel);
|
||||||
// this.visibilityRulesService.setModel(this.datasetProfileDefinitionModel);
|
// this.visibilityRulesService.setModel(this.datasetProfileDefinitionModel);
|
||||||
|
|
||||||
|
|
|
@ -248,6 +248,7 @@ export class DatasetDescriptionFieldEditorModel extends BaseFormModel {
|
||||||
description: [{ value: this.description, disabled: true }],
|
description: [{ value: this.description, disabled: true }],
|
||||||
extendedDescription: [{ value: this.extendedDescription, disabled: true }],
|
extendedDescription: [{ value: this.extendedDescription, disabled: true }],
|
||||||
title: [{ value: this.title, disabled: true }],
|
title: [{ value: this.title, disabled: true }],
|
||||||
|
defaultValue: [{ value: this.defaultValue, disabled: true }],
|
||||||
});
|
});
|
||||||
|
|
||||||
const multiplicityItemsFormArray = new Array<FormGroup>();
|
const multiplicityItemsFormArray = new Array<FormGroup>();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ApplicationRef, Injectable, NgZone } from '@angular/core';
|
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 { isNumeric } from 'rxjs/internal/util/isNumeric';
|
||||||
import { Rule } from '../../../../core/model/dataset-profile-definition/rule';
|
import { Rule } from '../../../../core/model/dataset-profile-definition/rule';
|
||||||
import { VisibilityRule } from './models/visibility-rule';
|
import { VisibilityRule } from './models/visibility-rule';
|
||||||
|
@ -10,6 +10,7 @@ export class VisibilityRulesService {
|
||||||
|
|
||||||
|
|
||||||
private visibilityRuleContext: VisibilityRulesContext;
|
private visibilityRuleContext: VisibilityRulesContext;
|
||||||
|
private form: AbstractControl;
|
||||||
private elementVisibilityMap = new Map<String, boolean>();
|
private elementVisibilityMap = new Map<String, boolean>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -24,9 +25,10 @@ export class VisibilityRulesService {
|
||||||
return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false;
|
return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public buildVisibilityRules(item: Array<Rule>) {
|
public buildVisibilityRules(item: Array<Rule>, form: AbstractControl) {
|
||||||
this.visibilityRuleContext = new VisibilityRulesContext();
|
this.visibilityRuleContext = new VisibilityRulesContext();
|
||||||
this.visibilityRuleContext.buildVisibilityRuleContext(item || []);
|
this.visibilityRuleContext.buildVisibilityRuleContext(item || []);
|
||||||
|
this.form = form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateValueAndVisibility(id: string, value: any) {
|
public updateValueAndVisibility(id: string, value: any) {
|
||||||
|
@ -38,10 +40,14 @@ export class VisibilityRulesService {
|
||||||
for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) {
|
for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) {
|
||||||
if (value != null && (this.parseValue(value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) {
|
if (value != null && (this.parseValue(value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) {
|
||||||
this.elementVisibilityMap.set(visibilityRule.targetControlId, false);
|
this.elementVisibilityMap.set(visibilityRule.targetControlId, false);
|
||||||
|
this.resetControlWithId(this.form, visibilityRule.targetControlId);
|
||||||
|
//this.updateValueAndVisibility(visibilityRule.targetControlId, null);
|
||||||
|
// this.clearValues(targetPathKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.elementVisibilityMap.set(visibilityRule.targetControlId, true);
|
this.elementVisibilityMap.set(visibilityRule.targetControlId, true);
|
||||||
|
//this.updateValueAndVisibility(visibilityRule.targetControlId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseValue(value: any) {
|
parseValue(value: any) {
|
||||||
|
@ -90,4 +96,34 @@ export class VisibilityRulesService {
|
||||||
return item;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue