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;
|
valid?: boolean;
|
||||||
isLeavingPage?: boolean;
|
isLeavingPage?: boolean;
|
||||||
save: () => Promise<void>;
|
save: () => Promise<void>;
|
||||||
|
discard?: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
@ -22,7 +23,9 @@ export class PendingChangesGuard implements CanDeactivate<ComponentCanDeactivate
|
|||||||
return dialogRef.afterClosed().pipe(
|
return dialogRef.afterClosed().pipe(
|
||||||
map(result => {
|
map(result => {
|
||||||
if (result === ConfirmOptions.CONFIRM) {
|
if (result === ConfirmOptions.CONFIRM) {
|
||||||
component.save();
|
component.save().then();
|
||||||
|
} else {
|
||||||
|
component.discard?.().then();
|
||||||
}
|
}
|
||||||
component.isLeavingPage = false;
|
component.isLeavingPage = false;
|
||||||
return !!result;
|
return !!result;
|
||||||
|
|||||||
@ -51,6 +51,7 @@ import { FileDataModel } from '../../../../models/file/file-data.model';
|
|||||||
import { filePreviewScreenProviders } from './file-preview-providers';
|
import { filePreviewScreenProviders } from './file-preview-providers';
|
||||||
import { ManualAnnotationService } from '../../services/manual-annotation.service';
|
import { ManualAnnotationService } from '../../services/manual-annotation.service';
|
||||||
import { PageRotationService } from './services/page-rotation.service';
|
import { PageRotationService } from './services/page-rotation.service';
|
||||||
|
import { ComponentCanDeactivate } from '../../../../guards/can-deactivate.guard';
|
||||||
import Annotation = Core.Annotations.Annotation;
|
import Annotation = Core.Annotations.Annotation;
|
||||||
import PDFNet = Core.PDFNet;
|
import PDFNet = Core.PDFNet;
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ const ALL_HOTKEY_ARRAY = ['Escape', 'F', 'f', 'ArrowUp', 'ArrowDown'];
|
|||||||
styleUrls: ['./file-preview-screen.component.scss'],
|
styleUrls: ['./file-preview-screen.component.scss'],
|
||||||
providers: filePreviewScreenProviders,
|
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;
|
readonly circleButtonTypes = CircleButtonTypes;
|
||||||
|
|
||||||
dialogRef: MatDialogRef<unknown>;
|
dialogRef: MatDialogRef<unknown>;
|
||||||
@ -125,6 +126,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get changed() {
|
||||||
|
return this._pageRotationService.hasRotations();
|
||||||
|
}
|
||||||
|
|
||||||
get visibleAnnotations(): AnnotationWrapper[] {
|
get visibleAnnotations(): AnnotationWrapper[] {
|
||||||
return this._fileData ? this._fileData.getVisibleAnnotations(this.viewModeService.viewMode) : [];
|
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> {
|
async updateViewMode(): Promise<void> {
|
||||||
if (!this._instance?.Core.documentViewer.getDocument()) {
|
if (!this._instance?.Core.documentViewer.getDocument()) {
|
||||||
return;
|
return;
|
||||||
@ -395,7 +404,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await firstValueFrom(this._pageRotationService.showConfirmationDialogIfHasRotations());
|
|
||||||
this._scrollViews();
|
this._scrollViews();
|
||||||
this.multiSelectService.deactivate();
|
this.multiSelectService.deactivate();
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import { AcceptRecommendationDialogComponent } from './dialogs/accept-recommenda
|
|||||||
import { AnnotationCardComponent } from './components/annotation-card/annotation-card.component';
|
import { AnnotationCardComponent } from './components/annotation-card/annotation-card.component';
|
||||||
import { AnnotationReferencesPageIndicatorComponent } from './components/annotation-references-page-indicator/annotation-references-page-indicator.component';
|
import { AnnotationReferencesPageIndicatorComponent } from './components/annotation-references-page-indicator/annotation-references-page-indicator.component';
|
||||||
import { HighlightsSeparatorComponent } from './components/highlights-separator/highlights-separator.component';
|
import { HighlightsSeparatorComponent } from './components/highlights-separator/highlights-separator.component';
|
||||||
|
import { PendingChangesGuard } from '../../../../guards/can-deactivate.guard';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
@ -31,6 +32,7 @@ const routes: Routes = [
|
|||||||
component: FilePreviewScreenComponent,
|
component: FilePreviewScreenComponent,
|
||||||
pathMatch: 'full',
|
pathMatch: 'full',
|
||||||
data: { reuse: true },
|
data: { reuse: true },
|
||||||
|
canDeactivate: [PendingChangesGuard],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user