mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
prevent loss of unsaved changes to settings on tab nav
This commit is contained in:
parent
5e5f56dc67
commit
4f876db5d1
@ -206,7 +206,16 @@ export class SettingsComponent
|
|||||||
SettingsNavIDs
|
SettingsNavIDs
|
||||||
).find(([navIDkey, navIDValue]) => navIDValue == navChangeEvent.nextId)
|
).find(([navIDkey, navIDValue]) => navIDValue == navChangeEvent.nextId)
|
||||||
if (foundNavIDkey)
|
if (foundNavIDkey)
|
||||||
this.router.navigate(['settings', foundNavIDkey.toLowerCase()])
|
// if its dirty we need to wait for confirmation
|
||||||
|
this.router
|
||||||
|
.navigate(['settings', foundNavIDkey.toLowerCase()])
|
||||||
|
.then((navigated) => {
|
||||||
|
if (!navigated && this.isDirty) {
|
||||||
|
this.activeNavID = navChangeEvent.activeId
|
||||||
|
} else if (navigated && this.isDirty) {
|
||||||
|
this.initialize()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load tab contents 'on demand', either on mouseover or focusin (i.e. before click) or called from nav change event
|
// Load tab contents 'on demand', either on mouseover or focusin (i.e. before click) or called from nav change event
|
||||||
@ -214,7 +223,7 @@ export class SettingsComponent
|
|||||||
if (navID == SettingsNavIDs.SavedViews && !this.savedViews) {
|
if (navID == SettingsNavIDs.SavedViews && !this.savedViews) {
|
||||||
this.savedViewService.listAll().subscribe((r) => {
|
this.savedViewService.listAll().subscribe((r) => {
|
||||||
this.savedViews = r.results
|
this.savedViews = r.results
|
||||||
this.initialize()
|
this.initialize(false)
|
||||||
})
|
})
|
||||||
} else if (
|
} else if (
|
||||||
navID == SettingsNavIDs.Mail &&
|
navID == SettingsNavIDs.Mail &&
|
||||||
@ -225,15 +234,17 @@ export class SettingsComponent
|
|||||||
|
|
||||||
this.mailRuleService.listAll().subscribe((r) => {
|
this.mailRuleService.listAll().subscribe((r) => {
|
||||||
this.mailRules = r.results
|
this.mailRules = r.results
|
||||||
this.initialize()
|
this.initialize(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize(resetSettings: boolean = true) {
|
||||||
this.unsubscribeNotifier.next(true)
|
this.unsubscribeNotifier.next(true)
|
||||||
|
|
||||||
|
const currentFormValue = this.settingsForm.value
|
||||||
|
|
||||||
let storeData = this.getCurrentSettings()
|
let storeData = this.getCurrentSettings()
|
||||||
|
|
||||||
if (this.savedViews) {
|
if (this.savedViews) {
|
||||||
@ -352,6 +363,11 @@ export class SettingsComponent
|
|||||||
this.settingsForm.get('themeColor').value
|
this.settingsForm.get('themeColor').value
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!resetSettings && currentFormValue) {
|
||||||
|
// prevents loss of unsaved changes
|
||||||
|
this.settingsForm.patchValue(currentFormValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { DirtyCheckGuard } from '@ngneat/dirty-check-forms'
|
import { DirtyCheckGuard } from '@ngneat/dirty-check-forms'
|
||||||
import { Observable, Subject } from 'rxjs'
|
import { Observable, Subject } from 'rxjs'
|
||||||
import { map } from 'rxjs/operators'
|
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { ConfirmDialogComponent } from 'src/app/components/common/confirm-dialog/confirm-dialog.component'
|
import { ConfirmDialogComponent } from 'src/app/components/common/confirm-dialog/confirm-dialog.component'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user