import {Component, Input, Output, EventEmitter} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import{EnvProperties} from './properties/env-properties'; //Usage Example @Component({ selector: 'paging-no-load', template: ` ` }) export class pagingFormatterNoLoad { @Input() public currentPage: number = 1; // @Input() public navigateTo: string; @Input() public term: string=''; @Input() public size: number=10; @Input() public totalResults: number = 10; @Input() public limitPaging: boolean = false; // @Input() public params; @Output() pageChange = new EventEmitter(); private limit: number; properties:EnvProperties; constructor (private route: ActivatedRoute) { } ngOnInit() { //console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages() +" Results num:"+this.totalResults); this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.properties = data.envSpecific; this.limit = this.properties.pagingLimit; } ); } getTotalPages(){ let total: number = 0; //let limit: number = 20;//OpenaireProperties.getPagingLimit(); var i= this.totalResults/this.size; var integerI=parseInt(''+i); total = parseInt(''+((i==integerI)?i:i+1)); if(this.limitPaging) { if((this.currentPage == this.limit) && (total > this.limit)) { total = this.limit; } else if((this.currentPage > this.limit) && (total > this.limit)) { total = this.currentPage; } } return total; } onPrev(){ this.currentPage=this.currentPage-1; this.pageChange.emit({ value: this.currentPage }); } onNext(){ this.currentPage=this.currentPage+1; this.pageChange.emit({ value: this.currentPage }); } onPage(pageNum: number){ this.currentPage=pageNum; this.pageChange.emit({ value: this.currentPage }); } }