mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-03 11:29:28 -05:00
21 lines
567 B
TypeScript
21 lines
567 B
TypeScript
import { CanDeactivate } from '@angular/router'
|
|
import { Injectable } from '@angular/core'
|
|
import { Observable } from 'rxjs'
|
|
|
|
export interface ComponentCanDeactivate {
|
|
canDeactivate: () => boolean | Observable<boolean>
|
|
}
|
|
|
|
@Injectable()
|
|
export class DirtyDocGuard implements CanDeactivate<ComponentCanDeactivate> {
|
|
canDeactivate(
|
|
component: ComponentCanDeactivate
|
|
): boolean | Observable<boolean> {
|
|
return component.canDeactivate()
|
|
? true
|
|
: confirm(
|
|
$localize`Warning: You have unsaved changes to your document(s).`
|
|
)
|
|
}
|
|
}
|