mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
minor refactor query params utils
This commit is contained in:
parent
1c83f489d1
commit
48f9cb09af
@ -10,7 +10,7 @@ import { PaperlessDocument } from '../data/paperless-document'
|
||||
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
|
||||
import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys'
|
||||
import { generateParams, getStateFromQueryParams } from '../utils/query-params'
|
||||
import { generateParams, parseParams } from '../utils/query-params'
|
||||
import { DocumentService, DOCUMENT_SORT_FIELDS } from './rest/document.service'
|
||||
import { SettingsService } from './settings.service'
|
||||
|
||||
@ -169,7 +169,7 @@ export class DocumentListViewService {
|
||||
loadFromQueryParams(queryParams: ParamMap) {
|
||||
const paramsEmpty: boolean = queryParams.keys.length == 0
|
||||
let newState: ListViewState = this.listViewStates.get(null)
|
||||
if (!paramsEmpty) newState = getStateFromQueryParams(queryParams)
|
||||
if (!paramsEmpty) newState = parseParams(queryParams)
|
||||
if (newState == undefined) newState = this.defaultListViewState() // if nothing in local storage
|
||||
|
||||
this.activeListViewState.filterRules = newState.filterRules
|
||||
@ -200,12 +200,7 @@ export class DocumentListViewService {
|
||||
if (updateQueryParams && !this._activeSavedViewId) {
|
||||
let base = ['/documents']
|
||||
this.router.navigate(base, {
|
||||
queryParams: generateParams(
|
||||
activeListViewState.filterRules,
|
||||
activeListViewState.sortField,
|
||||
activeListViewState.sortReverse,
|
||||
activeListViewState.currentPage
|
||||
),
|
||||
queryParams: generateParams(activeListViewState),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -7,23 +7,17 @@ const SORT_FIELD_PARAMETER = 'sort'
|
||||
const SORT_REVERSE_PARAMETER = 'reverse'
|
||||
const PAGE_PARAMETER = 'page'
|
||||
|
||||
export function generateParams(
|
||||
filterRules: FilterRule[],
|
||||
sortField: string,
|
||||
sortReverse: boolean,
|
||||
currentPage: number
|
||||
): Params {
|
||||
let params = {}
|
||||
params[SORT_FIELD_PARAMETER] = sortField
|
||||
params[SORT_REVERSE_PARAMETER] = sortReverse ? 1 : undefined
|
||||
params[PAGE_PARAMETER] = isNaN(currentPage) ? 1 : currentPage
|
||||
return {
|
||||
...queryParamsFromFilterRules(filterRules),
|
||||
...params,
|
||||
}
|
||||
export function generateParams(viewState: ListViewState): Params {
|
||||
let params = queryParamsFromFilterRules(viewState.filterRules)
|
||||
params[SORT_FIELD_PARAMETER] = viewState.sortField
|
||||
params[SORT_REVERSE_PARAMETER] = viewState.sortReverse ? 1 : undefined
|
||||
params[PAGE_PARAMETER] = isNaN(viewState.currentPage)
|
||||
? 1
|
||||
: viewState.currentPage
|
||||
return params
|
||||
}
|
||||
|
||||
export function getStateFromQueryParams(queryParams: ParamMap): ListViewState {
|
||||
export function parseParams(queryParams: ParamMap): ListViewState {
|
||||
let filterRules = filterRulesFromQueryParams(queryParams)
|
||||
let sortField = queryParams.get(SORT_FIELD_PARAMETER)
|
||||
let sortReverse =
|
||||
|
Loading…
x
Reference in New Issue
Block a user