2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2018-05-18 17:59:13 +02:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
import{EnvProperties} from './properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum" [term]="keyword"> </paging>
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'paging-no-load',
|
|
|
|
template: `
|
|
|
|
<ul *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage && currentPage <= getTotalPages() ) " class="uk-pagination">
|
|
|
|
|
|
|
|
<li *ngIf=" currentPage > 1" ><a (click)="onPage((currentPage -1))" aria-label="Previous">
|
|
|
|
<span><span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-left" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="13 16 7 10 13 4"></polyline></svg></span></span></a></li>
|
2018-05-18 14:47:26 +02:00
|
|
|
<li *ngIf=" currentPage -2 > 0"><a (click)="onPage((currentPage -2))">{{(currentPage -2) | number}}</a></li>
|
|
|
|
<li *ngIf=" currentPage -1 > 0 "><a (click)="onPage((currentPage -1))">{{(currentPage -1) | number}}</a></li>
|
|
|
|
<li class="uk-active"><span >{{currentPage | number}}</span></li>
|
|
|
|
<li *ngIf=" currentPage +1 <= getTotalPages() "><a (click)="onPage((currentPage +1))">{{(currentPage +1) | number}}</a></li>
|
|
|
|
<li *ngIf=" currentPage +2 <= getTotalPages() "><a (click)="onPage((currentPage +2))">{{(currentPage +2) | number}}</a></li>
|
|
|
|
<li *ngIf=" (currentPage -2 <= 0)&&(currentPage +3 <= getTotalPages()) "><a (click)="onPage((currentPage +3))">{{(currentPage +3) | number}}</a></li>
|
|
|
|
<li *ngIf=" (currentPage -1 <= 0)&&(currentPage +4 <= getTotalPages()) "><a (click)="onPage((currentPage +4))">{{(currentPage +4) | number}}</a></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
<li *ngIf="getTotalPages() > currentPage"><a (click)="onPage(currentPage +1)" aria-label="Next">
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03" points="7 4 13 10 7 16"></polyline></svg>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
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;
|
2018-05-18 17:59:13 +02:00
|
|
|
@Input() public limitPaging: boolean = false;
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
// @Input() public params;
|
|
|
|
|
|
|
|
@Output() pageChange = new EventEmitter();
|
|
|
|
|
2018-05-18 17:59:13 +02:00
|
|
|
private limit: number;
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
|
|
|
constructor (private route: ActivatedRoute) {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages() +" Results num:"+this.totalResults);
|
2018-05-18 17:59:13 +02:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
2018-05-18 18:08:30 +02:00
|
|
|
this.limit = this.properties.pagingLimit;
|
2018-05-18 17:59:13 +02:00
|
|
|
}
|
|
|
|
);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
getTotalPages(){
|
2018-05-18 17:59:13 +02:00
|
|
|
let total: number = 0;
|
|
|
|
//let limit: number = 20;//OpenaireProperties.getPagingLimit();
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
var i= this.totalResults/this.size;
|
|
|
|
var integerI=parseInt(''+i);
|
2018-05-18 17:59:13 +02:00
|
|
|
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;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|