fix repos not loading when signed in on repo list

This commit is contained in:
Jimmy Zelinskie 2015-03-04 15:54:47 -05:00
parent c967623ab1
commit 507d3fb973
2 changed files with 35 additions and 39 deletions

View file

@ -6,13 +6,10 @@
<i class="fa fa-star starred"></i>
Starred
</div>
<div ng-if="!starred && user.username == namespace.username" class="repo-list-title">
<div ng-if="!starred" class="repo-list-title">
<span class="avatar" size="24" hash="namespace.avatar"></span>
{{ namespace.username }}
</div>
<div ng-if="!starred && user.username != namespace.username" class="repo-list-title">
<span class="avatar" size="24" hash="namespace.avatar"></span>
<a href="/organization/{{ namespace.name }}">{{ namespace.name }}</a>
<a ng-if="user.username == namespace.name">{{ namespace.name }}</a>
<a ng-if="user.username != namespace.name" href="/organization/{{ namespace.name }}">{{ namespace.name }}</a>
</div>
<!-- Repositories -->

View file

@ -20,36 +20,33 @@
$scope.namespace = null;
$scope.page = 1;
$scope.publicPageCount = null;
$scope.all_repositories = {};
$scope.allRepositories = {};
// 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();
// relevant namespaces and collect the relevant repositories.
UserService.updateUserIn($scope, function(user) {
if (!user.anonymous) {
$scope.namespaces = [user];
for (var i = 0; i < user.organizations.length; i++) {
$scope.namespaces.push(user.organizations[i]);
}
// 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
});
});
// Load the repos.
loadStarredRepos();
loadRepos();
}
});
// 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 },
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();
}
}
);
// Star a repository or unstar a repository.
$scope.toggleStar = function(repo) {
if (repo.is_starred) {
unstarRepo(repo);
@ -58,6 +55,7 @@
}
}
// Star a repository and update the UI.
var starRepo = function(repo) {
var data = {
'namespace': repo.namespace,
@ -69,6 +67,7 @@
}, ApiService.errorDisplay('Could not star repository'));
};
// Unstar a repository and update the UI.
var unstarRepo = function(repo) {
var data = {
'repository': repo.namespace + '/' + repo.name
@ -83,11 +82,12 @@
// Finds a duplicate repo if it exists. If it doesn't, inserts the repo.
var findDuplicateRepo = function(repo) {
var found = $scope.all_repositories[repo.namespace + '/' + repo.name];
if (found != undefined) {
var found = $scope.allRepositories[repo.namespace + '/' + repo.name];
if (found) {
return found;
} else {
$scope.all_repositories[repo.namespace + '/' + repo.name] = repo;
$scope.allRepositories[repo.namespace + '/' + repo.name] = repo;
return repo;
}
};
@ -106,22 +106,21 @@
};
var loadRepos = function() {
if ($scope.namespaces.length == 0 || $scope.user.anonymous) {
if (!$scope.user || $scope.user.anonymous || $scope.namespaces.length == 0) {
return;
}
for (var i = 0; i < $scope.namespaces.length; i++) {
var namespace = $scope.namespaces[i];
var namespaceName = namespace.username || namespace.name;
$scope.namespaces.map(function(namespace) {
var options = {
'public': false,
'sort': true,
'namespace': namespaceName,
'namespace': namespace.name,
};
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
return resp.repositories.map(findDuplicateRepo);
});
}
});
};
}