diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index 4025f619c..8bd186cd4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -238,7 +238,14 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin @Override public int compareTo(Object o) { - return this.ordinal.compareTo(((Field) o).getOrdinal()); + Field comparedField = (Field) o; + if(this.ordinal != null) { + return this.ordinal.compareTo(comparedField.getOrdinal()); + } else if (comparedField.getOrdinal() != null) { + return comparedField.getOrdinal().compareTo(this.ordinal); + } else { + return 0; + } } @Override diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section-inner/form-section-inner.component.html b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section-inner/form-section-inner.component.html index 2d8594873..e271c4606 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section-inner/form-section-inner.component.html +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section-inner/form-section-inner.component.html @@ -20,8 +20,8 @@
- - {{compositeFieldFormGroup.get('multiplicity').value.placeholder}} diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.html b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.html index 9a15c0141..58c95a8fb 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.html +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.html @@ -32,8 +32,8 @@
- - {{compositeFieldFormGroup.get('multiplicity').value.placeholder}} @@ -105,8 +105,8 @@
- - {{fieldsetEntry.form.get('multiplicity').value.placeholder}} diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts index dfb4adefd..860a5676f 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-section/form-section.component.ts @@ -1,14 +1,24 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; -import { FormArray, FormGroup } from '@angular/forms'; -import { Rule } from '@app/core/model/dataset-profile-definition/rule'; -import { BaseComponent } from '@common/base/base.component'; -import { takeUntil } from 'rxjs/operators'; -import { DatasetDescriptionCompositeFieldEditorModel } from '../../dataset-description-form.model'; -import { ToCEntry, ToCEntryType } from '../../dataset-description.component'; -import { FormFocusService } from '../../form-focus/form-focus.service'; -import { LinkToScroll } from '../../tableOfContentsMaterial/table-of-contents'; -import { VisibilityRuleSource } from '../../visibility-rules/models/visibility-rule-source'; -import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + EventEmitter, + Input, + OnChanges, + OnInit, + Output, + SimpleChanges +} from '@angular/core'; +import {FormArray, FormGroup} from '@angular/forms'; +import {Rule} from '@app/core/model/dataset-profile-definition/rule'; +import {BaseComponent} from '@common/base/base.component'; +import {takeUntil} from 'rxjs/operators'; +import {DatasetDescriptionCompositeFieldEditorModel} from '../../dataset-description-form.model'; +import {ToCEntry, ToCEntryType} from '../../dataset-description.component'; +import {FormFocusService} from '../../form-focus/form-focus.service'; +import {LinkToScroll} from '../../tableOfContentsMaterial/table-of-contents'; +import {VisibilityRuleSource} from '../../visibility-rules/models/visibility-rule-source'; +import {VisibilityRulesService} from '../../visibility-rules/visibility-rules.service'; @Component({ @@ -47,7 +57,7 @@ export class FormSectionComponent extends BaseComponent implements OnInit, OnCha this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => { this.changeDetector.markForCheck(); }); - } + } ngOnInit() { // if (this.section) { @@ -57,6 +67,7 @@ export class FormSectionComponent extends BaseComponent implements OnInit, OnCha if (this.tocentry) {//maybe not needed as well this.form = this.tocentry.form as FormGroup; } + this.initMultipleFieldsVisibility(); } ngOnChanges(changes: SimpleChanges) { @@ -78,6 +89,133 @@ export class FormSectionComponent extends BaseComponent implements OnInit, OnCha // this.visibilityRulesService.triggerVisibilityEvaluation(); // } + setMultipleFieldVisibility(parentCompositeField, compositeField: DatasetDescriptionCompositeFieldEditorModel, idMappings: { old: string, new: string }[]) { + // ** COMPOSITE FIELD IS SHOWN OR HIDDEN FROM ANOTHER ELEMENT + const compositeFieldVisibilityDependencies = this.visibilityRulesService.getVisibilityDependency(parentCompositeField); + if (compositeFieldVisibilityDependencies && compositeFieldVisibilityDependencies.length) { + + compositeFieldVisibilityDependencies.forEach(x => { + const visRule: Rule = { + targetField: compositeField.id, + sourceField: x.sourceControlId, + requiredValue: x.sourceControlValue, + type: '' + } + this.visibilityRulesService.addNewRule(visRule); + }); + } + + // console.log('idMappings ', idMappings); + parentCompositeField.fields.forEach(element => { + // console.log(this.visibilityRulesService.getVisibilityDependency(element.id)); + const dependency = this.visibilityRulesService.getVisibilityDependency(element.id); + if (dependency && dependency.length) { + // * INNER VISIBILITY DEPENDENCIES + // * IF INNER INPUT HIDES ANOTHER INNER INPUT + const innerDependency = parentCompositeField.fields.reduce((innerD, currentElement) => { + const innerDependecies = dependency.filter(d => d.sourceControlId === currentElement.id); + return [...innerD, ...innerDependecies]; + }, []) as VisibilityRuleSource[]; + if (innerDependency.length) { + //Build visibility source + const updatedRules = innerDependency.map(x => { + const newId = idMappings.find(y => y.old === x.sourceControlId); + return {...x, sourceControlId: newId.new}; + }); + // const visRule: VisibilityRule = { + // targetControlId: idMappings.find(x => x.old === element.id).new, + // sourceVisibilityRules: updatedRules + // } + + + const rules = updatedRules.map(x => { + return { + requiredValue: x.sourceControlValue, + sourceField: x.sourceControlId, + targetField: idMappings.find(l => l.old === element.id).new, + type: '' + } as Rule; + }); + + rules.forEach(rule => { + this.visibilityRulesService.addNewRule(rule); + }) + + // this.visibilityRulesService.appendVisibilityRule(visRule); + } + + } + + + // * OUTER DEPENDENCIES + + // * IF INNER INPUT HIDES OUTER INPUTS + const innerIds = idMappings.map(x => x.old) as string[]; + + const outerTargets = this.visibilityRulesService.getVisibilityTargets(element.id).filter(x => !innerIds.includes(x)); + + outerTargets.forEach(target => { + + const outerRules = (this.visibilityRulesService.getVisibilityDependency(target) as VisibilityRuleSource[]).filter(x => x.sourceControlId === element.id); + const updatedRules = outerRules.map(x => { + console.log(idMappings, element); + return {...x, sourceControlId: idMappings.find(y => y.old === element.id).new}; + }); + + // const visRule: VisibilityRule = { + // targetControlId: target, + // sourceVisibilityRules: updatedRules + // } + + + const rules = updatedRules.map(x => { + return { + requiredValue: x.sourceControlValue, + sourceField: x.sourceControlId, + targetField: target, + type: '' + } as Rule; + }) + rules.forEach(rule => { + this.visibilityRulesService.addNewRule(rule); + }) + // this.visibilityRulesService.appendVisibilityRule(visRule); + }); + // * IF INNER INPUT IS HIDDEN BY OUTER INPUT + if (dependency && dependency.length) { + const fieldsThatHideInnerElement = dependency.filter(x => !innerIds.includes(x.sourceControlId)); + if (fieldsThatHideInnerElement.length) { + fieldsThatHideInnerElement.forEach(x => { + const visRule: Rule = { + targetField: idMappings.find(l => l.old === element.id).new, + sourceField: x.sourceControlId, + requiredValue: x.sourceControlValue, + type: '' + } + const shouldBeVisibile = this.visibilityRulesService.checkTargetVisibilityProvidedBySource(x.sourceControlId, element.id); + this.visibilityRulesService.addNewRule(visRule, shouldBeVisibile); + }); + } + } + // console.log(`for ${element.id} targets are`, outerTargets); + }); + } + + initMultipleFieldsVisibility() { + (this.form.get('compositeFields') as FormArray).controls.forEach(control => { + let parentCompositeField = (control as FormGroup).getRawValue(); + if (parentCompositeField.multiplicityItems && parentCompositeField.multiplicityItems.length > 0) { + parentCompositeField.multiplicityItems.forEach(compositeField => { + let idMappings: { old: string, new: string }[] = [{old: parentCompositeField.id, new: compositeField.id}]; + parentCompositeField.fields.forEach((field, index) => { + idMappings.push({ old: field.id, new: compositeField.fields[index].id }); + }); + this.setMultipleFieldVisibility(parentCompositeField, compositeField, idMappings); + }) + } + }); + } + addMultipleField(fieldsetIndex: number) { const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue(); const multiplicityItemsArray = ((this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))); @@ -93,144 +231,7 @@ export class FormSectionComponent extends BaseComponent implements OnInit, OnCha const idMappings = [] as { old: string, new: string }[]; const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, ordinal, idMappings); - - - - // ** COMPOSITE FIELD IS SHOWN OR HIDDEN FROM ANOTHER ELEMENT - const compositeFieldVisibilityDependencies = this.visibilityRulesService.getVisibilityDependency(compositeFieldToBeCloned); - if (compositeFieldVisibilityDependencies && compositeFieldVisibilityDependencies.length) { - - compositeFieldVisibilityDependencies.forEach(x => { - const visRule: Rule = { - targetField: compositeField.id, - sourceField: x.sourceControlId, - requiredValue: x.sourceControlValue, - type: '' - } - this.visibilityRulesService.addNewRule(visRule); - }); - } - - // console.log('idMappings ', idMappings); - compositeFieldToBeCloned.fields.forEach(element => { - // console.log(this.visibilityRulesService.getVisibilityDependency(element.id)); - const dependency = this.visibilityRulesService.getVisibilityDependency(element.id); - - - - try { - - if (dependency && dependency.length) { - - // * INNER VISIBILITY DEPENDENCIES - // * IF INNER INPUT HIDES ANOTHER INNER INPUT - - const innerDependency = compositeFieldToBeCloned.fields.reduce((innerD, currentElement) => { - - const innerDependecies = dependency.filter(d => d.sourceControlId === currentElement.id); - return [...innerD, ...innerDependecies]; - }, []) as VisibilityRuleSource[]; - - if (innerDependency.length) { - //Build visibility source - const updatedRules = innerDependency.map(x => { - const newId = idMappings.find(y => y.old === x.sourceControlId); - return { ...x, sourceControlId: newId.new }; - }); - // const visRule: VisibilityRule = { - // targetControlId: idMappings.find(x => x.old === element.id).new, - // sourceVisibilityRules: updatedRules - // } - - - const rules = updatedRules.map(x => { - return { - requiredValue: x.sourceControlValue, - sourceField: x.sourceControlId, - targetField: idMappings.find(l => l.old === element.id).new, - type: '' - } as Rule; - }); - - rules.forEach(rule => { - this.visibilityRulesService.addNewRule(rule); - }) - - // this.visibilityRulesService.appendVisibilityRule(visRule); - } - - } - - - // * OUTER DEPENDENCIES - - // * IF INNER INPUT HIDES OUTER INPUTS - const innerIds = idMappings.map(x => x.old) as string[]; - - const outerTargets = this.visibilityRulesService.getVisibilityTargets(element.id).filter(x => !innerIds.includes(x)); - - outerTargets.forEach(target => { - - const outerRules = (this.visibilityRulesService.getVisibilityDependency(target) as VisibilityRuleSource[]).filter(x => x.sourceControlId === element.id); - const updatedRules = outerRules.map(x => { - return { ...x, sourceControlId: idMappings.find(y => y.old === element.id).new }; - }); - - // const visRule: VisibilityRule = { - // targetControlId: target, - // sourceVisibilityRules: updatedRules - // } - - - const rules = updatedRules.map(x => { - return { - requiredValue: x.sourceControlValue, - sourceField: x.sourceControlId, - targetField: target, - type: '' - } as Rule; - }) - - rules.forEach(rule => { - this.visibilityRulesService.addNewRule(rule); - }) - - // this.visibilityRulesService.appendVisibilityRule(visRule); - - }); - - - - - - // * IF INNER INPUT IS HIDDEN BY OUTER INPUT - - if (dependency && dependency.length) { - const fieldsThatHideInnerElement = dependency.filter(x => !innerIds.includes(x.sourceControlId)); - - if (fieldsThatHideInnerElement.length) { - fieldsThatHideInnerElement.forEach(x => { - const visRule: Rule = { - targetField: idMappings.find(l => l.old === element.id).new, - sourceField: x.sourceControlId, - requiredValue: x.sourceControlValue, - type: '' - } - const shouldBeVisibile = this.visibilityRulesService.checkTargetVisibilityProvidedBySource(x.sourceControlId, element.id); - this.visibilityRulesService.addNewRule(visRule, shouldBeVisibile); - }); - } - } - - - // console.log(`for ${element.id} targets are`, outerTargets); - } catch { - console.log('error'); - } - - }); - // console.log(this.visibilityRulesService); - // console.log(this.visibilityRulesService.getVisibilityDependency()); + this.setMultipleFieldVisibility(compositeFieldToBeCloned, compositeField, idMappings); multiplicityItemsArray.push(compositeField.buildForm()); } @@ -264,7 +265,6 @@ export class FormSectionComponent extends BaseComponent implements OnInit, OnCha // } - onAskedToScroll(id: string) { this.panelExpanded = true; this.askedToScroll.emit(id); 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 8265bbc7c..40f9bca47 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 @@ -46,7 +46,6 @@ export class VisibilityRulesService { } public updateValueAndVisibility(id: string, value: any) { - console.log('updateValueAndVisibility'); const visibilityRules = this.visibilityRuleContext.rules.filter(item => item.sourceVisibilityRules.filter(source => source.sourceControlId === id).length > 0); if (visibilityRules.length > 0) { visibilityRules.forEach(item => this.evaluateVisibility(item, value, id)); @@ -347,7 +346,7 @@ export class VisibilityRulesService { public addNewRule(rule: Rule, currentVisibility = this.DEFAULTVISIBILITY): void { const targetId = rule.targetField; const sourceId = rule.sourceField; - + console.log(rule); this.visibilityRuleContext.addToVisibilityRulesContext(rule); @@ -368,7 +367,7 @@ export class VisibilityRulesService { /** - * Check what sourceId hides or shows the target field + * Check what sourceId hides or shows the target field * return true if no rule found */ public checkTargetVisibilityProvidedBySource(sourceId: string, targetId: string): boolean {