fix drawing annotations after reanalisys

This commit is contained in:
Dan Percic 2022-03-18 16:36:43 +02:00
parent 4e76aa43cf
commit fa76007bca
3 changed files with 30 additions and 17 deletions

View File

@ -29,7 +29,7 @@ import { FileWorkloadComponent } from './components/file-workload/file-workload.
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { FilesService } from '@services/entity-services/files.service'; import { FilesService } from '@services/entity-services/files.service';
import { FileManagementService } from '@services/entity-services/file-management.service'; import { FileManagementService } from '@services/entity-services/file-management.service';
import { catchError, filter, map, startWith, switchMap, tap, withLatestFrom } from 'rxjs/operators'; import { catchError, debounceTime, map, startWith, switchMap, tap } from 'rxjs/operators';
import { FilesMapService } from '@services/entity-services/files-map.service'; import { FilesMapService } from '@services/entity-services/files-map.service';
import { WatermarkService } from '@shared/services/watermark.service'; import { WatermarkService } from '@shared/services/watermark.service';
import { ExcludedPagesService } from './services/excluded-pages.service'; import { ExcludedPagesService } from './services/excluded-pages.service';
@ -210,6 +210,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
this._viewModeService.switchToStandard(); this._viewModeService.switchToStandard();
await this.ngOnInit(); await this.ngOnInit();
await this._fileDataService.loadRedactionLog();
this._lastPage = previousRoute.queryParams.page; this._lastPage = previousRoute.queryParams.page;
this._changeDetectorRef.markForCheck(); this._changeDetectorRef.markForCheck();
} }
@ -421,10 +422,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
const documentLoaded$ = this.pdf.documentLoaded$.pipe(tap(() => this.viewerReady())); const documentLoaded$ = this.pdf.documentLoaded$.pipe(tap(() => this.viewerReady()));
let start; let start;
return combineLatest([documentLoaded$, this._fileDataService.annotations$]).pipe( return combineLatest([documentLoaded$, this._fileDataService.annotations$]).pipe(
withLatestFrom(this.stateService.file$), debounceTime(300),
filter(([, file]) => !file.isProcessing),
tap(() => (start = new Date().getTime())), tap(() => (start = new Date().getTime())),
map(([[, annotations]]) => annotations), map(([, annotations]) => annotations),
startWith({} as Record<string, AnnotationWrapper>), startWith({} as Record<string, AnnotationWrapper>),
pairwise(), pairwise(),
tap(annotations => this.deleteAnnotations(...annotations)), tap(annotations => this.deleteAnnotations(...annotations)),
@ -446,7 +446,25 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
} }
drawChangedAnnotations(oldAnnotations: Record<string, AnnotationWrapper>, newAnnotations: Record<string, AnnotationWrapper>) { drawChangedAnnotations(oldAnnotations: Record<string, AnnotationWrapper>, newAnnotations: Record<string, AnnotationWrapper>) {
const annotationsToDraw = Object.values(newAnnotations).filter(newAnnotation => { let annotationsToDraw: readonly AnnotationWrapper[];
if (this.pdf.hasAnnotations) {
annotationsToDraw = this.#getAnnotationsToDraw(newAnnotations, oldAnnotations);
} else {
annotationsToDraw = Object.values(newAnnotations);
}
if (annotationsToDraw.length === 0) {
return firstValueFrom(of({}));
}
console.log('%c [ANNOTATIONS] To draw: ', 'color: aqua', annotationsToDraw);
const annotationsToDrawIds = annotationsToDraw.map(a => a.annotationId);
this.pdf.deleteAnnotations(annotationsToDrawIds);
return this._cleanupAndRedrawAnnotations(annotationsToDraw);
}
#getAnnotationsToDraw(newAnnotations: Record<string, AnnotationWrapper>, oldAnnotations: Record<string, AnnotationWrapper>) {
return Object.values(newAnnotations).filter(newAnnotation => {
const oldAnnotation = oldAnnotations[newAnnotation.id]; const oldAnnotation = oldAnnotations[newAnnotation.id];
if (!oldAnnotation) { if (!oldAnnotation) {
return true; return true;
@ -465,15 +483,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
return changed; return changed;
}); });
if (annotationsToDraw.length === 0) {
return firstValueFrom(of({}));
}
console.log('%c [ANNOTATIONS] To draw: ', 'color: aqua', annotationsToDraw);
const annotationsToDrawIds = annotationsToDraw.map(a => a.annotationId);
this.pdf.deleteAnnotations(annotationsToDrawIds);
return this._cleanupAndRedrawAnnotations(annotationsToDraw);
} }
async #deactivateMultiSelect() { async #deactivateMultiSelect() {
@ -601,7 +610,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
this._workloadComponent?.scrollAnnotations(); this._workloadComponent?.scrollAnnotations();
} }
private async _cleanupAndRedrawAnnotations(newAnnotations: AnnotationWrapper[]) { private async _cleanupAndRedrawAnnotations(newAnnotations: readonly AnnotationWrapper[]) {
if (!this.pdf.ready) { if (!this.pdf.ready) {
return; return;
} }

View File

@ -35,7 +35,7 @@ export class AnnotationDrawService {
private readonly _fileDataService: FileDataService, private readonly _fileDataService: FileDataService,
) {} ) {}
drawAnnotations(annotationWrappers: AnnotationWrapper[]) { drawAnnotations(annotationWrappers: readonly AnnotationWrapper[]) {
if (!this._pdf.instance || !this._pdf.ready) { if (!this._pdf.instance || !this._pdf.ready) {
return; return;
} }
@ -87,7 +87,7 @@ export class AnnotationDrawService {
return new this._pdf.instance.Core.Math.Quad(x1, y1, x2, y2, x3, y3, x4, y4); return new this._pdf.instance.Core.Math.Quad(x1, y1, x2, y2, x3, y3, x4, y4);
} }
private async _drawAnnotations(annotationWrappers: AnnotationWrapper[]) { private async _drawAnnotations(annotationWrappers: readonly AnnotationWrapper[]) {
const document = await this._pdf.documentViewer.getDocument()?.getPDFDoc(); const document = await this._pdf.documentViewer.getDocument()?.getPDFDoc();
if (!this._pdf.ready || !document) { if (!this._pdf.ready || !document) {
return; return;

View File

@ -34,6 +34,10 @@ export class PdfViewer {
return this.instance.Core.PDFNet; return this.instance.Core.PDFNet;
} }
get hasAnnotations() {
return this.annotationManager?.getAnnotationsList().length > 0 ?? false;
}
get paginationOffset() { get paginationOffset() {
return this.viewModeService.isCompare ? 2 : 1; return this.viewModeService.isCompare ? 2 : 1;
} }