OpenProject is the leading open source project management software.
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.
openproject/app/assets/javascripts/angular/services/pagination-service.js

61 lines
1.8 KiB

angular.module('openproject.services')
.service('PaginationService', ['DEFAULT_PAGINATION_OPTIONS', function(DEFAULT_PAGINATION_OPTIONS) {
var paginationOptions = {
page: DEFAULT_PAGINATION_OPTIONS.page,
perPage: DEFAULT_PAGINATION_OPTIONS.perPage,
perPageOptions: DEFAULT_PAGINATION_OPTIONS.perPageOptions,
maxVisiblePageOptions: DEFAULT_PAGINATION_OPTIONS.maxVisiblePageOptions,
optionsTruncationSize: DEFAULT_PAGINATION_OPTIONS.optionsTruncationSize
};
PaginationService = {
getPaginationOptions: function() {
return paginationOptions;
},
getPage: function() {
return paginationOptions.page;
},
setPage: function(page) {
paginationOptions.page = page;
},
getPerPage: function() {
return paginationOptions.perPage;
},
getMaxVisiblePageOptions: function() {
return paginationOptions.maxVisiblePageOptions;
},
getOptionsTruncationSize: function() {
return paginationOptions.optionsTruncationSize;
},
setPerPage: function(perPage) {
paginationOptions.perPage = perPage;
},
getPerPageOptions: function() {
return paginationOptions.perPageOptions;
},
setPerPageOptions: function(perPageOptions) {
paginationOptions.perPageOptions = perPageOptions;
},
getLowerPageBound: function() {
return paginationOptions.perPage * (paginationOptions.page - 1) + 1;
},
getUpperPageBound: function(limit) {
return Math.min(paginationOptions.perPage * paginationOptions.page, limit);
},
resetPage: function() {
paginationOptions.page = 1;
},
nextPage: function() {
paginationOptions.page = paginationOptions.page + 1;
},
previousPage: function() {
paginationOptions.page = paginationOptions.page - 1;
}
};
return PaginationService;
}]);