Add pagination to the tags view

This commit is contained in:
Joseph Schorr 2015-06-25 15:47:37 -04:00
parent 0d133b0fa4
commit 672e8a5ba9
7 changed files with 113 additions and 2 deletions

View file

@ -0,0 +1,8 @@
/**
* Slice filter.
*/
angular.module('quay').filter('slice', function() {
return function(arr, start, end) {
return (arr || []).slice(start, end);
};
});

View file

@ -24,7 +24,8 @@ angular.module('quay').directive('repoPanelTags', function () {
$scope.checkedTags = UIService.createCheckStateController([], 'name');
$scope.options = {
'predicate': 'last_modified_datetime',
'reverse': false
'reverse': false,
'page': 0
};
$scope.iterationState = {};

View file

@ -0,0 +1,41 @@
/**
* 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;
});