mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Ensure retain all params when loading saved views
This commit is contained in:
parent
261cab8450
commit
4da49c8d59
@ -119,31 +119,33 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
|
|
||||||
this.route.paramMap
|
this.route.paramMap
|
||||||
.pipe(
|
.pipe(
|
||||||
filter((params) => params.has('id')), // only on saved view
|
filter((params) => params.has('id')), // only on saved view e.g. /view/id
|
||||||
switchMap((params) => {
|
switchMap((params) => {
|
||||||
return this.savedViewService
|
return this.savedViewService
|
||||||
.getCached(+params.get('id'))
|
.getCached(+params.get('id'))
|
||||||
.pipe(map((view) => ({ params, view })))
|
.pipe(map((view) => ({ view })))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||||
.subscribe(({ view, params }) => {
|
.subscribe(({ view }) => {
|
||||||
if (!view) {
|
if (!view) {
|
||||||
this.router.navigate(['404'])
|
this.router.navigate(['404'])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.list.activateSavedView(view)
|
this.list.activateSavedView(view)
|
||||||
this.list.reload()
|
this.list.reload()
|
||||||
|
this.queryParamsService.updateFromView(view)
|
||||||
this.unmodifiedFilterRules = view.filter_rules
|
this.unmodifiedFilterRules = view.filter_rules
|
||||||
})
|
})
|
||||||
|
|
||||||
this.route.queryParamMap
|
this.route.queryParamMap
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(() => !this.route.snapshot.paramMap.has('id')), // only when not on saved view
|
filter(() => !this.route.snapshot.paramMap.has('id')), // only when not on /view/id
|
||||||
takeUntil(this.unsubscribeNotifier)
|
takeUntil(this.unsubscribeNotifier)
|
||||||
)
|
)
|
||||||
.subscribe((queryParams) => {
|
.subscribe((queryParams) => {
|
||||||
if (queryParams.has('view')) {
|
if (queryParams.has('view')) {
|
||||||
|
// loading a saved view on /documents
|
||||||
this.loadViewConfig(parseInt(queryParams.get('view')))
|
this.loadViewConfig(parseInt(queryParams.get('view')))
|
||||||
} else {
|
} else {
|
||||||
this.list.activateSavedView(null)
|
this.list.activateSavedView(null)
|
||||||
@ -176,11 +178,7 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
.subscribe((view) => {
|
.subscribe((view) => {
|
||||||
this.list.loadSavedView(view)
|
this.list.loadSavedView(view)
|
||||||
this.list.reload()
|
this.list.reload()
|
||||||
// update query params if needed
|
this.queryParamsService.updateFromView(view)
|
||||||
this.router.navigate([], {
|
|
||||||
relativeTo: this.route,
|
|
||||||
queryParams: { view: viewId },
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'
|
|||||||
import { ParamMap, Params, Router } from '@angular/router'
|
import { ParamMap, Params, Router } from '@angular/router'
|
||||||
import { FilterRule } from '../data/filter-rule'
|
import { FilterRule } from '../data/filter-rule'
|
||||||
import { FILTER_RULE_TYPES } from '../data/filter-rule-type'
|
import { FILTER_RULE_TYPES } from '../data/filter-rule-type'
|
||||||
|
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||||
import { DocumentListViewService } from './document-list-view.service'
|
import { DocumentListViewService } from './document-list-view.service'
|
||||||
|
|
||||||
const SORT_FIELD_PARAMETER = 'sort'
|
const SORT_FIELD_PARAMETER = 'sort'
|
||||||
@ -78,6 +79,19 @@ export class QueryParamsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFromView(view: PaperlessSavedView) {
|
||||||
|
if (!this.router.routerState.snapshot.url.includes('/view/')) {
|
||||||
|
// navigation for /documents?view=
|
||||||
|
this.router.navigate([], {
|
||||||
|
queryParams: { view: view.id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// make sure params are up-to-date
|
||||||
|
this.updateFilterRules(view.filter_rules, false)
|
||||||
|
this.sortParams[SORT_FIELD_PARAMETER] = this.list.sortField
|
||||||
|
this.sortParams[SORT_REVERSE_PARAMETER] = this.list.sortReverse
|
||||||
|
}
|
||||||
|
|
||||||
navigateWithFilterRules(filterRules: FilterRule[]) {
|
navigateWithFilterRules(filterRules: FilterRule[]) {
|
||||||
this.updateFilterRules(filterRules)
|
this.updateFilterRules(filterRules)
|
||||||
this.router.navigate(['/documents'], {
|
this.router.navigate(['/documents'], {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user