]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Handle page parameter on saved views
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sat, 6 Aug 2022 06:35:13 +0000 (23:35 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Sat, 6 Aug 2022 06:35:13 +0000 (23:35 -0700)
src-ui/src/app/components/document-list/document-list.component.ts
src-ui/src/app/services/document-list-view.service.ts
src-ui/src/app/utils/query-params.ts

index cf5cce42007219c35bcad4d14b8838901026b728..a73c54ad9243328d71235918ca465ca8b86cd3e4 100644 (file)
@@ -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 = {
index a21ee131211db51012a51f254d5bbc02247dd15b..adff2522339a989610354e160a8f1ae454c230d4 100644 (file)
@@ -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()
index 6af44e8c9a13bcb547ff980d892ad8cba88d352d..0849fab4b47821b7c2c07841cea78964002ef255 100644 (file)
@@ -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
 }