diff --git a/app/assets/javascripts/angular/config/work-packages-config.js b/app/assets/javascripts/angular/config/work-packages-config.js index 7efc248a1a..108840c448 100644 --- a/app/assets/javascripts/angular/config/work-packages-config.js +++ b/app/assets/javascripts/angular/config/work-packages-config.js @@ -39,5 +39,7 @@ angular.module('openproject.workPackages.config') .constant('DEFAULT_PAGINATION_OPTIONS', { page: 1, perPage: 10, - perPageOptions: [10, 20, 50, 100, 500, 1000] + perPageOptions: [10, 20, 50, 100, 500, 1000], + maxVisiblePageOptions: 9, + optionsTruncationSize: 2, }); diff --git a/app/assets/javascripts/angular/directives/components/table_pagination.js b/app/assets/javascripts/angular/directives/components/table_pagination.js index da86184942..f1571ab868 100644 --- a/app/assets/javascripts/angular/directives/components/table_pagination.js +++ b/app/assets/javascripts/angular/directives/components/table_pagination.js @@ -22,6 +22,7 @@ angular.module('openproject.uiComponents') PaginationService.setPage(pageNumber); updateCurrentRangeLabel(); + updatePageNumbers(); scope.updateResults(); // update table }; @@ -33,7 +34,7 @@ angular.module('openproject.uiComponents') */ function updateCurrentRangeLabel() { scope.currentRange = "(" + PaginationService.getLowerPageBound() + " - " + PaginationService.getUpperPageBound(scope.totalEntries) + "/" + scope.totalEntries + ")"; - } + }; /** * @name updatePageNumbers @@ -41,12 +42,29 @@ angular.module('openproject.uiComponents') * @description Defines a list of all pages in numerical order inside the scope */ function updatePageNumbers() { + var maxVisible = PaginationService.getMaxVisiblePageOptions(); + var truncSize = PaginationService.getOptionsTruncationSize(); + var pageNumbers = []; for (var i = 1; i <= Math.ceil(scope.totalEntries / scope.paginationOptions.perPage); i++) { pageNumbers.push(i); } + + scope.prePageNumbers = truncatePageNums(pageNumbers, PaginationService.getPage() >= maxVisible, 0, Math.min(PaginationService.getPage() - Math.ceil(maxVisible / 2), pageNumbers.length - maxVisible), truncSize); + scope.postPageNumbers = truncatePageNums(pageNumbers, pageNumbers.length >= maxVisible + (truncSize * 2), maxVisible, pageNumbers.length, 0); scope.pageNumbers = pageNumbers; - } + }; + + function truncatePageNums(pageNumbers, perform, disectFrom, disectLength, truncateFrom){ + if (perform){ + var tuncationSize = PaginationService.getOptionsTruncationSize(); + var truncatedNums = pageNumbers.splice(disectFrom, disectLength); + if (truncatedNums.length >= tuncationSize * 2) truncatedNums.splice(truncateFrom, truncatedNums.length - tuncationSize) + return truncatedNums; + } else { + return []; + } + }; scope.$watch('totalEntries', function() { updateCurrentRangeLabel(); diff --git a/app/assets/javascripts/angular/services/pagination-service.js b/app/assets/javascripts/angular/services/pagination-service.js index d90668cb6f..1c42cef7ac 100644 --- a/app/assets/javascripts/angular/services/pagination-service.js +++ b/app/assets/javascripts/angular/services/pagination-service.js @@ -4,7 +4,9 @@ angular.module('openproject.services') var paginationOptions = { page: DEFAULT_PAGINATION_OPTIONS.page, perPage: DEFAULT_PAGINATION_OPTIONS.perPage, - perPageOptions: DEFAULT_PAGINATION_OPTIONS.perPageOptions + perPageOptions: DEFAULT_PAGINATION_OPTIONS.perPageOptions, + maxVisiblePageOptions: DEFAULT_PAGINATION_OPTIONS.maxVisiblePageOptions, + optionsTruncationSize: DEFAULT_PAGINATION_OPTIONS.optionsTruncationSize }; PaginationService = { @@ -20,6 +22,12 @@ angular.module('openproject.services') getPerPage: function() { return paginationOptions.perPage; }, + getMaxVisiblePageOptions: function() { + return paginationOptions.maxVisiblePageOptions; + }, + getOptionsTruncationSize: function() { + return paginationOptions.optionsTruncationSize; + }, setPerPage: function(perPage) { paginationOptions.perPage = perPage; }, diff --git a/public/templates/components/table_pagination.html b/public/templates/components/table_pagination.html index 4664cd919f..a173e8ea28 100644 --- a/public/templates/components/table_pagination.html +++ b/public/templates/components/table_pagination.html @@ -6,6 +6,13 @@ href="">Previous + + + + ... + {{ pageNumber }} {{ pageNumber }} + ... + + + + - {{ perPageOption }} + {{ perPageOption }} {{ perPageOption }}