explore-services/src/app/common/pagingFormatterNoLoad.compo...

100 lines
3.6 KiB
TypeScript

import {Component, Input, Output, EventEmitter} from '@angular/core';
import {Router, ROUTER_DIRECTIVES} from '@angular/router-deprecated';
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum" [navigateTo]="Search" [term]="keyword"> </paging>
@Component({
selector: 'paging-no-load',
template: `
<div *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage && currentPage <= getTotalPages() ) " >
<ul class="pagination">
<li *ngIf=" currentPage > 1" ><a (click)="onPage((1))" aria-label="Previous">
<span aria-hidden="true">&laquo;</span></a></li>
<!--<li *ngIf=" currentPage > 1"><a (click)="onPage((currentPage -1))">\<</a></li>-->
<li *ngIf=" currentPage -2 > 0"><a (click)="onPage((currentPage -2))">{{currentPage -2}}</a></li>
<li *ngIf=" currentPage -1 > 0 "><a (click)="onPage((currentPage -1))">{{currentPage -1}}</a></li>
<li class="active"><a >{{currentPage}}</a></li>
<li *ngIf=" currentPage +1 <= getTotalPages() "><a (click)="onPage((currentPage +1))">{{currentPage +1}}</a></li>
<li *ngIf=" currentPage +2 <= getTotalPages() "><a (click)="onPage((currentPage +2))">{{currentPage +2}}</a></li>
<li *ngIf=" (currentPage -2 <= 0)&&(currentPage +3 <= getTotalPages()) "><a (click)="onPage((currentPage +3))">{{currentPage +3}}</a></li>
<li *ngIf=" (currentPage -1 <= 0)&&(currentPage +4 <= getTotalPages()) "><a (click)="onPage((currentPage +4))">{{currentPage +4}}</a></li>
<!--<li *ngIf=" getTotalPages() > currentPage "><a (click)="onPage((currentPage+1))">\></a></li>-->
<li *ngIf="getTotalPages() > currentPage"><a (click)="onPage((getTotalPages()))" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a></li>
</ul>
</div>
`,
directives: [
...ROUTER_DIRECTIVES
]
})
export class pagingFormatterNoLoad {
@Input() currentPage: number = 1;
@Input() navigateTo: string;
@Input() term: string='';
@Input() size: number=10;
@Input() totalResults: number = 10;
@Input() params;
@Output() pageChange = new EventEmitter();
constructor ( private _router: Router) {
}
ngOnInit() {
console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages() +" Results num:"+this.totalResults);
}
getTotalPages(){
return parseInt(''+(this.totalResults/this.size+1));
}
onPrev(){
this.currentPage=-1;
this.pageChange.emit({
value: this.currentPage
});
// if(this.params){
// let pageparams= this.params;
// pageparams.page=this.currentPage -1
// this._router.navigate( [this.navigateTo, pageparams] );
// }else{
// this._router.navigate( [this.navigateTo, { keyword: this.term, page: (this.currentPage -1) }] );
// }
}
onNext(){
// if(this.params){
// let pageparams= this.params;
// pageparams.page=this.currentPage +1;
// this._router.navigate( [this.navigateTo, pageparams] );
// }else{
// this._router.navigate( [this.navigateTo, { keyword: this.term, page: (this.currentPage +1) }] );
// }
this.currentPage=+1;
this.pageChange.emit({
value: this.currentPage
});
}
onPage(pageNum: number){
// if(this.params){
// let pageparams= this.params;
// pageparams.page=pageNum;
// this._router.navigate( [this.navigateTo, pageparams] );
// }else if(this.term!=''){
// this._router.navigate( [this.navigateTo, { keyword: this.term, page: pageNum, size: this.size }] );
// }else{
// this._router.navigate( [this.navigateTo, { page: pageNum, size: this.size }] );
// }
this.currentPage=pageNum;
this.pageChange.emit({
value: this.currentPage
});
}
}