@@ -6,31 +6,9 @@ const VIEWABLE_PAGES = 9;
6
6
7
7
// eslint-disable-next-line ember/no-new-mixins
8
8
export default Mixin . create ( {
9
- // Gives page numbers to the surrounding 9 pages.
10
- pages : computed ( 'currentPage' , 'availablePages' , function ( ) {
11
- let pages = [ ] ;
12
- let currentPage = this . currentPage ;
13
- let availablePages = this . availablePages ;
14
- let lowerBound = 0 ;
15
- let upperBound = 0 ;
16
-
17
- // Always show the same number of pages even if we're
18
- // at the beginning or at the end of the list.
19
- if ( availablePages - currentPage < Math . ceil ( VIEWABLE_PAGES / 2 ) ) {
20
- lowerBound = Math . max ( 0 , availablePages - VIEWABLE_PAGES ) ;
21
- upperBound = availablePages ;
22
- } else if ( currentPage <= Math . ceil ( VIEWABLE_PAGES / 2 ) ) {
23
- lowerBound = 0 ;
24
- upperBound = Math . min ( availablePages , VIEWABLE_PAGES ) ;
25
- } else {
26
- lowerBound = currentPage - Math . ceil ( VIEWABLE_PAGES / 2 ) ;
27
- upperBound = currentPage + Math . floor ( VIEWABLE_PAGES / 2 ) ;
28
- }
29
- for ( let i = lowerBound ; i < upperBound ; i ++ ) {
30
- pages . push ( i + 1 ) ;
31
- }
32
- return pages ;
33
- } ) ,
9
+ // wire up these ember-style variables to the expected query parameters
10
+ itemsPerPage : readOnly ( 'per_page' ) ,
11
+ selectedPage : readOnly ( 'page' ) ,
34
12
35
13
currentPage : computed ( 'selectedPage' , function ( ) {
36
14
return parseInt ( this . selectedPage , 10 ) || 1 ;
@@ -47,6 +25,10 @@ export default Mixin.create({
47
25
return Math . min ( this . currentPage * this . itemsPerPage , this . totalItems ) ;
48
26
} ) ,
49
27
28
+ availablePages : computed ( 'totalItems' , 'itemsPerPage' , function ( ) {
29
+ return Math . ceil ( this . totalItems / this . itemsPerPage || 1 ) ;
30
+ } ) ,
31
+
50
32
nextPage : computed ( 'currentPage' , 'availablePages' , function ( ) {
51
33
let nextPage = this . currentPage + 1 ;
52
34
let availablePages = this . availablePages ;
@@ -66,11 +48,29 @@ export default Mixin.create({
66
48
}
67
49
} ) ,
68
50
69
- availablePages : computed ( 'totalItems' , 'itemsPerPage' , function ( ) {
70
- return Math . ceil ( this . totalItems / this . itemsPerPage || 1 ) ;
71
- } ) ,
51
+ // Gives page numbers to the surrounding 9 pages.
52
+ pages : computed ( 'currentPage' , 'availablePages' , function ( ) {
53
+ let pages = [ ] ;
54
+ let currentPage = this . currentPage ;
55
+ let availablePages = this . availablePages ;
56
+ let lowerBound = 0 ;
57
+ let upperBound = 0 ;
72
58
73
- // wire up these ember-style variables to the expected query parameters
74
- itemsPerPage : readOnly ( 'per_page' ) ,
75
- selectedPage : readOnly ( 'page' ) ,
59
+ // Always show the same number of pages even if we're
60
+ // at the beginning or at the end of the list.
61
+ if ( availablePages - currentPage < Math . ceil ( VIEWABLE_PAGES / 2 ) ) {
62
+ lowerBound = Math . max ( 0 , availablePages - VIEWABLE_PAGES ) ;
63
+ upperBound = availablePages ;
64
+ } else if ( currentPage <= Math . ceil ( VIEWABLE_PAGES / 2 ) ) {
65
+ lowerBound = 0 ;
66
+ upperBound = Math . min ( availablePages , VIEWABLE_PAGES ) ;
67
+ } else {
68
+ lowerBound = currentPage - Math . ceil ( VIEWABLE_PAGES / 2 ) ;
69
+ upperBound = currentPage + Math . floor ( VIEWABLE_PAGES / 2 ) ;
70
+ }
71
+ for ( let i = lowerBound ; i < upperBound ; i ++ ) {
72
+ pages . push ( i + 1 ) ;
73
+ }
74
+ return pages ;
75
+ } ) ,
76
76
} ) ;
0 commit comments