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

75 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Component, Input, OnDestroy, OnInit } from '@angular/core'
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'
import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
import { DocumentService } from 'src/app/services/rest/document.service'
2022-03-23 22:03:10 -07:00
import { PaperlessTag } from 'src/app/data/paperless-tag'
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type'
import { QueryParamsService } from 'src/app/services/query-params.service'
@Component({
selector: 'app-saved-view-widget',
templateUrl: './saved-view-widget.component.html',
styleUrls: ['./saved-view-widget.component.scss'],
})
export class SavedViewWidgetComponent implements OnInit, OnDestroy {
2020-11-29 23:32:03 +01:00
constructor(
private documentService: DocumentService,
private router: Router,
private queryParamsService: QueryParamsService,
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() {
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 {
2022-05-04 22:31:09 -07:00
this.router.navigate(['documents'], {
queryParams: { view: this.savedView.id },
})
}
2020-11-29 23:32:03 +01:00
}
2022-03-23 22:03:10 -07:00
clickTag(tag: PaperlessTag) {
this.queryParamsService.loadFilterRules([
2022-03-23 22:03:10 -07:00
{ rule_type: FILTER_HAS_TAGS_ALL, value: tag.id.toString() },
])
}
}