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