2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input} from '@angular/core';
|
2018-05-18 17:59:13 +02:00
|
|
|
import {Router, ActivatedRoute} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
|
|
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum" [term]="keyword"> </paging>
|
|
|
|
import {RouterHelper} from './routerHelper.class';
|
2018-05-18 17:59:13 +02:00
|
|
|
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
|
|
|
@Component({
|
|
|
|
selector: 'paging',
|
|
|
|
template: `
|
|
|
|
|
|
|
|
|
2020-02-24 14:33:34 +01:00
|
|
|
<ul *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage && currentPage <= getTotalPages() ) "
|
2020-07-14 15:13:44 +02:00
|
|
|
[class]="(isDisabled ? 'uk-disabled' : '') + ' uk-pagination uk-margin-remove-bottom uk-flex uk-flex-middle'">
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
<!--li *ngIf=" currentPage > 1" ><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',1)" routerLinkActive="router-link-active" [routerLink]=baseUrl 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-->
|
|
|
|
<li *ngIf=" currentPage > 1" ><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage - 1))" routerLinkActive="router-link-active" [routerLink]=baseUrl 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>
|
|
|
|
<!--<li *ngIf=" currentPage > 1"><a [href]="onPage((currentPage -1))">\<</a></li>-->
|
|
|
|
|
2018-05-18 14:47:26 +02:00
|
|
|
<li *ngIf=" currentPage -2 > 0"><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage - 2))" routerLinkActive="router-link-active" [routerLink]=baseUrl>{{(currentPage -2) | number}}</a></li>
|
|
|
|
<li *ngIf=" currentPage -1 > 0 "><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage - 1))" routerLinkActive="router-link-active" [routerLink]=baseUrl>{{(currentPage -1) | number}}</a></li>
|
|
|
|
<li class="uk-active"><span >{{currentPage | number}}</span></li>
|
|
|
|
<li *ngIf=" currentPage +1 <= getTotalPages() "><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage +1))" routerLinkActive="router-link-active" [routerLink]=baseUrl>{{(currentPage +1) | number}}</a></li>
|
|
|
|
<li *ngIf=" currentPage +2 <= getTotalPages() "><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage +2))" routerLinkActive="router-link-active" [routerLink]=baseUrl>{{(currentPage +2) | number}}</a></li>
|
|
|
|
<li *ngIf=" (currentPage -2 <= 0)&&(currentPage +3 <= getTotalPages()) "><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage +3))" routerLinkActive="router-link-active" [routerLink]=baseUrl>{{(currentPage +3) | number}}</a></li>
|
|
|
|
<li *ngIf=" (currentPage -1 <= 0)&&(currentPage +4 <= getTotalPages()) "><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage +4))" routerLinkActive="router-link-active" [routerLink]=baseUrl >{{(currentPage +4) | number}}</a></li>
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
<li *ngIf="getTotalPages() > currentPage"><a [queryParams]="routerHelper.createQueryParamsPaging(parameterNames,parameterValues,'page',(currentPage + 1))" routerLinkActive="router-link-active" [routerLink]=baseUrl 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 PagingFormatter {
|
2020-07-14 15:13:44 +02:00
|
|
|
@Input() isDisabled: boolean = false;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Input() currentPage: number = 1;
|
|
|
|
@Input() size: number=10;
|
|
|
|
@Input() totalResults: number = 10;
|
|
|
|
@Input() baseUrl:string="";
|
|
|
|
@Input() parameterNames:string[];
|
|
|
|
@Input() parameterValues:string[];
|
|
|
|
|
2018-05-18 17:59:13 +02:00
|
|
|
private limit: number;
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
|
|
|
|
2020-11-18 17:06:27 +01:00
|
|
|
constructor () {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
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-02-05 14:14:59 +01:00
|
|
|
let total: number = 0;
|
2018-05-18 17:59:13 +02:00
|
|
|
//let limit: number = 20;//OpenaireProperties.getPagingLimit();
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
var i:number =parseInt(''+(this.totalResults/this.size));
|
2018-02-05 14:14:59 +01:00
|
|
|
total = (((this.totalResults/this.size) == i )? i :(i+1)) ;
|
|
|
|
|
2018-05-18 17:59:13 +02:00
|
|
|
if((this.currentPage == this.limit) && (total > this.limit)) {
|
|
|
|
total = this.limit;
|
|
|
|
} else if((this.currentPage > this.limit) && (total > this.limit)) {
|
2018-02-05 14:14:59 +01:00
|
|
|
total = this.currentPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// onPage(pageNum: number){
|
|
|
|
// return this.sanitizer.bypassSecurityTrustUrl( this.baseUrl+((this.baseUrl.indexOf("?") > -1 )?'&':'?')+ "page=" + (pageNum));
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
}
|