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.
This commit is contained in:
jonaswinkler
2020-12-14 16:51:01 +01:00
parent 10440ec820
commit 94c07839a4
7 changed files with 186 additions and 266 deletions

View File

@@ -63,7 +63,7 @@
</app-page-header>
<div class="w-100 mb-4">
<app-filter-editor [(filterEditorService)]="filterEditorService" (apply)="applyFilterRules()" (clear)="clearFilterRules()" #filterEditor></app-filter-editor>
<app-filter-editor [(filterRules)]="list.filterRules" #filterEditor></app-filter-editor>
</div>
<div class="d-flex justify-content-between align-items-center">

View File

@@ -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)
}
}