From 07d970e9ec0fd147c9a7d6fa28ed7b3a744871e6 Mon Sep 17 00:00:00 2001 From: tareq89 Date: Wed, 20 Jul 2016 19:01:12 +0600 Subject: [PATCH] #75 history component pagination works --- app/job/job-history/job-history.component.css | 4 ++ .../job-history/job-history.component.html | 12 +++--- app/job/job-history/job-history.component.ts | 37 +++++++++++++++---- app/job/shared/job.service.ts | 6 +-- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/job/job-history/job-history.component.css b/app/job/job-history/job-history.component.css index e69de29..3a808a2 100644 --- a/app/job/job-history/job-history.component.css +++ b/app/job/job-history/job-history.component.css @@ -0,0 +1,4 @@ +.selected { + background-color: #337ab7 !important; + color: white; +} \ No newline at end of file diff --git a/app/job/job-history/job-history.component.html b/app/job/job-history/job-history.component.html index 9ec1d3e..0352394 100644 --- a/app/job/job-history/job-history.component.html +++ b/app/job/job-history/job-history.component.html @@ -53,14 +53,14 @@
diff --git a/app/job/job-history/job-history.component.ts b/app/job/job-history/job-history.component.ts index 2bd8372..3846265 100644 --- a/app/job/job-history/job-history.component.ts +++ b/app/job/job-history/job-history.component.ts @@ -4,6 +4,7 @@ import { Router, ROUTER_DIRECTIVES } from '@angular/router-deprecated'; import {JobService} from '../shared/job.service'; import {Job} from '../shared/job'; +import {Pagination} from '../../shared/pagination'; import {ComponentServiceStatus} from '../../shared/component-service-status'; @@ -18,7 +19,8 @@ export type ComponentMode = "WIDGET" | "FULL"; selector: 'job-history', templateUrl: 'app/job/job-history/job-history.component.html', directives: [ProgressBubbleComponent, WidgetHeaderComponent, WidgetBodyComponent], - providers: [JobService] + providers: [JobService], + styleUrls: ['app/job/job-history/job-history.component.css'] }) export class JobHistoryComponent implements OnInit { @Input() @@ -31,7 +33,8 @@ export class JobHistoryComponent implements OnInit { accessMode: AccessMode = "DEFAULT"; componentMode: ComponentMode = "WIDGET"; statusMessage: string; - paginationArray: number[]; + pagination: Pagination; + paginationArray: Object[]; constructor(private jobService: JobService, private router: Router) { } @@ -51,32 +54,46 @@ export class JobHistoryComponent implements OnInit { .subscribe((pagedJob) => { this.manageHistory(pagedJob); }, (error) => { - this.statusMessage = error.Message || "Failed to fetch data from server"; - this.status = "FAILED"; + this.manageError(error); }); } getJobsWithPageNumber(page: number){ - this.status = "IN_PROGRESS" + 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"; + this.manageError(error); + }) + } + + + loadJobWithUrl(url: string){ + this.status = "IN_PROGRESS"; + this.jobService.getJobs(url) + .subscribe((pagedJob)=> { + this.manageHistory(pagedJob) + }, (error) => { + this.manageError(error); }) } private manageHistory(pagedJob){ this.status = "SUCCESSFUL"; this.jobs = pagedJob.data; + this.pagination = pagedJob.pagination; // 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); + let page = { isSelected: "", pageNo: i } + if (pagedJob.pagination.Page == i) { + page.isSelected = "selected" + } + this.paginationArray.push(page); } if (!this.jobs.length) { @@ -84,6 +101,10 @@ export class JobHistoryComponent implements OnInit { this.statusMessage = "It looks lonely here. Why don't you put an order?"; } } + private manageError(error){ + this.statusMessage = error.Message || "Failed to fetch data from server"; + this.status = "FAILED"; + } setJobStatusLabelClass(state: string) { switch (state) { diff --git a/app/job/shared/job.service.ts b/app/job/shared/job.service.ts index 10b27ba..a47c9e3 100644 --- a/app/job/shared/job.service.ts +++ b/app/job/shared/job.service.ts @@ -48,11 +48,7 @@ export class JobService { 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); - + let historyUrl = this.jobUrl + '/odata' + queryString + "&page=" + page; //FIXME: this url should be constructed by _queryBuilder return this.getJobs(historyUrl) }