diff --git a/apps/red-ui/src/app/guards/can-deactivate.guard.ts b/apps/red-ui/src/app/guards/can-deactivate.guard.ts index 38a494c00..df72bc9c3 100644 --- a/apps/red-ui/src/app/guards/can-deactivate.guard.ts +++ b/apps/red-ui/src/app/guards/can-deactivate.guard.ts @@ -8,6 +8,7 @@ export interface ComponentCanDeactivate { valid?: boolean; isLeavingPage?: boolean; save: () => Promise; + discard?: () => Promise; } @Injectable({ providedIn: 'root' }) @@ -22,7 +23,9 @@ export class PendingChangesGuard implements CanDeactivate { if (result === ConfirmOptions.CONFIRM) { - component.save(); + component.save().then(); + } else { + component.discard?.().then(); } component.isLeavingPage = false; return !!result; diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 0f14c28c2..70d08c0ea 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -51,6 +51,7 @@ import { FileDataModel } from '../../../../models/file/file-data.model'; import { filePreviewScreenProviders } from './file-preview-providers'; import { ManualAnnotationService } from '../../services/manual-annotation.service'; import { PageRotationService } from './services/page-rotation.service'; +import { ComponentCanDeactivate } from '../../../../guards/can-deactivate.guard'; import Annotation = Core.Annotations.Annotation; import PDFNet = Core.PDFNet; @@ -61,7 +62,7 @@ const ALL_HOTKEY_ARRAY = ['Escape', 'F', 'f', 'ArrowUp', 'ArrowDown']; styleUrls: ['./file-preview-screen.component.scss'], providers: filePreviewScreenProviders, }) -export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnInit, OnDestroy, OnAttach, OnDetach { +export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnInit, OnDestroy, OnAttach, OnDetach, ComponentCanDeactivate { readonly circleButtonTypes = CircleButtonTypes; dialogRef: MatDialogRef; @@ -125,6 +126,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni }); } + get changed() { + return this._pageRotationService.hasRotations(); + } + get visibleAnnotations(): AnnotationWrapper[] { return this._fileData ? this._fileData.getVisibleAnnotations(this.viewModeService.viewMode) : []; } @@ -148,6 +153,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni ); } + async save() { + await this._pageRotationService.applyRotation(); + } + async updateViewMode(): Promise { if (!this._instance?.Core.documentViewer.getDocument()) { return; @@ -395,7 +404,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni return; } - await firstValueFrom(this._pageRotationService.showConfirmationDialogIfHasRotations()); this._scrollViews(); this.multiSelectService.deactivate(); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview.module.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview.module.ts index a93b7966c..111fd80c2 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview.module.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview.module.ts @@ -24,6 +24,7 @@ import { AcceptRecommendationDialogComponent } from './dialogs/accept-recommenda import { AnnotationCardComponent } from './components/annotation-card/annotation-card.component'; import { AnnotationReferencesPageIndicatorComponent } from './components/annotation-references-page-indicator/annotation-references-page-indicator.component'; import { HighlightsSeparatorComponent } from './components/highlights-separator/highlights-separator.component'; +import { PendingChangesGuard } from '../../../../guards/can-deactivate.guard'; const routes: Routes = [ { @@ -31,6 +32,7 @@ const routes: Routes = [ component: FilePreviewScreenComponent, pathMatch: 'full', data: { reuse: true }, + canDeactivate: [PendingChangesGuard], }, ];