]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Ensure retain all params when loading saved views 881/head
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Fri, 6 May 2022 18:27:18 +0000 (11:27 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Fri, 6 May 2022 18:27:18 +0000 (11:27 -0700)
src-ui/src/app/components/document-list/document-list.component.ts
src-ui/src/app/services/query-params.service.ts

index 39cce66f8ab811532592cf0de41003c6e4af6798..01c2bee3436e14d1eeda21fdc105001ddf229952 100644 (file)
@@ -119,31 +119,33 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
 
     this.route.paramMap
       .pipe(
-        filter((params) => params.has('id')), // only on saved view
+        filter((params) => params.has('id')), // only on saved view e.g. /view/id
         switchMap((params) => {
           return this.savedViewService
             .getCached(+params.get('id'))
-            .pipe(map((view) => ({ params, view })))
+            .pipe(map((view) => ({ view })))
         })
       )
       .pipe(takeUntil(this.unsubscribeNotifier))
-      .subscribe(({ view, params }) => {
+      .subscribe(({ view }) => {
         if (!view) {
           this.router.navigate(['404'])
           return
         }
         this.list.activateSavedView(view)
         this.list.reload()
+        this.queryParamsService.updateFromView(view)
         this.unmodifiedFilterRules = view.filter_rules
       })
 
     this.route.queryParamMap
       .pipe(
-        filter(() => !this.route.snapshot.paramMap.has('id')), // only when not on saved view
+        filter(() => !this.route.snapshot.paramMap.has('id')), // only when not on /view/id
         takeUntil(this.unsubscribeNotifier)
       )
       .subscribe((queryParams) => {
         if (queryParams.has('view')) {
+          // loading a saved view on /documents
           this.loadViewConfig(parseInt(queryParams.get('view')))
         } else {
           this.list.activateSavedView(null)
@@ -176,11 +178,7 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit {
       .subscribe((view) => {
         this.list.loadSavedView(view)
         this.list.reload()
-        // update query params if needed
-        this.router.navigate([], {
-          relativeTo: this.route,
-          queryParams: { view: viewId },
-        })
+        this.queryParamsService.updateFromView(view)
       })
   }
 
index c2e40ad6c6215a680ca2e87bc5415c8209d15a3e..92346ff00ddbab832ec5150b79aecd12417378eb 100644 (file)
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'
 import { ParamMap, Params, Router } from '@angular/router'
 import { FilterRule } from '../data/filter-rule'
 import { FILTER_RULE_TYPES } from '../data/filter-rule-type'
+import { PaperlessSavedView } from '../data/paperless-saved-view'
 import { DocumentListViewService } from './document-list-view.service'
 
 const SORT_FIELD_PARAMETER = 'sort'
@@ -78,6 +79,19 @@ export class QueryParamsService {
     }
   }
 
+  updateFromView(view: PaperlessSavedView) {
+    if (!this.router.routerState.snapshot.url.includes('/view/')) {
+      // navigation for /documents?view=
+      this.router.navigate([], {
+        queryParams: { view: view.id },
+      })
+    }
+    // make sure params are up-to-date
+    this.updateFilterRules(view.filter_rules, false)
+    this.sortParams[SORT_FIELD_PARAMETER] = this.list.sortField
+    this.sortParams[SORT_REVERSE_PARAMETER] = this.list.sortReverse
+  }
+
   navigateWithFilterRules(filterRules: FilterRule[]) {
     this.updateFilterRules(filterRules)
     this.router.navigate(['/documents'], {