mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Handle page parameter on saved views
This commit is contained in:
parent
ca75fb5664
commit
a6f3378c21
@ -6,7 +6,7 @@ import {
|
||||
ViewChild,
|
||||
ViewChildren,
|
||||
} from '@angular/core'
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { ActivatedRoute, convertToParamMap, Router } from '@angular/router'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { filter, first, map, Subject, switchMap, takeUntil } from 'rxjs'
|
||||
import { FilterRule, isFullTextFilterRule } from 'src/app/data/filter-rule'
|
||||
@ -126,7 +126,11 @@ export class DocumentListComponent implements OnInit, OnDestroy {
|
||||
this.router.navigate(['404'])
|
||||
return
|
||||
}
|
||||
this.list.activateSavedView(view)
|
||||
|
||||
this.list.activateSavedViewWithQueryParams(
|
||||
view,
|
||||
convertToParamMap(this.route.snapshot.queryParams)
|
||||
)
|
||||
this.list.reload()
|
||||
this.unmodifiedFilterRules = view.filter_rules
|
||||
})
|
||||
@ -139,7 +143,13 @@ export class DocumentListComponent implements OnInit, OnDestroy {
|
||||
.subscribe((queryParams) => {
|
||||
if (queryParams.has('view')) {
|
||||
// loading a saved view on /documents
|
||||
this.loadViewConfig(parseInt(queryParams.get('view')))
|
||||
this.savedViewService
|
||||
.getCached(parseInt(queryParams.get('view')))
|
||||
.pipe(first())
|
||||
.subscribe((view) => {
|
||||
this.list.activateSavedView(view)
|
||||
this.list.reload()
|
||||
})
|
||||
} else {
|
||||
this.list.activateSavedView(null)
|
||||
this.list.loadFromQueryParams(queryParams)
|
||||
@ -154,16 +164,6 @@ export class DocumentListComponent implements OnInit, OnDestroy {
|
||||
this.unsubscribeNotifier.complete()
|
||||
}
|
||||
|
||||
loadViewConfig(viewId: number) {
|
||||
this.savedViewService
|
||||
.getCached(viewId)
|
||||
.pipe(first())
|
||||
.subscribe((view) => {
|
||||
this.list.activateSavedView(view)
|
||||
this.list.reload()
|
||||
})
|
||||
}
|
||||
|
||||
saveViewConfig() {
|
||||
if (this.list.activeSavedViewId != null) {
|
||||
let savedView: PaperlessSavedView = {
|
||||
|
@ -147,6 +147,15 @@ export class DocumentListViewService {
|
||||
}
|
||||
}
|
||||
|
||||
activateSavedViewWithQueryParams(
|
||||
view: PaperlessSavedView,
|
||||
queryParams: ParamMap
|
||||
) {
|
||||
let params = parseParams(queryParams)
|
||||
this.activateSavedView(view)
|
||||
this.activeListViewState.currentPage = params.currentPage
|
||||
}
|
||||
|
||||
loadSavedView(view: PaperlessSavedView, closeCurrentView: boolean = false) {
|
||||
if (closeCurrentView) {
|
||||
this._activeSavedViewId = null
|
||||
@ -212,12 +221,16 @@ export class DocumentListViewService {
|
||||
this.isReloading = false
|
||||
activeListViewState.collectionSize = result.count
|
||||
activeListViewState.documents = result.results
|
||||
|
||||
if (updateQueryParams && !this._activeSavedViewId) {
|
||||
let base = ['/documents']
|
||||
this.router.navigate(base, {
|
||||
queryParams: generateParams(activeListViewState),
|
||||
})
|
||||
} else if (this._activeSavedViewId) {
|
||||
this.router.navigate([], {
|
||||
queryParams: generateParams(activeListViewState, true),
|
||||
queryParamsHandling: 'merge',
|
||||
})
|
||||
}
|
||||
|
||||
if (onFinish) {
|
||||
@ -305,7 +318,6 @@ export class DocumentListViewService {
|
||||
|
||||
set currentPage(page: number) {
|
||||
if (this.activeListViewState.currentPage == page) return
|
||||
this._activeSavedViewId = null
|
||||
this.activeListViewState.currentPage = page
|
||||
this.reload()
|
||||
this.saveDocumentListView()
|
||||
|
@ -7,13 +7,18 @@ const SORT_FIELD_PARAMETER = 'sort'
|
||||
const SORT_REVERSE_PARAMETER = 'reverse'
|
||||
const PAGE_PARAMETER = 'page'
|
||||
|
||||
export function generateParams(viewState: ListViewState): Params {
|
||||
export function generateParams(
|
||||
viewState: ListViewState,
|
||||
pageOnly: boolean = false
|
||||
): Params {
|
||||
let params = queryParamsFromFilterRules(viewState.filterRules)
|
||||
params[SORT_FIELD_PARAMETER] = viewState.sortField
|
||||
params[SORT_REVERSE_PARAMETER] = viewState.sortReverse ? 1 : undefined
|
||||
if (pageOnly) params = {}
|
||||
params[PAGE_PARAMETER] = isNaN(viewState.currentPage)
|
||||
? 1
|
||||
: viewState.currentPage
|
||||
if (pageOnly && viewState.currentPage == 1) params[PAGE_PARAMETER] = null
|
||||
return params
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user