From ed5a4a2d3e914a96915b3293397cd2b7a8b9e624 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Wed, 4 Nov 2020 19:28:08 +0100 Subject: [PATCH] adjustable page size fixes #8 --- .../document-list.component.html | 2 +- .../filter-editor.component.html | 3 - .../manage/settings/settings.component.html | 86 ++++++++++++------- .../manage/settings/settings.component.ts | 18 +++- src-ui/src/app/data/storage-keys.ts | 5 ++ .../services/document-list-view.service.ts | 14 ++- 6 files changed, 87 insertions(+), 41 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index b66cfbfa0..1455cabbc 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -73,7 +73,7 @@ -
diff --git a/src-ui/src/app/components/filter-editor/filter-editor.component.html b/src-ui/src/app/components/filter-editor/filter-editor.component.html index 1cca0fd7f..48780e950 100644 --- a/src-ui/src/app/components/filter-editor/filter-editor.component.html +++ b/src-ui/src/app/components/filter-editor/filter-editor.component.html @@ -1,8 +1,5 @@
- {{rule.type.name}}
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 e8931ccdf..146d0c1be 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.html +++ b/src-ui/src/app/components/manage/settings/settings.component.html @@ -3,37 +3,61 @@ - + +
+ + + \ No newline at end of file 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 c56cd6a78..e14c2bd7b 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.ts +++ b/src-ui/src/app/components/manage/settings/settings.component.ts @@ -1,5 +1,8 @@ import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup } from '@angular/forms'; import { SavedViewConfig } from 'src/app/data/saved-view-config'; +import { GENERAL_SETTINGS } from 'src/app/data/storage-keys'; +import { DocumentListViewService } from 'src/app/services/document-list-view.service'; import { SavedViewConfigService } from 'src/app/services/saved-view-config.service'; @Component({ @@ -9,11 +12,14 @@ import { SavedViewConfigService } from 'src/app/services/saved-view-config.servi }) export class SettingsComponent implements OnInit { - constructor( - private savedViewConfigService: SavedViewConfigService - ) { } + settingsForm = new FormGroup({ + 'documentListItemPerPage': new FormControl(+localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT) + }) - active + constructor( + private savedViewConfigService: SavedViewConfigService, + private documentListViewService: DocumentListViewService + ) { } ngOnInit(): void { } @@ -22,4 +28,8 @@ export class SettingsComponent implements OnInit { this.savedViewConfigService.deleteConfig(config) } + saveSettings() { + localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage) + this.documentListViewService.updatePageSize() + } } diff --git a/src-ui/src/app/data/storage-keys.ts b/src-ui/src/app/data/storage-keys.ts index aa39b31d1..cc4a05ec2 100644 --- a/src-ui/src/app/data/storage-keys.ts +++ b/src-ui/src/app/data/storage-keys.ts @@ -1,3 +1,8 @@ export const OPEN_DOCUMENT_SERVICE = { DOCUMENTS: 'open-documents-service:openDocuments' +} + +export const GENERAL_SETTINGS = { + DOCUMENT_LIST_SIZE: 'general-settings:documentListSize', + DOCUMENT_LIST_SIZE_DEFAULT: 50 } \ No newline at end of file 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 0ea509863..e554f2c8f 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -3,6 +3,7 @@ import { Observable } from 'rxjs'; import { cloneFilterRules, FilterRule } from '../data/filter-rule'; import { PaperlessDocument } from '../data/paperless-document'; import { SavedViewConfig } from '../data/saved-view-config'; +import { GENERAL_SETTINGS } from '../data/storage-keys'; import { DocumentService, SORT_DIRECTION_DESCENDING } from './rest/document.service'; @@ -15,6 +16,7 @@ export class DocumentListViewService { documents: PaperlessDocument[] = [] currentPage = 1 + currentPageSize: number = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT collectionSize: number currentFilterRules: FilterRule[] = [] @@ -39,7 +41,7 @@ export class DocumentListViewService { this.documentService.list( this.currentPage, - null, + this.currentPageSize, sortField, sortDirection, filterRules).subscribe( @@ -64,7 +66,7 @@ export class DocumentListViewService { } getLastPage(): number { - return Math.ceil(this.collectionSize / 25) + return Math.ceil(this.collectionSize / this.currentPageSize) } hasNext(doc: number) { @@ -98,5 +100,13 @@ export class DocumentListViewService { }) } + updatePageSize() { + let newPageSize = +localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT + if (newPageSize != this.currentPageSize) { + this.currentPageSize = newPageSize + //this.reload() + } + } + constructor(private documentService: DocumentService) { } }