diff --git a/src-ui/src/app/components/manage/settings/settings.component.html b/src-ui/src/app/components/manage/settings/settings.component.html index 73e4f8194..f71f12238 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.html +++ b/src-ui/src/app/components/manage/settings/settings.component.html @@ -34,24 +34,35 @@ Saved views - - - - Title - Show in dashboard - Show in sidebar - Actions - - - - - {{ view.name }} - {{ view.show_on_dashboard | yesno }} - {{ view.show_in_sidebar | yesno }} - Delete - - - + + + + + Name + + + + + Appears on + + + Show on dashboard + + + + Show in sidebar + + + + + Actions + Delete + + + + No saved views defined. + + 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 08275bbb2..41bb21156 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.ts +++ b/src-ui/src/app/components/manage/settings/settings.component.ts @@ -11,10 +11,13 @@ import { Toast, ToastService } from 'src/app/services/toast.service'; templateUrl: './settings.component.html', styleUrls: ['./settings.component.scss'] }) -export class SettingsComponent { +export class SettingsComponent implements OnInit { + + savedViewGroup = new FormGroup({}) settingsForm = new FormGroup({ - 'documentListItemPerPage': new FormControl(+localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT) + 'documentListItemPerPage': new FormControl(+localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT), + 'savedViews': this.savedViewGroup }) constructor( @@ -23,14 +26,40 @@ export class SettingsComponent { private toastService: ToastService ) { } + savedViews: PaperlessSavedView[] + + ngOnInit() { + this.savedViewService.listAll().subscribe(r => { + this.savedViews = r.results + for (let view of this.savedViews) { + this.savedViewGroup.addControl(view.id.toString(), new FormGroup({ + "id": new FormControl(view.id), + "name": new FormControl(view.name), + "show_on_dashboard": new FormControl(view.show_on_dashboard), + "show_in_sidebar": new FormControl(view.show_in_sidebar) + })) + } + }) + } + deleteSavedView(savedView: PaperlessSavedView) { this.savedViewService.delete(savedView).subscribe(() => { + this.savedViewGroup.removeControl(savedView.id.toString()) + this.savedViews.splice(this.savedViews.indexOf(savedView), 1) this.toastService.showToast(Toast.make("Information", `Saved view "${savedView.name} deleted.`)) }) } saveSettings() { - localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage) - this.documentListViewService.updatePageSize() + 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() + }) + } } diff --git a/src-ui/src/app/services/rest/abstract-paperless-service.ts b/src-ui/src/app/services/rest/abstract-paperless-service.ts index 6ec4346ed..93e1a0c85 100644 --- a/src-ui/src/app/services/rest/abstract-paperless-service.ts +++ b/src-ui/src/app/services/rest/abstract-paperless-service.ts @@ -92,4 +92,10 @@ export abstract class AbstractPaperlessService { this._listAll = null return this.http.put(this.getResourceUrl(o.id), o) } -} \ No newline at end of file + + patch(o: T): Observable { + this._listAll = null + return this.http.patch(this.getResourceUrl(o.id), o) + } + +} diff --git a/src-ui/src/app/services/rest/saved-view.service.ts b/src-ui/src/app/services/rest/saved-view.service.ts index 14c18b0e2..9a81e01e5 100644 --- a/src-ui/src/app/services/rest/saved-view.service.ts +++ b/src-ui/src/app/services/rest/saved-view.service.ts @@ -1,5 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { combineLatest, Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'; import { AbstractPaperlessService } from './abstract-paperless-service'; @@ -44,6 +45,12 @@ export class SavedViewService extends AbstractPaperlessService { + return combineLatest(objects.map(o => super.patch(o))).pipe( + tap(() => this.reload()) + ) + } + delete(o: PaperlessSavedView) { return super.delete(o).pipe( tap(() => this.reload()) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 43b5e5992..2def07fdd 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -159,11 +159,15 @@ class SavedViewSerializer(serializers.ModelSerializer): "sort_field", "sort_reverse", "filter_rules"] def update(self, instance, validated_data): - rules_data = validated_data.pop('filter_rules') + if 'filter_rules' in validated_data: + rules_data = validated_data.pop('filter_rules') + else: + rules_data = None super(SavedViewSerializer, self).update(instance, validated_data) - SavedViewFilterRule.objects.filter(saved_view=instance).delete() - for rule_data in rules_data: - SavedViewFilterRule.objects.create(saved_view=instance, **rule_data) + if rules_data: + SavedViewFilterRule.objects.filter(saved_view=instance).delete() + for rule_data in rules_data: + SavedViewFilterRule.objects.create(saved_view=instance, **rule_data) return instance def create(self, validated_data):