mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00

update ngx-file-drop Update ng-bootstrap, ng-select, cookie-service and ui-tour Update setup-jest.ts bump typescript to 5.1.6 bump ngx-color and tslib
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { first, Observable, Subject } from 'rxjs'
|
|
import { DocumentListComponent } from '../components/document-list/document-list.component'
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
|
import { ConfirmDialogComponent } from '../components/common/confirm-dialog/confirm-dialog.component'
|
|
import { SettingsService } from '../services/settings.service'
|
|
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
|
|
|
|
@Injectable()
|
|
export class DirtySavedViewGuard {
|
|
constructor(
|
|
private modalService: NgbModal,
|
|
private settings: SettingsService
|
|
) {}
|
|
|
|
canDeactivate(
|
|
component: DocumentListComponent
|
|
): boolean | Observable<boolean> {
|
|
return component.savedViewIsModified &&
|
|
this.settings.get(SETTINGS_KEYS.SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE)
|
|
? this.warn(component)
|
|
: true
|
|
}
|
|
|
|
warn(component: DocumentListComponent) {
|
|
let modal = this.modalService.open(ConfirmDialogComponent, {
|
|
backdrop: 'static',
|
|
})
|
|
modal.componentInstance.title = $localize`Unsaved Changes`
|
|
modal.componentInstance.messageBold =
|
|
$localize`You have unsaved changes to the saved view` +
|
|
' "' +
|
|
component.getTitle()
|
|
;('".')
|
|
modal.componentInstance.message = $localize`Are you sure you want to close this saved view?`
|
|
modal.componentInstance.btnClass = 'btn-secondary'
|
|
modal.componentInstance.btnCaption = $localize`Close`
|
|
modal.componentInstance.alternativeBtnClass = 'btn-primary'
|
|
modal.componentInstance.alternativeBtnCaption = $localize`Save and close`
|
|
modal.componentInstance.alternativeClicked.pipe(first()).subscribe(() => {
|
|
modal.componentInstance.buttonsEnabled = false
|
|
component.saveViewConfig()
|
|
modal.close()
|
|
})
|
|
modal.componentInstance.confirmClicked.pipe(first()).subscribe(() => {
|
|
modal.componentInstance.buttonsEnabled = false
|
|
modal.close()
|
|
})
|
|
|
|
const subject = new Subject<boolean>()
|
|
modal.componentInstance.confirmSubject = subject
|
|
modal.componentInstance.alternativeSubject = subject
|
|
|
|
return subject
|
|
}
|
|
}
|