diff --git a/app/job/job-history/job-history.component.html b/app/job/job-history/job-history.component.html index 00da049..9ec1d3e 100644 --- a/app/job/job-history/job-history.component.html +++ b/app/job/job-history/job-history.component.html @@ -51,4 +51,18 @@ + + +
+
\ No newline at end of file diff --git a/app/job/job-history/job-history.component.ts b/app/job/job-history/job-history.component.ts index e846825..2bd8372 100644 --- a/app/job/job-history/job-history.component.ts +++ b/app/job/job-history/job-history.component.ts @@ -31,6 +31,7 @@ export class JobHistoryComponent implements OnInit { accessMode: AccessMode = "DEFAULT"; componentMode: ComponentMode = "WIDGET"; statusMessage: string; + paginationArray: number[]; constructor(private jobService: JobService, private router: Router) { } @@ -48,18 +49,42 @@ export class JobHistoryComponent implements OnInit { this.jobs = new Array(); this.jobService.getHistory() .subscribe((pagedJob) => { - this.status = "SUCCESSFUL"; - this.jobs = pagedJob.data; - if (!this.jobs.length) { - this.status = "EMPTY"; - this.statusMessage = "It looks lonely here. Why don't you put an order?"; - } + this.manageHistory(pagedJob); }, (error) => { this.statusMessage = error.Message || "Failed to fetch data from server"; this.status = "FAILED"; }); } + + + getJobsWithPageNumber(page: number){ + this.status = "IN_PROGRESS" + this.jobService.getHistoryWithPageNumber(page) + .subscribe((pagedJob) => { + this.manageHistory(pagedJob) + },(error) => { + this.statusMessage = error.Message || "Failed to fetch data from server"; + this.status = "FAILED"; + }) + } + + private manageHistory(pagedJob){ + this.status = "SUCCESSFUL"; + this.jobs = pagedJob.data; + + // FIXME: This is an ugly code I confess + this.paginationArray = new Array(); + for (var i = 0; i < pagedJob.pagination.TotalPages; i++) { + this.paginationArray.push(i + 1); + } + + if (!this.jobs.length) { + this.status = "EMPTY"; + this.statusMessage = "It looks lonely here. Why don't you put an order?"; + } + } + setJobStatusLabelClass(state: string) { switch (state) { case "COMPLETED": diff --git a/app/job/shared/job.service.ts b/app/job/shared/job.service.ts index 6e07a90..10b27ba 100644 --- a/app/job/shared/job.service.ts +++ b/app/job/shared/job.service.ts @@ -25,20 +25,35 @@ export class JobService { private jobUrl = AppSettings.TASKCAT_API_BASE + 'job'; private assetLocationUrl = AppSettings.SHADOWCAT_API_BASE + "location/"; + getJobs(jobUrl): Observable> { + return this.shttp.secureGet(jobUrl) + .map(this._extractData) + .catch(error => { + let errMsg = error.message || 'Exception when fetching job history'; + console.error(errMsg); // log to console instead + return Observable.throw(errMsg); + }); + } + getHistory(): Observable> { let queryString: string = this._queryBuilder.orderBy([ { propName: "CreateTime", orderDirection: "desc" }]).toQueryString(); + let historyUrl = this.jobUrl + '/odata' + queryString - return this.shttp.secureGet(this.jobUrl + '/odata' + queryString) - .map(this._extractData) - .catch(error => { - let errMsg = error.message || 'Exception when fetching job history'; - console.error(errMsg); // log to console instead - return Observable.throw(errMsg); - }); + return this.getJobs(historyUrl); + } + + getHistoryWithPageNumber(page:number): Observable> { + let queryString: string = this._queryBuilder.toQueryString(); + let historyUrl = this.jobUrl + '/odata' + queryString + "&page=" + page; + console.log(this.jobUrl); + console.log(queryString); + console.log(historyUrl); + + return this.getJobs(historyUrl) } diff --git a/app/shared/query-builder/query-builder.ts b/app/shared/query-builder/query-builder.ts index ad4d111..dde35db 100644 --- a/app/shared/query-builder/query-builder.ts +++ b/app/shared/query-builder/query-builder.ts @@ -20,6 +20,14 @@ export class QueryBuilder { return this; } + public page(props: number): QueryBuilder { + let querySegment: string = "page"; + let pageSegment = props.toString(); + this._querySegments.push(querySegment.concat("=", pageSegment)); + + return this; + } + public toQueryString(): string { return "?".concat(this._querySegments.join("&")); }