move delete annotations to pdf viewer
This commit is contained in:
parent
973abdedb9
commit
f8bbc25c0d
@ -52,6 +52,7 @@ import { ManualAnnotationService } from '../../services/manual-annotation.servic
|
||||
import { DossiersService } from '../../../../services/dossiers/dossiers.service';
|
||||
import { PageRotationService } from './services/page-rotation.service';
|
||||
import { ComponentCanDeactivate } from '../../../../guards/can-deactivate.guard';
|
||||
import { PdfViewer } from './services/pdf-viewer.service';
|
||||
import Annotation = Core.Annotations.Annotation;
|
||||
import PDFNet = Core.PDFNet;
|
||||
|
||||
@ -110,9 +111,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
private readonly _errorService: ErrorService,
|
||||
private readonly _pageRotationService: PageRotationService,
|
||||
private readonly _skippedService: SkippedService,
|
||||
private readonly _pdf: PdfViewer,
|
||||
private readonly _manualAnnotationService: ManualAnnotationService,
|
||||
readonly excludedPagesService: ExcludedPagesService,
|
||||
readonly viewModeService: ViewModeService,
|
||||
private readonly _viewModeService: ViewModeService,
|
||||
readonly multiSelectService: MultiSelectService,
|
||||
readonly documentInfoService: DocumentInfoService,
|
||||
) {
|
||||
@ -131,7 +133,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
get visibleAnnotations(): AnnotationWrapper[] {
|
||||
return this._fileData ? this._fileData.getVisibleAnnotations(this.viewModeService.viewMode) : [];
|
||||
return this._fileData ? this._fileData.getVisibleAnnotations(this._viewModeService.viewMode) : [];
|
||||
}
|
||||
|
||||
get allAnnotations(): AnnotationWrapper[] {
|
||||
@ -147,7 +149,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
private get _canPerformAnnotationActions$() {
|
||||
return combineLatest([this.stateService.file$, this.viewModeService.viewMode$, this.viewModeService.compareMode$]).pipe(
|
||||
const viewMode$ = this._viewModeService.viewMode$.pipe(tap(() => this.#deactivateMultiSelect()));
|
||||
|
||||
return combineLatest([this.stateService.file$, viewMode$, this._viewModeService.compareMode$]).pipe(
|
||||
map(([file, viewMode]) => this.permissionsService.canPerformAnnotationActions(file) && viewMode === 'STANDARD'),
|
||||
shareDistinctLast(),
|
||||
);
|
||||
@ -167,16 +171,13 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
textHighlightAnnotationIds.includes(a.Id),
|
||||
);
|
||||
|
||||
this._instance.Core.annotationManager.deleteAnnotations(textHighlightAnnotations, {
|
||||
imported: true,
|
||||
force: true,
|
||||
});
|
||||
this._pdf.deleteAnnotations(textHighlightAnnotations);
|
||||
|
||||
const ocrAnnotationIds = this._fileData.allAnnotations.filter(a => a.isOCR).map(a => a.id);
|
||||
const annotations = this._getAnnotations(a => a.getCustomData('redact-manager'));
|
||||
const redactions = annotations.filter(a => a.getCustomData('redaction'));
|
||||
|
||||
switch (this.viewModeService.viewMode) {
|
||||
switch (this._viewModeService.viewMode) {
|
||||
case 'STANDARD': {
|
||||
this._setAnnotationsColor(redactions, 'annotationColor');
|
||||
const standardEntries = annotations
|
||||
@ -237,8 +238,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
if (!file.canBeOpened) {
|
||||
return this._router.navigate([this._dossiersService.find(this.dossierId)?.routerLink]);
|
||||
}
|
||||
this.viewModeService.compareMode = false;
|
||||
this.viewModeService.switchToStandard();
|
||||
this._viewModeService.compareMode = false;
|
||||
this._viewModeService.switchToStandard();
|
||||
|
||||
await this.ngOnInit();
|
||||
this._lastPage = previousRoute.queryParams.page;
|
||||
@ -250,7 +251,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
this._loadingService.start();
|
||||
await this.userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId);
|
||||
this._subscribeToFileUpdates();
|
||||
this.viewModeService.viewMode$.pipe(tap(() => this.#deactivateMultiSelect())).subscribe();
|
||||
|
||||
const file = await this.stateService.file;
|
||||
if (file?.analysisRequired && !file.excludedFromAutomaticAnalysis) {
|
||||
@ -265,14 +265,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
const startTime = new Date().getTime();
|
||||
if (deletePreviousAnnotations) {
|
||||
const annotationsToDelete = this._instance?.Core.annotationManager?.getAnnotationsList() || [];
|
||||
try {
|
||||
this._instance?.Core.annotationManager?.deleteAnnotations(annotationsToDelete, {
|
||||
imported: true,
|
||||
force: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
this._pdf.deleteAnnotations(annotationsToDelete);
|
||||
|
||||
console.log(`[REDACTION] Delete previous annotations time: ${new Date().getTime() - startTime} ms`);
|
||||
}
|
||||
const processStartTime = new Date().getTime();
|
||||
@ -342,7 +336,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
const annotation = this._instance.Core.annotationManager.getAnnotationById(
|
||||
response.manualRedactionEntryWrapper.rectId,
|
||||
);
|
||||
this._instance.Core.annotationManager.deleteAnnotation(annotation);
|
||||
this._pdf.deleteAnnotations([annotation]);
|
||||
const distinctPages = manualRedactionEntryWrapper.manualRedactionEntry.positions
|
||||
.map(p => p.page)
|
||||
.filter((item, pos, self) => self.indexOf(item) === pos);
|
||||
@ -463,7 +457,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
async switchView(viewMode: ViewMode) {
|
||||
this.viewModeService.viewMode = viewMode;
|
||||
this._viewModeService.viewMode = viewMode;
|
||||
await this.updateViewMode();
|
||||
this._scrollViews();
|
||||
}
|
||||
@ -489,7 +483,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
if (!currentPage) {
|
||||
this.activeViewerPage = 1;
|
||||
} else {
|
||||
this.activeViewerPage = this.viewModeService.isCompare
|
||||
this.activeViewerPage = this._viewModeService.isCompare
|
||||
? currentPage % 2 === 0
|
||||
? currentPage / 2
|
||||
: (currentPage + 1) / 2
|
||||
@ -523,7 +517,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
const allPages = [...Array(file.numberOfPages).keys()].map(page => page + 1);
|
||||
await clearStamps(pdfDoc, pdfNet, allPages);
|
||||
|
||||
if (this.viewModeService.isRedacted) {
|
||||
if (this._viewModeService.isRedacted) {
|
||||
const dossier = this._dossiersService.find(this.dossierId);
|
||||
if (dossier.watermarkPreviewEnabled) {
|
||||
await this._stampPreview(pdfDoc, dossier.dossierTemplateId);
|
||||
@ -653,10 +647,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
if (!annotationsToDelete) {
|
||||
this._instance.Core.annotationManager.deleteAnnotations(this._instance.Core.annotationManager.getAnnotationsList(), {
|
||||
imported: true,
|
||||
force: true,
|
||||
});
|
||||
this._pdf.deleteAnnotations();
|
||||
}
|
||||
annotationsToDelete?.forEach(annotation => {
|
||||
this._findAndDeleteAnnotation(annotation.id);
|
||||
@ -688,7 +679,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
annotations,
|
||||
this.fileId,
|
||||
this.dossierId,
|
||||
!!this.viewModeService.isCompare,
|
||||
!!this._viewModeService.isCompare,
|
||||
);
|
||||
}
|
||||
|
||||
@ -714,14 +705,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
private _findAndDeleteAnnotation(id: string) {
|
||||
const viewerAnnotation = this._instance?.Core.annotationManager.getAnnotationById(id);
|
||||
if (viewerAnnotation) {
|
||||
this._instance.Core.annotationManager.deleteAnnotation(viewerAnnotation, {
|
||||
imported: true,
|
||||
force: true,
|
||||
});
|
||||
this._pdf.deleteAnnotations([viewerAnnotation]);
|
||||
}
|
||||
}
|
||||
|
||||
/* View in fullscreen */
|
||||
private _openFullScreen() {
|
||||
const documentElement = document.documentElement;
|
||||
if (documentElement.requestFullscreen) {
|
||||
|
||||
@ -80,14 +80,6 @@ export class PdfViewer {
|
||||
}
|
||||
}
|
||||
|
||||
private get _documentViewer() {
|
||||
return this.instance?.Core.documentViewer;
|
||||
}
|
||||
|
||||
private get _annotationManager() {
|
||||
return this.instance?.Core.annotationManager;
|
||||
}
|
||||
|
||||
private get _currentInternalPage() {
|
||||
return this.instance?.Core.documentViewer?.getCurrentPage();
|
||||
}
|
||||
@ -143,12 +135,12 @@ export class PdfViewer {
|
||||
}
|
||||
|
||||
translateQuad(page: number, quad: Core.Math.Quad) {
|
||||
const rotation = this._documentViewer.getCompleteRotation(page);
|
||||
const rotation = this.documentViewer.getCompleteRotation(page);
|
||||
return translateQuads(page, rotation, quad);
|
||||
}
|
||||
|
||||
deselectAllAnnotations() {
|
||||
this._annotationManager.deselectAllAnnotations();
|
||||
this.annotationManager.deselectAllAnnotations();
|
||||
}
|
||||
|
||||
selectAnnotations(annotations?: AnnotationWrapper[], multiSelectActive: boolean = false) {
|
||||
@ -160,23 +152,34 @@ export class PdfViewer {
|
||||
}
|
||||
|
||||
const annotationsFromViewer = annotations.map(ann => this._getAnnotationById(ann.id));
|
||||
this._annotationManager.jumpToAnnotation(annotationsFromViewer[0]);
|
||||
this._annotationManager.selectAnnotations(annotationsFromViewer);
|
||||
this.annotationManager.jumpToAnnotation(annotationsFromViewer[0]);
|
||||
this.annotationManager.selectAnnotations(annotationsFromViewer);
|
||||
}
|
||||
|
||||
deleteAnnotations(annotations: Annotation[] = this.annotationManager?.getAnnotationsList() ?? []) {
|
||||
try {
|
||||
this.annotationManager.deleteAnnotations(annotations, {
|
||||
imported: true,
|
||||
force: true,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('Error while deleting annotations: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
deselectAnnotations(annotations: AnnotationWrapper[]) {
|
||||
const ann = annotations.map(a => this._getAnnotationById(a.id));
|
||||
this._annotationManager.deselectAnnotations(ann);
|
||||
this.annotationManager.deselectAnnotations(ann);
|
||||
}
|
||||
|
||||
private _navigateToPage(pageNumber: number) {
|
||||
if (this._currentInternalPage !== pageNumber) {
|
||||
this._documentViewer.displayPageLocation(pageNumber, 0, 0);
|
||||
this.documentViewer.displayPageLocation(pageNumber, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private _getAnnotationById(id: string): Annotation {
|
||||
return this._annotationManager.getAnnotationById(id);
|
||||
return this.annotationManager.getAnnotationById(id);
|
||||
}
|
||||
|
||||
#convertPath(path: string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user