Client: move some methods in the requestStats model

pull/10/head
Chocobozzz 2016-09-23 17:25:09 +02:00
parent b539c9b34c
commit bed3143eb9
4 changed files with 30 additions and 16 deletions

View 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>

View 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 => {

View 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);
}
}

View 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));
}
}