From 9317f55d819c24f098f92c7677a5b47c507879e9 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 19 Aug 2024 12:01:09 +0300 Subject: [PATCH] fix delete annotation --- .../annotation-actions.component.ts | 30 +++++++++---------- .../services/file-data.service.ts | 12 ++++++-- .../services/annotation-manager.service.ts | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts index 3e2b3f822..8c27eee07 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts @@ -1,7 +1,9 @@ +import { AsyncPipe, NgIf } from '@angular/common'; import { Component, computed, Input, OnChanges } from '@angular/core'; import { CircleButtonComponent, getConfig, HelpModeService, IqserAllowDirective, IqserPermissionsService } from '@iqser/common-ui'; import { AnnotationPermissions } from '@models/file/annotation.permissions'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; +import { TranslateModule } from '@ngx-translate/core'; import { PermissionsService } from '@services/permissions.service'; import { Roles } from '@users/roles'; import { REDAnnotationManager } from '../../../pdf-viewer/services/annotation-manager.service'; @@ -9,10 +11,8 @@ import { AnnotationActionsService } from '../../services/annotation-actions.serv import { AnnotationReferencesService } from '../../services/annotation-references.service'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; import { MultiSelectService } from '../../services/multi-select.service'; -import { ViewModeService } from '../../services/view-mode.service'; import { SkippedService } from '../../services/skipped.service'; -import { AsyncPipe, NgIf } from '@angular/common'; -import { TranslateModule } from '@ngx-translate/core'; +import { ViewModeService } from '../../services/view-mode.service'; export const AnnotationButtonTypes = { default: 'default', @@ -62,10 +62,6 @@ export class AnnotationActionsComponent implements OnChanges { return this.#annotations; } - get isImageHint(): boolean { - return this.annotations.every(annotation => annotation.IMAGE_HINT); - } - @Input() set annotations(annotations: AnnotationWrapper[]) { this.#annotations = annotations.filter(a => a !== undefined); @@ -73,6 +69,10 @@ export class AnnotationActionsComponent implements OnChanges { this._annotationId = this.#annotations[0]?.id; } + get isImageHint(): boolean { + return this.annotations.every(annotation => annotation.IMAGE_HINT); + } + get canEdit(): boolean { const canEditRedactions = this.annotationPermissions.canChangeLegalBasis || @@ -132,6 +132,14 @@ export class AnnotationActionsComponent implements OnChanges { return this.annotations.every(a => a.superType === type); } + get #annotationChangesAllowed() { + return (!this.#isDocumine || !this._state.file().excludedFromAutomaticAnalysis) && !this.#somePending; + } + + get #somePending() { + return this.#annotations.some(a => a.pending); + } + ngOnChanges(): void { this.#setPermissions(); } @@ -183,12 +191,4 @@ export class AnnotationActionsComponent implements OnChanges { this._state.file().excludedFromAutomaticAnalysis, ); } - - get #annotationChangesAllowed() { - return (!this.#isDocumine || !this._state.file().excludedFromAutomaticAnalysis) && !this.#somePending; - } - - get #somePending() { - return this.#annotations.some(a => a.pending); - } } diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index 423fba710..99a98fe76 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -75,7 +75,14 @@ export class FileDataService extends EntitiesService(JSON.parse(localStorage.getItem(localStorageKey) || '[]')); + const storedAnnotations = JSON.parse(localStorage.getItem(localStorageKey) || '[]') as []; + this.#annotations = signal( + storedAnnotations.map(a => { + const newAnn = new AnnotationWrapper(); + Object.assign(newAnn, a); + return newAnn; + }), + ); this.annotations$ = toObservable(this.#annotations); this.annotations = this.#annotations.asReadonly(); this.earmarks = this.#earmarks.asReadonly(); @@ -226,7 +233,8 @@ export class FileDataService extends EntitiesService) { + annotations = annotations ?? []; return annotations.map((item: string | AnnotationWrapper) => this.#getById(item)).filter(a => !!a); }