]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/admin/requests/request-stats/request-stats.component.ts
First version with PostgreSQL
[github/Chocobozzz/PeerTube.git] / client / src / app / admin / requests / request-stats / request-stats.component.ts
CommitLineData
eb4f957e
C
1import { Component, OnInit, OnDestroy } from '@angular/core';
2
3import { RequestService, RequestStats } from '../shared';
4
5@Component({
6 selector: 'my-request-stats',
7 templateUrl: './request-stats.component.html',
8 styleUrls: [ './request-stats.component.scss' ]
9})
10export class RequestStatsComponent implements OnInit, OnDestroy {
11 stats: RequestStats = null;
12
13 private interval: NodeJS.Timer = null;
14
15 constructor(private requestService: RequestService) { }
16
17 ngOnInit() {
18 this.getStats();
19 }
20
21 ngOnDestroy() {
feb4bdfd 22 if (this.stats !== null && this.stats.secondsInterval !== null) {
eb4f957e
C
23 clearInterval(this.interval);
24 }
25 }
26
eb4f957e
C
27 getStats() {
28 this.requestService.getStats().subscribe(
29 stats => {
eb4f957e
C
30 this.stats = stats;
31 this.runInterval();
32 },
33
da4971c1 34 err => alert(err.text)
eb4f957e
C
35 );
36 }
37
38 private runInterval() {
39 this.interval = setInterval(() => {
40 this.stats.remainingMilliSeconds -= 1000;
41
42 if (this.stats.remainingMilliSeconds <= 0) {
43 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
44 clearInterval(this.interval);
45 }
46 }, 1000);
47 }
48
49
50}