From 609ee147fea5f8ab965fe70250d6995dd0412978 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 4 Apr 2022 16:53:19 +0300 Subject: [PATCH] reload file when applying rotation --- .../services/annotation-draw.service.ts | 2 +- .../services/page-rotation.service.ts | 14 ++++++++++---- .../services/pdf-viewer.service.ts | 18 +++++++++--------- libs/common-ui | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-draw.service.ts index 89873fcaf..2203aff27 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-draw.service.ts @@ -138,7 +138,7 @@ export class AnnotationDrawService { private _computeAnnotation(annotationWrapper: AnnotationWrapper) { const pageNumber = this._viewModeService.isCompare ? annotationWrapper.pageNumber * 2 - 1 : annotationWrapper.pageNumber; - if (pageNumber > this._pdf.documentViewer.getPageCount()) { + if (pageNumber > this._pdf.pageCount) { // skip imported annotations from files that have more pages than the current one return; } diff --git a/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts b/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts index df276d163..47e9a9d40 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts @@ -1,10 +1,9 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject, firstValueFrom, of } from 'rxjs'; -import { PermissionsService } from '@services/permissions.service'; import { RotationType, RotationTypes } from '@red/domain'; import { FileManagementService } from '@services/entity-services/file-management.service'; import { FilePreviewStateService } from './file-preview-state.service'; -import { distinctUntilChanged, map, tap } from 'rxjs/operators'; +import { distinctUntilChanged, map, switchMap, tap, withLatestFrom } from 'rxjs/operators'; import { PdfViewer } from './pdf-viewer.service'; import { HeaderElements } from '../shared/constants'; import { @@ -17,6 +16,7 @@ import { import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { MatDialog } from '@angular/material/dialog'; import { ViewerHeaderConfigService } from './viewer-header-config.service'; +import { FilesService } from '../../../services/entity-services/files.service'; const ACTION_BUTTONS = [HeaderElements.APPLY_ROTATION, HeaderElements.DISCARD_ROTATION]; const ONE_ROTATION_DEGREE = 90; @@ -30,8 +30,8 @@ export class PageRotationService { private readonly _dialog: MatDialog, private readonly _loadingService: LoadingService, private readonly _screenState: FilePreviewStateService, - private readonly _permissionsService: PermissionsService, private readonly _fileManagementService: FileManagementService, + private readonly _filesService: FilesService, private readonly _headerConfigService: ViewerHeaderConfigService, ) {} @@ -53,7 +53,13 @@ export class PageRotationService { const request = this._fileManagementService.rotatePage({ pages }, dossierId, fileId); this.clearRotationsHideActions(); - return firstValueFrom(request.pipe(tap(() => this._loadingService.stop()))); + return firstValueFrom( + request.pipe( + withLatestFrom(this._screenState.file$), + switchMap(([, file]) => this._filesService.reload(dossierId, file)), + tap(() => this._loadingService.stop()), + ), + ); } discardRotation() { diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-viewer.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-viewer.service.ts index 2999b0df5..ad120218a 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-viewer.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-viewer.service.ts @@ -64,22 +64,22 @@ export class PdfViewer { } get totalPages() { - return this._viewModeService.isCompare ? Math.ceil(this._totalInternalPages / 2) : this._totalInternalPages; + return this._viewModeService.isCompare ? Math.ceil(this.pageCount / 2) : this.pageCount; } - private get _currentInternalPage() { - return this.documentViewer?.getCurrentPage() ?? 1; - } - - private get _totalInternalPages() { + get pageCount() { try { - return this.documentViewer?.getPageCount() ?? 1; + return this.instance?.Core.documentViewer?.getPageCount() ?? 1; } catch { // might throw Error: getPageCount was called before the 'documentLoaded' event return 1; } } + private get _currentInternalPage() { + return this.instance?.Core.documentViewer?.getCurrentPage() ?? 1; + } + async lockDocument() { const document = await this.documentViewer.getDocument()?.getPDFDoc(); if (!document) { @@ -160,8 +160,8 @@ export class PdfViewer { } navigateNextPage() { - if (this._currentInternalPage < this._totalInternalPages) { - this._navigateToPage(Math.min(this._currentInternalPage + this.paginationOffset, this._totalInternalPages)); + if (this._currentInternalPage < this.pageCount) { + this._navigateToPage(Math.min(this._currentInternalPage + this.paginationOffset, this.pageCount)); } } diff --git a/libs/common-ui b/libs/common-ui index 8e1529891..1e6ebf252 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 8e15298919c2ae3b0abb243c3c6912eb97d6db68 +Subproject commit 1e6ebf252fa3be1704595d42dc621380a0d07ca0