From 0e78f32009ae97d7b91531f2dabb3b5bd210fc29 Mon Sep 17 00:00:00 2001
From: jonaswinkler <jonas.winkler@jpwinkler.de>
Date: Wed, 16 Dec 2020 16:04:20 +0100
Subject: [PATCH] fixed an issue with the settings not saving in case no saved
 views are present

---
 .../manage/settings/settings.component.ts     | 20 ++++++++++++++-----
 .../services/document-list-view.service.ts    |  4 ++--
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts
index 41bb21156..f839010b1 100644
--- a/src-ui/src/app/components/manage/settings/settings.component.ts
+++ b/src-ui/src/app/components/manage/settings/settings.component.ts
@@ -50,16 +50,26 @@ export class SettingsComponent implements OnInit {
     })
   }
 
+  private saveLocalSettings() {
+    localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
+    this.documentListViewService.updatePageSize()
+    this.toastService.showToast(Toast.make("Information", "Settings saved successfully."))
+  }
+
   saveSettings() {
     let x = []
     for (let id in this.savedViewGroup.value) {
       x.push(this.savedViewGroup.value[id])
     }
-    this.savedViewService.patchMany(x).subscribe(s => {
-      this.toastService.showToast(Toast.make("Information", "Settings saved successfully."))
-      localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage)
-      this.documentListViewService.updatePageSize()
-    })
+    if (x.length > 0) {
+      this.savedViewService.patchMany(x).subscribe(s => {
+        this.saveLocalSettings()
+      }, error => {
+        this.toastService.showToast(Toast.makeError(`Error while storing settings on server: ${JSON.stringify(error.error)}`))
+      })
+    } else {
+      this.saveLocalSettings()
+    }
 
   }
 }
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 7405fcd24..a549f373d 100644
--- a/src-ui/src/app/services/document-list-view.service.ts
+++ b/src-ui/src/app/services/document-list-view.service.ts
@@ -116,13 +116,13 @@ export class DocumentListViewService {
   set filterRules(filterRules: FilterRule[]) {
     //we're going to clone the filterRules object, since we don't
     //want changes in the filter editor to propagate into here right away.
-    this.view.filter_rules = cloneFilterRules(filterRules)
+    this.view.filter_rules = filterRules
     this.reload()
     this.saveDocumentListView()
   }
 
   get filterRules(): FilterRule[] {
-    return cloneFilterRules(this.view.filter_rules)
+    return this.view.filter_rules
   }
 
   set sortField(field: string) {