From a6b0fcb191510b1d532093192ee58aff6d05deee Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 13 May 2021 15:24:45 +0300 Subject: [PATCH] show fields' content when changing mode --- .../file-preview-screen.component.ts | 70 ++++++++++--------- .../services/annotation-draw.service.ts | 1 + 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/apps/red-ui/src/app/modules/projects/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/projects/screens/file-preview-screen/file-preview-screen.component.ts index cbcd81e74..a1dd91afc 100644 --- a/apps/red-ui/src/app/modules/projects/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/projects/screens/file-preview-screen/file-preview-screen.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectorRef, Component, HostListener, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, ActivatedRouteSnapshot, Router } from '@angular/router'; import { AppStateService } from '@state/app-state.service'; -import { WebViewerInstance } from '@pdftron/webviewer'; +import { Annotations, WebViewerInstance } from '@pdftron/webviewer'; import { PdfViewerComponent } from '../../components/pdf-viewer/pdf-viewer.component'; import { debounce } from '@utils/debounce'; import { MatDialogRef, MatDialogState } from '@angular/material/dialog'; @@ -129,39 +129,31 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, } updateViewMode() { - const allAnnotations = this._instance.annotManager.getAnnotationsList(); - - const redactions = allAnnotations.filter((a) => a.getCustomData('redaction')); + const annotations = this._getAnnotations((a) => a.getCustomData('redacto-manager')); + const redactions = annotations.filter((a) => a.getCustomData('redaction')); switch (this.viewMode) { case 'STANDARD': { - const standardEntries = allAnnotations.filter((a) => !a.getCustomData('changeLogRemoved')); - const nonStandardEntries = allAnnotations.filter((a) => a.getCustomData('changeLogRemoved')); - redactions.forEach((redaction) => { - redaction['StrokeColor'] = redaction.getCustomData('annotationColor'); - }); - this._instance.annotManager.showAnnotations(standardEntries); - this._instance.annotManager.hideAnnotations(nonStandardEntries); + this._setAnnotationsColor(redactions, 'annotationColor'); + const standardEntries = annotations.filter((a) => !a.getCustomData('changeLogRemoved')); + const nonStandardEntries = annotations.filter((a) => a.getCustomData('changeLogRemoved')); + this._show(standardEntries); + this._hide(nonStandardEntries); break; } case 'DELTA': { - const changeLogEntries = allAnnotations.filter((a) => a.getCustomData('changeLog')); - const nonChangeLogEntries = allAnnotations.filter((a) => !a.getCustomData('changeLog')); - redactions.forEach((redaction) => { - redaction['StrokeColor'] = redaction.getCustomData('annotationColor'); - }); - this._instance.annotManager.showAnnotations(changeLogEntries); - this._instance.annotManager.hideAnnotations(nonChangeLogEntries); + const changeLogEntries = annotations.filter((a) => a.getCustomData('changeLog')); + const nonChangeLogEntries = annotations.filter((a) => !a.getCustomData('changeLog')); + this._setAnnotationsColor(redactions, 'annotationColor'); + this._show(changeLogEntries); + this._hide(nonChangeLogEntries); break; } case 'REDACTED': { - const redactionEntries = allAnnotations.filter((a) => a.getCustomData('redaction')); - const nonRedactionEntries = allAnnotations.filter((a) => !a.getCustomData('redaction')); - redactions.forEach((redaction) => { - redaction['StrokeColor'] = redaction.getCustomData('redactionColor'); - }); - this._instance.annotManager.showAnnotations(redactionEntries); - this._instance.annotManager.hideAnnotations(nonRedactionEntries); + const nonRedactionEntries = annotations.filter((a) => !a.getCustomData('redaction')); + this._setAnnotationsColor(redactions, 'redactionColor'); + this._show(redactions); + this._hide(nonRedactionEntries); break; } } @@ -580,12 +572,26 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, } private _handleIgnoreAnnotationsDrawing() { - const allAnnotations = this._instance.annotManager.getAnnotationsList(); - const ignoreAnnotations = allAnnotations.filter((a) => a.getCustomData('skipped')); - if (this.hideSkipped) { - this._instance.annotManager.hideAnnotations(ignoreAnnotations); - } else { - this._instance.annotManager.showAnnotations(ignoreAnnotations); - } + const ignored = this._getAnnotations((a) => a.getCustomData('skipped')); + return this.hideSkipped ? this._hide(ignored) : this._show(ignored); + } + + private _getAnnotations(predicate: (value) => unknown) { + const annotations = this._instance.annotManager.getAnnotationsList(); + return predicate ? annotations.filter(predicate) : annotations; + } + + private _hide(annotations: Annotations.Annotation[]): void { + this._instance.annotManager.hideAnnotations(annotations); + } + + private _show(annotations: Annotations.Annotation[]): void { + this._instance.annotManager.showAnnotations(annotations); + } + + private _setAnnotationsColor(annotations, customData: string) { + annotations.forEach((annotation) => { + annotation['StrokeColor'] = annotation.getCustomData(customData); + }); } } diff --git a/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts index a538707c0..ec9b5060d 100644 --- a/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts @@ -83,6 +83,7 @@ export class AnnotationDrawService { highlight.Opacity = annotationWrapper.isChangeLogRemoved ? 0.2 : 1; highlight.Hidden = annotationWrapper.isChangeLogRemoved || (hideSkipped && annotationWrapper.isSkipped) || annotationWrapper.isOCR; + highlight.setCustomData('redacto-manager', true); highlight.setCustomData('redaction', annotationWrapper.isRedacted); highlight.setCustomData('skipped', annotationWrapper.isSkipped); highlight.setCustomData('changeLog', annotationWrapper.isChangeLogEntry);