X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Frequests%2Frequest-stats%2Frequest-stats.component.ts;h=cca4926cf237c901bb8a8e35910cf53223ef8c18;hb=df98563e2104b82b119c00a3cd83cd0dc1242d25;hp=85dd7e492918d733d8cc4d18af75dc8cf4e33485;hpb=99fdec464802e5d720fe08ead06b63368b115baf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.ts b/client/src/app/+admin/requests/request-stats/request-stats.component.ts index 85dd7e492..cca4926cf 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.ts +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.ts @@ -1,12 +1,12 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core' -import { NotificationsService } from 'angular2-notifications'; +import { NotificationsService } from 'angular2-notifications' -import { RequestService, RequestStats } from '../shared'; +import { RequestService, RequestStats } from '../shared' @Component({ - selector: 'my-request-stats', - templateUrl: './request-stats.component.html', + selector: 'my-request-stats', + templateUrl: './request-stats.component.html', styleUrls: [ './request-stats.component.scss' ] }) export class RequestStatsComponent implements OnInit, OnDestroy { @@ -14,70 +14,67 @@ export class RequestStatsComponent implements OnInit, OnDestroy { requestScheduler: 'Basic request scheduler', requestVideoEventScheduler: 'Video events request scheduler', requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' - }; + } stats: { [ id: string ]: RequestStats } = { requestScheduler: null, requestVideoEventScheduler: null, requestVideoQaduScheduler: null - }; + } private intervals: { [ id: string ]: number } = { requestScheduler: null, requestVideoEventScheduler: null, requestVideoQaduScheduler: null - }; + } private timeouts: { [ id: string ]: number } = { requestScheduler: null, requestVideoEventScheduler: null, requestVideoQaduScheduler: null - }; - + } - constructor( + constructor ( private notificationsService: NotificationsService, private requestService: RequestService - ) { } + ) { } - ngOnInit() { - this.getStats(); - this.runIntervals(); + ngOnInit () { + this.getStats() + this.runIntervals() } - ngOnDestroy() { + ngOnDestroy () { Object.keys(this.stats).forEach(requestSchedulerName => { if (this.intervals[requestSchedulerName] !== null) { - window.clearInterval(this.intervals[requestSchedulerName]); + window.clearInterval(this.intervals[requestSchedulerName]) } if (this.timeouts[requestSchedulerName] !== null) { - window.clearTimeout(this.timeouts[requestSchedulerName]); + window.clearTimeout(this.timeouts[requestSchedulerName]) } - }); + }) } - getStats() { + getStats () { this.requestService.getStats().subscribe( stats => this.stats = stats, err => this.notificationsService.error('Error', err.text) - ); + ) } - private runIntervals() { + private runIntervals () { Object.keys(this.intervals).forEach(requestSchedulerName => { this.intervals[requestSchedulerName] = window.setInterval(() => { - const stats = this.stats[requestSchedulerName]; + const stats = this.stats[requestSchedulerName] - stats.remainingMilliSeconds -= 1000; + stats.remainingMilliSeconds -= 1000 if (stats.remainingMilliSeconds <= 0) { - this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100); + this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100) } - }, 1000); - }); + }, 1000) + }) } - - }