From bed3143eb9e16079b9614446572525e3f69b76a8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Sep 2016 17:25:09 +0200 Subject: Client: move some methods in the requestStats model --- .../request-stats/request-stats.component.html | 4 +-- .../request-stats/request-stats.component.ts | 10 +------ .../admin/requests/shared/request-stats.model.ts | 31 ++++++++++++++++++---- .../app/admin/requests/shared/request.service.ts | 1 + 4 files changed, 30 insertions(+), 16 deletions(-) (limited to 'client/src') diff --git a/client/src/app/admin/requests/request-stats/request-stats.component.html b/client/src/app/admin/requests/request-stats/request-stats.component.html index 114fd371f..04e5937f8 100644 --- a/client/src/app/admin/requests/request-stats/request-stats.component.html +++ b/client/src/app/admin/requests/request-stats/request-stats.component.html @@ -3,12 +3,12 @@
Interval seconds between requests: - {{ secondsInterval }} + {{ stats.secondsInterval }}
Remaining time before the scheduled request: - {{ remainingSeconds }} + {{ stats.remainingSeconds }}
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 8ff4eb540..6a9739bbf 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 @@ -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 => { diff --git a/client/src/app/admin/requests/shared/request-stats.model.ts b/client/src/app/admin/requests/shared/request-stats.model.ts index 7e4b26bca..dfa956f10 100644 --- a/client/src/app/admin/requests/shared/request-stats.model.ts +++ b/client/src/app/admin/requests/shared/request-stats.model.ts @@ -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); + } + } diff --git a/client/src/app/admin/requests/shared/request.service.ts b/client/src/app/admin/requests/shared/request.service.ts index 59d138039..aeec37448 100644 --- a/client/src/app/admin/requests/shared/request.service.ts +++ b/client/src/app/admin/requests/shared/request.service.ts @@ -16,6 +16,7 @@ export class RequestService { getStats(): Observable { return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') .map(this.restExtractor.extractDataGet) + .map((data) => new RequestStats(data)) .catch((res) => this.restExtractor.handleError(res)); } } -- cgit v1.2.3