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/pages/repo-list.js

120 lines
3.5 KiB
JavaScript
Raw Normal View History

(function() {
/**
* Repository listing page. Shows all repositories for all visibile namespaces.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('repo-list', 'repo-list.html', RepoListCtrl, {
2015-02-23 20:22:41 +00:00
'newLayout': true,
'title': 'Repositories',
'description': 'View and manage Docker repositories'
2015-06-29 09:33:00 +00:00
})
}]);
2015-02-23 20:22:41 +00:00
function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService, CookieService, Features) {
$scope.namespace = null;
$scope.page = 1;
$scope.publicPageCount = null;
$scope.allRepositories = {};
$scope.loading = true;
$scope.resources = [];
$scope.showAsList = CookieService.get('quay.repoview') == 'list';
$scope.Features = Features;
2015-02-23 20:22:41 +00:00
// When loading the UserService, if the user is logged in, create a list of
// relevant namespaces and collect the relevant repositories.
UserService.updateUserIn($scope, function(user) {
$scope.loading = false;
2015-02-23 20:22:41 +00:00
if (!user.anonymous) {
// Add our user to our list of namespaces.
$scope.namespaces = [{
'name': user.username,
'avatar': user.avatar
}];
// Add each org to our list of namespaces.
user.organizations.map(function(org) {
$scope.namespaces.push({
'name': org.name,
'avatar': org.avatar
});
});
2015-02-23 20:22:41 +00:00
// Load the repos.
loadStarredRepos();
loadRepos();
}
});
2015-02-23 20:22:41 +00:00
$scope.setShowAsList = function(value) {
$scope.showAsList = value;
CookieService.putPermanent('quay.repoview', value ? 'list' : 'grid');
};
$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
};
// 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;
}
var options = {
'starred': true,
'last_modified': true,
'popularity': true
};
$scope.starred_repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
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() {
if (!$scope.user || $scope.user.anonymous || $scope.namespaces.length == 0) {
2015-02-23 20:22:41 +00:00
return;
}
$scope.namespaces.map(function(namespace) {
var options = {
'namespace': namespace.name,
'last_modified': true,
'popularity': true
};
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
return resp.repositories.map(findDuplicateRepo);
});
$scope.resources.push(namespace.repositories);
});
2015-02-23 20:22:41 +00:00
};
}
})();