Project

General

Profile

« Previous | Next » 

Revision 56837

adminPg-metrics: pagination update

View differences:

modules/uoa-repository-dashboard-gui/branches/metrics/src/app/pages/adminPg/adminPg-metrics.component.html
129 129

  
130 130
                  <ul class="uk-pagination uk-flex-center" uk-margin>
131 131
                    <li><a (click)="previousPage()"><span uk-pagination-previous></span></a></li>
132
                    <li class="uk-active"><span>{{+dataForm.get('page').value + 1}}</span></li>
132
<!--                    <li class="uk-active"><span>{{+dataForm.get('page').value + 1}}</span></li>-->
133
                    <li [ngClass]="{'uk-active': (this.dataForm.get('page').value == page) }" *ngFor="let page of pages">
134
                      <a (click)="selectPage(page)">{{page+1}}</a> </li>
133 135
                    <li><a (click)="nextPage()"><span uk-pagination-next></span></a></li>
134 136
                  </ul>
135 137

  
modules/uoa-repository-dashboard-gui/branches/metrics/src/app/pages/adminPg/adminPg-metrics.component.ts
45 45

  
46 46
  @ViewChild('confirmApprovalModal')
47 47
  public confirmApprovalModal: ConfirmationDialogComponent;
48
  private wholePageTotal: number;
48
  private pageTotal: number;
49 49
  private piwiksTotal: number;
50
  private pages = [];
51
  private offset = 4;
50 52

  
51 53
  constructor(private piwikService: PiwikService,
52 54
              private fb: FormBuilder,
......
92 94
      .subscribe(
93 95
        piwiks => {
94 96
          this.piwiks = piwiks;
97
          this.getPages();
95 98
        },
96 99
        error => {
97 100
          console.log(error);
......
158 161
    this.handleChange();
159 162
  }
160 163

  
164
  getPages() {
165
    this.pages = [];
166
    this.pageTotal = Math.ceil(this.piwiks.total / (this.dataForm.get('quantity').value));
167
    for (let i = (+this.dataForm.get('page').value + 1 - this.offset); i < (+this.dataForm.get('page').value + 1 + this.offset); i++) {
168
        if (i >= 0 && i < this.pageTotal) {
169
          this.pages.push(i);
170
      }
171
    }
172
  }
173

  
174
  selectPage(page) {
175
    this.dataForm.get('page').setValue(page);
176
    this.dataForm.get('from').setValue(((+this.dataForm.get('page').value) * (+this.dataForm.get('quantity').value)));
177
    this.handleChange();
178
  }
179

  
161 180
  previousPage() {
162 181
    if (this.dataForm.get('page').value > 0) {
163 182
      this.dataForm.get('page').setValue(+this.dataForm.get('page').value - 1);
......
167 186
  }
168 187

  
169 188
  nextPage() {
170
    if ((this.dataForm.get('searchField').value) !== '') { this.piwiksTotal = this.piwiks.to; } else { this.piwiksTotal = this.piwiks.total; }
171
    this.wholePageTotal = Math.floor(this.piwiksTotal / (this.dataForm.get('quantity').value)) - 1;
172
    if ((this.dataForm.get('page').value <= this.wholePageTotal) && (this.piwiks.total % (this.dataForm.get('quantity').value) !== 0)) {
189
    // if ((this.dataForm.get('searchField').value) !== '') { this.piwiksTotal = this.piwiks.to; } else { this.piwiksTotal = this.piwiks.total; }
190
    this.pageTotal = Math.ceil(this.piwiks.total / (this.dataForm.get('quantity').value)) - 1;
191
    if (this.dataForm.get('page').value < this.pageTotal) {
173 192
      this.dataForm.get('page').setValue(+this.dataForm.get('page').value + 1);
174 193
      this.dataForm.get('from').setValue(+this.dataForm.get('from').value + +this.dataForm.get('quantity').value);
175 194
      this.handleChange();

Also available in: Unified diff