This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/page-controls.js
2019-11-12 11:09:47 -05:00

41 lines
No EOL
1.3 KiB
JavaScript

/**
* An element which displays controls for moving between pages of paginated results.
*/
angular.module('quay').directive('pageControls', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/page-controls.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
'currentPage': '=currentPage',
'pageSize': '=pageSize',
'totalCount': '=totalCount'
},
controller: function($scope, $element) {
$scope.getPageStart = function(currentPage, pageSize, totalCount) {
return Math.min((currentPage * pageSize) + 1, totalCount);
};
$scope.getPageEnd = function(currentPage, pageSize, totalCount) {
return Math.min(((currentPage + 1) * pageSize), totalCount);
};
$scope.getPageCount = function(pageSize, totalCount) {
return Math.ceil(totalCount / pageSize);
};
$scope.changePage = function(offset) {
$scope.currentPage += offset;
$scope.currentPage = Math.max($scope.currentPage, 0);
$scope.currentPage = Math.min($scope.currentPage, $scope.getPageCount($scope.pageSize, $scope.totalCount));
};
$scope.setPage = function(page) {
$scope.currentPage = page;
};
}
};
return directiveDefinitionObject;
});