github.com/manicqin/nomad@v0.9.5/ui/app/components/list-pagination.js (about) 1 import Component from '@ember/component'; 2 import { computed } from '@ember/object'; 3 import { computed as overridable } from 'ember-overridable-computed'; 4 5 export default Component.extend({ 6 source: overridable(() => []), 7 size: 25, 8 page: 1, 9 spread: 2, 10 11 startsAt: computed('size', 'page', function() { 12 return (this.page - 1) * this.size + 1; 13 }), 14 15 endsAt: computed('source.[]', 'size', 'page', function() { 16 return Math.min(this.page * this.size, this.get('source.length')); 17 }), 18 19 lastPage: computed('source.[]', 'size', function() { 20 return Math.ceil(this.get('source.length') / this.size); 21 }), 22 23 pageLinks: computed('source.[]', 'page', 'spread', function() { 24 const { spread, page, lastPage } = this; 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) 35 .fill(null) 36 .map((_, index) => ({ 37 pageNumber: lowerBound + index, 38 })); 39 }), 40 41 list: computed('source.[]', 'page', 'size', function() { 42 const size = this.size; 43 const start = (this.page - 1) * size; 44 return this.source.slice(start, start + size); 45 }), 46 });