Add page support to the public repo list
This commit is contained in:
parent
f8b4057b26
commit
58b3ce2647
4 changed files with 82 additions and 5 deletions
|
@ -50,6 +50,8 @@ function SecurityCtrl($scope) {
|
|||
|
||||
function RepoListCtrl($scope, Restangular, UserService, ApiService) {
|
||||
$scope.namespace = null;
|
||||
$scope.page = 1;
|
||||
$scope.publicPageCount = null;
|
||||
|
||||
// Monitor changes in the user.
|
||||
UserService.updateUserIn($scope, function() {
|
||||
|
@ -61,6 +63,23 @@ function RepoListCtrl($scope, Restangular, UserService, ApiService) {
|
|||
loadMyRepos(namespace);
|
||||
});
|
||||
|
||||
$scope.movePublicPage = function(increment) {
|
||||
if ($scope.publicPageCount == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.page += increment;
|
||||
if ($scope.page < 1) {
|
||||
$scope.page = 1;
|
||||
}
|
||||
|
||||
if ($scope.page > $scope.publicPageCount) {
|
||||
$scope.page = $scope.publicPageCount;
|
||||
}
|
||||
|
||||
loadPublicRepos();
|
||||
};
|
||||
|
||||
var loadMyRepos = function(namespace) {
|
||||
if (!$scope.user || $scope.user.anonymous || !namespace) {
|
||||
return;
|
||||
|
@ -74,8 +93,17 @@ function RepoListCtrl($scope, Restangular, UserService, ApiService) {
|
|||
};
|
||||
|
||||
var loadPublicRepos = function() {
|
||||
var options = {'public': true, 'private': false, 'sort': true, 'limit': 10};
|
||||
var options = {
|
||||
'public': true,
|
||||
'private': false,
|
||||
'sort': true,
|
||||
'limit': 10,
|
||||
'page': $scope.page,
|
||||
'count': true
|
||||
};
|
||||
|
||||
$scope.public_repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
||||
$scope.publicPageCount = Math.ceil(resp.count / 10);
|
||||
return resp.repositories;
|
||||
});
|
||||
};
|
||||
|
|
Reference in a new issue