Project

General

Profile

1
import {Component, Input, Output, EventEmitter} from '@angular/core';
2

    
3

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

    
6
@Component({
7
  selector: 'paging-no-load',
8
  template: `
9
   <ul  *ngIf=" ( getTotalPages() > 0 ) && (getTotalPages() > 1) && ( 0 < currentPage &&  currentPage <= getTotalPages() ) " class="uk-pagination">
10

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

    
27

    
28
 </ul>
29

    
30
  `
31
})
32

    
33
export class pagingFormatterNoLoad {
34
  @Input() public currentPage: number = 1;
35
  // @Input() public navigateTo: string;
36
  @Input() public term: string='';
37
  @Input() public size: number=10;
38
  @Input() public totalResults: number = 10;
39
  // @Input() public params;
40

    
41
  @Output() pageChange  = new EventEmitter();
42

    
43
  constructor () {
44
   }
45

    
46
  ngOnInit() {
47
      console.info("In paging -- CurrentPage:"+this.currentPage+" "+"total Pages = "+this.getTotalPages()  +" Results num:"+this.totalResults);
48
  }
49
  getTotalPages(){
50
    var i= this.totalResults/this.size;
51
    var integerI=parseInt(''+i);
52
    return parseInt(''+((i==integerI)?i:i+1));
53
  }
54
  onPrev(){
55
    this.currentPage=this.currentPage-1;
56
    this.pageChange.emit({
57
     value: this.currentPage
58
   });
59

    
60
  }
61

    
62
  onNext(){
63

    
64
    this.currentPage=this.currentPage+1;
65
    this.pageChange.emit({
66
     value: this.currentPage
67
   });
68
  }
69
  onPage(pageNum: number){
70

    
71
     this.currentPage=pageNum;
72
     this.pageChange.emit({
73
      value: this.currentPage
74
    });
75
  }
76
}
(13-13/16)