mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix browser unsaved changes with custom guard
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { Component, HostListener } from '@angular/core'
|
||||
import { FormControl } from '@angular/forms'
|
||||
import { ActivatedRoute, Router, Params } from '@angular/router'
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { from, Observable } from 'rxjs'
|
||||
import {
|
||||
debounceTime,
|
||||
@@ -23,13 +23,14 @@ import {
|
||||
} from 'src/app/services/rest/remote-version.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { TasksService } from 'src/app/services/tasks.service'
|
||||
import { ComponentCanDeactivate } from 'src/app/guards/dirty-doc.guard'
|
||||
|
||||
@Component({
|
||||
selector: 'app-app-frame',
|
||||
templateUrl: './app-frame.component.html',
|
||||
styleUrls: ['./app-frame.component.scss'],
|
||||
})
|
||||
export class AppFrameComponent {
|
||||
export class AppFrameComponent implements ComponentCanDeactivate {
|
||||
constructor(
|
||||
public router: Router,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
@@ -64,6 +65,11 @@ export class AppFrameComponent {
|
||||
return this.openDocumentsService.getOpenDocuments()
|
||||
}
|
||||
|
||||
@HostListener('window:beforeunload')
|
||||
canDeactivate(): Observable<boolean> | boolean {
|
||||
return !this.openDocumentsService.hasDirty()
|
||||
}
|
||||
|
||||
searchAutoComplete = (text$: Observable<string>) =>
|
||||
text$.pipe(
|
||||
debounceTime(200),
|
||||
|
Reference in New Issue
Block a user