1 |
61381
|
k.triantaf
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2 |
|
|
import {ActivatedRoute} from '@angular/router';
|
3 |
|
|
import{EnvProperties} from './properties/env-properties';
|
4 |
|
|
import {properties} from "../../../environments/environment";
|
5 |
|
|
|
6 |
|
|
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum" [term]="keyword"> </paging>
|
7 |
|
|
|
8 |
|
|
@Component({
|
9 |
|
|
selector: 'paging-no-load',
|
10 |
|
|
template: `
|
11 |
|
|
<ul disabled *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage && currentPage <= getTotalPages() ) " [ngClass]="customClasses"
|
12 |
|
|
class="uk-pagination uk-flex uk-flex-middle">
|
13 |
|
|
|
14 |
|
|
<li *ngIf=" currentPage > 1" ><a (click)="onPage((currentPage -1))" aria-label="Previous">
|
15 |
|
|
<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>
|
16 |
|
|
<li *ngIf=" currentPage -2 > 0"><a (click)="onPage((currentPage -2))">{{(currentPage -2) | number}}</a></li>
|
17 |
|
|
<li *ngIf=" currentPage -1 > 0 "><a (click)="onPage((currentPage -1))">{{(currentPage -1) | number}}</a></li>
|
18 |
|
|
<li class="uk-active"><span >{{currentPage | number}}</span></li>
|
19 |
|
|
<li *ngIf=" currentPage +1 <= getTotalPages() "><a (click)="onPage((currentPage +1))">{{(currentPage +1) | number}}</a></li>
|
20 |
|
|
<li *ngIf=" currentPage +2 <= getTotalPages() "><a (click)="onPage((currentPage +2))">{{(currentPage +2) | number}}</a></li>
|
21 |
|
|
<li *ngIf=" (currentPage -2 <= 0)&&(currentPage +3 <= getTotalPages()) "><a (click)="onPage((currentPage +3))">{{(currentPage +3) | number}}</a></li>
|
22 |
|
|
<li *ngIf=" (currentPage -1 <= 0)&&(currentPage +4 <= getTotalPages()) "><a (click)="onPage((currentPage +4))">{{(currentPage +4) | number}}</a></li>
|
23 |
|
|
<li *ngIf="getTotalPages() > currentPage">
|
24 |
|
|
<a (click)="onPage(currentPage +1)" aria-label="Next">
|
25 |
|
|
<span class="uk-icon">
|
26 |
|
|
<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>
|
27 |
|
|
</span>
|
28 |
|
|
</a>
|
29 |
|
|
</li>
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
</ul>
|
33 |
|
|
|
34 |
|
|
`
|
35 |
|
|
})
|
36 |
|
|
|
37 |
|
|
export class pagingFormatterNoLoad {
|
38 |
|
|
@Input() public currentPage: number = 1;
|
39 |
|
|
@Input() public customClasses: string = '';
|
40 |
|
|
// @Input() public navigateTo: string;
|
41 |
|
|
@Input() public term: string='';
|
42 |
|
|
@Input() public size: number=10;
|
43 |
|
|
@Input() public totalResults: number = 10;
|
44 |
|
|
@Input() public limitPaging: boolean = false;
|
45 |
|
|
|
46 |
|
|
// @Input() public params;
|
47 |
|
|
|
48 |
|
|
@Output() pageChange = new EventEmitter();
|
49 |
|
|
|
50 |
|
|
private limit: number;
|
51 |
|
|
properties:EnvProperties;
|
52 |
|
|
@Input()
|
53 |
|
|
public loading:boolean = false;
|
54 |
|
|
|
55 |
|
|
constructor (private route: ActivatedRoute) {
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
ngOnInit() {
|
59 |
|
|
//console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages() +" Results num:"+this.totalResults);
|
60 |
|
|
|
61 |
|
|
this.properties = properties;
|
62 |
|
|
this.limit = this.properties.pagingLimit;
|
63 |
|
|
|
64 |
|
|
}
|
65 |
|
|
getTotalPages(){
|
66 |
|
|
let total: number = 0;
|
67 |
|
|
//let limit: number = 20;//OpenaireProperties.getPagingLimit();
|
68 |
|
|
|
69 |
|
|
var i= this.totalResults/this.size;
|
70 |
|
|
var integerI=parseInt(''+i);
|
71 |
|
|
total = parseInt(''+((i==integerI)?i:i+1));
|
72 |
|
|
|
73 |
|
|
if(this.limitPaging) {
|
74 |
|
|
if((this.currentPage == this.limit) && (total > this.limit)) {
|
75 |
|
|
total = this.limit;
|
76 |
|
|
} else if((this.currentPage > this.limit) && (total > this.limit)) {
|
77 |
|
|
total = this.currentPage;
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
return total;
|
81 |
|
|
}
|
82 |
|
|
onPrev(){
|
83 |
|
|
this.currentPage=this.currentPage-1;
|
84 |
|
|
this.pageChange.emit({
|
85 |
|
|
value: this.currentPage
|
86 |
|
|
});
|
87 |
|
|
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
onNext(){
|
91 |
|
|
|
92 |
|
|
this.currentPage=this.currentPage+1;
|
93 |
|
|
this.pageChange.emit({
|
94 |
|
|
value: this.currentPage
|
95 |
|
|
});
|
96 |
|
|
}
|
97 |
|
|
onPage(pageNum: number){
|
98 |
|
|
if(!this.loading) {
|
99 |
|
|
this.currentPage = pageNum;
|
100 |
|
|
this.pageChange.emit({
|
101 |
|
|
value: this.currentPage
|
102 |
|
|
});
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
}
|