From 94839668a474308f6224f7e39082c92302db844e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 20 Apr 2022 16:25:34 +0300 Subject: [PATCH] RED-3224 fix --- .../annotation-actions.component.ts | 8 ++++---- .../file-workload/file-workload.component.ts | 4 ++-- .../page-exclusion/page-exclusion.component.ts | 4 ++-- .../page-indicator/page-indicator.component.ts | 8 ++++---- .../pdf-viewer/pdf-viewer.component.ts | 16 ++++++++-------- .../file-preview-screen.component.ts | 10 +++++----- .../services/annotation-actions.service.ts | 8 ++++++-- .../file-preview/services/file-data.service.ts | 2 +- .../services/file-preview-state.service.ts | 17 ++++++----------- .../file-preview/services/stamp.service.ts | 4 ++-- .../services/viewer-header-config.service.ts | 2 +- 11 files changed, 41 insertions(+), 42 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts index 4ec11bb2a..706020c4b 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.ts @@ -86,8 +86,8 @@ export class AnnotationActionsComponent implements OnChanges { return this.annotations[0]?.typeLabel?.split('.')[1]; } - async ngOnChanges(): Promise { - await this._setPermissions(); + ngOnChanges(): void { + this._setPermissions(); this._changeRef.markForCheck(); } @@ -130,8 +130,8 @@ export class AnnotationActionsComponent implements OnChanges { return this.annotationActionsService.cancelResize($event, this.annotations[0]); } - private async _setPermissions() { - const dossier = await this._state.dossier; + private _setPermissions() { + const dossier = this._state.dossier; this.annotationPermissions = AnnotationPermissions.forUser( this._permissionsService.isApprover(dossier), this._userService.currentUser, diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts index de7a3d0ac..d5a978496 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts @@ -25,7 +25,7 @@ import { shareDistinctLast, shareLast, } from '@iqser/common-ui'; -import { combineLatest, Observable } from 'rxjs'; +import { combineLatest, firstValueFrom, Observable } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { File } from '@red/domain'; import { ExcludedPagesService } from '../../services/excluded-pages.service'; @@ -252,7 +252,7 @@ export class FileWorkloadComponent { } scrollQuickNavLast(): Promise { - return this.state.file.then(file => this.selectPage.emit(file.numberOfPages)); + return firstValueFrom(this.state.file$).then(file => this.selectPage.emit(file.numberOfPages)); } pageSelectedByClick($event: number): void { diff --git a/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts b/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts index 518e180f1..1e2328ae9 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts @@ -53,7 +53,7 @@ export class PageExclusionComponent { async excludePagesRange(inputValue: string): Promise { this._loadingService.start(); const value = inputValue.replace(/[^0-9-,]/g, ''); - const file = await this._state.file; + const file = this._state.file; try { const pageRanges = value.split(',').map(range => { const splitted = range.split('-'); @@ -78,7 +78,7 @@ export class PageExclusionComponent { async includePagesRange(range: IPageRange): Promise { this._loadingService.start(); - const file = await this._state.file; + const file = this._state.file; const includePages$ = this._reanalysisService.includePages( { pageRanges: [range], diff --git a/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.ts b/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.ts index ff26797e7..430b10af9 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/page-indicator/page-indicator.component.ts @@ -69,11 +69,11 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnDestroy ngOnChanges() { this._setReadState(); - return this.handlePageRead(); + this.handlePageRead(); } async toggleReadState() { - const file = await this._stateService.file; + const file = this._stateService.file; if (this._permissionService.canMarkPagesAsViewed(file)) { if (this.read) { await this._markPageUnread(); @@ -83,8 +83,8 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnDestroy } } - async handlePageRead() { - const file = await this._stateService.file; + handlePageRead(): void { + const file = this._stateService.file; if (!this._permissionService.canMarkPagesAsViewed(file)) { return; } diff --git a/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts index d6355694b..61d2493de 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts @@ -104,13 +104,13 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha .subscribe(); } - async ngOnChanges(changes: SimpleChanges): Promise { + ngOnChanges(changes: SimpleChanges): void { if (!this.instance) { return; } if (changes.canPerformActions) { - await this._handleCustomActions(); + this._handleCustomActions(); } } @@ -136,7 +136,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha const loadCompareDocument = async () => { this._loadingService.start(); const mergedDocument = await pdfNet.PDFDoc.create(); - const file = await this.stateService.file; + const file = this.stateService.file; await loadCompareDocumentWrapper( currentDocument, compareDocument, @@ -256,11 +256,11 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha } }); - this.documentViewer.addEventListener('textSelected', async (quads, selectedText, pageNumber: number) => { + this.documentViewer.addEventListener('textSelected', (quads, selectedText, pageNumber: number) => { this._selectedText = selectedText; const textActions = [TextPopups.ADD_DICTIONARY, TextPopups.ADD_FALSE_POSITIVE]; - const file = await this.stateService.file; + const file = this.stateService.file; if (this.viewModeService.isCompare && pageNumber % 2 === 0) { this.instance.UI.disableElements(['textPopup']); @@ -391,7 +391,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha ]); } - const actions = this._annotationActionsService.getViewerAvailableActions(this.dossier, annotationWrappers); + const actions = this._annotationActionsService.getViewerAvailableActions(); this.instance.UI.annotationPopup.add(actions); } @@ -487,7 +487,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha this.manualAnnotationRequested.emit({ manualRedactionEntry, type }); } - private async _handleCustomActions() { + private _handleCustomActions() { this.instance.UI.setToolMode('AnnotationEdit'); const textPopupsToToggle = [TextPopups.ADD_REDACTION, TextPopups.ADD_RECTANGLE, TextPopups.ADD_FALSE_POSITIVE]; const headerItemsToToggle = [ @@ -496,7 +496,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha HeaderElements.ROTATE_RIGHT_BUTTON, ]; - const isCurrentPageExcluded = this.pdfViewer.isCurrentPageExcluded(await this.stateService.file); + const isCurrentPageExcluded = this.pdfViewer.isCurrentPageExcluded(this.stateService.file); if (this.canPerformActions && !isCurrentPageExcluded) { try { diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index f68b5d4d4..5a9595bff 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -197,7 +197,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } async ngOnAttach(previousRoute: ActivatedRouteSnapshot): Promise { - const file = await this.state.file; + const file = this.state.file; if (!file.canBeOpened) { this._navigateToDossier(); return; @@ -212,7 +212,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } async ngOnInit(): Promise { - const file = await this.state.file; + const file = this.state.file; if (!file) { this._handleDeletedFile(); @@ -247,8 +247,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } openManualAnnotationDialog(manualRedactionEntryWrapper: ManualRedactionEntryWrapper) { - return this._ngZone.run(async () => { - const file = await this.state.file; + return this._ngZone.run(() => { + const file = this.state.file; this.dialogRef = this._dialogService.openDialog( 'manualAnnotation', @@ -333,7 +333,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni const pageNumber: string = this._lastPage || this._activatedRoute.snapshot.queryParams.page; if (pageNumber) { setTimeout(async () => { - const file = await this.state.file; + const file = this.state.file; let page = parseInt(pageNumber, 10); if (page < 1 || Number.isNaN(page)) { diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index a5cbc9e85..2758d5147 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -27,7 +27,7 @@ import { AcceptRecommendationDialogComponent, AcceptRecommendationReturnType, } from '../dialogs/accept-recommendation-dialog/accept-recommendation-dialog.component'; -import { defaultDialogConfig, List } from '@iqser/common-ui'; +import { defaultDialogConfig, List, ListingService } from '@iqser/common-ui'; import { filter } from 'rxjs/operators'; import { MatDialog } from '@angular/material/dialog'; import { FilePreviewStateService } from './file-preview-state.service'; @@ -54,6 +54,7 @@ export class AnnotationActionsService { private readonly _dictionariesMapService: DictionariesMapService, private readonly _state: FilePreviewStateService, private readonly _fileDataService: FileDataService, + private readonly _listingService: ListingService, ) {} private get _dossier(): Dossier { @@ -190,7 +191,10 @@ export class AnnotationActionsService { }); } - getViewerAvailableActions(dossier: Dossier, annotations: AnnotationWrapper[]): Record[] { + getViewerAvailableActions(): Record[] { + const dossier = this._state.dossier; + const annotations = this._listingService.selected; + const availableActions = []; const annotationPermissions = annotations.map(annotation => ({ annotation, diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index db76c6547..72562c3cf 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -105,7 +105,7 @@ export class FileDataService extends EntitiesService { async annotationsChanged() { this._multiSelectService.deactivate(); - const file = await this._state.file; + const file = this._state.file; const fileReloaded = await firstValueFrom(this._filesService.reload(file.dossierId, file)); if (!fileReloaded) { await this.loadAnnotations(file); diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts index 079d30bdb..10fc0c3f1 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts @@ -5,7 +5,7 @@ import { ActivatedRoute } from '@angular/router'; import { FilesMapService } from '@services/entity-services/files-map.service'; import { PermissionsService } from '@services/permissions.service'; import { boolFactory } from '@iqser/common-ui'; -import { filter, startWith } from 'rxjs/operators'; +import { filter, startWith, tap } from 'rxjs/operators'; import { FileManagementService } from '@services/entity-services/file-management.service'; import { DOSSIER_ID, FILE_ID } from '@utils/constants'; import { dossiersServiceResolver } from '@services/entity-services/dossiers.service.provider'; @@ -26,6 +26,9 @@ export class FilePreviewStateService { readonly dossierTemplateId: string; readonly fileId: string; + dossier: Dossier; + file: File; + constructor( private readonly _fileManagementService: FileManagementService, private readonly _injector: Injector, @@ -41,8 +44,8 @@ export class FilePreviewStateService { this.dossierId = _route.snapshot.paramMap.get(DOSSIER_ID); this.dossierTemplateId = dossiersService.find(this.dossierId).dossierTemplateId; - this.dossier$ = dossiersService.getEntityChanged$(this.dossierId); - this.file$ = _filesMapService.watch$(this.dossierId, this.fileId); + this.dossier$ = dossiersService.getEntityChanged$(this.dossierId).pipe(tap(dossier => (this.dossier = dossier))); + this.file$ = _filesMapService.watch$(this.dossierId, this.fileId).pipe(tap(file => (this.file = file))); [this.isReadonly$, this.isWritable$] = boolFactory( combineLatest([this.file$, this.dossier$]), ([file, dossier]) => !_permissionsService.canPerformAnnotationActions(file, dossier), @@ -52,14 +55,6 @@ export class FilePreviewStateService { this.dossierFileChange$ = this.#dossierFilesChange$(); } - get file(): Promise { - return firstValueFrom(this.file$); - } - - get dossier(): Promise { - return firstValueFrom(this.dossier$); - } - get blob(): Promise { return firstValueFrom(this.blob$); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts b/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts index 40758b128..5119a9cf3 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/stamp.service.ts @@ -27,7 +27,7 @@ export class StampService { return; } - const file = await this._state.file; + const file = this._state.file; const allPages = [...Array(file.numberOfPages).keys()].map(page => page + 1); try { @@ -38,7 +38,7 @@ export class StampService { } if (this._viewModeService.isRedacted) { - const dossier = await this._state.dossier; + const dossier = this._state.dossier; if (dossier.watermarkPreviewEnabled) { await this._stampPreview(pdfDoc, dossier.dossierTemplateId); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts b/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts index f0e3f8e9c..647620f42 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts @@ -168,7 +168,7 @@ export class ViewerHeaderConfigService { const blob = await this._stateService.blob; const currentDocument = await pdfNet.PDFDoc.createFromBuffer(await blob.arrayBuffer()); - const filename = (await this._stateService.file).filename ?? 'document.pdf'; + const filename = this._stateService.file.filename ?? 'document.pdf'; this._pdfViewer.instance.UI.loadDocument(currentDocument, { filename }); this.disable([HeaderElements.CLOSE_COMPARE_BUTTON]);