diff options
Diffstat (limited to 'client/src/app/admin/requests/request-stats/request-stats.component.ts')
-rw-r--r-- | client/src/app/admin/requests/request-stats/request-stats.component.ts | 51 |
1 files changed, 51 insertions, 0 deletions
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 new file mode 100644 index 000000000..4b0844574 --- /dev/null +++ b/client/src/app/admin/requests/request-stats/request-stats.component.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
2 | |||
3 | import { 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 | }) | ||
10 | export 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() { | ||
22 | if (this.stats.secondsInterval !== null) { | ||
23 | clearInterval(this.interval); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | getStats() { | ||
28 | this.requestService.getStats().subscribe( | ||
29 | stats => { | ||
30 | console.log(stats); | ||
31 | this.stats = stats; | ||
32 | this.runInterval(); | ||
33 | }, | ||
34 | |||
35 | err => alert(err.text) | ||
36 | ); | ||
37 | } | ||
38 | |||
39 | private runInterval() { | ||
40 | this.interval = setInterval(() => { | ||
41 | this.stats.remainingMilliSeconds -= 1000; | ||
42 | |||
43 | if (this.stats.remainingMilliSeconds <= 0) { | ||
44 | setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); | ||
45 | clearInterval(this.interval); | ||
46 | } | ||
47 | }, 1000); | ||
48 | } | ||
49 | |||
50 | |||
51 | } | ||