mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-24 02:02:23 -04:00
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { HttpClient } from '@angular/common/http'
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'
|
|
import { Observable, Subscription } from 'rxjs'
|
|
import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
|
|
import { environment } from 'src/environments/environment'
|
|
|
|
export interface Statistics {
|
|
documents_total?: number
|
|
documents_inbox?: number
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-statistics-widget',
|
|
templateUrl: './statistics-widget.component.html',
|
|
styleUrls: ['./statistics-widget.component.scss'],
|
|
})
|
|
export class StatisticsWidgetComponent implements OnInit, OnDestroy {
|
|
loading: boolean = true
|
|
|
|
constructor(
|
|
private http: HttpClient,
|
|
private consumerStatusService: ConsumerStatusService
|
|
) {}
|
|
|
|
statistics: Statistics = {}
|
|
|
|
subscription: Subscription
|
|
|
|
private getStatistics(): Observable<Statistics> {
|
|
return this.http.get(`${environment.apiBaseUrl}statistics/`)
|
|
}
|
|
|
|
reload() {
|
|
this.loading = true
|
|
this.getStatistics().subscribe((statistics) => {
|
|
this.loading = false
|
|
this.statistics = statistics
|
|
})
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.reload()
|
|
this.subscription = this.consumerStatusService
|
|
.onDocumentConsumptionFinished()
|
|
.subscribe((status) => {
|
|
this.reload()
|
|
})
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
this.subscription.unsubscribe()
|
|
}
|
|
}
|