dependency field fix

This commit is contained in:
Efstratios Giannopoulos 2024-04-18 12:20:05 +03:00
parent ed96403d25
commit ef016f5419
3 changed files with 40 additions and 20 deletions

View File

@ -611,7 +611,7 @@ public class DescriptionServiceImpl implements DescriptionService {
Map<String, List<UUID>> fieldToReferenceMap = new HashMap<>();
List<DescriptionReferenceEntity> descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(descriptionId).collect();
List<DescriptionReferenceEntity> descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).isActive(IsActive.Active).descriptionIds(descriptionId).collect();
Map<UUID, List<DescriptionReferenceEntity>> descriptionReferenceEntityByReferenceId = new HashMap<>();
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferences){
List<DescriptionReferenceEntity> descriptionReferenceEntities = descriptionReferenceEntityByReferenceId.getOrDefault(descriptionReferenceEntity.getReferenceId(), null);

View File

@ -767,7 +767,7 @@ public class DmpServiceImpl implements DmpService {
private void patchAndSaveReferences(List<DmpReferencePersist> models, UUID dmpId, eu.eudat.commons.types.dmpblueprint.DefinitionEntity blueprintDefinition) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>();
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(dmpId).collect();
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(dmpId).isActives(IsActive.Active).collect();
Map<UUID, List<DmpReferenceEntity>> dmpReferenceEntityByReferenceId = new HashMap<>();
for (DmpReferenceEntity dmpReferenceEntity : dmpReferences){
List<DmpReferenceEntity> dmpReferenceEntities = dmpReferenceEntityByReferenceId.getOrDefault(dmpReferenceEntity.getReferenceId(), null);

View File

@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ReferenceType } from '@app/core/model/reference-type/reference-type';
@ -13,13 +13,14 @@ import { Reference, ReferencePersist } from '@app/core/model/reference/reference
import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup';
import { Guid } from '@common/types/guid';
import { nameof } from 'ts-simple-nameof';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-reference-field-component',
templateUrl: 'reference-field.component.html',
styleUrls: ['./reference-field.component.scss']
})
export class ReferenceFieldComponent extends BaseComponent implements OnInit {
export class ReferenceFieldComponent extends BaseComponent implements OnInit, OnChanges {
@Input() referenceType: ReferenceType = null;
@Input() form: UntypedFormGroup = null;
@ -31,11 +32,13 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
@Input() dependencies: UntypedFormGroup = null;
referenceToUse: Reference[]= [];
referenceToUseInitialized = false;
referenceDepedencyIds: Guid[] = [];
multipleAutoCompleteSearchConfiguration: MultipleAutoCompleteConfiguration;
singleAutoCompleteSearchConfiguration: SingleAutoCompleteConfiguration;
dependenciesSubscription: Subscription = null;
constructor(
private referenceService: ReferenceService,
public enumUtils: EnumUtils,
@ -43,13 +46,9 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
) { super(); }
ngOnInit() {
const referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id);
if (referenceDepedencyIds.length > 0) {
this.referenceToUseInitialized = false;
this.dependencies.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(changes => {
this.resolveReferenceDepedency(referenceDepedencyIds);
});
this.resolveReferenceDepedency(referenceDepedencyIds);
this.referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id);
if (this.referenceDepedencyIds.length > 0) {
this.resolveReferenceDepedency(true);
} else {
if (this.multiple) {
this.multipleAutoCompleteSearchConfiguration = this.referenceService.getMultipleAutoCompleteSearchConfiguration(this.referenceType.id, null);
@ -59,7 +58,20 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
}
}
resolveReferenceDepedency(referenceDepedencyIds: Guid[]) {
ngOnChanges(changes: SimpleChanges) {
if ((changes['dependencies'] || changes['referenceType']) && this.dependencies != null && this.referenceType != null) {
this.referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id);
if (this.referenceDepedencyIds.length > 0) {
if (this.dependenciesSubscription != null) this.dependenciesSubscription.unsubscribe();
this.resolveReferenceDepedency(true);
this.dependenciesSubscription = this.dependencies.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(changes => {
this.resolveReferenceDepedency(false);
});
}
}
}
resolveReferenceDepedency(isInitial: boolean) {
const referenceToUse : Reference[]= [];
Object.keys(this.dependencies.controls).forEach(controlName => {
// (this.dependencies.get(controlName).get('references').value as Reference[]).filter(x=> sourcesWithDependencies.some(y => y.referenceTypeDependencies) x.type.id == this.referenceType.id &&)
@ -67,7 +79,7 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
if (foudReferences != null) {
for (let i = 0; i < foudReferences.length; i++) {
const foudReference = foudReferences[i];
if (foudReference?.typeId && referenceDepedencyIds.includes(foudReference.typeId)) {
if (foudReference?.typeId && this.referenceDepedencyIds.includes(foudReference.typeId)) {
const typed = foudReference as ReferencePersist;
referenceToUse.push({
@ -84,20 +96,28 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
id: typed.typeId,
}
})
} else if (foudReference?.type?.id && referenceDepedencyIds.includes(foudReference.type.id)) {
} else if (foudReference?.type?.id && this.referenceDepedencyIds.includes(foudReference.type.id)) {
const typed = foudReference as Reference;
if (typed != null) referenceToUse.push(typed);
}
}
}
});
if (this.referenceToUseInitialized && (!referenceToUse.map(x => x.reference).every(x => this.referenceToUse.map(y => y.reference).includes(x)) ||
if (!isInitial && (!referenceToUse.map(x => x.reference).every(x => this.referenceToUse.map(y => y.reference).includes(x)) ||
!this.referenceToUse.map(x => x.reference).every(x => referenceToUse.map(y => y.reference).includes(x)))) {
this.form.setValue(null, {onlySelf: true, emitEvent: false});
}
this.referenceToUse = referenceToUse;
this.referenceToUseInitialized = true;
this.form.setValue([]);
this.form.updateValueAndValidity();
} else {
this.referenceToUse = referenceToUse;
}
// if (this.referenceToUseInitialized && (!referenceToUse.map(x => x.reference).every(x => this.referenceToUse.map(y => y.reference).includes(x)) ||
// !this.referenceToUse.map(x => x.reference).every(x => referenceToUse.map(y => y.reference).includes(x)))) {
// this.form.setValue(null, {onlySelf: true, emitEvent: false});
// }
// this.referenceToUse = referenceToUse;
// this.referenceToUseInitialized = true;
if (this.multiple) {
this.multipleAutoCompleteSearchConfiguration = this.referenceService.getMultipleAutoCompleteSearchConfiguration(this.referenceType.id, this.referenceToUse);