2022-03-11 10:53:32 -08:00
|
|
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core'
|
|
|
|
|
import { Router } from '@angular/router'
|
2022-05-15 23:25:46 -07:00
|
|
|
import { Subscription } from 'rxjs'
|
2022-03-11 10:53:32 -08:00
|
|
|
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'
|
2022-05-15 22:55:25 -07:00
|
|
|
import { OpenDocumentsService } from 'src/app/services/open-documents.service'
|
2022-05-20 15:16:17 -07:00
|
|
|
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
2022-11-12 04:03:35 -08:00
|
|
|
import { ComponentWithPermissions } from 'src/app/components/with-permissions/with-permissions.component'
|
2020-11-07 12:05:15 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-saved-view-widget',
|
|
|
|
|
templateUrl: './saved-view-widget.component.html',
|
2022-03-11 10:53:32 -08:00
|
|
|
styleUrls: ['./saved-view-widget.component.scss'],
|
2020-11-07 12:05:15 +01:00
|
|
|
})
|
2022-11-12 04:03:35 -08:00
|
|
|
export class SavedViewWidgetComponent
|
|
|
|
|
extends ComponentWithPermissions
|
|
|
|
|
implements OnInit, OnDestroy
|
|
|
|
|
{
|
2022-05-08 09:03:29 -07:00
|
|
|
loading: boolean = true
|
|
|
|
|
|
2020-11-29 23:32:03 +01:00
|
|
|
constructor(
|
|
|
|
|
private documentService: DocumentService,
|
|
|
|
|
private router: Router,
|
2022-05-20 15:16:17 -07:00
|
|
|
private list: DocumentListViewService,
|
2022-05-15 22:55:25 -07:00
|
|
|
private consumerStatusService: ConsumerStatusService,
|
2022-05-15 23:25:46 -07:00
|
|
|
public openDocumentsService: OpenDocumentsService
|
2022-11-12 04:03:35 -08:00
|
|
|
) {
|
|
|
|
|
super()
|
|
|
|
|
}
|
2020-11-07 12:05:15 +01:00
|
|
|
|
|
|
|
|
@Input()
|
2020-12-14 19:26:36 +01:00
|
|
|
savedView: PaperlessSavedView
|
2020-11-07 12:05:15 +01:00
|
|
|
|
2020-11-22 22:35:39 +01:00
|
|
|
documents: PaperlessDocument[] = []
|
2020-11-07 12:05:15 +01:00
|
|
|
|
|
|
|
|
subscription: Subscription
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.reload()
|
2022-03-11 10:53:32 -08:00
|
|
|
this.subscription = this.consumerStatusService
|
|
|
|
|
.onDocumentConsumptionFinished()
|
|
|
|
|
.subscribe((status) => {
|
|
|
|
|
this.reload()
|
|
|
|
|
})
|
2020-11-07 12:05:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this.subscription.unsubscribe()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reload() {
|
2022-05-23 01:54:21 -07:00
|
|
|
this.loading = this.documents.length == 0
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documentService
|
|
|
|
|
.listFiltered(
|
|
|
|
|
1,
|
|
|
|
|
10,
|
|
|
|
|
this.savedView.sort_field,
|
|
|
|
|
this.savedView.sort_reverse,
|
|
|
|
|
this.savedView.filter_rules
|
|
|
|
|
)
|
|
|
|
|
.subscribe((result) => {
|
2022-05-08 09:03:29 -07:00
|
|
|
this.loading = false
|
2022-03-11 10:53:32 -08:00
|
|
|
this.documents = result.results
|
|
|
|
|
})
|
2020-11-07 12:05:15 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-29 23:32:03 +01:00
|
|
|
showAll() {
|
2020-12-14 19:26:36 +01:00
|
|
|
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 },
|
|
|
|
|
})
|
2021-01-17 00:15:45 +01:00
|
|
|
}
|
2020-11-29 23:32:03 +01:00
|
|
|
}
|
2022-03-23 22:03:10 -07:00
|
|
|
|
2022-11-22 15:25:27 -08:00
|
|
|
clickTag(tag: PaperlessTag, event: MouseEvent) {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
2022-05-20 15:16:17 -07:00
|
|
|
this.list.quickFilter([
|
2022-03-23 22:03:10 -07:00
|
|
|
{ rule_type: FILTER_HAS_TAGS_ALL, value: tag.id.toString() },
|
|
|
|
|
])
|
|
|
|
|
}
|
2020-11-07 12:05:15 +01:00
|
|
|
}
|