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