From d59676d6dcd0a6b29a78f23d8adade18a96852f3 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Mon, 8 Apr 2024 14:19:42 +0300 Subject: [PATCH] annotation fixes --- .../annotation-dialog.component.ts | 2 +- .../form-field-set/form-field-set.component.html | 2 +- .../form-field-set/form-field-set.component.ts | 13 ++++++++++--- .../description-form-annotation.service.ts | 14 ++++++-------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts index 7025fcb82..8191bb871 100644 --- a/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts +++ b/dmp-frontend/src/app/ui/annotations/annotation-dialog-component/annotation-dialog.component.ts @@ -59,7 +59,7 @@ export class AnnotationDialogComponent extends BaseComponent { this.entityId = data.entityId; this.anchor = data.anchor; this.entityType = data.entityType; - dialogRef.beforeClosed().pipe(takeUntil(this._destroyed)).subscribe(() => dialogRef.close(this.changesMade)); + dialogRef.backdropClick().pipe(takeUntil(this._destroyed)).subscribe(() => dialogRef.close(this.changesMade)); } ngOnInit(): void { diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html index d8bb4fb03..6ba49efd2 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html @@ -6,7 +6,7 @@
diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts index 452315966..063435ee4 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts @@ -51,6 +51,8 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { @Input() placeholderTitle: boolean = false; @Input() validationErrorModel: ValidationErrorModel; + annotationsCount: number = 0; + constructor( private dialog: MatDialog, private changeDetector: ChangeDetectorRef, @@ -60,6 +62,13 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { } ngOnInit() { + this.descriptionFormAnnotationService.getAnnotationCountObservable().pipe(takeUntil(this._destroyed)).subscribe((annotationsPerAnchor: Map) => { + const newCount = annotationsPerAnchor?.has(this.fieldSet.id) ? annotationsPerAnchor.get(this.fieldSet.id) : 0; + if (newCount != this.annotationsCount) { + this.annotationsCount = newCount; + this.changeDetector.markForCheck(); + } + }); // this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => { // // console.log('getElementVisibilityMapObservable form field'); // if (x[this.fieldSet.id]) { @@ -138,9 +147,7 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { }); dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(changesMade => { if (changesMade) { - this.descriptionFormAnnotationService.refreshAnnotations(() => { - this.changeDetector.markForCheck(); - }); + this.descriptionFormAnnotationService.refreshAnnotations(); } }); } diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/description-form-annotation.service.ts b/dmp-frontend/src/app/ui/description/editor/description-form/description-form-annotation.service.ts index 3ce850251..0cdc17ff8 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/description-form-annotation.service.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/description-form-annotation.service.ts @@ -7,6 +7,7 @@ import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/serv import { BaseService } from '@common/base/base.service'; import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; +import { BehaviorSubject, Observable } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { nameof } from 'ts-simple-nameof'; @@ -18,6 +19,7 @@ export class DescriptionFormAnnotationService extends BaseService { private entityId: Guid; private annotationsPerAnchor: Map; + private annotationCountSubject: BehaviorSubject> = new BehaviorSubject>(null); constructor( private annotationService: AnnotationService, @@ -32,15 +34,11 @@ export class DescriptionFormAnnotationService extends BaseService { this.refreshAnnotations(); } - public getCount(anchor: string) { - if (this.annotationsPerAnchor?.has(anchor)) { - return this.annotationsPerAnchor.get(anchor); - } else { - return 0; - } + public getAnnotationCountObservable(): Observable> { + return this.annotationCountSubject.asObservable(); } - public refreshAnnotations(onSuccess?: () => void) { + public refreshAnnotations() { const lookup: AnnotationLookup = new AnnotationLookup(); lookup.entityIds = [this.entityId]; lookup.entityTypes = [AnnotationEntityType.Description]; @@ -62,7 +60,7 @@ export class DescriptionFormAnnotationService extends BaseService { } this.annotationsPerAnchor.set(item.anchor, this.annotationsPerAnchor.get(item.anchor) + 1); } - onSuccess ? onSuccess() : null; + this.annotationCountSubject.next(this.annotationsPerAnchor); }, error => this.onCallbackError(error), );