2015-02-20 23:15:48 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Repository listing page. Shows all repositories for all visibile namespaces.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
2015-02-23 19:23:54 +00:00
|
|
|
pages.create('repo-list', 'repo-list.html', RepoListCtrl, {
|
2015-02-23 20:22:41 +00:00
|
|
|
'newLayout': true,
|
2015-02-23 19:23:54 +00:00
|
|
|
'title': 'Repositories',
|
|
|
|
'description': 'View and manage Docker repositories'
|
2015-02-23 20:22:41 +00:00
|
|
|
}, ['layout'])
|
|
|
|
|
|
|
|
pages.create('repo-list', 'old-repo-list.html', OldRepoListCtrl, {
|
|
|
|
'title': 'Repositories',
|
|
|
|
'description': 'View and manage Docker repositories'
|
|
|
|
}, ['old-layout']);
|
2015-02-20 23:15:48 +00:00
|
|
|
}]);
|
|
|
|
|
2015-02-23 20:22:41 +00:00
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
function RepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
|
|
|
|
$scope.namespace = null;
|
|
|
|
$scope.page = 1;
|
|
|
|
$scope.publicPageCount = null;
|
|
|
|
|
2015-02-23 20:22:41 +00:00
|
|
|
// When loading the UserService, if the user is logged in, create a list of
|
|
|
|
// relevant namespaces for later collecting relevant repositories.
|
|
|
|
UserService.load(function() {
|
|
|
|
var user = UserService.currentUser();
|
|
|
|
if (!user.anonymous) {
|
|
|
|
$scope.namespaces = [user];
|
|
|
|
for (var i = 0; i < user.organizations.length; i++) {
|
|
|
|
$scope.namespaces.push(user.organizations[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// If someone signs in on this page, we have to watch the user and re-load
|
|
|
|
// their repositories after they've signed in to actually have any content
|
|
|
|
// on the page.
|
|
|
|
$scope.$watch(function(scope) { return scope.user },
|
2015-02-24 22:50:54 +00:00
|
|
|
function(user) {
|
|
|
|
if (!user.anonymous) {
|
|
|
|
$scope.namespaces = [user];
|
|
|
|
for (var i = 0; i < user.organizations.length; i++) {
|
|
|
|
$scope.namespaces.push(user.organizations[i]);
|
|
|
|
}
|
|
|
|
loadStarredRepos();
|
|
|
|
loadRepos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-02-23 20:22:41 +00:00
|
|
|
|
|
|
|
$scope.toggleStar = function(repo) {
|
|
|
|
if (repo.is_starred) {
|
|
|
|
unstarRepo(repo);
|
|
|
|
} else {
|
|
|
|
starRepo(repo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var starRepo = function(repo) {
|
|
|
|
var data = {
|
|
|
|
'namespace': repo.namespace,
|
|
|
|
'repository': repo.name
|
|
|
|
};
|
|
|
|
ApiService.createStar(data).then(function(result) {
|
2015-02-25 21:19:54 +00:00
|
|
|
repo.is_starred = true;
|
|
|
|
refreshStars();
|
2015-02-23 20:22:41 +00:00
|
|
|
}, ApiService.errorDisplay('Could not star repository'));
|
|
|
|
};
|
|
|
|
|
|
|
|
var unstarRepo = function(repo) {
|
|
|
|
var data = {
|
|
|
|
'repository': repo.namespace + '/' + repo.name
|
|
|
|
};
|
|
|
|
ApiService.deleteStar(null, data).then(function(result) {
|
2015-02-25 21:19:54 +00:00
|
|
|
repo.is_starred = false;
|
|
|
|
refreshStars();
|
2015-02-23 20:22:41 +00:00
|
|
|
}, ApiService.errorDisplay('Could not unstar repository'));
|
|
|
|
};
|
|
|
|
|
2015-02-25 21:19:54 +00:00
|
|
|
var refreshStars = function() {
|
|
|
|
var starred = [];
|
|
|
|
$scope.namespaces.map(function(namespace) {
|
|
|
|
namespace.repositories.value.map(function(repository) {
|
|
|
|
if (repository.is_starred) {
|
|
|
|
starred.push(repository);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$scope.starred_repositories.value = starred;
|
2015-02-23 20:22:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var loadStarredRepos = function() {
|
|
|
|
if (!$scope.user || $scope.user.anonymous) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.starred_repositories = ApiService.listStarredReposAsResource().get(function(resp) {
|
|
|
|
return resp.repositories.map(function(repo) {
|
|
|
|
repo.is_starred = true;
|
|
|
|
return repo;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Iterate over all of the $scope.namespaces and collect their respective
|
|
|
|
// repositories.
|
|
|
|
var loadRepos = function() {
|
|
|
|
if ($scope.namespaces.length == 0 || $scope.user.anonymous) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < $scope.namespaces.length; i++) {
|
|
|
|
var namespace = $scope.namespaces[i];
|
|
|
|
var namespaceName = namespace.username || namespace.name;
|
|
|
|
var options = {
|
|
|
|
'public': false,
|
|
|
|
'sort': true,
|
|
|
|
'namespace': namespaceName,
|
|
|
|
};
|
|
|
|
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
|
|
|
return resp.repositories;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function OldRepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
|
|
|
|
$scope.namespace = null;
|
|
|
|
$scope.page = 1;
|
|
|
|
$scope.publicPageCount = null;
|
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
// Monitor changes in the user.
|
|
|
|
UserService.updateUserIn($scope, function() {
|
|
|
|
loadMyRepos($scope.namespace);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Monitor changes in the namespace.
|
|
|
|
$scope.$watch('namespace', function(namespace) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = {'public': false, 'sort': true, 'namespace': namespace};
|
|
|
|
|
|
|
|
$scope.user_repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
|
|
|
return resp.repositories;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadPublicRepos = function() {
|
|
|
|
var options = {
|
|
|
|
'public': true,
|
|
|
|
'private': false,
|
|
|
|
'sort': true,
|
|
|
|
'limit': 10,
|
|
|
|
'page': $scope.page,
|
|
|
|
'count': $scope.page == 1
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.public_repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
|
|
|
if (resp.count) {
|
|
|
|
$scope.publicPageCount = Math.ceil(resp.count / 10);
|
|
|
|
}
|
|
|
|
return resp.repositories;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
loadPublicRepos();
|
|
|
|
}
|
2015-02-23 20:22:41 +00:00
|
|
|
})();
|