annotation fixes

This commit is contained in:
Diamantis Tziotzios 2024-04-08 14:19:42 +03:00
parent fad3448e3e
commit d59676d6dc
4 changed files with 18 additions and 13 deletions

View File

@ -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 {

View File

@ -6,7 +6,7 @@
</div>
<div class="col-auto">
<button mat-icon-button class="col-auto annotation-icon" (click)="showAnnotations(fieldSet.id)">
<mat-icon matTooltip="{{'DATASET-EDITOR.QUESTION.EXTENDED-DESCRIPTION.ANNOTATIONS' | translate}}" [matBadge]="descriptionFormAnnotationService.getCount(fieldSet.id)" [matBadgeHidden]="descriptionFormAnnotationService.getCount(fieldSet.id) <= 0" matBadgeColor="warn">comment</mat-icon>
<mat-icon matTooltip="{{'DATASET-EDITOR.QUESTION.EXTENDED-DESCRIPTION.ANNOTATIONS' | translate}}" [matBadge]="annotationsCount" [matBadgeHidden]="annotationsCount <= 0" matBadgeColor="warn">comment</mat-icon>
</button>
</div>
</div>

View File

@ -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<string, number>) => {
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();
}
});
}

View File

@ -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<string, number>;
private annotationCountSubject: BehaviorSubject<Map<string, number>> = new BehaviorSubject<Map<string, number>>(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<Map<string, number>> {
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),
);