1 import { Component, OnInit, OnDestroy } from '@angular/core';
3 import { RequestService, RequestStats } from '../shared';
6 selector: 'my-request-stats',
7 templateUrl: './request-stats.component.html',
8 styleUrls: [ './request-stats.component.scss' ]
10 export class RequestStatsComponent implements OnInit, OnDestroy {
11 stats: RequestStats = null;
13 private interval: NodeJS.Timer = null;
15 constructor(private requestService: RequestService) { }
22 if (this.secondsInterval !== null) {
23 clearInterval(this.interval);
27 get remainingSeconds() {
28 return Math.floor(this.stats.remainingMilliSeconds / 1000);
31 get secondsInterval() {
32 return Math.floor(this.stats.milliSecondsInterval / 1000);
36 this.requestService.getStats().subscribe(
47 private runInterval() {
48 this.interval = setInterval(() => {
49 this.stats.remainingMilliSeconds -= 1000;
51 if (this.stats.remainingMilliSeconds <= 0) {
52 setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
53 clearInterval(this.interval);