diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index cf5cce420..a73c54ad9 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -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 = { diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index a21ee1312..adff25223 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -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() diff --git a/src-ui/src/app/utils/query-params.ts b/src-ui/src/app/utils/query-params.ts index 6af44e8c9..0849fab4b 100644 --- a/src-ui/src/app/utils/query-params.ts +++ b/src-ui/src/app/utils/query-params.ts @@ -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 }