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.entityId = data.entityId;
this.anchor = data.anchor; this.anchor = data.anchor;
this.entityType = data.entityType; 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 { ngOnInit(): void {

View File

@ -6,7 +6,7 @@
</div> </div>
<div class="col-auto"> <div class="col-auto">
<button mat-icon-button class="col-auto annotation-icon" (click)="showAnnotations(fieldSet.id)"> <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> </button>
</div> </div>
</div> </div>

View File

@ -51,6 +51,8 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
@Input() placeholderTitle: boolean = false; @Input() placeholderTitle: boolean = false;
@Input() validationErrorModel: ValidationErrorModel; @Input() validationErrorModel: ValidationErrorModel;
annotationsCount: number = 0;
constructor( constructor(
private dialog: MatDialog, private dialog: MatDialog,
private changeDetector: ChangeDetectorRef, private changeDetector: ChangeDetectorRef,
@ -60,6 +62,13 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
} }
ngOnInit() { 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 => { // this.visibilityRulesService.getElementVisibilityMapObservable().pipe(takeUntil(this._destroyed)).subscribe(x => {
// // console.log('getElementVisibilityMapObservable form field'); // // console.log('getElementVisibilityMapObservable form field');
// if (x[this.fieldSet.id]) { // if (x[this.fieldSet.id]) {
@ -138,9 +147,7 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
}); });
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(changesMade => { dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(changesMade => {
if (changesMade) { if (changesMade) {
this.descriptionFormAnnotationService.refreshAnnotations(() => { this.descriptionFormAnnotationService.refreshAnnotations();
this.changeDetector.markForCheck();
});
} }
}); });
} }

View File

@ -7,6 +7,7 @@ import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/serv
import { BaseService } from '@common/base/base.service'; import { BaseService } from '@common/base/base.service';
import { Guid } from '@common/types/guid'; import { Guid } from '@common/types/guid';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof'; import { nameof } from 'ts-simple-nameof';
@ -18,6 +19,7 @@ export class DescriptionFormAnnotationService extends BaseService {
private entityId: Guid; private entityId: Guid;
private annotationsPerAnchor: Map<string, number>; private annotationsPerAnchor: Map<string, number>;
private annotationCountSubject: BehaviorSubject<Map<string, number>> = new BehaviorSubject<Map<string, number>>(null);
constructor( constructor(
private annotationService: AnnotationService, private annotationService: AnnotationService,
@ -32,15 +34,11 @@ export class DescriptionFormAnnotationService extends BaseService {
this.refreshAnnotations(); this.refreshAnnotations();
} }
public getCount(anchor: string) { public getAnnotationCountObservable(): Observable<Map<string, number>> {
if (this.annotationsPerAnchor?.has(anchor)) { return this.annotationCountSubject.asObservable();
return this.annotationsPerAnchor.get(anchor);
} else {
return 0;
}
} }
public refreshAnnotations(onSuccess?: () => void) { public refreshAnnotations() {
const lookup: AnnotationLookup = new AnnotationLookup(); const lookup: AnnotationLookup = new AnnotationLookup();
lookup.entityIds = [this.entityId]; lookup.entityIds = [this.entityId];
lookup.entityTypes = [AnnotationEntityType.Description]; lookup.entityTypes = [AnnotationEntityType.Description];
@ -62,7 +60,7 @@ export class DescriptionFormAnnotationService extends BaseService {
} }
this.annotationsPerAnchor.set(item.anchor, this.annotationsPerAnchor.get(item.anchor) + 1); this.annotationsPerAnchor.set(item.anchor, this.annotationsPerAnchor.get(item.anchor) + 1);
} }
onSuccess ? onSuccess() : null; this.annotationCountSubject.next(this.annotationsPerAnchor);
}, },
error => this.onCallbackError(error), error => this.onCallbackError(error),
); );