From e0613fcefb678ef8cad1cafcf528d8f792325baa Mon Sep 17 00:00:00 2001 From: bradley Date: Wed, 3 Aug 2016 15:02:10 -0400 Subject: [PATCH 1/8] Added fix for non-working ellipses + Modified pagination to work with json object + Added display attribute for dynamic link creation text + Modified navigation to work with set id + Checked for ellipses and type to properly navigate + Fixed introduced previous button cycle behaviour --- src/directives/pagination/dirPagination.js | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index a1a7265..0a20226 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -222,7 +222,7 @@ } function dirPaginationControlsTemplateInstaller($templateCache) { - $templateCache.put('angularUtils.directives.dirPagination.template', ''); + $templateCache.put('angularUtils.directives.dirPagination.template', ''); } function dirPaginationControlsDirective(paginationService, paginationTemplate) { @@ -327,10 +327,18 @@ }); scope.setCurrent = function(num) { - if (paginationService.isRegistered(paginationId) && isValidPageNumber(num)) { - num = parseInt(num, 10); + //quick fix for bug with previous arrow + if(num === 0) return; + + if (paginationService.isRegistered(paginationId) && (isValidPageNumber(num.id) || isValidPageNumber(num))) { + num = isValidPageNumber(num.id) === true ? parseInt(num.id, 10) : parseInt(num, 10); paginationService.setCurrentPage(paginationId, num); } + paginationService.setCurrentPage(paginationId, scope.pages[1].id - 1); + } + paginationService.setCurrentPage(paginationId, scope.pages[3].id + 1); + } + } }; /** @@ -369,7 +377,7 @@ var page = parseInt(paginationService.getCurrentPage(paginationId)) || 1; scope.pages = generatePagesArray(page, paginationService.getCollectionLength(paginationId), paginationService.getItemsPerPage(paginationId), paginationRange); scope.pagination.current = page; - scope.pagination.last = scope.pages[scope.pages.length - 1]; + scope.pagination.last = scope.pages.last; if (scope.pagination.last < scope.pagination.current) { scope.setCurrent(scope.pagination.last); } else { @@ -426,16 +434,20 @@ var i = 1; while (i <= totalPages && i <= paginationRange) { var pageNumber = calculatePageNumber(i, currentPage, paginationRange, totalPages); - - var openingEllipsesNeeded = (i === 2 && (position === 'middle' || position === 'end')); - var closingEllipsesNeeded = (i === paginationRange - 1 && (position === 'middle' || position === 'start')); - if (ellipsesNeeded && (openingEllipsesNeeded || closingEllipsesNeeded)) { - pages.push('...'); - } else { - pages.push(pageNumber); + + var openingEllipsesNeeded = (i === 1 && (position === 'middle' || position === 'end')); + var closingEllipsesNeeded = (i === paginationRange && (position === 'middle' || position === 'start')); + if (ellipsesNeeded && openingEllipsesNeeded) { + } + else if(ellipsesNeeded && closingEllipsesNeeded){ + }else { + pages.push({"id":pageNumber, "display": pageNumber}); } i ++; } + + //set last page value + pages.last = totalPages; return pages; } From 687f0230b695e71909083ea29358f9a192fc105f Mon Sep 17 00:00:00 2001 From: cr1x56 Date: Wed, 3 Aug 2016 15:18:33 -0400 Subject: [PATCH 2/8] Fixed weird issue from previous commit --- src/directives/pagination/dirPagination.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index 0a20226..0df654d 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -334,8 +334,11 @@ num = isValidPageNumber(num.id) === true ? parseInt(num.id, 10) : parseInt(num, 10); paginationService.setCurrentPage(paginationId, num); } + else { //ellipses were hit + if(num.id == "before-ellipses"){ //before ellipses paginationService.setCurrentPage(paginationId, scope.pages[1].id - 1); } + else { //after ellipses paginationService.setCurrentPage(paginationId, scope.pages[3].id + 1); } } @@ -438,8 +441,10 @@ var openingEllipsesNeeded = (i === 1 && (position === 'middle' || position === 'end')); var closingEllipsesNeeded = (i === paginationRange && (position === 'middle' || position === 'start')); if (ellipsesNeeded && openingEllipsesNeeded) { + pages.push({"id":"before-ellipses", "display": "..."}); } else if(ellipsesNeeded && closingEllipsesNeeded){ + pages.push({"id":"after-ellipses", "display": "..."}); }else { pages.push({"id":pageNumber, "display": pageNumber}); } From d19525c71f5a21aa8f340c29b050c9e28795f0ae Mon Sep 17 00:00:00 2001 From: bradley Date: Wed, 3 Aug 2016 15:20:08 -0400 Subject: [PATCH 3/8] Fixed commit to master issue --- src/directives/pagination/dirPagination.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index 0a20226..bfb2b57 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -334,8 +334,11 @@ num = isValidPageNumber(num.id) === true ? parseInt(num.id, 10) : parseInt(num, 10); paginationService.setCurrentPage(paginationId, num); } + else { //ellipses were hit + if(num.id == "before-ellipses"){ //before ellipses paginationService.setCurrentPage(paginationId, scope.pages[1].id - 1); } + else { //after ellipses paginationService.setCurrentPage(paginationId, scope.pages[3].id + 1); } } @@ -438,8 +441,10 @@ var openingEllipsesNeeded = (i === 1 && (position === 'middle' || position === 'end')); var closingEllipsesNeeded = (i === paginationRange && (position === 'middle' || position === 'start')); if (ellipsesNeeded && openingEllipsesNeeded) { + pages.push({"id":"before-ellipses", "display": "..."}); } else if(ellipsesNeeded && closingEllipsesNeeded){ + pages.push({"id":"after-ellipses", "display": "..."}); }else { pages.push({"id":pageNumber, "display": pageNumber}); } @@ -648,4 +653,4 @@ }; }; } -})(); +})(); \ No newline at end of file From 0bc2bab0d3ea4e7cc33611606739a1ddde253942 Mon Sep 17 00:00:00 2001 From: cr1x56 Date: Wed, 3 Aug 2016 15:28:24 -0400 Subject: [PATCH 4/8] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8338d9..e42bea3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# Working Plunker +http://plnkr.co/edit/ZU2iAOMf0SrmoAC5cdjU?p=preview + # Angular Utilities I am working on a large-scale AngularJS-based project and I'll be extracting @@ -33,4 +36,4 @@ This code is made available under the MIT license, so feel free to use any of th ## License -MIT \ No newline at end of file +MIT From 633e6bc9f6a420f3aee157e50fecfe90a55b639a Mon Sep 17 00:00:00 2001 From: bradley Date: Wed, 3 Aug 2016 15:31:39 -0400 Subject: [PATCH 5/8] Fixed active link style --- src/directives/pagination/dirPagination.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index bfb2b57..eb4efdd 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -222,7 +222,7 @@ } function dirPaginationControlsTemplateInstaller($templateCache) { - $templateCache.put('angularUtils.directives.dirPagination.template', ''); + $templateCache.put('angularUtils.directives.dirPagination.template', ''); } function dirPaginationControlsDirective(paginationService, paginationTemplate) { From 2f14db3fb048262b01031d47483e865d6070c95e Mon Sep 17 00:00:00 2001 From: cr1x56 Date: Wed, 3 Aug 2016 15:36:01 -0400 Subject: [PATCH 6/8] Fixed active link style --- src/directives/pagination/dirPagination.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/directives/pagination/dirPagination.js b/src/directives/pagination/dirPagination.js index bfb2b57..6451378 100644 --- a/src/directives/pagination/dirPagination.js +++ b/src/directives/pagination/dirPagination.js @@ -222,7 +222,7 @@ } function dirPaginationControlsTemplateInstaller($templateCache) { - $templateCache.put('angularUtils.directives.dirPagination.template', ''); + $templateCache.put('angularUtils.directives.dirPagination.template', ''); } function dirPaginationControlsDirective(paginationService, paginationTemplate) { @@ -653,4 +653,4 @@ }; }; } -})(); \ No newline at end of file +})(); From a5c04790efa4594632080581ef170aacd98db0bf Mon Sep 17 00:00:00 2001 From: cr1x56 Date: Wed, 3 Aug 2016 15:38:31 -0400 Subject: [PATCH 7/8] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index e42bea3..6b5645a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# Working Plunker -http://plnkr.co/edit/ZU2iAOMf0SrmoAC5cdjU?p=preview - # Angular Utilities I am working on a large-scale AngularJS-based project and I'll be extracting From 987f07de22f25e5d90913b5413dc85ecc3b5daa1 Mon Sep 17 00:00:00 2001 From: cr1x56 Date: Wed, 3 Aug 2016 15:39:43 -0400 Subject: [PATCH 8/8] Update README.md --- src/directives/pagination/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/directives/pagination/README.md b/src/directives/pagination/README.md index 6791ebe..24ac048 100644 --- a/src/directives/pagination/README.md +++ b/src/directives/pagination/README.md @@ -9,6 +9,8 @@ an attribute, drop in your navigation wherever you like, and boom - instant, ful (**Looking for the Angular2 version? [Right here!](https://github.com/michaelbromley/ng2-pagination)**) ## Demo +# Working Plunker +[Updated Plunker](http://plnkr.co/edit/ZU2iAOMf0SrmoAC5cdjU?p=preview) [Here is a working demo on Plunker](http://plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview) which demonstrates some cool features such as live-binding the "itemsPerPage" and filtering of the collection.