fix drawing annotations after reanalisys
This commit is contained in:
parent
4e76aa43cf
commit
fa76007bca
@ -29,7 +29,7 @@ import { FileWorkloadComponent } from './components/file-workload/file-workload.
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { FilesService } from '@services/entity-services/files.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 { WatermarkService } from '@shared/services/watermark.service';
|
||||
import { ExcludedPagesService } from './services/excluded-pages.service';
|
||||
@ -210,6 +210,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
this._viewModeService.switchToStandard();
|
||||
|
||||
await this.ngOnInit();
|
||||
await this._fileDataService.loadRedactionLog();
|
||||
this._lastPage = previousRoute.queryParams.page;
|
||||
this._changeDetectorRef.markForCheck();
|
||||
}
|
||||
@ -421,10 +422,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
const documentLoaded$ = this.pdf.documentLoaded$.pipe(tap(() => this.viewerReady()));
|
||||
let start;
|
||||
return combineLatest([documentLoaded$, this._fileDataService.annotations$]).pipe(
|
||||
withLatestFrom(this.stateService.file$),
|
||||
filter(([, file]) => !file.isProcessing),
|
||||
debounceTime(300),
|
||||
tap(() => (start = new Date().getTime())),
|
||||
map(([[, annotations]]) => annotations),
|
||||
map(([, annotations]) => annotations),
|
||||
startWith({} as Record<string, AnnotationWrapper>),
|
||||
pairwise(),
|
||||
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>) {
|
||||
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];
|
||||
if (!oldAnnotation) {
|
||||
return true;
|
||||
@ -465,15 +483,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
|
||||
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() {
|
||||
@ -601,7 +610,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
this._workloadComponent?.scrollAnnotations();
|
||||
}
|
||||
|
||||
private async _cleanupAndRedrawAnnotations(newAnnotations: AnnotationWrapper[]) {
|
||||
private async _cleanupAndRedrawAnnotations(newAnnotations: readonly AnnotationWrapper[]) {
|
||||
if (!this.pdf.ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ export class AnnotationDrawService {
|
||||
private readonly _fileDataService: FileDataService,
|
||||
) {}
|
||||
|
||||
drawAnnotations(annotationWrappers: AnnotationWrapper[]) {
|
||||
drawAnnotations(annotationWrappers: readonly AnnotationWrapper[]) {
|
||||
if (!this._pdf.instance || !this._pdf.ready) {
|
||||
return;
|
||||
}
|
||||
@ -87,7 +87,7 @@ export class AnnotationDrawService {
|
||||
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();
|
||||
if (!this._pdf.ready || !document) {
|
||||
return;
|
||||
|
||||
@ -34,6 +34,10 @@ export class PdfViewer {
|
||||
return this.instance.Core.PDFNet;
|
||||
}
|
||||
|
||||
get hasAnnotations() {
|
||||
return this.annotationManager?.getAnnotationsList().length > 0 ?? false;
|
||||
}
|
||||
|
||||
get paginationOffset() {
|
||||
return this.viewModeService.isCompare ? 2 : 1;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user