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-06-29 09:33:00 +00:00
|
|
|
})
|
2015-02-20 23:15:48 +00:00
|
|
|
}]);
|
|
|
|
|
2015-02-23 20:22:41 +00:00
|
|
|
|
2017-08-07 19:59:06 +00:00
|
|
|
function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService, Features, Config) {
|
2015-05-07 17:10:16 +00:00
|
|
|
$scope.namespace = null;
|
|
|
|
$scope.page = 1;
|
|
|
|
$scope.publicPageCount = null;
|
2015-03-04 20:54:47 +00:00
|
|
|
$scope.allRepositories = {};
|
2015-03-05 21:17:18 +00:00
|
|
|
$scope.loading = true;
|
2015-06-09 21:58:57 +00:00
|
|
|
$scope.resources = [];
|
2015-11-02 18:52:53 +00:00
|
|
|
$scope.Features = Features;
|
2015-02-20 23:15:48 +00:00
|
|
|
|
2015-02-23 20:22:41 +00:00
|
|
|
// When loading the UserService, if the user is logged in, create a list of
|
2015-03-04 20:54:47 +00:00
|
|
|
// relevant namespaces and collect the relevant repositories.
|
|
|
|
UserService.updateUserIn($scope, function(user) {
|
2015-03-05 21:17:18 +00:00
|
|
|
$scope.loading = false;
|
2015-02-23 20:22:41 +00:00
|
|
|
if (!user.anonymous) {
|
2015-03-04 20:54:47 +00:00
|
|
|
// Add our user to our list of namespaces.
|
2015-05-07 17:10:16 +00:00
|
|
|
$scope.namespaces = [{
|
|
|
|
'name': user.username,
|
|
|
|
'avatar': user.avatar
|
|
|
|
}];
|
2015-03-04 20:54:47 +00:00
|
|
|
|
|
|
|
// Add each org to our list of namespaces.
|
|
|
|
user.organizations.map(function(org) {
|
2015-05-07 17:10:16 +00:00
|
|
|
$scope.namespaces.push({
|
|
|
|
'name': org.name,
|
2017-08-07 19:59:06 +00:00
|
|
|
'avatar': org.avatar,
|
|
|
|
'public': org.public
|
2015-05-07 17:10:16 +00:00
|
|
|
});
|
2015-03-04 20:54:47 +00:00
|
|
|
});
|
2015-02-23 20:22:41 +00:00
|
|
|
|
2015-05-07 17:10:16 +00:00
|
|
|
// Load the repos.
|
|
|
|
loadStarredRepos();
|
2015-03-04 20:54:47 +00:00
|
|
|
loadRepos();
|
2015-02-24 22:50:54 +00:00
|
|
|
}
|
2015-03-04 20:54:47 +00:00
|
|
|
});
|
2015-02-23 20:22:41 +00:00
|
|
|
|
2015-03-05 19:21:46 +00:00
|
|
|
$scope.isOrganization = function(namespace) {
|
|
|
|
return !!UserService.getOrganization(namespace);
|
|
|
|
};
|
|
|
|
|
2015-03-10 05:03:39 +00:00
|
|
|
$scope.starToggled = function(repo) {
|
2015-02-23 20:22:41 +00:00
|
|
|
if (repo.is_starred) {
|
2015-02-26 18:58:29 +00:00
|
|
|
$scope.starred_repositories.value.push(repo);
|
2015-03-10 05:03:39 +00:00
|
|
|
} else {
|
2015-02-26 18:58:29 +00:00
|
|
|
$scope.starred_repositories.value = $scope.starred_repositories.value.filter(function(repo) {
|
|
|
|
return repo.is_starred;
|
|
|
|
});
|
2015-03-10 05:03:39 +00:00
|
|
|
}
|
2015-02-23 20:22:41 +00:00
|
|
|
};
|
|
|
|
|
2015-05-07 17:10:16 +00:00
|
|
|
// Finds a duplicate repo if it exists. If it doesn't, inserts the repo.
|
|
|
|
var findDuplicateRepo = function(repo) {
|
|
|
|
var found = $scope.allRepositories[repo.namespace + '/' + repo.name];
|
|
|
|
if (found) {
|
|
|
|
return found;
|
|
|
|
} else {
|
|
|
|
$scope.allRepositories[repo.namespace + '/' + repo.name] = repo;
|
|
|
|
return repo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadStarredRepos = function() {
|
|
|
|
if (!$scope.user || $scope.user.anonymous) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:20:24 +00:00
|
|
|
var options = {
|
|
|
|
'starred': true,
|
|
|
|
'last_modified': true,
|
|
|
|
'popularity': true
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.starred_repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
2015-05-07 17:10:16 +00:00
|
|
|
return resp.repositories.map(function(repo) {
|
|
|
|
repo = findDuplicateRepo(repo);
|
|
|
|
repo.is_starred = true;
|
|
|
|
return repo;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-02-23 20:22:41 +00:00
|
|
|
var loadRepos = function() {
|
2015-05-07 17:10:16 +00:00
|
|
|
if (!$scope.user || $scope.user.anonymous || $scope.namespaces.length == 0) {
|
2015-02-23 20:22:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-07 17:10:16 +00:00
|
|
|
$scope.namespaces.map(function(namespace) {
|
|
|
|
var options = {
|
|
|
|
'namespace': namespace.name,
|
2015-06-09 21:58:57 +00:00
|
|
|
'last_modified': true,
|
2017-08-07 19:59:06 +00:00
|
|
|
'popularity': true,
|
|
|
|
'public': namespace.public
|
2015-05-07 17:10:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
|
|
|
return resp.repositories.map(findDuplicateRepo);
|
|
|
|
});
|
2015-06-09 21:58:57 +00:00
|
|
|
|
|
|
|
$scope.resources.push(namespace.repositories);
|
2015-03-04 20:54:47 +00:00
|
|
|
});
|
2015-02-23 20:22:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|