2021-02-18 17:29:21 +01:00
|
|
|
import { Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
|
2020-12-14 19:26:36 +01:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2020-10-30 22:46:43 +01:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
2021-01-27 18:47:02 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2021-04-04 00:03:51 +02:00
|
|
|
import { FilterRule } from 'src/app/data/filter-rule';
|
2021-04-03 21:07:36 +02:00
|
|
|
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type';
|
2020-12-22 02:59:09 +01:00
|
|
|
import { PaperlessDocument } from 'src/app/data/paperless-document';
|
2020-12-14 19:26:36 +01:00
|
|
|
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
|
2021-01-04 17:08:52 +01:00
|
|
|
import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive';
|
2021-01-27 18:47:02 +01:00
|
|
|
import { ConsumerStatusService } from 'src/app/services/consumer-status.service';
|
2020-10-30 23:43:19 +01:00
|
|
|
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
|
2020-12-25 00:58:17 -08:00
|
|
|
import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service';
|
2020-12-14 19:26:36 +01:00
|
|
|
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
|
2021-02-18 17:29:21 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
2020-12-18 16:03:52 -08:00
|
|
|
import { FilterEditorComponent } from './filter-editor/filter-editor.component';
|
2020-10-30 22:46:43 +01:00
|
|
|
import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-view-config-dialog.component';
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-document-list',
|
|
|
|
|
templateUrl: './document-list.component.html',
|
2020-11-22 14:43:59 +01:00
|
|
|
styleUrls: ['./document-list.component.scss']
|
2020-10-27 01:10:18 +01:00
|
|
|
})
|
2021-01-27 18:47:02 +01:00
|
|
|
export class DocumentListComponent implements OnInit, OnDestroy {
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
constructor(
|
2020-11-28 21:27:04 +01:00
|
|
|
public list: DocumentListViewService,
|
2020-12-14 19:26:36 +01:00
|
|
|
public savedViewService: SavedViewService,
|
2020-10-30 22:46:43 +01:00
|
|
|
public route: ActivatedRoute,
|
2020-12-14 19:26:36 +01:00
|
|
|
private router: Router,
|
2020-11-28 21:27:04 +01:00
|
|
|
private toastService: ToastService,
|
2021-01-27 18:47:02 +01:00
|
|
|
private modalService: NgbModal,
|
|
|
|
|
private consumerStatusService: ConsumerStatusService
|
|
|
|
|
) { }
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2020-12-14 16:51:01 +01:00
|
|
|
@ViewChild("filterEditor")
|
|
|
|
|
private filterEditor: FilterEditorComponent
|
2020-10-27 01:10:18 +01:00
|
|
|
|
2021-01-04 17:08:52 +01:00
|
|
|
@ViewChildren(SortableDirective) headers: QueryList<SortableDirective>;
|
2020-10-27 01:10:18 +01:00
|
|
|
|
|
|
|
|
displayMode = 'smallCards' // largeCards, smallCards, details
|
|
|
|
|
|
2021-04-04 00:03:51 +02:00
|
|
|
unmodifiedFilterRules: FilterRule[] = []
|
2021-01-06 07:57:33 -08:00
|
|
|
|
2021-01-27 18:47:02 +01:00
|
|
|
private consumptionFinishedSubscription: Subscription
|
|
|
|
|
|
2021-01-06 10:57:13 -08:00
|
|
|
get isFiltered() {
|
|
|
|
|
return this.list.filterRules?.length > 0
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 00:07:31 +01:00
|
|
|
getTitle() {
|
2021-02-18 17:29:21 +01:00
|
|
|
return this.list.activeSavedViewTitle || $localize`Documents`
|
2020-11-08 00:07:31 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
getSortFields() {
|
2020-10-30 23:43:19 +01:00
|
|
|
return DOCUMENT_SORT_FIELDS
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-04 17:08:52 +01:00
|
|
|
onSort(event: SortEvent) {
|
|
|
|
|
this.list.setSort(event.column, event.reverse)
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 23:14:19 -08:00
|
|
|
get isBulkEditing(): boolean {
|
|
|
|
|
return this.list.selected.size > 0
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 01:10:18 +01:00
|
|
|
saveDisplayMode() {
|
|
|
|
|
localStorage.setItem('document-list:displayMode', this.displayMode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
if (localStorage.getItem('document-list:displayMode') != null) {
|
|
|
|
|
this.displayMode = localStorage.getItem('document-list:displayMode')
|
|
|
|
|
}
|
2021-01-27 18:47:02 +01:00
|
|
|
this.consumptionFinishedSubscription = this.consumerStatusService.onDocumentConsumptionFinished().subscribe(() => {
|
|
|
|
|
this.list.reload()
|
|
|
|
|
})
|
2020-10-30 22:46:43 +01:00
|
|
|
this.route.paramMap.subscribe(params => {
|
|
|
|
|
if (params.has('id')) {
|
2020-12-14 19:26:36 +01:00
|
|
|
this.savedViewService.getCached(+params.get('id')).subscribe(view => {
|
|
|
|
|
if (!view) {
|
|
|
|
|
this.router.navigate(["404"])
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-02-18 17:29:21 +01:00
|
|
|
this.list.activateSavedView(view)
|
2021-01-06 07:59:46 -08:00
|
|
|
this.list.reload()
|
2021-04-04 00:03:51 +02:00
|
|
|
this.unmodifiedFilterRules = view.filter_rules
|
2020-12-14 19:26:36 +01:00
|
|
|
})
|
2020-10-30 22:46:43 +01:00
|
|
|
} else {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.list.activateSavedView(null)
|
2021-01-06 07:59:46 -08:00
|
|
|
this.list.reload()
|
2021-04-04 00:03:51 +02:00
|
|
|
this.unmodifiedFilterRules = []
|
2020-10-30 22:46:43 +01:00
|
|
|
}
|
|
|
|
|
})
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 18:47:02 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
if (this.consumptionFinishedSubscription) {
|
|
|
|
|
this.consumptionFinishedSubscription.unsubscribe()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 19:26:36 +01:00
|
|
|
loadViewConfig(view: PaperlessSavedView) {
|
2021-02-18 17:29:21 +01:00
|
|
|
this.list.loadSavedView(view)
|
2020-12-14 19:39:16 +01:00
|
|
|
this.list.reload()
|
2020-10-30 22:46:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveViewConfig() {
|
2021-02-18 17:29:21 +01:00
|
|
|
if (this.list.activeSavedViewId != null) {
|
|
|
|
|
let savedView: PaperlessSavedView = {
|
|
|
|
|
id: this.list.activeSavedViewId,
|
|
|
|
|
filter_rules: this.list.filterRules,
|
|
|
|
|
sort_field: this.list.sortField,
|
|
|
|
|
sort_reverse: this.list.sortReverse
|
|
|
|
|
}
|
|
|
|
|
this.savedViewService.patch(savedView).subscribe(result => {
|
|
|
|
|
this.toastService.showInfo($localize`View "${this.list.activeSavedViewTitle}" saved successfully.`)
|
2021-04-04 01:25:54 +02:00
|
|
|
this.unmodifiedFilterRules = this.list.filterRules
|
2021-02-18 17:29:21 +01:00
|
|
|
})
|
|
|
|
|
}
|
2020-11-28 21:27:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveViewConfigAs() {
|
2020-10-30 22:46:43 +01:00
|
|
|
let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})
|
2020-12-18 14:55:21 -08:00
|
|
|
modal.componentInstance.defaultName = this.filterEditor.generateFilterName()
|
2020-10-30 22:46:43 +01:00
|
|
|
modal.componentInstance.saveClicked.subscribe(formValue => {
|
2021-01-03 21:44:53 +01:00
|
|
|
modal.componentInstance.buttonsEnabled = false
|
2021-02-18 17:29:21 +01:00
|
|
|
let savedView: PaperlessSavedView = {
|
2020-12-14 19:26:36 +01:00
|
|
|
name: formValue.name,
|
|
|
|
|
show_on_dashboard: formValue.showOnDashboard,
|
|
|
|
|
show_in_sidebar: formValue.showInSideBar,
|
|
|
|
|
filter_rules: this.list.filterRules,
|
|
|
|
|
sort_reverse: this.list.sortReverse,
|
|
|
|
|
sort_field: this.list.sortField
|
2020-12-14 21:14:33 +01:00
|
|
|
}
|
2021-01-04 00:20:10 -08:00
|
|
|
|
2020-12-14 21:14:33 +01:00
|
|
|
this.savedViewService.create(savedView).subscribe(() => {
|
2020-12-14 19:26:36 +01:00
|
|
|
modal.close()
|
2020-12-28 21:52:09 +01:00
|
|
|
this.toastService.showInfo($localize`View "${savedView.name}" created successfully.`)
|
2021-01-03 21:44:53 +01:00
|
|
|
}, error => {
|
|
|
|
|
modal.componentInstance.error = error.error
|
|
|
|
|
modal.componentInstance.buttonsEnabled = true
|
2020-10-30 22:46:43 +01:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-11-28 21:28:07 +01:00
|
|
|
|
2021-01-14 14:10:23 -08:00
|
|
|
toggleSelected(document: PaperlessDocument, event: MouseEvent): void {
|
2021-01-15 01:59:29 -08:00
|
|
|
if (!event.shiftKey) this.list.toggleSelected(document)
|
|
|
|
|
else this.list.selectRangeTo(document)
|
2021-01-14 10:56:30 -08:00
|
|
|
}
|
|
|
|
|
|
2020-12-11 15:20:47 -08:00
|
|
|
clickTag(tagID: number) {
|
2020-12-19 22:14:52 -08:00
|
|
|
this.list.selectNone()
|
2020-12-21 11:12:48 -08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.filterEditor.toggleTag(tagID)
|
|
|
|
|
})
|
2020-11-28 21:28:07 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-11 15:20:47 -08:00
|
|
|
clickCorrespondent(correspondentID: number) {
|
2020-12-19 22:14:52 -08:00
|
|
|
this.list.selectNone()
|
2020-12-21 11:12:48 -08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.filterEditor.toggleCorrespondent(correspondentID)
|
|
|
|
|
})
|
2020-11-28 21:28:07 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-11 15:20:47 -08:00
|
|
|
clickDocumentType(documentTypeID: number) {
|
2020-12-19 22:14:52 -08:00
|
|
|
this.list.selectNone()
|
2020-12-21 11:12:48 -08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
this.filterEditor.toggleDocumentType(documentTypeID)
|
|
|
|
|
})
|
2020-11-28 22:14:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-17 22:25:22 +01:00
|
|
|
clickMoreLike(documentID: number) {
|
2021-04-03 21:07:36 +02:00
|
|
|
this.list.quickFilter([{rule_type: FILTER_FULLTEXT_MORELIKE, value: documentID.toString()}])
|
2021-03-17 22:25:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-22 02:59:09 +01:00
|
|
|
trackByDocumentId(index, item: PaperlessDocument) {
|
|
|
|
|
return item.id
|
|
|
|
|
}
|
2020-10-27 01:10:18 +01:00
|
|
|
}
|