paperless-ngx/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts

57 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Component, Input, OnDestroy, OnInit } from '@angular/core';
2020-11-29 23:32:03 +01:00
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
2020-11-29 23:32:03 +01:00
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { ConsumerStatusService } from 'src/app/services/consumer-status.service';
import { DocumentService } from 'src/app/services/rest/document.service';
@Component({
selector: 'app-saved-view-widget',
templateUrl: './saved-view-widget.component.html',
2020-11-22 22:35:39 +01:00
styleUrls: ['./saved-view-widget.component.scss']
})
2020-11-22 22:35:39 +01:00
export class SavedViewWidgetComponent implements OnInit {
2020-11-29 23:32:03 +01:00
constructor(
private documentService: DocumentService,
private router: Router,
private list: DocumentListViewService,
private consumerStatusService: ConsumerStatusService) { }
@Input()
savedView: PaperlessSavedView
2020-11-22 22:35:39 +01:00
documents: PaperlessDocument[] = []
subscription: Subscription
ngOnInit(): void {
this.reload()
this.subscription = this.consumerStatusService.onDocumentConsumptionFinished().subscribe(status => {
this.reload()
})
}
ngOnDestroy(): void {
this.subscription.unsubscribe()
}
reload() {
2020-12-22 01:17:07 +01:00
this.documentService.listFiltered(1,10,this.savedView.sort_field, this.savedView.sort_reverse, this.savedView.filter_rules).subscribe(result => {
this.documents = result.results
})
}
2020-11-29 23:32:03 +01:00
showAll() {
if (this.savedView.show_in_sidebar) {
2020-12-07 12:46:46 +01:00
this.router.navigate(['view', this.savedView.id])
} else {
this.list.load(this.savedView)
this.router.navigate(["documents"])
}
2020-11-29 23:32:03 +01:00
}
}