Project

General

Profile

1
import {Component, Input, Output, EventEmitter} from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import{EnvProperties} from './properties/env-properties';
4

    
5
//Usage Example <paging [currentPage]="page" [totalResults]="resultsNum"    [term]="keyword"> </paging>
6

    
7
@Component({
8
  selector: 'paging-no-load',
9
  template: `
10
   <ul disabled  *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage &&  currentPage <= getTotalPages() ) " [ngClass]="customClasses"
11
       class="uk-pagination uk-flex uk-flex-middle">
12

    
13
   <li *ngIf=" currentPage  > 1" ><a (click)="onPage((currentPage -1))" aria-label="Previous">
14
       <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>
15
   <li *ngIf=" currentPage -2 > 0"><a (click)="onPage((currentPage -2))">{{(currentPage -2) | number}}</a></li>
16
   <li *ngIf=" currentPage -1 > 0 "><a (click)="onPage((currentPage -1))">{{(currentPage -1) | number}}</a></li>
17
   <li class="uk-active"><span >{{currentPage | number}}</span></li>
18
   <li *ngIf=" currentPage +1 <= getTotalPages() "><a (click)="onPage((currentPage +1))">{{(currentPage +1) | number}}</a></li>
19
   <li *ngIf=" currentPage +2 <= getTotalPages() "><a (click)="onPage((currentPage +2))">{{(currentPage +2) | number}}</a></li>
20
   <li *ngIf=" (currentPage -2 <= 0)&&(currentPage +3 <= getTotalPages()) "><a (click)="onPage((currentPage +3))">{{(currentPage +3) | number}}</a></li>
21
   <li *ngIf=" (currentPage -1 <= 0)&&(currentPage +4 <= getTotalPages()) "><a (click)="onPage((currentPage +4))">{{(currentPage +4) | number}}</a></li>
22
   <li *ngIf="getTotalPages()  > currentPage">
23
     <a (click)="onPage(currentPage +1)" aria-label="Next">
24
       <span class="uk-icon">
25
        <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>
26
       </span>
27
     </a>
28
  </li>
29

    
30

    
31
 </ul>
32

    
33
  `
34
})
35

    
36
export class pagingFormatterNoLoad {
37
  @Input() public currentPage: number = 1;
38
  @Input() public customClasses: string = '';
39
  // @Input() public navigateTo: string;
40
  @Input() public term: string='';
41
  @Input() public size: number=10;
42
  @Input() public totalResults: number = 10;
43
  @Input() public limitPaging: boolean = false;
44

    
45
  // @Input() public params;
46

    
47
  @Output() pageChange  = new EventEmitter();
48

    
49
  private limit: number;
50
  properties:EnvProperties;
51
  @Input()
52
  public loading:boolean = false;
53

    
54
  constructor (private route: ActivatedRoute) {
55
   }
56

    
57
  ngOnInit() {
58
      //console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages()  +" Results num:"+this.totalResults);
59
      this.route.data
60
        .subscribe((data: { envSpecific: EnvProperties }) => {
61
           this.properties = data.envSpecific;
62
           this.limit = this.properties.pagingLimit;
63
         }
64
       );
65
  }
66
  getTotalPages(){
67
    let total: number = 0;
68
    //let limit: number = 20;//OpenaireProperties.getPagingLimit();
69

    
70
    var i= this.totalResults/this.size;
71
    var integerI=parseInt(''+i);
72
    total = parseInt(''+((i==integerI)?i:i+1));
73

    
74
    if(this.limitPaging) {
75
      if((this.currentPage == this.limit) && (total > this.limit)) {
76
        total = this.limit;
77
      } else if((this.currentPage > this.limit) && (total > this.limit)) {
78
        total = this.currentPage;
79
      }
80
    }
81
    return total;
82
  }
83
  onPrev(){
84
    this.currentPage=this.currentPage-1;
85
    this.pageChange.emit({
86
     value: this.currentPage
87
   });
88

    
89
  }
90

    
91
  onNext(){
92

    
93
    this.currentPage=this.currentPage+1;
94
    this.pageChange.emit({
95
     value: this.currentPage
96
   });
97
  }
98
  onPage(pageNum: number){
99
    if(!this.loading) {
100
      this.currentPage = pageNum;
101
      this.pageChange.emit({
102
        value: this.currentPage
103
      });
104
    }
105
  }
106
}
(18-18/20)