]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Client: move some methods in the requestStats model
authorChocobozzz <florian.bigard@gmail.com>
Fri, 23 Sep 2016 15:25:09 +0000 (17:25 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 23 Sep 2016 15:25:09 +0000 (17:25 +0200)
client/src/app/admin/requests/request-stats/request-stats.component.html
client/src/app/admin/requests/request-stats/request-stats.component.ts
client/src/app/admin/requests/shared/request-stats.model.ts
client/src/app/admin/requests/shared/request.service.ts

index 114fd371f73906e997f13da5cc899bca3371f1cc..04e5937f8fd236ba0ecac8edbd071ca46598a1e5 100644 (file)
@@ -3,12 +3,12 @@
 <div *ngIf="stats !== null">
   <div>
     <span class="label-description">Interval seconds between requests:</span>
-    {{ secondsInterval }}
+    {{ stats.secondsInterval }}
   </div>
 
   <div>
     <span class="label-description">Remaining time before the scheduled request:</span>
-    {{ remainingSeconds }}
+    {{ stats.remainingSeconds }}
   </div>
 
   <div>
index 8ff4eb540d5a4a9110a7bb64dbfdb8218b29f7fd..6a9739bbf19add9267be7c05ea2e886fdd870fdb 100644 (file)
@@ -19,19 +19,11 @@ export class RequestStatsComponent implements OnInit, OnDestroy {
   }
 
   ngOnDestroy() {
-    if (this.secondsInterval !== null) {
+    if (this.stats.secondsInterval !== null) {
       clearInterval(this.interval);
     }
   }
 
-  get remainingSeconds() {
-    return Math.floor(this.stats.remainingMilliSeconds / 1000);
-  }
-
-  get secondsInterval() {
-    return Math.floor(this.stats.milliSecondsInterval / 1000);
-  }
-
   getStats() {
     this.requestService.getStats().subscribe(
       stats => {
index 7e4b26bca40fdb2b547e0f4a411021163886a650..dfa956f10a62d53fda446220dc4b067916415ffe 100644 (file)
@@ -1,8 +1,29 @@
-export interface RequestStats {
+export interface Request {
+  request: any;
+  to: any;
+}
+
+export class RequestStats {
   milliSecondsInterval: number;
        remainingMilliSeconds: number;
-  requests: {
-    request: any,
-    to: any
-  }[];
+  requests: Request[];
+
+  constructor(hash: {
+    milliSecondsInterval: number,
+    remainingMilliSeconds: number,
+    requests: Request[];
+  }) {
+    this.milliSecondsInterval = hash.milliSecondsInterval;
+    this.remainingMilliSeconds = hash.remainingMilliSeconds;
+    this.requests = hash.requests;
+  }
+
+  get remainingSeconds() {
+    return Math.floor(this.remainingMilliSeconds / 1000);
+  }
+
+  get secondsInterval() {
+    return Math.floor(this.milliSecondsInterval / 1000);
+  }
+
 }
index 59d138039b627606893645076efa8fcfaf6ace77..aeec37448904b26a80a2fdcded4e005b787c453c 100644 (file)
@@ -16,6 +16,7 @@ export class RequestService {
   getStats(): Observable<RequestStats> {
     return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats')
                         .map(this.restExtractor.extractDataGet)
+                        .map((data) => new RequestStats(data))
                         .catch((res) => this.restExtractor.handleError(res));
   }
 }