mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Add settings routing
This commit is contained in:
parent
14cf4f7095
commit
4f9a31244b
@ -47,6 +47,11 @@ const routes: Routes = [
|
||||
component: SettingsComponent,
|
||||
canDeactivate: [DirtyFormGuard],
|
||||
},
|
||||
{
|
||||
path: 'settings/:section',
|
||||
component: SettingsComponent,
|
||||
canDeactivate: [DirtyFormGuard],
|
||||
},
|
||||
{ path: 'tasks', component: TasksComponent },
|
||||
],
|
||||
},
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
<form [formGroup]="settingsForm" (ngSubmit)="saveSettings()">
|
||||
|
||||
<ul ngbNav #nav="ngbNav" (navChange)="maybeInitializeTab($event)" [(activeId)]="activeNavID" class="nav-tabs">
|
||||
<ul ngbNav #nav="ngbNav" (navChange)="onNavChange($event)" [(activeId)]="activeNavID" class="nav-tabs">
|
||||
<li [ngbNavItem]="SettingsNavIDs.General">
|
||||
<a ngbNavLink i18n>General</a>
|
||||
<ng-template ngbNavContent>
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
Subject,
|
||||
} from 'rxjs'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||
import { ActivatedRoute } from '@angular/router'
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { ViewportScroller } from '@angular/common'
|
||||
import { TourService } from 'ngx-ui-tour-ng-bootstrap'
|
||||
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
|
||||
@ -120,6 +120,7 @@ export class SettingsComponent
|
||||
@Inject(LOCALE_ID) public currentLocale: string,
|
||||
private viewportScroller: ViewportScroller,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router,
|
||||
public readonly tourService: TourService,
|
||||
private modalService: NgbModal
|
||||
) {
|
||||
@ -128,6 +129,23 @@ export class SettingsComponent
|
||||
})
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.initialize()
|
||||
|
||||
this.activatedRoute.paramMap.subscribe((paramMap) => {
|
||||
const section = paramMap.get('section')
|
||||
if (section) {
|
||||
const navIDKey: string = Object.keys(SettingsNavIDs).find(
|
||||
(navID) => navID.toLowerCase() == section
|
||||
)
|
||||
if (navIDKey) {
|
||||
this.activeNavID = SettingsNavIDs[navIDKey]
|
||||
this.maybeInitializeTab(this.activeNavID)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
if (this.activatedRoute.snapshot.fragment) {
|
||||
this.viewportScroller.scrollToAnchor(
|
||||
@ -182,23 +200,25 @@ export class SettingsComponent
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.initialize()
|
||||
onNavChange(navChangeEvent: NgbNavChangeEvent) {
|
||||
this.maybeInitializeTab(navChangeEvent.nextId)
|
||||
const [foundNavIDkey, foundNavIDValue] = Object.entries(
|
||||
SettingsNavIDs
|
||||
).find(([navIDkey, navIDValue]) => navIDValue == navChangeEvent.nextId)
|
||||
if (foundNavIDkey)
|
||||
this.router.navigate(['settings', foundNavIDkey.toLowerCase()])
|
||||
}
|
||||
|
||||
// Load tab contents 'on demand', either on mouseover or focusin (i.e. before click) or on nav change event
|
||||
maybeInitializeTab(navIDorEvent: number | NgbNavChangeEvent): void {
|
||||
const navID =
|
||||
typeof navIDorEvent == 'number' ? navIDorEvent : navIDorEvent.nextId
|
||||
// initialize saved views
|
||||
// Load tab contents 'on demand', either on mouseover or focusin (i.e. before click) or called from nav change event
|
||||
maybeInitializeTab(navID: number): void {
|
||||
if (navID == SettingsNavIDs.SavedViews && !this.savedViews) {
|
||||
this.savedViewService.listAll().subscribe((r) => {
|
||||
this.savedViews = r.results
|
||||
this.initialize()
|
||||
})
|
||||
} else if (
|
||||
(navID == SettingsNavIDs.Mail && !this.mailAccounts) ||
|
||||
!this.mailRules
|
||||
navID == SettingsNavIDs.Mail &&
|
||||
(!this.mailAccounts || !this.mailRules)
|
||||
) {
|
||||
this.mailAccountService.listAll().subscribe((r) => {
|
||||
this.mailAccounts = r.results
|
||||
|
Loading…
x
Reference in New Issue
Block a user