<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>
}
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 => {
-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);
+ }
+
}
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));
}
}