diff --git a/apps/red-ui/src/app/models/file/annotation-permissions.utils.ts b/apps/red-ui/src/app/models/file/annotation-permissions.utils.ts index 5d64803f6..fd1ff6d7c 100644 --- a/apps/red-ui/src/app/models/file/annotation-permissions.utils.ts +++ b/apps/red-ui/src/app/models/file/annotation-permissions.utils.ts @@ -32,7 +32,7 @@ export const canChangeLegalBasis = (annotation: AnnotationWrapper, canAddRedacti canAddRedaction && annotation.isRedacted && !annotation.pending; export const canRecategorizeAnnotation = (annotation: AnnotationWrapper, canRecategorize: boolean) => - canRecategorize && (annotation.isImage || annotation.HINT) && !annotation.pending; + canRecategorize && (annotation.isImage || annotation.isDictBasedHint) && !annotation.pending; export const canResizeAnnotation = (annotation: AnnotationWrapper, canAddRedaction: boolean) => canAddRedaction && diff --git a/apps/red-ui/src/app/models/file/annotation.wrapper.ts b/apps/red-ui/src/app/models/file/annotation.wrapper.ts index 996bb68c8..eeaa7c420 100644 --- a/apps/red-ui/src/app/models/file/annotation.wrapper.ts +++ b/apps/red-ui/src/app/models/file/annotation.wrapper.ts @@ -186,10 +186,6 @@ export class AnnotationWrapper implements IListable { return Math.floor(this.positions[0].height); } - get previewAnnotation() { - return this.isRedacted; - } - static fromEarmark(earmark: Earmark) { const annotationWrapper = new AnnotationWrapper(); @@ -244,27 +240,30 @@ export class AnnotationWrapper implements IListable { annotationWrapper.engines = logEntry.engines ?? []; annotationWrapper.section = logEntry.section; annotationWrapper.reference = logEntry.reference || []; - annotationWrapper.hasBeenResized = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.RESIZE && c.processed, - ); + annotationWrapper.hasBeenResized = !!logEntry.manualChanges?.find(c => c.manualRedactionType === ManualRedactionTypes.RESIZE); annotationWrapper.hasBeenRecategorized = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.RECATEGORIZE && c.processed, + c => c.manualRedactionType === ManualRedactionTypes.RECATEGORIZE, ); annotationWrapper.hasLegalBasisChanged = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.LEGAL_BASIS_CHANGE && c.processed, + c => c.manualRedactionType === ManualRedactionTypes.LEGAL_BASIS_CHANGE, ); annotationWrapper.hasBeenForcedHint = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.FORCE_HINT && c.processed, + c => c.manualRedactionType === ManualRedactionTypes.FORCE_HINT, ); annotationWrapper.hasBeenForcedRedaction = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.FORCE_REDACT && c.processed, + c => c.manualRedactionType === ManualRedactionTypes.FORCE_REDACT, ); annotationWrapper.hasBeenRemovedByManualOverride = !!logEntry.manualChanges?.find( - c => c.manualRedactionType === ManualRedactionTypes.REMOVE_LOCALLY && c.processed, + c => c.manualRedactionType === ManualRedactionTypes.REMOVE_LOCALLY, ); - this.#createContent(annotationWrapper, logEntry, isDocumine, legalBasisList); - this.#setSuperType(annotationWrapper, logEntry); + const content = this.#createContent(annotationWrapper, logEntry, isDocumine); + annotationWrapper.shortContent = this.#getShortContent(annotationWrapper, legalBasisList) || content; + annotationWrapper.content = content; + + const lastRelevantManualChange = logEntry.manualChanges?.at(-1); + annotationWrapper.pending = lastRelevantManualChange && !lastRelevantManualChange.processed; + annotationWrapper.superType = SuperTypeMapper[logEntry.entryType][logEntry.state](logEntry); annotationWrapper.superTypeLabel = annotationTypesTranslations[annotationWrapper.superType]; annotationWrapper.typeLabel = dictionary.virtual ? undefined : dictionary.label; @@ -276,18 +275,7 @@ export class AnnotationWrapper implements IListable { return annotationWrapper; } - static #setSuperType(annotationWrapper: AnnotationWrapper, logEntry: IEntityLogEntry) { - const lastRelevantManualChange = logEntry.manualChanges?.at(-1); - annotationWrapper.pending = lastRelevantManualChange && !lastRelevantManualChange.processed; - annotationWrapper.superType = SuperTypeMapper[logEntry.entryType][logEntry.state](logEntry); - } - - static #createContent( - annotationWrapper: AnnotationWrapper, - logEntry: IEntityLogEntry, - isDocumine: boolean, - legalBasisList: ILegalBasis[], - ) { + static #createContent(annotationWrapper: AnnotationWrapper, logEntry: IEntityLogEntry, isDocumine: boolean) { let content = ''; if (logEntry.matchedRule) { content += `Rule ${logEntry.matchedRule} matched${isDocumine ? ':' : ''} \n\n`; @@ -320,8 +308,7 @@ export class AnnotationWrapper implements IListable { content += `${prefix} "${logEntry.section}"`; } - annotationWrapper.shortContent = this.#getShortContent(annotationWrapper, legalBasisList) || content; - annotationWrapper.content = content; + return content; } static #getShortContent(annotationWrapper: AnnotationWrapper, legalBasisList: ILegalBasis[]) { 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 f064a2682..38eadfafe 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 @@ -1,9 +1,20 @@ -import { effect, Injectable, Signal, signal } from '@angular/core'; +import { effect, inject, Injectable, Signal, signal } from '@angular/core'; import { toObservable } from '@angular/core/rxjs-interop'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { EntitiesService, getConfig, Toaster } from '@iqser/common-ui'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; -import { ChangeType, ChangeTypes, EntryStates, File, IEntityLog, IEntityLogEntry, ViewedPage, ViewMode, ViewModes } from '@red/domain'; +import { + ChangeType, + ChangeTypes, + EntryStates, + File, + IEntityLog, + IEntityLogEntry, + SuperTypeMapper, + ViewedPage, + ViewMode, + ViewModes, +} from '@red/domain'; import { DictionaryService } from '@services/entity-services/dictionary.service'; import { EarmarksService } from '@services/files/earmarks.service'; import { FilesService } from '@services/files/files.service'; @@ -35,6 +46,8 @@ export class FileDataService extends EntitiesService>(new Map()); #originalViewedPages: ViewedPage[] = []; readonly #isDocumine = getConfig().IS_DOCUMINE; + readonly #logger = inject(NGXLogger); + readonly #toaster = inject(Toaster); protected readonly _entityClass = AnnotationWrapper; missingTypes = new Set(); readonly earmarks: Signal>; @@ -53,8 +66,6 @@ export class FileDataService extends EntitiesService !a.isFalsePositive); @@ -131,7 +142,7 @@ export class FileDataService extends EntitiesService 0) { - this._toaster.error(_('error.missing-types'), { + this.#toaster.error(_('error.missing-types'), { disableTimeOut: true, params: { missingTypes: Array.from(this.missingTypes).join(', ') }, }); @@ -142,12 +153,12 @@ export class FileDataService extends EntitiesService dict.type === entry.type); if (!dictionary && checkDictionary) { const dictionaryRequest = this._dictionaryService.loadDictionaryDataForDossierTemplate(this._state.dossierTemplateId); diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts index a5dcead27..4ce67b20c 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-draw.service.ts @@ -163,7 +163,7 @@ export class AnnotationDrawService { (hideSkipped && annotationWrapper.isSkipped) || this._annotationManager.isHidden(annotationWrapper.id); annotation.setCustomData('redact-manager', 'true'); - annotation.setCustomData('redaction', String(annotationWrapper.previewAnnotation)); + annotation.setCustomData('redaction', String(annotationWrapper.isRedacted)); annotation.setCustomData('skipped', String(annotationWrapper.isSkipped)); annotation.setCustomData('changeLog', String(annotationWrapper.isChangeLogEntry)); annotation.setCustomData('changeLogRemoved', String(annotationWrapper.isIgnored)); diff --git a/libs/red-domain/src/lib/files/super-types.ts b/libs/red-domain/src/lib/files/super-types.ts index 12091f4e9..9dbf33fae 100644 --- a/libs/red-domain/src/lib/files/super-types.ts +++ b/libs/red-domain/src/lib/files/super-types.ts @@ -14,62 +14,61 @@ export const SuperTypes = { export type SuperType = ValuesOf; -function throwWrongSuperType(entry: IEntityLogEntry): never { - console.log('throwWrongSuperType', entry); - throw new Error(`A ${entry.state} ${entry.entryType} should never be mapped to a super type`); +function wrongSuperTypeHandler(): never | undefined { + return undefined; } /** * https://knecon.atlassian.net/wiki/spaces/RED/pages/102072322/EntityLog+-+Enum+combinations */ -export const SuperTypeMapper: Record SuperType>> = { +export const SuperTypeMapper: Record SuperType | undefined>> = { [EntityTypes.ENTITY]: { [EntryStates.APPLIED]: entry => (entry.manualChanges.length ? SuperTypes.ManualRedaction : SuperTypes.Redaction), [EntryStates.SKIPPED]: () => SuperTypes.Skipped, [EntryStates.IGNORED]: () => SuperTypes.Redaction, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.HINT]: { - [EntryStates.APPLIED]: entry => (entry.manualChanges.length ? SuperTypes.ManualHint : SuperTypes.Hint), + [EntryStates.APPLIED]: wrongSuperTypeHandler, [EntryStates.SKIPPED]: entry => (entry.manualChanges.length ? SuperTypes.ManualHint : SuperTypes.Hint), [EntryStates.IGNORED]: () => SuperTypes.IgnoredHint, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.FALSE_POSITIVE]: { - [EntryStates.APPLIED]: throwWrongSuperType, - [EntryStates.SKIPPED]: throwWrongSuperType, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.APPLIED]: wrongSuperTypeHandler, + [EntryStates.SKIPPED]: wrongSuperTypeHandler, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.RECOMMENDATION]: { - [EntryStates.APPLIED]: throwWrongSuperType, + [EntryStates.APPLIED]: wrongSuperTypeHandler, [EntryStates.SKIPPED]: () => SuperTypes.Recommendation, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.FALSE_RECOMMENDATION]: { - [EntryStates.APPLIED]: throwWrongSuperType, - [EntryStates.SKIPPED]: throwWrongSuperType, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.APPLIED]: wrongSuperTypeHandler, + [EntryStates.SKIPPED]: wrongSuperTypeHandler, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.AREA]: { [EntryStates.APPLIED]: () => SuperTypes.Redaction, - [EntryStates.SKIPPED]: throwWrongSuperType, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.SKIPPED]: wrongSuperTypeHandler, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.IMAGE]: { [EntryStates.APPLIED]: () => SuperTypes.Redaction, [EntryStates.SKIPPED]: () => SuperTypes.Skipped, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, [EntityTypes.IMAGE_HINT]: { - [EntryStates.APPLIED]: throwWrongSuperType, + [EntryStates.APPLIED]: wrongSuperTypeHandler, [EntryStates.SKIPPED]: () => SuperTypes.Hint, - [EntryStates.IGNORED]: throwWrongSuperType, - [EntryStates.REMOVED]: throwWrongSuperType, + [EntryStates.IGNORED]: wrongSuperTypeHandler, + [EntryStates.REMOVED]: wrongSuperTypeHandler, }, }; diff --git a/libs/red-domain/src/lib/redaction-log/manual-change.ts b/libs/red-domain/src/lib/redaction-log/manual-change.ts index 63e95fe9a..41cb75594 100644 --- a/libs/red-domain/src/lib/redaction-log/manual-change.ts +++ b/libs/red-domain/src/lib/redaction-log/manual-change.ts @@ -1,10 +1,9 @@ -import { LogEntryStatus, ManualRedactionType } from './types'; +import { ManualRedactionType } from './types'; export interface IManualChange { userId: string; processedDate: string; requestedDate: string; - annotationStatus: LogEntryStatus; manualRedactionType: ManualRedactionType; propertyChanges: { [key: string]: any }; processed: boolean; diff --git a/libs/red-domain/src/lib/redaction-log/manual-redaction-entry.ts b/libs/red-domain/src/lib/redaction-log/manual-redaction-entry.ts index 92712e2f7..917f08cb7 100644 --- a/libs/red-domain/src/lib/redaction-log/manual-redaction-entry.ts +++ b/libs/red-domain/src/lib/redaction-log/manual-redaction-entry.ts @@ -1,5 +1,4 @@ import { IRectangle } from '../geometry'; -import { LogEntryStatus } from './types'; export interface IManualRedactionEntry { addToDictionary?: boolean; @@ -11,7 +10,6 @@ export interface IManualRedactionEntry { reason?: string; requestDate?: string; softDeletedTime?: string; - status?: LogEntryStatus; type?: string; user?: string; value?: string; diff --git a/libs/red-domain/src/lib/redaction-log/types.ts b/libs/red-domain/src/lib/redaction-log/types.ts index ff114eff4..06ce98d73 100644 --- a/libs/red-domain/src/lib/redaction-log/types.ts +++ b/libs/red-domain/src/lib/redaction-log/types.ts @@ -21,10 +21,3 @@ export const ManualRedactionTypes = { } as const; export type ManualRedactionType = ValuesOf; - -export const LogEntryStatuses = { - APPROVED: 'APPROVED', - DECLINED: 'DECLINED', -} as const; - -export type LogEntryStatus = ValuesOf;