1
0
Fork 0

Client: move some methods in the requestStats model

This commit is contained in:
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 *ngIf="stats !== null">
<div> <div>
<span class="label-description">Interval seconds between requests:</span> <span class="label-description">Interval seconds between requests:</span>
{{ secondsInterval }} {{ stats.secondsInterval }}
</div> </div>
<div> <div>
<span class="label-description">Remaining time before the scheduled request:</span> <span class="label-description">Remaining time before the scheduled request:</span>
{{ remainingSeconds }} {{ stats.remainingSeconds }}
</div> </div>
<div> <div>

View File

@ -19,19 +19,11 @@ export class RequestStatsComponent implements OnInit, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
if (this.secondsInterval !== null) { if (this.stats.secondsInterval !== null) {
clearInterval(this.interval); clearInterval(this.interval);
} }
} }
get remainingSeconds() {
return Math.floor(this.stats.remainingMilliSeconds / 1000);
}
get secondsInterval() {
return Math.floor(this.stats.milliSecondsInterval / 1000);
}
getStats() { getStats() {
this.requestService.getStats().subscribe( this.requestService.getStats().subscribe(
stats => { stats => {

View File

@ -1,8 +1,29 @@
export interface RequestStats { export interface Request {
request: any;
to: any;
}
export class RequestStats {
milliSecondsInterval: number; milliSecondsInterval: number;
remainingMilliSeconds: number; remainingMilliSeconds: number;
requests: { requests: Request[];
request: any,
to: any 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> { getStats(): Observable<RequestStats> {
return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats')
.map(this.restExtractor.extractDataGet) .map(this.restExtractor.extractDataGet)
.map((data) => new RequestStats(data))
.catch((res) => this.restExtractor.handleError(res)); .catch((res) => this.restExtractor.handleError(res));
} }
} }