kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.9 KiB
107 lines
3.9 KiB
11 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
11 years ago
|
angular.module('openproject.uiComponents')
|
||
|
|
||
11 years ago
|
.directive('tablePagination', ['PaginationService', function(PaginationService) {
|
||
11 years ago
|
return {
|
||
|
restrict: 'EA',
|
||
|
templateUrl: '/templates/components/table_pagination.html',
|
||
|
scope: {
|
||
11 years ago
|
totalEntries: '=',
|
||
11 years ago
|
updateResults: '&'
|
||
11 years ago
|
},
|
||
11 years ago
|
link: function(scope, element, attributes) {
|
||
|
scope.paginationOptions = PaginationService.getPaginationOptions();
|
||
|
|
||
11 years ago
|
scope.selectPerPage = function(perPage){
|
||
11 years ago
|
PaginationService.setPerPage(perPage);
|
||
11 years ago
|
|
||
11 years ago
|
updatePageNumbers();
|
||
|
scope.showPage(1);
|
||
11 years ago
|
};
|
||
|
|
||
11 years ago
|
scope.showPage = function(pageNumber){
|
||
11 years ago
|
PaginationService.setPage(pageNumber);
|
||
|
|
||
|
updateCurrentRangeLabel();
|
||
11 years ago
|
updatePageNumbers();
|
||
11 years ago
|
|
||
|
scope.updateResults(); // update table
|
||
11 years ago
|
};
|
||
|
|
||
11 years ago
|
/**
|
||
|
* @name updateCurrentRange
|
||
|
*
|
||
|
* @description Defines a string containing page bound information inside the directive scope
|
||
|
*/
|
||
11 years ago
|
function updateCurrentRangeLabel() {
|
||
11 years ago
|
if (scope.totalEntries){
|
||
|
scope.currentRange = "(" + PaginationService.getLowerPageBound() + " - " + PaginationService.getUpperPageBound(scope.totalEntries) + "/" + scope.totalEntries + ")";
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/**
|
||
|
* @name updatePageNumbers
|
||
|
*
|
||
|
* @description Defines a list of all pages in numerical order inside the scope
|
||
|
*/
|
||
11 years ago
|
function updatePageNumbers() {
|
||
11 years ago
|
var maxVisible = PaginationService.getMaxVisiblePageOptions();
|
||
|
var truncSize = PaginationService.getOptionsTruncationSize();
|
||
|
|
||
11 years ago
|
var pageNumbers = [];
|
||
11 years ago
|
for (var i = 1; i <= Math.ceil(scope.totalEntries / scope.paginationOptions.perPage); i++) {
|
||
11 years ago
|
pageNumbers.push(i);
|
||
|
}
|
||
11 years ago
|
|
||
|
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);
|
||
11 years ago
|
scope.pageNumbers = pageNumbers;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
function truncatePageNums(pageNumbers, perform, disectFrom, disectLength, truncateFrom){
|
||
|
if (perform){
|
||
|
var tuncationSize = PaginationService.getOptionsTruncationSize();
|
||
|
var truncatedNums = pageNumbers.splice(disectFrom, disectLength);
|
||
11 years ago
|
if (truncatedNums.length >= tuncationSize * 2) truncatedNums.splice(truncateFrom, truncatedNums.length - tuncationSize);
|
||
11 years ago
|
return truncatedNums;
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
scope.$watch('totalEntries', function() {
|
||
11 years ago
|
updateCurrentRangeLabel();
|
||
11 years ago
|
updatePageNumbers();
|
||
|
});
|
||
|
|
||
11 years ago
|
}
|
||
11 years ago
|
};
|
||
|
}]);
|