diff --git a/src-ui/src/app/app.module.ts b/src-ui/src/app/app.module.ts index ad12c9c47..af2c46492 100644 --- a/src-ui/src/app/app.module.ts +++ b/src-ui/src/app/app.module.ts @@ -48,6 +48,7 @@ import { WidgetFrameComponent } from './components/dashboard/widgets/widget-fram import { WelcomeWidgetComponent } from './components/dashboard/widgets/welcome-widget/welcome-widget.component'; import { YesNoPipe } from './pipes/yes-no.pipe'; import { FileSizePipe } from './pipes/file-size.pipe'; +import { FilterPipe } from './pipes/filter.pipe'; @NgModule({ declarations: [ @@ -88,7 +89,8 @@ import { FileSizePipe } from './pipes/file-size.pipe'; WidgetFrameComponent, WelcomeWidgetComponent, YesNoPipe, - FileSizePipe + FileSizePipe, + FilterPipe ], imports: [ BrowserModule, 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 8608ed92b..886b5832a 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 @@ -1,5 +1,4 @@ -
+
@@ -42,13 +42,14 @@
+
@@ -58,18 +59,69 @@ - +
+
+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
-
Filter
+
Advanced Filters
@@ -125,5 +177,12 @@
- +
+ + 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 09e73dd96..9870f3dc1 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 @@ -11,6 +11,12 @@ import { SavedViewConfigService } from 'src/app/services/saved-view-config.servi import { Toast, ToastService } from 'src/app/services/toast.service'; import { environment } from 'src/environments/environment'; import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-view-config-dialog.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'; +import { TagService } from 'src/app/services/rest/tag.service'; +import { CorrespondentService } from 'src/app/services/rest/correspondent.service'; +import { DocumentTypeService } from 'src/app/services/rest/document-type.service'; @Component({ selector: 'app-document-list', @@ -25,13 +31,20 @@ export class DocumentListComponent implements OnInit { public route: ActivatedRoute, private toastService: ToastService, public modalService: NgbModal, - private titleService: Title) { } + private titleService: Title, + private tagService: TagService, + private correspondentService: CorrespondentService, + private documentTypeService: DocumentTypeService) { } displayMode = 'smallCards' // largeCards, smallCards, details filterRules: FilterRule[] = [] showFilter = false + tags: PaperlessTag[] = [] + correspondents: PaperlessCorrespondent[] = [] + documentTypes: PaperlessDocumentType[] = [] + get isFiltered() { return this.list.filterRules?.length > 0 } @@ -67,6 +80,9 @@ export class DocumentListComponent implements OnInit { this.list.clear() this.list.reload() }) + this.tagService.listAll().subscribe(result => this.tags = result.results) + this.correspondentService.listAll().subscribe(result => this.correspondents = result.results) + this.documentTypeService.listAll().subscribe(result => this.documentTypes = result.results) } applyFilterRules() { @@ -103,8 +119,8 @@ export class DocumentListComponent implements OnInit { }) } - filterByTag(tag_id: number) { - let filterRules = this.list.filterRules + filterByTag(tag_id: number, singleton: boolean = false) { + let filterRules = singleton ? [] : this.list.filterRules if (filterRules.find(rule => rule.type.id == FILTER_HAS_TAG && rule.value == tag_id)) { return } @@ -114,8 +130,8 @@ export class DocumentListComponent implements OnInit { this.applyFilterRules() } - filterByCorrespondent(correspondent_id: number) { - let filterRules = this.list.filterRules + filterByCorrespondent(correspondent_id: number, singleton: boolean = false) { + let filterRules = singleton ? [] : this.list.filterRules let existing_rule = filterRules.find(rule => rule.type.id == FILTER_CORRESPONDENT) if (existing_rule && existing_rule.value == correspondent_id) { return @@ -128,8 +144,8 @@ export class DocumentListComponent implements OnInit { this.applyFilterRules() } - filterByDocumentType(document_type_id: number) { - let filterRules = this.list.filterRules + filterByDocumentType(document_type_id: number, singleton: boolean = false) { + let filterRules = singleton ? [] : this.list.filterRules let existing_rule = filterRules.find(rule => rule.type.id == FILTER_DOCUMENT_TYPE) if (existing_rule && existing_rule.value == document_type_id) { return diff --git a/src-ui/src/app/pipes/filter.pipe.ts b/src-ui/src/app/pipes/filter.pipe.ts new file mode 100644 index 000000000..f799f40cc --- /dev/null +++ b/src-ui/src/app/pipes/filter.pipe.ts @@ -0,0 +1,17 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'filter' +}) +export class FilterPipe implements PipeTransform { + transform(items: any[], searchText: string): any[] { + if (!items) return []; + if (!searchText) return items; + + return items.filter(item => { + return Object.keys(item).some(key => { + return String(item[key]).toLowerCase().includes(searchText.toLowerCase()); + }); + }); + } +}