2022-03-11 10:53:32 -08:00
|
|
|
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'
|
2020-11-07 12:05:15 +01:00
|
|
|
|
|
|
|
|
export interface Statistics {
|
|
|
|
|
documents_total?: number
|
|
|
|
|
documents_inbox?: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-statistics-widget',
|
|
|
|
|
templateUrl: './statistics-widget.component.html',
|
2022-03-11 10:53:32 -08:00
|
|
|
styleUrls: ['./statistics-widget.component.scss'],
|
2020-11-07 12:05:15 +01:00
|
|
|
})
|
2021-02-06 00:13:49 +01:00
|
|
|
export class StatisticsWidgetComponent implements OnInit, OnDestroy {
|
2022-05-08 09:03:29 -07:00
|
|
|
loading: boolean = true
|
|
|
|
|
|
2022-03-11 10:53:32 -08:00
|
|
|
constructor(
|
|
|
|
|
private http: HttpClient,
|
|
|
|
|
private consumerStatusService: ConsumerStatusService
|
|
|
|
|
) {}
|
2020-11-07 12:05:15 +01:00
|
|
|
|
|
|
|
|
statistics: Statistics = {}
|
|
|
|
|
|
2021-02-06 00:13:49 +01:00
|
|
|
subscription: Subscription
|
2021-06-13 10:48:46 -04:00
|
|
|
|
2021-02-06 00:13:49 +01:00
|
|
|
private getStatistics(): Observable<Statistics> {
|
2020-11-22 22:35:39 +01:00
|
|
|
return this.http.get(`${environment.apiBaseUrl}statistics/`)
|
|
|
|
|
}
|
2020-11-22 22:49:37 +01:00
|
|
|
|
2021-02-06 00:13:49 +01:00
|
|
|
reload() {
|
2022-05-08 09:03:29 -07:00
|
|
|
this.loading = true
|
2022-03-11 10:53:32 -08:00
|
|
|
this.getStatistics().subscribe((statistics) => {
|
2022-05-08 09:03:29 -07:00
|
|
|
this.loading = false
|
2020-11-07 12:05:15 +01:00
|
|
|
this.statistics = statistics
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 00:13:49 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.reload()
|
2022-03-11 10:53:32 -08:00
|
|
|
this.subscription = this.consumerStatusService
|
|
|
|
|
.onDocumentConsumptionFinished()
|
|
|
|
|
.subscribe((status) => {
|
|
|
|
|
this.reload()
|
|
|
|
|
})
|
2021-02-06 00:13:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this.subscription.unsubscribe()
|
|
|
|
|
}
|
2020-11-07 12:05:15 +01:00
|
|
|
}
|