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