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';
|
2020-11-18 17:06:27 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum" [term]="keyword"> </paging>
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'paging-no-load',
|
|
|
|
template: `
|
2020-03-12 14:49:10 +01:00
|
|
|
<ul disabled *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage && currentPage <= getTotalPages() ) " [ngClass]="customClasses"
|
2022-04-20 16:40:18 +02:00
|
|
|
class="uk-pagination uk-flex uk-flex-middle ">
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2022-04-20 16:40:18 +02:00
|
|
|
<li [class.uk-invisible]="currentPage <= 1" ><a (click)="onPage((currentPage -1))" aria-label="Previous">
|
2017-12-19 13:53:46 +01:00
|
|
|
<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>
|
2022-04-20 16:40:18 +02:00
|
|
|
<li [class.uk-invisible]="getTotalPages() <= currentPage">
|
2020-03-12 14:49:10 +01:00
|
|
|
<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>
|
2017-12-19 13:53:46 +01:00
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
|
|
|
export class pagingFormatterNoLoad {
|
|
|
|
@Input() public currentPage: number = 1;
|
2022-04-20 16:40:18 +02:00
|
|
|
@Input() public customClasses: string = 'uk-flex-center';
|
2017-12-19 13:53:46 +01:00
|
|
|
// @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;
|
2019-10-01 10:26:17 +02:00
|
|
|
@Input()
|
|
|
|
public loading:boolean = false;
|
2018-05-18 17:59:13 +02:00
|
|
|
|
|
|
|
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);
|
2020-11-18 17:06:27 +01:00
|
|
|
|
|
|
|
this.properties = properties;
|
|
|
|
this.limit = this.properties.pagingLimit;
|
|
|
|
|
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){
|
2019-10-01 10:26:17 +02:00
|
|
|
if(!this.loading) {
|
|
|
|
this.currentPage = pageNum;
|
|
|
|
this.pageChange.emit({
|
|
|
|
value: this.currentPage
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|