update statistics when new documents are added

This commit is contained in:
jonaswinkler 2021-02-06 00:13:49 +01:00
parent 96d7114fa7
commit 00903bd90c
2 changed files with 22 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import { DocumentService } from 'src/app/services/rest/document.service';
templateUrl: './saved-view-widget.component.html', templateUrl: './saved-view-widget.component.html',
styleUrls: ['./saved-view-widget.component.scss'] styleUrls: ['./saved-view-widget.component.scss']
}) })
export class SavedViewWidgetComponent implements OnInit { export class SavedViewWidgetComponent implements OnInit, OnDestroy {
constructor( constructor(
private documentService: DocumentService, private documentService: DocumentService,

View File

@ -1,6 +1,7 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { ConsumerStatusService } from 'src/app/services/consumer-status.service';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
export interface Statistics { export interface Statistics {
@ -14,20 +15,34 @@ export interface Statistics {
templateUrl: './statistics-widget.component.html', templateUrl: './statistics-widget.component.html',
styleUrls: ['./statistics-widget.component.scss'] styleUrls: ['./statistics-widget.component.scss']
}) })
export class StatisticsWidgetComponent implements OnInit { export class StatisticsWidgetComponent implements OnInit, OnDestroy {
constructor(private http: HttpClient) { } constructor(private http: HttpClient,
private consumerStatusService: ConsumerStatusService) { }
statistics: Statistics = {} statistics: Statistics = {}
getStatistics(): Observable<Statistics> { subscription: Subscription
private getStatistics(): Observable<Statistics> {
return this.http.get(`${environment.apiBaseUrl}statistics/`) return this.http.get(`${environment.apiBaseUrl}statistics/`)
} }
ngOnInit(): void { reload() {
this.getStatistics().subscribe(statistics => { this.getStatistics().subscribe(statistics => {
this.statistics = statistics this.statistics = statistics
}) })
} }
ngOnInit(): void {
this.reload()
this.subscription = this.consumerStatusService.onDocumentConsumptionFinished().subscribe(status => {
this.reload()
})
}
ngOnDestroy(): void {
this.subscription.unsubscribe()
}
} }