File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ import Component from '@ember/component' ;
2+
3+ export default class PaginationPillsComponent extends Component {
4+ didReceiveAttrs ( ) {
5+ const length = this . pages
6+ this . set ( 'pagesArray' , Array . from ( { length} , ( v , i ) => ++ i ) )
7+ }
8+ }
Original file line number Diff line number Diff line change 1+ <nav aria-label =" Page navigation" >
2+ <ul class =" pagination justify-content-center" >
3+ <li class =" page-item" >
4+ <button
5+ class =" page-link"
6+ {{ action setPage (dec pagination.currentPage )}}
7+ disabled ={{ eq pagination.currentPage 1 }} >
8+ Previous
9+ </button >
10+ </li >
11+
12+ {{ #each pagesArray as |page |}}
13+ <li class =" page-item" >
14+ <button
15+ class =" page-link active {{ if (eq page pagination.currentPage ) " bg-red white" }} "
16+ {{ action setPage page }} >
17+ {{ page }}
18+ </button >
19+ </li >
20+ {{ /each }}
21+
22+ <li class =" page-item" >
23+ <button
24+ class =" page-link"
25+ {{ action setPage (inc pagination.currentPage )}}
26+ disabled ={{ not pagination.nextOffset }} >
27+ Next
28+ </button >
29+ </li >
30+ </ul >
31+ </nav >
Original file line number Diff line number Diff line change 11import Controller from '@ember/controller' ;
22import { inject as service } from '@ember/service' ;
33import { task , timeout } from 'ember-concurrency' ;
4+ import { computed } from '@ember/object' ;
45
56export default Controller . extend ( {
67 store : service ( ) ,
78 queryParams : [ 'page' , 'limit' ] ,
89 page : 1 ,
910 limit : 10 ,
1011 searchString : '' ,
12+ pageCount : computed ( 'limit' , 'questions' , function ( ) {
13+ return Math . ceil ( this . questions . meta . pagination . count / this . limit )
14+ } ) ,
1115 searchTask : task ( function * ( ) {
1216 yield timeout ( 250 )
1317
Original file line number Diff line number Diff line change 6565 </div >
6666 </div >
6767 {{ /each }}
68+ {{ pagination-pills
69+ pagination =questions.meta.pagination
70+ pages =pageCount
71+ setPage = (action (mut page ))}}
6872</div >
6973{{ outlet }}
Original file line number Diff line number Diff line change 1+ import { module , test } from 'qunit' ;
2+ import { setupRenderingTest } from 'ember-qunit' ;
3+ import { render } from '@ember/test-helpers' ;
4+ import hbs from 'htmlbars-inline-precompile' ;
5+
6+ module ( 'Integration | Component | pagination-pills' , function ( hooks ) {
7+ setupRenderingTest ( hooks ) ;
8+
9+ test ( 'it renders' , async function ( assert ) {
10+ // Set any properties with this.set('myProperty', 'value');
11+ // Handle any actions with this.set('myAction', function(val) { ... });
12+
13+ await render ( hbs `{{pagination-pills}}` ) ;
14+
15+ assert . equal ( this . element . textContent . trim ( ) , '' ) ;
16+
17+ // Template block usage:
18+ await render ( hbs `
19+ {{#pagination-pills}}
20+ template block text
21+ {{/pagination-pills}}
22+ ` ) ;
23+
24+ assert . equal ( this . element . textContent . trim ( ) , 'template block text' ) ;
25+ } ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments