import {Component, Input} from '@angular/core';
import {Router} from '@angular/router';
import {DomSanitizer} from '@angular/platform-browser';
//Usage Example
import {RouterHelper} from './routerHelper.class';
@Component({
selector: 'paging',
template: `
`
})
export class PagingFormatter {
@Input() currentPage: number = 1;
@Input() size: number=10;
@Input() totalResults: number = 10;
@Input() baseUrl:string="";
@Input() parameterNames:string[];
@Input() parameterValues:string[];
public routerHelper:RouterHelper = new RouterHelper();
constructor ( private _router: Router, private sanitizer:DomSanitizer) {
}
ngOnInit() {
}
getTotalPages(){
let total: number = 0;
let limit: number = 20;//OpenaireProperties.getPagingLimit();
var i:number =parseInt(''+(this.totalResults/this.size));
total = (((this.totalResults/this.size) == i )? i :(i+1)) ;
if((this.currentPage == limit) && (total > limit)) {
total = limit;
} else if((this.currentPage > limit) && (total > limit)) {
total = this.currentPage;
}
return total;
}
// onPage(pageNum: number){
// return this.sanitizer.bypassSecurityTrustUrl( this.baseUrl+((this.baseUrl.indexOf("?") > -1 )?'&':'?')+ "page=" + (pageNum));
//
// }
}