|  | 
| 1 | 1 | import Component from '@ember/component'; | 
| 2 |  | -import { computed, action } from '@ember/object'; | 
|  | 2 | +import { computed, action, get } from '@ember/object'; | 
| 3 | 3 | 
 | 
| 4 | 4 | export default class extends Component { | 
| 5 | 5 | 
 | 
| 6 | 6 |   totalCount = 100; | 
| 7 | 7 | 
 | 
| 8 |  | -  @computed() | 
|  | 8 | +  metaPagesCountProperty = 'page[size]'; | 
|  | 9 | +  metaItemsCountProperty = 'count'; | 
|  | 10 | + | 
|  | 11 | +  @computed('currentPage', 'pageSize', 'totalContentLength') | 
| 9 | 12 |   get currentRange() { | 
| 10 |  | -    return '1-10'; | 
|  | 13 | +    let firstIndex = this.totalContentLength === 0 ? 0 : (this.currentPage - 1) * this.pageSize + 1; | 
|  | 14 | +    let lastIndex = this.currentPage === this.pageCount ? this.totalContentLength : this.currentPage * this.pageSize; | 
|  | 15 | +    return `${firstIndex} - ${lastIndex}`; | 
| 11 | 16 |   } | 
| 12 | 17 | 
 | 
| 13 |  | -  @computed() | 
|  | 18 | +  @computed('currentPage', 'pageSize', 'totalContentLength') | 
| 14 | 19 |   get pageCount() { | 
| 15 |  | -    return 10; | 
|  | 20 | +    let totalPages = 0; | 
|  | 21 | +    if (this.pageSize < this.totalContentLength) { | 
|  | 22 | +      totalPages = parseInt(this.totalContentLength / this.pageSize); | 
|  | 23 | +      if (this.totalContentLength % this.pageSize) { | 
|  | 24 | +        totalPages += 1; | 
|  | 25 | +      } | 
|  | 26 | +    } | 
|  | 27 | +    return totalPages; | 
|  | 28 | +  } | 
|  | 29 | + | 
|  | 30 | +  @computed('metaData') | 
|  | 31 | +  get totalContentLength() { | 
|  | 32 | +    return get(this.metaData, this.metaItemsCountProperty); | 
|  | 33 | +  } | 
|  | 34 | + | 
|  | 35 | +  @computed('currentPage') | 
|  | 36 | +  get moveToPreviousPageDisabled() { | 
|  | 37 | +    return this.currentPage <= 1; | 
|  | 38 | + | 
|  | 39 | +  } | 
|  | 40 | +  @computed('currentPage', 'pageCount') | 
|  | 41 | +  get moveToNextPageDisabled() { | 
|  | 42 | +    return this.currentPage >= this.pageCount; | 
| 16 | 43 |   } | 
| 17 | 44 | 
 | 
| 18 | 45 |   @action | 
| 19 | 46 |   moveToNextPage() { | 
| 20 |  | -    this.incrementProperty('currentPage'); | 
|  | 47 | +    if (!this.moveToNextPageDisabled) { | 
|  | 48 | +      this.incrementProperty('currentPage'); | 
|  | 49 | +    } | 
| 21 | 50 |   } | 
| 22 | 51 | 
 | 
| 23 | 52 |   @action | 
| 24 | 53 |   moveToPreviousPage() { | 
| 25 |  | -    this.decrementProperty('currentPage'); | 
|  | 54 | +    if (!this.moveToPreviousPageDisabled) { | 
|  | 55 | +      this.decrementProperty('currentPage'); | 
|  | 56 | +    } | 
|  | 57 | +  } | 
|  | 58 | + | 
|  | 59 | +  @action | 
|  | 60 | +  moveToLastPage() { | 
|  | 61 | +    if (!this.moveToNextPageDisabled) { | 
|  | 62 | +      this.set('currentPage', this.pageCount); | 
|  | 63 | +    } | 
|  | 64 | +  } | 
|  | 65 | + | 
|  | 66 | +  @action | 
|  | 67 | +  moveToFirstPage() { | 
|  | 68 | +    if (!this.moveToPreviousPageDisabled) { | 
|  | 69 | +      this.set('currentPage', 1); | 
|  | 70 | +    } | 
| 26 | 71 |   } | 
| 27 | 72 | } | 
0 commit comments