show unsaved changes when leaving file preview
This commit is contained in:
parent
c892507798
commit
38c41b5153
@ -8,6 +8,7 @@ export interface ComponentCanDeactivate {
|
||||
valid?: boolean;
|
||||
isLeavingPage?: boolean;
|
||||
save: () => Promise<void>;
|
||||
discard?: () => Promise<void>;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@ -22,7 +23,9 @@ export class PendingChangesGuard implements CanDeactivate<ComponentCanDeactivate
|
||||
return dialogRef.afterClosed().pipe(
|
||||
map(result => {
|
||||
if (result === ConfirmOptions.CONFIRM) {
|
||||
component.save();
|
||||
component.save().then();
|
||||
} else {
|
||||
component.discard?.().then();
|
||||
}
|
||||
component.isLeavingPage = false;
|
||||
return !!result;
|
||||
|
||||
@ -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<unknown>;
|
||||
@ -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<void> {
|
||||
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();
|
||||
|
||||
|
||||
@ -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],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user