diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 16:14:11 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-27 16:14:11 +0100 |
commit | 7ddd02c9b8c1e088f6679a2227f105e6439fc992 (patch) | |
tree | a1ff7af17f2a95abe85a2380834957e44032e8c2 /client/src/app/+admin/requests/request-stats/request-stats.component.ts | |
parent | cddadde81f91219204cec1f4057a191c02a70894 (diff) | |
download | PeerTube-7ddd02c9b8c1e088f6679a2227f105e6439fc992.tar.gz PeerTube-7ddd02c9b8c1e088f6679a2227f105e6439fc992.tar.zst PeerTube-7ddd02c9b8c1e088f6679a2227f105e6439fc992.zip |
Client: better notifications for a beautiful world
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 | 25 |
1 files changed, 17 insertions, 8 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 index 23b836779..18855a5f8 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,6 +1,7 @@ | |||
1 | import { setInterval } from 'timers' | ||
2 | import { Component, OnInit, OnDestroy } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
3 | 2 | ||
3 | import { NotificationsService } from 'angular2-notifications'; | ||
4 | |||
4 | import { RequestService, RequestStats } from '../shared'; | 5 | import { RequestService, RequestStats } from '../shared'; |
5 | 6 | ||
6 | @Component({ | 7 | @Component({ |
@@ -11,9 +12,13 @@ import { RequestService, RequestStats } from '../shared'; | |||
11 | export class RequestStatsComponent implements OnInit, OnDestroy { | 12 | export class RequestStatsComponent implements OnInit, OnDestroy { |
12 | stats: RequestStats = null; | 13 | stats: RequestStats = null; |
13 | 14 | ||
14 | private interval: NodeJS.Timer = null; | 15 | private interval: number = null; |
16 | private timeout: number = null; | ||
15 | 17 | ||
16 | constructor(private requestService: RequestService) { } | 18 | constructor( |
19 | private notificationsService: NotificationsService, | ||
20 | private requestService: RequestService | ||
21 | ) { } | ||
17 | 22 | ||
18 | ngOnInit() { | 23 | ngOnInit() { |
19 | this.getStats(); | 24 | this.getStats(); |
@@ -21,8 +26,12 @@ export class RequestStatsComponent implements OnInit, OnDestroy { | |||
21 | } | 26 | } |
22 | 27 | ||
23 | ngOnDestroy() { | 28 | ngOnDestroy() { |
24 | if (this.stats !== null && this.stats.secondsInterval !== null) { | 29 | if (this.interval !== null) { |
25 | clearInterval(this.interval); | 30 | window.clearInterval(this.interval); |
31 | } | ||
32 | |||
33 | if (this.timeout !== null) { | ||
34 | window.clearTimeout(this.timeout); | ||
26 | } | 35 | } |
27 | } | 36 | } |
28 | 37 | ||
@@ -30,16 +39,16 @@ export class RequestStatsComponent implements OnInit, OnDestroy { | |||
30 | this.requestService.getStats().subscribe( | 39 | this.requestService.getStats().subscribe( |
31 | stats => this.stats = stats, | 40 | stats => this.stats = stats, |
32 | 41 | ||
33 | err => alert(err.text) | 42 | err => this.notificationsService.error('Error', err.text) |
34 | ); | 43 | ); |
35 | } | 44 | } |
36 | 45 | ||
37 | private runInterval() { | 46 | private runInterval() { |
38 | this.interval = setInterval(() => { | 47 | this.interval = window.setInterval(() => { |
39 | this.stats.remainingMilliSeconds -= 1000; | 48 | this.stats.remainingMilliSeconds -= 1000; |
40 | 49 | ||
41 | if (this.stats.remainingMilliSeconds <= 0) { | 50 | if (this.stats.remainingMilliSeconds <= 0) { |
42 | setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); | 51 | this.timeout = window.setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); |
43 | } | 52 | } |
44 | }, 1000); | 53 | }, 1000); |
45 | } | 54 | } |