From 94c07839a4af0adc8be6e35e42d14818cf33b6ba Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Mon, 14 Dec 2020 16:51:01 +0100 Subject: [PATCH] refactored filter service - I wasn't too happy with that in the end. - The filter editor should not be concerned about managing filter rule state. - Therefore, it should not access a service for filter rules. - The editor should simply be given a set of rules, and edit that rule set. - The only entity that should manage filter state should be the document list service, and the saved view service in the form of filters associated with saved views. --- .../document-list.component.html | 2 +- .../document-list/document-list.component.ts | 41 +--- .../filter-dropdown-date.component.ts | 4 +- .../filter-editor.component.html | 12 +- .../filter-editor/filter-editor.component.ts | 195 +++++++++++++++--- .../filter-editor-view.service.spec.ts | 16 -- .../services/filter-editor-view.service.ts | 182 ---------------- 7 files changed, 186 insertions(+), 266 deletions(-) delete mode 100644 src-ui/src/app/services/filter-editor-view.service.spec.ts delete mode 100644 src-ui/src/app/services/filter-editor-view.service.ts 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 b1b2c8f94..df86507f0 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 @@ -63,7 +63,7 @@
- +
diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index 8d090f001..f04b5d301 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -2,21 +2,14 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { ActivatedRoute } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; -import { cloneFilterRules, FilterRule } from 'src/app/data/filter-rule'; -import { FILTER_CORRESPONDENT, FILTER_DOCUMENT_TYPE, FILTER_HAS_TAG, FILTER_RULE_TYPES } from 'src/app/data/filter-rule-type'; import { SavedViewConfig } from 'src/app/data/saved-view-config'; import { DocumentListViewService } from 'src/app/services/document-list-view.service'; -import { FilterEditorViewService } from 'src/app/services/filter-editor-view.service'; import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service'; import { SavedViewConfigService } from 'src/app/services/saved-view-config.service'; import { Toast, ToastService } from 'src/app/services/toast.service'; import { environment } from 'src/environments/environment'; +import { FilterEditorComponent } from '../filter-editor/filter-editor.component'; import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-view-config-dialog.component'; -import { FilterEditorComponent } from 'src/app/components/filter-editor/filter-editor.component'; -import { PaperlessTag } from 'src/app/data/paperless-tag'; -import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'; -import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'; - @Component({ selector: 'app-document-list', templateUrl: './document-list.component.html', @@ -27,26 +20,20 @@ export class DocumentListComponent implements OnInit { constructor( public list: DocumentListViewService, public savedViewConfigService: SavedViewConfigService, - public filterEditorService: FilterEditorViewService, public route: ActivatedRoute, private toastService: ToastService, public modalService: NgbModal, private titleService: Title) { } + @ViewChild("filterEditor") + private filterEditor: FilterEditorComponent + displayMode = 'smallCards' // largeCards, smallCards, details get isFiltered() { return this.list.filterRules?.length > 0 } - set filterRules(filterRules: FilterRule[]) { - this.filterEditorService.filterRules = filterRules - } - - get filterRules(): FilterRule[] { - return this.filterEditorService.filterRules - } - getTitle() { return this.list.savedViewTitle || "Documents" } @@ -66,29 +53,18 @@ export class DocumentListComponent implements OnInit { this.route.paramMap.subscribe(params => { if (params.has('id')) { this.list.savedView = this.savedViewConfigService.getConfig(params.get('id')) - this.filterEditorService.filterRules = this.list.filterRules this.titleService.setTitle(`${this.list.savedView.title} - ${environment.appTitle}`) } else { this.list.savedView = null - this.filterEditorService.filterRules = this.list.filterRules this.titleService.setTitle(`Documents - ${environment.appTitle}`) } this.list.clear() this.list.reload() }) - this.filterEditorService.filterRules = this.list.filterRules } - applyFilterRules() { - this.list.filterRules = this.filterEditorService.filterRules - } - - clearFilterRules() { - this.list.filterRules = this.filterEditorService.filterRules - } loadViewConfig(config: SavedViewConfig) { - this.filterEditorService.filterRules = cloneFilterRules(config.filterRules) this.list.load(config) } @@ -113,18 +89,15 @@ export class DocumentListComponent implements OnInit { } clickTag(tagID: number) { - this.filterEditorService.toggleFilterByTag(tagID) - this.applyFilterRules() + this.filterEditor.toggleTag(tagID) } clickCorrespondent(correspondentID: number) { - this.filterEditorService.toggleFilterByCorrespondent(correspondentID) - this.applyFilterRules() + this.filterEditor.toggleCorrespondent(correspondentID) } clickDocumentType(documentTypeID: number) { - this.filterEditorService.toggleFilterByDocumentType(documentTypeID) - this.applyFilterRules() + this.filterEditor.toggleDocumentType(documentTypeID) } } diff --git a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts index f69028bf0..fbe9bdc14 100644 --- a/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts +++ b/src-ui/src/app/components/filter-editor/filter-dropdown-date/filter-dropdown-date.component.ts @@ -1,6 +1,4 @@ -import { Component, EventEmitter, Input, Output, ElementRef, ViewChild, OnChanges, SimpleChange } from '@angular/core'; -import { FilterRule } from 'src/app/data/filter-rule'; -import { ObjectWithId } from 'src/app/data/object-with-id'; +import { Component, EventEmitter, Input, Output, ElementRef, ViewChild, SimpleChange } from '@angular/core'; import { NgbDate, NgbDateStruct, NgbDatepicker } from '@ng-bootstrap/ng-bootstrap'; @Component({ 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 3452d12b3..b50ed53e3 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 @@ -6,14 +6,14 @@
- - - + + + - - + + -