diff --git a/apps/red-ui/src/app/app.component.ts b/apps/red-ui/src/app/app.component.ts index 73a852ee1..975c8e82d 100644 --- a/apps/red-ui/src/app/app.component.ts +++ b/apps/red-ui/src/app/app.component.ts @@ -1,7 +1,7 @@ import { Component, ViewContainerRef } from '@angular/core'; import { RouterHistoryService } from '@services/router-history.service'; import { UserService } from '@services/user.service'; -import { PdfViewer } from '@shared/components/reusable-pdf-viewer/pdf-viewer.service'; +import { PdfViewer } from '@shared/components/pdf-viewer/pdf-viewer.service'; @Component({ selector: 'redaction-root', diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index ae1fcb6f4..135966f5d 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -52,7 +52,7 @@ import { LoggerModule, NgxLoggerLevel, TOKEN_LOGGER_CONFIG, TOKEN_LOGGER_RULES_S import { LoggerRulesService } from '@services/logger-rules.service'; import { ILoggerConfig } from '@red/domain'; import { SystemPreferencesService } from '@services/system-preferences.service'; -import { PdfViewerComponent } from '@shared/components/reusable-pdf-viewer/pdf-viewer.component'; +import { PdfViewerComponent } from '@shared/components/pdf-viewer/pdf-viewer.component'; export function httpLoaderFactory(httpClient: HttpClient, configService: ConfigService): PruningTranslationLoader { return new PruningTranslationLoader(httpClient, '/assets/i18n/', `.json?version=${configService.values.FRONTEND_APP_VERSION}`); 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 fd53a3327..38189cf80 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 @@ -11,7 +11,7 @@ import { HelpModeService } from '@iqser/common-ui'; import { FileDataService } from '../../services/file-data.service'; import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service'; import { ViewModeService } from '../../services/view-mode.service'; -import { REDAnnotationManager } from '../../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { REDAnnotationManager } from '../../../shared/components/pdf-viewer/annotation-manager.service'; export const AnnotationButtonTypes = { dark: 'dark', diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts index d0621b5b9..0ae2f38ee 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts @@ -17,7 +17,7 @@ import { UserPreferenceService } from '@services/user-preference.service'; import { ViewModeService } from '../../services/view-mode.service'; import { BehaviorSubject } from 'rxjs'; import { TextHighlightsGroup } from '@red/domain'; -import { REDAnnotationManager } from '../../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { REDAnnotationManager } from '../../../shared/components/pdf-viewer/annotation-manager.service'; import { AnnotationsListingService } from '../../services/annotations-listing.service'; @Component({ 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 9b3ddd6f0..b85b27c47 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 @@ -35,8 +35,8 @@ import { FilePreviewStateService } from '../../services/file-preview-state.servi import { ViewModeService } from '../../services/view-mode.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { FileDataService } from '../../services/file-data.service'; -import { PdfViewer } from '../../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; -import { REDAnnotationManager } from '../../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { PdfViewer } from '../../../shared/components/pdf-viewer/pdf-viewer.service'; +import { REDAnnotationManager } from '../../../shared/components/pdf-viewer/annotation-manager.service'; import { AnnotationsListingService } from '../../services/annotations-listing.service'; const COMMAND_KEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape']; 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 da9c727b0..00929fd83 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 @@ -16,7 +16,7 @@ import { IViewedPage } from '@red/domain'; import { AutoUnsubscribe } from '@iqser/common-ui'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; import { firstValueFrom } from 'rxjs'; -import { PageRotationService } from '../../services/page-rotation.service'; +import { PageRotationService } from '../../../shared/components/pdf-viewer/page-rotation.service'; @Component({ selector: 'redaction-page-indicator', @@ -61,7 +61,7 @@ export class PageIndicatorComponent extends AutoUnsubscribe implements OnDestroy } ngOnInit() { - this.addSubscription = this.pageRotationService.isRotated(this.number).subscribe(value => { + this.addSubscription = this.pageRotationService.isRotated$(this.number).subscribe(value => { this.isRotated = value; this._changeDetectorRef.detectChanges(); }); diff --git a/apps/red-ui/src/app/modules/file-preview/components/pdf-paginator/pdf-paginator.component.ts b/apps/red-ui/src/app/modules/file-preview/components/pdf-paginator/pdf-paginator.component.ts index 0b0b3e22c..cc50e792a 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/pdf-paginator/pdf-paginator.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/pdf-paginator/pdf-paginator.component.ts @@ -31,17 +31,18 @@ import { toPosition } from '../../utils/pdf-calculation.utils'; import { MultiSelectService } from '../../services/multi-select.service'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; import { map, switchMap, tap, withLatestFrom } from 'rxjs/operators'; -import { PageRotationService } from '../../services/page-rotation.service'; +import { PageRotationService } from '../../../shared/components/pdf-viewer/page-rotation.service'; import { HeaderElements, TextPopups } from '../../utils/constants'; import { FilePreviewDialogService } from '../../services/file-preview-dialog.service'; import { loadCompareDocumentWrapper } from '../../utils/compare-mode.utils'; import { from } from 'rxjs'; import { FileDataService } from '../../services/file-data.service'; -import { ViewerHeaderConfigService } from '../../services/viewer-header-config.service'; +import { ViewerHeaderService } from '../../../shared/components/pdf-viewer/viewer-header.service'; import { ManualRedactionService } from '../../services/manual-redaction.service'; -import { PdfViewer } from '../../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; -import { REDAnnotationManager } from '../../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { PdfViewer } from '../../../shared/components/pdf-viewer/pdf-viewer.service'; +import { REDAnnotationManager } from '../../../shared/components/pdf-viewer/annotation-manager.service'; import { translateQuads } from '../../../../utils'; +import { ROTATION_ACTION_BUTTONS } from '../../../shared/components/pdf-viewer/constants'; import Annotation = Core.Annotations.Annotation; @Component({ @@ -78,7 +79,7 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On private readonly _loadingService: LoadingService, private readonly _pageRotationService: PageRotationService, private readonly _fileDataService: FileDataService, - private readonly _headerConfigService: ViewerHeaderConfigService, + private readonly _viewerHeaderService: ViewerHeaderService, private readonly _errorService: ErrorService, private readonly _annotationManager: REDAnnotationManager, readonly pdf: PdfViewer, @@ -102,7 +103,10 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On withLatestFrom(this._state.file$), tap(() => this._errorService.clear()), tap(([blob, file]) => this.pdf.loadDocument(blob, file)), - tap(() => this._pageRotationService.clearRotationsHideActions()), + tap(() => { + this._pageRotationService.clearRotations(); + this._viewerHeaderService.disable(ROTATION_ACTION_BUTTONS); + }), ) .subscribe(); } @@ -150,8 +154,8 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On }, this.instance.Core.PDFNet, ); - this._headerConfigService.disable([HeaderElements.COMPARE_BUTTON]); - this._headerConfigService.enable([HeaderElements.CLOSE_COMPARE_BUTTON]); + this._viewerHeaderService.disable([HeaderElements.COMPARE_BUTTON]); + this._viewerHeaderService.enable([HeaderElements.CLOSE_COMPARE_BUTTON]); this._loadingService.stop(); }; @@ -246,7 +250,7 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On } private _configureElements() { - this._headerConfigService.initialize(this.compareFileInput); + this._viewerHeaderService.initialize(this.compareFileInput); const dossierTemplateId = this.dossier.dossierTemplateId; const color = this._annotationDrawService.getAndConvertColor(dossierTemplateId, 'manual'); @@ -323,8 +327,8 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On } private _cleanUpSelectionAndButtonState() { - this._headerConfigService.disable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); - this._headerConfigService.enable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); + this._viewerHeaderService.disable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); + this._viewerHeaderService.enable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); } private _configureTextPopup() { @@ -407,7 +411,7 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On // happens } this.pdf.enable(textPopupsToToggle); - this._headerConfigService.enable(headerItemsToToggle); + this._viewerHeaderService.enable(headerItemsToToggle); if (this._selectedText.length > 2) { this.pdf.enable([TextPopups.ADD_DICTIONARY, TextPopups.ADD_FALSE_POSITIVE]); @@ -432,7 +436,7 @@ export class PdfPaginatorComponent extends AutoUnsubscribe implements OnInit, On } this.pdf.disable(textPopupElementsToDisable); - this._headerConfigService.disable(headerElementsToDisable); + this._viewerHeaderService.disable(headerElementsToDisable); } private _getManualRedaction( diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-providers.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-providers.ts index 9795d5679..5bbd9831f 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-providers.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-providers.ts @@ -11,9 +11,7 @@ import { AnnotationReferencesService } from './services/annotation-references.se import { EntitiesService, FilterService, ListingService, SearchService } from '@iqser/common-ui'; import { AnnotationProcessingService } from './services/annotation-processing.service'; import { dossiersServiceProvider } from '@services/entity-services/dossiers.service.provider'; -import { PageRotationService } from './services/page-rotation.service'; import { FileDataService } from './services/file-data.service'; -import { ViewerHeaderConfigService } from './services/viewer-header-config.service'; import { AnnotationsListingService } from './services/annotations-listing.service'; import { StampService } from './services/stamp.service'; @@ -29,12 +27,10 @@ export const filePreviewScreenProviders = [ AnnotationActionsService, FilePreviewStateService, AnnotationReferencesService, - PageRotationService, AnnotationProcessingService, FileDataService, { provide: EntitiesService, useExisting: FileDataService }, dossiersServiceProvider, - ViewerHeaderConfigService, AnnotationsListingService, { provide: ListingService, useExisting: AnnotationsListingService }, SearchService, 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 4c675fd97..bd8306aec 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 @@ -43,15 +43,17 @@ import { FilePreviewStateService } from './services/file-preview-state.service'; import { filePreviewScreenProviders } from './file-preview-providers'; import { ManualRedactionService } from './services/manual-redaction.service'; import { DossiersService } from '@services/dossiers/dossiers.service'; -import { PageRotationService } from './services/page-rotation.service'; +import { PageRotationService } from '../shared/components/pdf-viewer/page-rotation.service'; import { ComponentCanDeactivate } from '@guards/can-deactivate.guard'; import { FilePreviewDialogService } from './services/file-preview-dialog.service'; import { FileDataService } from './services/file-data.service'; import { ActionsHelpModeKeys, ALL_HOTKEYS } from './utils/constants'; import { NGXLogger } from 'ngx-logger'; import { StampService } from './services/stamp.service'; -import { PdfViewer } from '../shared/components/reusable-pdf-viewer/pdf-viewer.service'; -import { REDAnnotationManager } from '../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { PdfViewer } from '../shared/components/pdf-viewer/pdf-viewer.service'; +import { REDAnnotationManager } from '../shared/components/pdf-viewer/annotation-manager.service'; +import { ViewerHeaderService } from '../shared/components/pdf-viewer/viewer-header.service'; +import { ROTATION_ACTION_BUTTONS } from '../shared/components/pdf-viewer/constants'; import Annotation = Core.Annotations.Annotation; @Component({ @@ -101,6 +103,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private readonly _changeDetectorRef: ChangeDetectorRef, private readonly _dialogService: FilePreviewDialogService, private readonly _pageRotationService: PageRotationService, + private readonly _viewerHeaderService: ViewerHeaderService, private readonly _annotationDrawService: AnnotationDrawService, private readonly _annotationProcessingService: AnnotationProcessingService, private readonly _stampService: StampService, @@ -138,6 +141,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni async save() { await this._pageRotationService.applyRotation(); + this._viewerHeaderService.disable(ROTATION_ACTION_BUTTONS); } async updateViewMode(): Promise { 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 10b92ff5f..8c45e5b07 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 @@ -34,8 +34,8 @@ import { FilePreviewStateService } from './file-preview-state.service'; import { FilePreviewDialogService } from './file-preview-dialog.service'; import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service'; import { FileDataService } from './file-data.service'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; -import { REDAnnotationManager } from '../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { PdfViewer } from '../../shared/components/pdf-viewer/pdf-viewer.service'; +import { REDAnnotationManager } from '../../shared/components/pdf-viewer/annotation-manager.service'; import Quad = Core.Math.Quad; @Injectable() 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 479db4e0c..b34b98a7c 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 @@ -13,7 +13,7 @@ import { DictionariesMapService } from '@services/entity-services/dictionaries-m import { FilePreviewStateService } from './file-preview-state.service'; import { FileDataService } from './file-data.service'; import { SuperTypes } from '@models/file/super-types'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; +import { PdfViewer } from '../../shared/components/pdf-viewer/pdf-viewer.service'; import Annotation = Core.Annotations.Annotation; import Quad = Core.Math.Quad; diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotations-listing.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotations-listing.service.ts index 71d18eed8..d02617731 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotations-listing.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotations-listing.service.ts @@ -3,8 +3,8 @@ import { Injectable } from '@angular/core'; import { EntitiesService, FilterService, ListingService, SearchService } from '@iqser/common-ui'; import { filter, tap } from 'rxjs/operators'; import { MultiSelectService } from './multi-select.service'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; -import { REDAnnotationManager } from '../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { PdfViewer } from '../../shared/components/pdf-viewer/pdf-viewer.service'; +import { REDAnnotationManager } from '../../shared/components/pdf-viewer/annotation-manager.service'; @Injectable() export class AnnotationsListingService extends ListingService { diff --git a/apps/red-ui/src/app/modules/file-preview/services/skipped.service.ts b/apps/red-ui/src/app/modules/file-preview/services/skipped.service.ts index 48bf024ac..3b51e9d31 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/skipped.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/skipped.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { skip, tap } from 'rxjs/operators'; import { shareDistinctLast } from '@iqser/common-ui'; -import { REDAnnotationManager } from '../../shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { REDAnnotationManager } from '../../shared/components/pdf-viewer/annotation-manager.service'; @Injectable() export class SkippedService { 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 5bc5c72ad..e93efa803 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 @@ -7,7 +7,7 @@ import { TranslateService } from '@ngx-translate/core'; import { Core } from '@pdftron/webviewer'; import { firstValueFrom } from 'rxjs'; import { WatermarkService } from '@services/entity-services/watermark.service'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; +import { PdfViewer } from '../../shared/components/pdf-viewer/pdf-viewer.service'; import PDFNet = Core.PDFNet; @Injectable() diff --git a/apps/red-ui/src/app/modules/shared-dossiers/components/file-actions/file-actions.component.ts b/apps/red-ui/src/app/modules/shared-dossiers/components/file-actions/file-actions.component.ts index 4f181ef51..6f5a8eff1 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/components/file-actions/file-actions.component.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/components/file-actions/file-actions.component.ts @@ -23,8 +23,10 @@ import { ExcludedPagesService } from '../../../file-preview/services/excluded-pa import { DocumentInfoService } from '../../../file-preview/services/document-info.service'; import { ExpandableFileActionsComponent } from '@shared/components/expandable-file-actions/expandable-file-actions.component'; import { firstValueFrom, Observable } from 'rxjs'; -import { PageRotationService } from '../../../file-preview/services/page-rotation.service'; +import { PageRotationService } from '../../../shared/components/pdf-viewer/page-rotation.service'; import { FileAssignService } from '../../services/file-assign.service'; +import { ViewerHeaderService } from '../../../shared/components/pdf-viewer/viewer-header.service'; +import { ROTATION_ACTION_BUTTONS } from '../../../shared/components/pdf-viewer/constants'; @Component({ selector: 'redaction-file-actions [file] [type] [dossier]', @@ -77,7 +79,8 @@ export class FileActionsComponent implements OnChanges { constructor( @Optional() private readonly _excludedPagesService: ExcludedPagesService, @Optional() private readonly _documentInfoService: DocumentInfoService, - @Optional() private readonly _pageRotationService: PageRotationService, + private readonly _pageRotationService: PageRotationService, + private readonly _viewerHeaderService: ViewerHeaderService, private readonly _permissionsService: PermissionsService, private readonly _activeDossiersService: ActiveDossiersService, private readonly _dialogService: DossiersDialogService, @@ -362,6 +365,7 @@ export class FileActionsComponent implements OnChanges { } if (this._pageRotationService) { await firstValueFrom(this._pageRotationService.showConfirmationDialogIfHasRotations()); + this._viewerHeaderService.disable(ROTATION_ACTION_BUTTONS); } this._loadingService.start(); await firstValueFrom(this._reanalysisService.ocrFiles([this.file], this.file.dossierId)); diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/annotation-manager.service.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/annotation-manager.service.ts similarity index 97% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/annotation-manager.service.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/annotation-manager.service.ts index 5d2d23f91..4f9cf21c4 100644 --- a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/annotation-manager.service.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/annotation-manager.service.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; import { Core } from '@pdftron/webviewer'; import type { List } from '@iqser/common-ui'; -import { AnnotationPredicate, DeleteAnnotationsOptions } from '@shared/components/reusable-pdf-viewer/types'; +import { AnnotationPredicate, DeleteAnnotationsOptions } from '@shared/components/pdf-viewer/types'; import type { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { fromEvent, Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; -import { getIds } from '@shared/components/reusable-pdf-viewer/functions'; +import { getIds } from '@shared/components/pdf-viewer/functions'; import AnnotationManager = Core.AnnotationManager; import Annotation = Core.Annotations.Annotation; diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/constants.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/constants.ts similarity index 88% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/constants.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/constants.ts index f9282494c..02cd43469 100644 --- a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/constants.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/constants.ts @@ -1,5 +1,8 @@ import { CustomError, List } from '@iqser/common-ui'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import { HeaderElements } from '../../../file-preview/utils/constants'; + +export const ROTATION_ACTION_BUTTONS = [HeaderElements.APPLY_ROTATION, HeaderElements.DISCARD_ROTATION]; export const ALLOWED_KEYBOARD_SHORTCUTS: List = ['+', '-', 'p', 'r', 'Escape'] as const; diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/functions.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/functions.ts similarity index 88% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/functions.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/functions.ts index df8c42f39..0a3c7f937 100644 --- a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/functions.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/functions.ts @@ -1,6 +1,6 @@ import { List } from '@iqser/common-ui'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; -import { ALLOWED_KEYBOARD_SHORTCUTS } from '@shared/components/reusable-pdf-viewer/constants'; +import { ALLOWED_KEYBOARD_SHORTCUTS } from '@shared/components/pdf-viewer/constants'; export function stopAndPrevent($event: T) { $event.preventDefault(); diff --git a/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/page-rotation.service.ts similarity index 61% rename from apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/page-rotation.service.ts index 48b74580d..2b5dac3d7 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/page-rotation.service.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/page-rotation.service.ts @@ -1,10 +1,8 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject, firstValueFrom, of } from 'rxjs'; import { RotationType, RotationTypes } from '@red/domain'; -import { FileManagementService } from '@services/files/file-management.service'; -import { FilePreviewStateService } from './file-preview-state.service'; -import { distinctUntilChanged, map, switchMap, tap, withLatestFrom } from 'rxjs/operators'; -import { HeaderElements } from '../utils/constants'; +import { FileManagementService } from '../../../../services/files/file-management.service'; +import { distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'; import { ConfirmationDialogComponent, ConfirmationDialogInput, @@ -14,14 +12,17 @@ import { } from '@iqser/common-ui'; 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/files/files.service'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; +import { FilesService } from '../../../../services/files/files.service'; +import { PdfViewer } from './pdf-viewer.service'; +import { ActivatedRoute } from '@angular/router'; +import { FilesMapService } from '../../../../services/files/files-map.service'; +import { NGXLogger } from 'ngx-logger'; -const ACTION_BUTTONS = [HeaderElements.APPLY_ROTATION, HeaderElements.DISCARD_ROTATION]; const ONE_ROTATION_DEGREE = 90; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class PageRotationService { readonly #rotations$ = new BehaviorSubject>({}); @@ -29,13 +30,14 @@ export class PageRotationService { private readonly _pdf: PdfViewer, private readonly _dialog: MatDialog, private readonly _loadingService: LoadingService, - private readonly _screenState: FilePreviewStateService, + private readonly _activatedRoute: ActivatedRoute, + private readonly _logger: NGXLogger, private readonly _fileManagementService: FileManagementService, private readonly _filesService: FilesService, - private readonly _headerConfigService: ViewerHeaderConfigService, + private readonly _filesMapService: FilesMapService, ) {} - isRotated(page: number) { + isRotated$(page: number) { return this.#rotations$.pipe( map(rotations => !!rotations[page]), distinctUntilChanged(), @@ -49,17 +51,25 @@ export class PageRotationService { applyRotation() { this._loadingService.start(); const pages = this.#rotations$.value; - const { dossierId, fileId } = this._screenState; - const request = this._fileManagementService.rotatePage({ pages }, dossierId, fileId); - this.clearRotationsHideActions(); + const dossierId = this._activatedRoute.snapshot.paramMap.get('dossierId'); + const fileId = this._activatedRoute.snapshot.paramMap.get('fileId'); - return firstValueFrom( - request.pipe( - withLatestFrom(this._screenState.file$), - switchMap(([, file]) => this._filesService.reload(dossierId, file)), - tap(() => this._loadingService.stop()), - ), - ); + if (!dossierId || !fileId) { + this._loadingService.stop(); + return this._logger.error('No dossier id or file id while applying rotations: ', dossierId, fileId); + } + + const file = this._filesMapService.get(dossierId, fileId); + if (!file) { + this._loadingService.stop(); + return this._logger.error('Cannot find file: ', dossierId, fileId); + } + + const request$ = this._fileManagementService.rotatePage({ pages }, dossierId, fileId); + this.clearRotations(); + const reloaded$ = request$.pipe(switchMap(() => this._filesService.reload(dossierId, file))); + + return firstValueFrom(reloaded$.pipe(tap(() => this._loadingService.stop()))); } discardRotation() { @@ -72,7 +82,7 @@ export class PageRotationService { } } - this.clearRotationsHideActions(); + this.clearRotations(); } addRotation(rotation: RotationType): void { @@ -87,24 +97,17 @@ export class PageRotationService { } else { this._pdf.documentViewer.rotateClockwise(pageNumber); } - - if (this.hasRotations()) { - this.#showActionButtons(); - } else { - this.#hideActionButtons(); - } } clearRotations() { this.#rotations$.next({}); } - clearRotationsHideActions() { - this.clearRotations(); - this.#hideActionButtons(); + showConfirmationDialogIfHasRotations() { + return this.hasRotations() ? this.#showConfirmationDialog() : of(ConfirmOptions.DISCARD_CHANGES); } - showConfirmationDialog() { + #showConfirmationDialog() { const ref = this._dialog.open(ConfirmationDialogComponent, { ...defaultDialogConfig, data: new ConfirmationDialogInput({ @@ -119,16 +122,4 @@ export class PageRotationService { .afterClosed() .pipe(tap((option: ConfirmOptions) => (option === ConfirmOptions.CONFIRM ? this.applyRotation() : this.discardRotation()))); } - - showConfirmationDialogIfHasRotations() { - return this.hasRotations() ? this.showConfirmationDialog() : of(ConfirmOptions.DISCARD_CHANGES); - } - - #showActionButtons() { - this._headerConfigService.enable(ACTION_BUTTONS); - } - - #hideActionButtons() { - this._headerConfigService.disable(ACTION_BUTTONS); - } } diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.component.ts similarity index 90% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.component.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.component.ts index 598056509..c65178811 100644 --- a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.component.ts @@ -1,6 +1,6 @@ import { Component, ElementRef, ViewChild } from '@angular/core'; import { PdfViewer } from './pdf-viewer.service'; -import { REDAnnotationManager } from '@shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { REDAnnotationManager } from '@shared/components/pdf-viewer/annotation-manager.service'; @Component({ selector: 'redaction-pdf-viewer', diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.service.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.service.ts similarity index 98% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.service.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.service.ts index 39bf9d168..692373856 100644 --- a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/pdf-viewer.service.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/pdf-viewer.service.ts @@ -10,10 +10,10 @@ import { BehaviorSubject, combineLatest, fromEvent, merge, Observable } from 'rx import { ConfigService } from '@services/config.service'; import { NGXLogger } from 'ngx-logger'; import { DISABLED_HOTKEYS, DOCUMENT_LOADING_ERROR, USELESS_ELEMENTS } from './constants'; -import { Rgb } from '@shared/components/reusable-pdf-viewer/types'; +import { Rgb } from '@shared/components/pdf-viewer/types'; import { UserPreferenceService } from '@services/user-preference.service'; -import { asList, stopAndPrevent, stopAndPreventIfNotAllowed } from '@shared/components/reusable-pdf-viewer/functions'; -import { REDAnnotationManager } from '@shared/components/reusable-pdf-viewer/annotation-manager.service'; +import { asList, stopAndPrevent, stopAndPreventIfNotAllowed } from '@shared/components/pdf-viewer/functions'; +import { REDAnnotationManager } from '@shared/components/pdf-viewer/annotation-manager.service'; import AnnotationManager = Core.AnnotationManager; import TextTool = Core.Tools.TextTool; import Annotation = Core.Annotations.Annotation; diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/tooltips.service.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/tooltips.service.ts similarity index 100% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/tooltips.service.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/tooltips.service.ts diff --git a/apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/types.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/types.ts similarity index 100% rename from apps/red-ui/src/app/modules/shared/components/reusable-pdf-viewer/types.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/types.ts diff --git a/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/viewer-header.service.ts similarity index 72% rename from apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts rename to apps/red-ui/src/app/modules/shared/components/pdf-viewer/viewer-header.service.ts index a7ef7b323..a70891896 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/viewer-header-config.service.ts +++ b/apps/red-ui/src/app/modules/shared/components/pdf-viewer/viewer-header.service.ts @@ -1,21 +1,25 @@ import { ElementRef, Inject, Injectable, Injector } from '@angular/core'; import { IHeaderElement, RotationTypes } from '@red/domain'; -import { HeaderElements, HeaderElementType } from '../utils/constants'; +import { HeaderElements, HeaderElementType } from '../../../file-preview/utils/constants'; import { TranslateService } from '@ngx-translate/core'; -import { BASE_HREF } from '../../../tokens'; -import { TooltipsService } from '../../shared/components/reusable-pdf-viewer/tooltips.service'; -import { environment } from '@environments/environment'; -import { FilePreviewStateService } from './file-preview-state.service'; +import { BASE_HREF_FN, BaseHrefFn } from '../../../../tokens'; +import { TooltipsService } from './tooltips.service'; import { PageRotationService } from './page-rotation.service'; -import { PdfViewer } from '../../shared/components/reusable-pdf-viewer/pdf-viewer.service'; +import { PdfViewer } from './pdf-viewer.service'; +import { ROTATION_ACTION_BUTTONS } from './constants'; +import { ActivatedRoute } from '@angular/router'; +import { FilesMapService } from '../../../../services/files/files-map.service'; -@Injectable() -export class ViewerHeaderConfigService { - private _divider: IHeaderElement = { - type: 'divider', - }; - private _buttons: Map; - private _config: Map = new Map([ +const divider: IHeaderElement = { + type: 'divider', +}; + +@Injectable({ + providedIn: 'root', +}) +export class ViewerHeaderService { + #buttons: Map; + readonly #config = new Map([ [HeaderElements.SHAPE_TOOL_GROUP_BUTTON, true], [HeaderElements.TOGGLE_TOOLTIPS, true], [HeaderElements.COMPARE_BUTTON, true], @@ -25,15 +29,15 @@ export class ViewerHeaderConfigService { [HeaderElements.APPLY_ROTATION, false], [HeaderElements.DISCARD_ROTATION, false], ]); - private _rotationService: PageRotationService; + #docBeforeCompare: Blob; constructor( - @Inject(BASE_HREF) private readonly _baseHref: string, + @Inject(BASE_HREF_FN) private readonly _convertPath: BaseHrefFn, private readonly _injector: Injector, private readonly _translateService: TranslateService, private readonly _pdf: PdfViewer, + private readonly _rotationService: PageRotationService, private readonly _tooltipsService: TooltipsService, - private readonly _stateService: FilePreviewStateService, ) {} private get _rectangle(): IHeaderElement { @@ -66,9 +70,7 @@ export class ViewerHeaderConfigService { dataElement: HeaderElements.CLOSE_COMPARE_BUTTON, img: this._convertPath('/assets/icons/general/pdftron-action-close-compare.svg'), title: 'Leave Compare Mode', - onClick: async () => { - await this._closeCompareMode(); - }, + onClick: () => this._closeCompareMode(), }; } @@ -78,7 +80,10 @@ export class ViewerHeaderConfigService { element: HeaderElements.ROTATE_LEFT_BUTTON, dataElement: HeaderElements.ROTATE_LEFT_BUTTON, img: this._convertPath('/assets/icons/general/rotate-left.svg'), - onClick: () => this._rotationService.addRotation(RotationTypes.LEFT), + onClick: () => { + this._rotationService.addRotation(RotationTypes.LEFT); + this.#toggleRotationActionButtons(); + }, }; } @@ -98,6 +103,7 @@ export class ViewerHeaderConfigService { `; paragraph.addEventListener('click', async () => { await this._rotationService.applyRotation(); + this.disable(ROTATION_ACTION_BUTTONS); }); return paragraph; }, @@ -118,7 +124,10 @@ export class ViewerHeaderConfigService { cursor: pointer; opacity: 0.7; `; - paragraph.addEventListener('click', () => this._rotationService.discardRotation()); + paragraph.addEventListener('click', () => { + this._rotationService.discardRotation(); + this.disable(ROTATION_ACTION_BUTTONS); + }); return paragraph; }, }; @@ -130,14 +139,15 @@ export class ViewerHeaderConfigService { element: HeaderElements.ROTATE_RIGHT_BUTTON, dataElement: HeaderElements.ROTATE_RIGHT_BUTTON, img: this._convertPath('/assets/icons/general/rotate-right.svg'), - onClick: () => this._rotationService.addRotation(RotationTypes.RIGHT), + onClick: () => { + this._rotationService.addRotation(RotationTypes.RIGHT); + this.#toggleRotationActionButtons(); + }, }; } initialize(compareFileInput: ElementRef): void { - this._rotationService = this._injector.get(PageRotationService); - - this._buttons = new Map([ + this.#buttons = new Map([ [HeaderElements.SHAPE_TOOL_GROUP_BUTTON, this._rectangle], [HeaderElements.ROTATE_LEFT_BUTTON, this._rotateLeft], [HeaderElements.ROTATE_RIGHT_BUTTON, this._rotateRight], @@ -159,15 +169,23 @@ export class ViewerHeaderConfigService { this._updateState(elements, false); } - private async _closeCompareMode() { - this._pdf.closeCompareMode(); - const pdfNet = this._pdf.PDFNet; - await pdfNet.initialize(environment.licenseKey ? atob(environment.licenseKey) : null); - const blob = await this._stateService.blob; - const currentDocument = await pdfNet.PDFDoc.createFromBuffer(await blob.arrayBuffer()); + #toggleRotationActionButtons() { + if (this._rotationService.hasRotations()) { + this.enable(ROTATION_ACTION_BUTTONS); + } else { + this.disable(ROTATION_ACTION_BUTTONS); + } + } - const filename = this._stateService.file.filename ?? 'document.pdf'; - this._pdf.instance.UI.loadDocument(currentDocument, { filename }); + private _closeCompareMode() { + this._pdf.closeCompareMode(); + const activatedRoute = this._injector.get(ActivatedRoute); + const dossierId = activatedRoute.snapshot.paramMap.get('dossierId'); + const fileId = activatedRoute.snapshot.paramMap.get('fileId'); + const file = this._injector.get(FilesMapService).get(dossierId, fileId); + const filename = file.filename ?? 'document.pdf'; + + this._pdf.instance.UI.loadDocument(this.#docBeforeCompare, { filename }); this.disable([HeaderElements.CLOSE_COMPARE_BUTTON]); this.enable([HeaderElements.COMPARE_BUTTON]); @@ -182,15 +200,20 @@ export class ViewerHeaderConfigService { dataElement: HeaderElements.COMPARE_BUTTON, img: this._convertPath('/assets/icons/general/pdftron-action-compare.svg'), title: 'Compare', - onClick: () => compareFileInput.nativeElement.click(), + onClick: async () => { + compareFileInput.nativeElement.click(); + const data = await this._pdf.documentViewer.getDocument().getFileData(); + const arr = new Uint8Array(data); + this.#docBeforeCompare = new Blob([arr], { type: 'application/pdf' }); + }, }; } private _pushGroup(items: IHeaderElement[], group: HeaderElementType[]): void { const enabledItems = group.filter(item => this._isEnabled(item)); if (enabledItems.length) { - items.push(this._divider); - enabledItems.forEach(item => items.push(this._buttons.get(item))); + items.push(divider); + enabledItems.forEach(item => items.push(this.#buttons.get(item))); } } @@ -214,15 +237,11 @@ export class ViewerHeaderConfigService { } private _updateState(elements: HeaderElementType[], value: boolean): void { - elements.forEach(element => this._config.set(element, value)); + elements.forEach(element => this.#config.set(element, value)); this._updateElements(); } private _isEnabled(key: HeaderElementType): boolean { - return this._config.get(key); - } - - private _convertPath(path: string): string { - return this._baseHref + path; + return this.#config.get(key); } }