Skip to content

Commit

Permalink
Reduce the number of buttons in the pagination (9 at most)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Mar 1, 2015
1 parent e0698a0 commit 0653e4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ define(function (require) {
nbPages = this.nbPages;

// display page links around the current page
if (page > 3) {
if (page > 2) {
input.push('1');
}
if (page == 4) {
input.push('2');
}
if (page > 4) {
input.push('.');
}
if (page > 2) {
input.push(page - 2);
}
if (page > 1) {
input.push(page - 1);
}
input.push(page);
if (page < nbPages) {
input.push(page + 1);
}
if (page < (nbPages - 1)) {
input.push(page + 2);
if (page == (nbPages - 3)) {
input.push(nbPages - 1);
}
if (page < (nbPages - 3)) {
input.push('.');
}
if (page < (nbPages - 2)) {
if (page < (nbPages - 1)) {
input.push(nbPages);
}

Expand Down
36 changes: 17 additions & 19 deletions src/javascripts/test/unit/Crud/list/maDatagridPaginationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,17 @@ define(function (require) {
scope.totalItems = 37;
scope.itemsPerPage = 10;
scope.page = 1;
function checkPrevLink(rank, expected) {
var element = $compile(directiveUsage)(scope)[0];
scope.$digest();
var lastButton = element.querySelectorAll('.pagination-bar .pagination li')[rank];
expect(lastButton.innerText.trim()).toBe(expected);
}
checkPrevLink(1, '1');
checkPrevLink(2, '2');
checkPrevLink(3, '3');
checkPrevLink(4, '4');
var element = $compile(directiveUsage)(scope)[0];
scope.$digest();
var buttons = element.querySelectorAll('.pagination-bar .pagination li');
expect(buttons[1].innerText.trim()).toBe('1');
expect(buttons[2].innerText.trim()).toBe('2');
expect(buttons[3].innerText.trim()).toBe('3');
expect(buttons[4].innerText.trim()).toBe('4');
});

it('should display truncated centered page range if number of pages is above 5', function() {
scope.totalItems = 77;
scope.totalItems = 87;
scope.itemsPerPage = 10;
function checkPageLinks(page, expected) {
scope.page = page;
Expand All @@ -124,14 +121,15 @@ define(function (require) {
var buttonsText = buttons.map(function(button) { return button.innerText.trim(); });
expect(buttonsText).toEqual(expected);
}
checkPageLinks(1, ['', '1', '2', '3', '…', '8', 'Next »']);
checkPageLinks(2, ['« Prev', '1', '2', '3', '4', '…', '8', 'Next »']);
checkPageLinks(3, ['« Prev', '1', '2', '3', '4', '5', '…', '8', 'Next »']);
checkPageLinks(4, ['« Prev', '1', '2', '3', '4', '5', '6', '…', '8', 'Next »']);
checkPageLinks(5, ['« Prev', '1', '…', '3', '4', '5', '6', '7', '8', 'Next »']);
checkPageLinks(6, ['« Prev', '1', '…', '4', '5', '6', '7', '8', 'Next »']);
checkPageLinks(7, ['« Prev', '1', '…', '5', '6', '7', '8', 'Next »']);
checkPageLinks(8, ['« Prev', '1', '…', '6', '7', '8', '']);
checkPageLinks(1, ['', '1', '2', '…', '9', 'Next »']);
checkPageLinks(2, ['« Prev', '1', '2', '3', '…', '9', 'Next »']);
checkPageLinks(3, ['« Prev', '1', '2', '3', '4', '…', '9', 'Next »']);
checkPageLinks(4, ['« Prev', '1', '2', '3', '4', '5', '…', '9', 'Next »']);
checkPageLinks(5, ['« Prev', '1', '…', '4', '5', '6', '…', '9', 'Next »']);
checkPageLinks(6, ['« Prev', '1', '…', '5', '6', '7', '8', '9', 'Next »']);
checkPageLinks(7, ['« Prev', '1', '…', '6', '7', '8', '9', 'Next »']);
checkPageLinks(8, ['« Prev', '1', '…', '7', '8', '9', 'Next »']);
checkPageLinks(9, ['« Prev', '1', '…', '8', '9', '']);
});
});
});

0 comments on commit 0653e4c

Please sign in to comment.