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

178 lines
4.9 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-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-23 20:22:41 +00:00
2015-02-26 18:58:29 +00:00
function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService) {
$scope.allRepositories = {};
$scope.loading = true;
$scope.namespaces = [];
$scope.namespaceMap = {};
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;
var addNamespace = function(namespace) {
var name = namespace.username || namespace.name;
var namespaceInfo = {
'name': name,
'avatar': namespace.avatar,
'repositories': {
'loading': true,
'value': []
}
};
$scope.namespaceMap[name] = namespaceInfo;
$scope.namespaces.push(namespaceInfo);
};
2015-02-23 20:22:41 +00:00
if (!user.anonymous) {
// Add our user to our list of namespaces.
addNamespace(user);
// Add each org to our list of namespaces.
user.organizations.map(function(org) {
addNamespace(org);
});
2015-02-23 20:22:41 +00:00
$scope.starred_repositories = {
'loading': true,
'value': []
};
// Load the repositories.
loadRepos();
}
});
2015-02-23 20:22:41 +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
};
var loadRepos = function() {
if (!$scope.user || $scope.user.anonymous || $scope.loading) {
2015-02-23 20:22:41 +00:00
return;
}
var options = {
'public': false,
'sort': true
};
$scope.repositoriesResource = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
for (var i = 0; i < resp.repositories.length; ++i) {
var repository = resp.repositories[i];
var namespace = repository.namespace;
var namespaceInfo = $scope.namespaceMap[namespace];
if (!namespaceInfo) {
continue;
}
namespaceInfo.repositories.value.push(repository);
if (repository.is_starred) {
$scope.starred_repositories.value.push(repository);
}
}
for (var i = 0; i < $scope.namespaces.length; ++i) {
var namespaceInfo = $scope.namespaces[i];
namespaceInfo.repositories.loading = false;
}
$scope.starred_repositories.loading = false;
});
2015-02-23 20:22:41 +00:00
};
}
function OldRepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
$scope.namespace = null;
$scope.page = 1;
$scope.publicPageCount = null;
// 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
})();