paperless-ngx/src-ui/src/app/components/document-list/document-list.component.ts

90 lines
3 KiB
TypeScript
Raw Normal View History

2020-10-27 01:10:18 +01:00
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
2020-10-30 22:46:43 +01:00
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { cloneFilterRules, FilterRule } from 'src/app/data/filter-rule';
import { SavedViewConfig } from 'src/app/data/saved-view-config';
2020-10-30 23:43:19 +01:00
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service';
2020-10-30 22:46:43 +01:00
import { SavedViewConfigService } from 'src/app/services/saved-view-config.service';
import { Toast, ToastService } from 'src/app/services/toast.service';
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',
styleUrls: ['./document-list.component.scss']
2020-10-27 01:10:18 +01:00
})
export class DocumentListComponent implements OnInit {
constructor(
public list: DocumentListViewService,
2020-10-30 22:46:43 +01:00
public savedViewConfigService: SavedViewConfigService,
public route: ActivatedRoute,
private toastService: ToastService,
2020-10-30 22:46:43 +01:00
public modalService: NgbModal) { }
2020-10-27 01:10:18 +01:00
displayMode = 'smallCards' // largeCards, smallCards, details
2020-10-30 22:46:43 +01:00
filterRules: FilterRule[] = []
2020-10-27 01:10:18 +01:00
showFilter = false
getTitle() {
return this.list.savedViewTitle || "Documents"
}
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
}
saveDisplayMode() {
localStorage.setItem('document-list:displayMode', this.displayMode)
}
ngOnInit(): void {
if (localStorage.getItem('document-list:displayMode') != null) {
this.displayMode = localStorage.getItem('document-list:displayMode')
}
2020-10-30 22:46:43 +01:00
this.route.paramMap.subscribe(params => {
if (params.has('id')) {
this.list.savedView = this.savedViewConfigService.getConfig(params.get('id'))
2020-10-30 22:46:43 +01:00
} else {
this.list.savedView = null
2020-10-30 22:46:43 +01:00
}
this.filterRules = this.list.filterRules
//this.showFilter = this.filterRules.length > 0
// prevents temporarily visible results from previous views
this.list.documents = []
this.list.reload()
2020-10-30 22:46:43 +01:00
})
2020-10-27 01:10:18 +01:00
}
2020-10-30 22:46:43 +01:00
applyFilterRules() {
this.list.filterRules = this.filterRules
2020-10-27 01:10:18 +01:00
}
2020-10-30 22:46:43 +01:00
loadViewConfig(config: SavedViewConfig) {
2020-10-30 23:16:54 +01:00
this.filterRules = cloneFilterRules(config.filterRules)
this.list.load(config)
2020-10-30 22:46:43 +01:00
}
saveViewConfig() {
this.savedViewConfigService.updateConfig(this.list.savedView)
this.toastService.showToast(Toast.make("Information", `View "${this.list.savedView.title}" saved successfully.`))
}
saveViewConfigAs() {
2020-10-30 22:46:43 +01:00
let modal = this.modalService.open(SaveViewConfigDialogComponent, {backdrop: 'static'})
modal.componentInstance.saveClicked.subscribe(formValue => {
this.savedViewConfigService.newConfig({
2020-10-30 22:46:43 +01:00
title: formValue.title,
showInDashboard: formValue.showInDashboard,
showInSideBar: formValue.showInSideBar,
filterRules: this.list.filterRules,
sortDirection: this.list.sortDirection,
sortField: this.list.sortField
2020-10-30 22:46:43 +01:00
})
modal.close()
})
}
2020-10-27 01:10:18 +01:00
}