]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Retain saved view filters when changing a saved view
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Wed, 26 Oct 2022 17:39:09 +0000 (10:39 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Wed, 26 Oct 2022 17:39:09 +0000 (10:39 -0700)
src-ui/src/app/services/document-list-view.service.ts

index 1dea011c020cd8605b4c849713ed69415969810f..5f0c7a237efe516b9c3b7862a81f7915ba7eb9be 100644 (file)
@@ -171,15 +171,15 @@ export class DocumentListViewService {
     this.reduceSelectionToFilter()
 
     if (!this.router.routerState.snapshot.url.includes('/view/')) {
-      this.router.navigate([], {
-        queryParams: { view: view.id },
-      })
+      this.router.navigate(['view', view.id])
     }
   }
 
   loadFromQueryParams(queryParams: ParamMap) {
     const paramsEmpty: boolean = queryParams.keys.length == 0
-    let newState: ListViewState = this.listViewStates.get(null)
+    let newState: ListViewState = this.listViewStates.get(
+      this._activeSavedViewId
+    )
     if (!paramsEmpty) newState = paramsToViewState(queryParams)
     if (newState == undefined) newState = this.defaultListViewState() // if nothing in local storage
 
@@ -225,7 +225,10 @@ export class DocumentListViewService {
             let base = ['/documents']
             this.router.navigate(base, {
               queryParams: paramsFromViewState(activeListViewState),
-              replaceUrl: !this.router.routerState.snapshot.url.includes('?'), // in case navigating from params-less /documents
+              replaceUrl: !(
+                this.router.routerState.snapshot.url.includes('?') ||
+                this.router.routerState.snapshot.url.includes('/view/')
+              ), // in case navigating from params-less /documents or /view
             })
           } else if (this._activeSavedViewId) {
             this.router.navigate([], {
@@ -288,9 +291,9 @@ export class DocumentListViewService {
   }
 
   set sortField(field: string) {
-    this._activeSavedViewId = null
     this.activeListViewState.sortField = field
     this.reload()
+    this._activeSavedViewId = null
     this.saveDocumentListView()
   }
 
@@ -299,9 +302,9 @@ export class DocumentListViewService {
   }
 
   set sortReverse(reverse: boolean) {
-    this._activeSavedViewId = null
     this.activeListViewState.sortReverse = reverse
     this.reload()
+    this._activeSavedViewId = null
     this.saveDocumentListView()
   }