github.com/emate/nomad@v0.8.2-wo-binpacking/ui/app/components/list-pagination.js (about)

     1  import Component from '@ember/component';
     2  import { computed } from '@ember/object';
     3  
     4  export default Component.extend({
     5    source: computed(() => []),
     6    size: 25,
     7    page: 1,
     8    spread: 2,
     9  
    10    startsAt: computed('size', 'page', function() {
    11      return (this.get('page') - 1) * this.get('size') + 1;
    12    }),
    13  
    14    endsAt: computed('source.[]', 'size', 'page', function() {
    15      return Math.min(this.get('page') * this.get('size'), this.get('source.length'));
    16    }),
    17  
    18    lastPage: computed('source.[]', 'size', function() {
    19      return Math.ceil(this.get('source.length') / this.get('size'));
    20    }),
    21  
    22    pageLinks: computed('source.[]', 'page', 'spread', function() {
    23      const { spread, page, lastPage } = this.getProperties('spread', 'page', 'lastPage');
    24  
    25      // When there is only one page, don't bother with page links
    26      if (lastPage === 1) {
    27        return [];
    28      }
    29  
    30      const lowerBound = Math.max(1, page - spread);
    31      const upperBound = Math.min(lastPage, page + spread) + 1;
    32  
    33      return Array(upperBound - lowerBound)
    34        .fill(null)
    35        .map((_, index) => ({
    36          pageNumber: lowerBound + index,
    37        }));
    38    }),
    39  
    40    list: computed('source.[]', 'page', 'size', function() {
    41      const size = this.get('size');
    42      const start = (this.get('page') - 1) * size;
    43      return this.get('source').slice(start, start + size);
    44    }),
    45  });