]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/requests/request-stats/request-stats.component.ts
Use typescript standard and lint all files
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / requests / request-stats / request-stats.component.ts
index 18855a5f8e0469871a1c5db4e4a3ca38695abe79..cca4926cf237c901bb8a8e35910cf53223ef8c18 100644 (file)
@@ -1,57 +1,80 @@
-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 {
-  stats: RequestStats = null;
+  statsTitles = {
+    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 interval: number = null;
-  private timeout: number = 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.runInterval();
+  ngOnInit () {
+    this.getStats()
+    this.runIntervals()
   }
 
-  ngOnDestroy() {
-    if (this.interval !== null) {
-      window.clearInterval(this.interval);
-    }
+  ngOnDestroy () {
+    Object.keys(this.stats).forEach(requestSchedulerName => {
+      if (this.intervals[requestSchedulerName] !== null) {
+        window.clearInterval(this.intervals[requestSchedulerName])
+      }
 
-    if (this.timeout !== null) {
-      window.clearTimeout(this.timeout);
-    }
+      if (this.timeouts[requestSchedulerName] !== null) {
+        window.clearTimeout(this.timeouts[requestSchedulerName])
+      }
+    })
   }
 
-  getStats() {
+  getStats () {
     this.requestService.getStats().subscribe(
       stats => this.stats = stats,
 
       err => this.notificationsService.error('Error', err.text)
-    );
+    )
   }
 
-  private runInterval() {
-    this.interval = window.setInterval(() => {
-      this.stats.remainingMilliSeconds -= 1000;
-
-      if (this.stats.remainingMilliSeconds <= 0) {
-        this.timeout = window.setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100);
-      }
-    }, 1000);
-  }
+  private runIntervals () {
+    Object.keys(this.intervals).forEach(requestSchedulerName => {
+      this.intervals[requestSchedulerName] = window.setInterval(() => {
+        const stats = this.stats[requestSchedulerName]
 
+        stats.remainingMilliSeconds -= 1000
 
+        if (stats.remainingMilliSeconds <= 0) {
+          this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100)
+        }
+      }, 1000)
+    })
+  }
 }