move constants

This commit is contained in:
Dan Percic 2022-03-16 11:33:32 +02:00
parent 9c5bf9082e
commit ee6f8dab02
4 changed files with 55 additions and 75 deletions

View File

@ -7,9 +7,9 @@ import { tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class TextHighlightService extends GenericService<unknown> {
export class TextHighlightService extends GenericService<TextHighlightResponse> {
constructor(protected readonly _injector: Injector, private readonly _toaster: Toaster) {
super(_injector, '');
super(_injector, 'texthighlights-conversion');
}
@Validate()
@ -20,7 +20,7 @@ export class TextHighlightService extends GenericService<unknown> {
operation: TextHighlightOperation.INFO,
};
return this._post<TextHighlightResponse>(request, 'texthighlights-conversion');
return this._post(request);
}
@Validate()
@ -31,10 +31,6 @@ export class TextHighlightService extends GenericService<unknown> {
@RequiredParam() operation: TextHighlightOperation,
) {
const request: TextHighlightRequest = { dossierId, fileId, colors, operation };
return this._post<TextHighlightResponse>(request, 'texthighlights-conversion').pipe(
tap(() => {
this._toaster.success(_('highlight-action-dialog.success'), { params: { operation } });
}),
);
return this._post(request).pipe(tap(() => this._toaster.success(_('highlight-action-dialog.success'), { params: { operation } })));
}
}

View File

@ -49,11 +49,10 @@ import { ComponentCanDeactivate } from '../../guards/can-deactivate.guard';
import { PdfViewer } from './services/pdf-viewer.service';
import { FilePreviewDialogService } from './services/file-preview-dialog.service';
import { FileDataService } from './services/file-data.service';
import { ALL_HOTKEYS } from './shared/constants';
import Annotation = Core.Annotations.Annotation;
import PDFNet = Core.PDFNet;
const ALL_HOTKEY_ARRAY = ['Escape', 'F', 'f', 'ArrowUp', 'ArrowDown'];
@Component({
templateUrl: './file-preview-screen.component.html',
styleUrls: ['./file-preview-screen.component.scss'],
@ -155,12 +154,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
return;
}
const textHighlightAnnotationIds = this._fileDataService.textHighlightAnnotations.map(a => a.id);
const textHighlightAnnotations = this._pdf.getAnnotations((a: Core.Annotations.Annotation) =>
textHighlightAnnotationIds.includes(a.Id),
);
this._pdf.deleteAnnotations(textHighlightAnnotations);
this._pdf.deleteAnnotations(this._fileDataService.textHighlightAnnotations.map(a => a.id));
const ocrAnnotationIds = this.allAnnotations.filter(a => a.isOCR).map(a => a.id);
const annotations = this._pdf.getAnnotations(a => a.getCustomData('redact-manager'));
@ -317,8 +311,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
const response = new ManualAnnotationResponse(entryWrapper, addAnnotationResponse);
if (response?.annotationId) {
const annotation = this._pdf.annotationManager.getAnnotationById(response.manualRedactionEntryWrapper.rectId);
this._pdf.deleteAnnotations([annotation]);
this._pdf.deleteAnnotations([response.manualRedactionEntryWrapper.rectId]);
const distinctPages = manualRedactionEntryWrapper.manualRedactionEntry.positions
.map(p => p.page)
.filter((item, pos, self) => self.indexOf(item) === pos);
@ -355,7 +348,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
return;
}
if (!ALL_HOTKEY_ARRAY.includes($event.key) || this.dialogRef?.getState() === MatDialogState.OPEN) {
if (!ALL_HOTKEYS.includes($event.key) || this.dialogRef?.getState() === MatDialogState.OPEN) {
return;
}
@ -599,7 +592,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
console.log('skip reloading annotations');
return;
}
this._deleteAnnotations();
this._pdf.deleteAnnotations();
await this._cleanupAndRedrawAnnotations();
await this.updateViewMode();
}
@ -615,23 +608,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
const currentPageAnnotations = this.visibleAnnotations.filter(a => a.pageNumber === page);
await this._fileDataService.loadRedactionLog();
this._deleteAnnotations(currentPageAnnotations);
this._pdf.deleteAnnotations(currentPageAnnotations.map(a => a.id));
await this._cleanupAndRedrawAnnotations(annotation => annotation.pageNumber === page);
}
private _deleteAnnotations(annotationsToDelete?: AnnotationWrapper[]) {
if (!this._pdf.ready) {
return;
}
if (!annotationsToDelete) {
this._pdf.deleteAnnotations();
}
annotationsToDelete?.forEach(annotation => {
this._findAndDeleteAnnotation(annotation.id);
});
}
private async _cleanupAndRedrawAnnotations(newAnnotationsFilter?: (annotation: AnnotationWrapper) => boolean) {
if (!this._pdf.ready) {
return;
@ -671,13 +651,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
});
}
private _findAndDeleteAnnotation(id: string) {
const viewerAnnotation = this._pdf.annotationManager.getAnnotationById(id);
if (viewerAnnotation) {
this._pdf.deleteAnnotations([viewerAnnotation]);
}
}
private _openFullScreen() {
const documentElement = document.documentElement;
if (documentElement.requestFullscreen) {

View File

@ -6,43 +6,11 @@ import { File } from '@red/domain';
import { Inject, Injectable } from '@angular/core';
import { BASE_HREF } from '../../../tokens';
import { environment } from '@environments/environment';
import { DISABLED_HOTKEYS } from '../shared/constants';
import Annotation = Core.Annotations.Annotation;
import DocumentViewer = Core.DocumentViewer;
import AnnotationManager = Core.AnnotationManager;
const DISABLED_HOTKEYS = [
'CTRL+SHIFT+EQUAL',
'COMMAND+SHIFT+EQUAL',
'CTRL+SHIFT+MINUS',
'COMMAND+SHIFT+MINUS',
'CTRL+V',
'COMMAND+V',
'CTRL+Y',
'COMMAND+Y',
'CTRL+O',
'COMMAND+O',
'CTRL+P',
'COMMAND+P',
'SPACE',
'UP',
'DOWN',
'R',
'P',
'A',
'C',
'E',
'I',
'L',
'N',
'O',
'T',
'S',
'G',
'H',
'K',
'U',
] as const;
@Injectable()
export class PdfViewer {
ready = false;
@ -187,11 +155,18 @@ export class PdfViewer {
this.annotationManager.selectAnnotations(annotationsFromViewer);
}
deleteAnnotations(annotations: Annotation[] = this.getAnnotations()) {
deleteAnnotations(annotationsIds?: readonly string[]) {
if (!this.ready) {
return;
}
let annotations: Annotation[];
if (!annotationsIds) {
annotations = this.getAnnotations();
} else {
annotations = this.getAnnotationsById(annotationsIds);
}
try {
this.annotationManager.deleteAnnotations(annotations, {
imported: true,

View File

@ -1,4 +1,7 @@
export const ALLOWED_KEYBOARD_SHORTCUTS: readonly string[] = ['+', '-', 'p', 'r', 'Escape'] as const;
export const ALL_HOTKEYS = ['Escape', 'F', 'f', 'ArrowUp', 'ArrowDown'];
export const HeaderElements = {
SHAPE_TOOL_GROUP_BUTTON: 'shapeToolGroupButton',
ROTATE_LEFT_BUTTON: 'rotateLeftButton',
@ -17,3 +20,36 @@ export const TextPopups = {
ADD_RECTANGLE: 'add-rectangle',
ADD_FALSE_POSITIVE: 'add-false-positive',
} as const;
export const DISABLED_HOTKEYS = [
'CTRL+SHIFT+EQUAL',
'COMMAND+SHIFT+EQUAL',
'CTRL+SHIFT+MINUS',
'COMMAND+SHIFT+MINUS',
'CTRL+V',
'COMMAND+V',
'CTRL+Y',
'COMMAND+Y',
'CTRL+O',
'COMMAND+O',
'CTRL+P',
'COMMAND+P',
'SPACE',
'UP',
'DOWN',
'R',
'P',
'A',
'C',
'E',
'I',
'L',
'N',
'O',
'T',
'S',
'G',
'H',
'K',
'U',
] as const;