fix repos not loading when signed in on repo list
This commit is contained in:
parent
c967623ab1
commit
507d3fb973
2 changed files with 35 additions and 39 deletions
|
@ -6,13 +6,10 @@
|
||||||
<i class="fa fa-star starred"></i>
|
<i class="fa fa-star starred"></i>
|
||||||
Starred
|
Starred
|
||||||
</div>
|
</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>
|
<span class="avatar" size="24" hash="namespace.avatar"></span>
|
||||||
{{ namespace.username }}
|
<a ng-if="user.username == namespace.name">{{ namespace.name }}</a>
|
||||||
</div>
|
<a ng-if="user.username != namespace.name" href="/organization/{{ namespace.name }}">{{ namespace.name }}</a>
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Repositories -->
|
<!-- Repositories -->
|
||||||
|
|
|
@ -20,36 +20,33 @@
|
||||||
$scope.namespace = null;
|
$scope.namespace = null;
|
||||||
$scope.page = 1;
|
$scope.page = 1;
|
||||||
$scope.publicPageCount = null;
|
$scope.publicPageCount = null;
|
||||||
$scope.all_repositories = {};
|
$scope.allRepositories = {};
|
||||||
|
|
||||||
// When loading the UserService, if the user is logged in, create a list of
|
// When loading the UserService, if the user is logged in, create a list of
|
||||||
// relevant namespaces for later collecting relevant repositories.
|
// relevant namespaces and collect the relevant repositories.
|
||||||
UserService.load(function() {
|
UserService.updateUserIn($scope, function(user) {
|
||||||
var user = UserService.currentUser();
|
|
||||||
if (!user.anonymous) {
|
if (!user.anonymous) {
|
||||||
$scope.namespaces = [user];
|
// Add our user to our list of namespaces.
|
||||||
for (var i = 0; i < user.organizations.length; i++) {
|
$scope.namespaces = [{
|
||||||
$scope.namespaces.push(user.organizations[i]);
|
'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
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// If someone signs in on this page, we have to watch the user and re-load
|
// Load the repos.
|
||||||
// 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();
|
loadStarredRepos();
|
||||||
loadRepos();
|
loadRepos();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
|
// Star a repository or unstar a repository.
|
||||||
$scope.toggleStar = function(repo) {
|
$scope.toggleStar = function(repo) {
|
||||||
if (repo.is_starred) {
|
if (repo.is_starred) {
|
||||||
unstarRepo(repo);
|
unstarRepo(repo);
|
||||||
|
@ -58,6 +55,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Star a repository and update the UI.
|
||||||
var starRepo = function(repo) {
|
var starRepo = function(repo) {
|
||||||
var data = {
|
var data = {
|
||||||
'namespace': repo.namespace,
|
'namespace': repo.namespace,
|
||||||
|
@ -69,6 +67,7 @@
|
||||||
}, ApiService.errorDisplay('Could not star repository'));
|
}, ApiService.errorDisplay('Could not star repository'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Unstar a repository and update the UI.
|
||||||
var unstarRepo = function(repo) {
|
var unstarRepo = function(repo) {
|
||||||
var data = {
|
var data = {
|
||||||
'repository': repo.namespace + '/' + repo.name
|
'repository': repo.namespace + '/' + repo.name
|
||||||
|
@ -83,11 +82,12 @@
|
||||||
|
|
||||||
// Finds a duplicate repo if it exists. If it doesn't, inserts the repo.
|
// Finds a duplicate repo if it exists. If it doesn't, inserts the repo.
|
||||||
var findDuplicateRepo = function(repo) {
|
var findDuplicateRepo = function(repo) {
|
||||||
var found = $scope.all_repositories[repo.namespace + '/' + repo.name];
|
var found = $scope.allRepositories[repo.namespace + '/' + repo.name];
|
||||||
if (found != undefined) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
} else {
|
} 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() {
|
var loadRepos = function() {
|
||||||
if ($scope.namespaces.length == 0 || $scope.user.anonymous) {
|
if (!$scope.user || $scope.user.anonymous || $scope.namespaces.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < $scope.namespaces.length; i++) {
|
$scope.namespaces.map(function(namespace) {
|
||||||
var namespace = $scope.namespaces[i];
|
|
||||||
var namespaceName = namespace.username || namespace.name;
|
|
||||||
var options = {
|
var options = {
|
||||||
'public': false,
|
'public': false,
|
||||||
'sort': true,
|
'sort': true,
|
||||||
'namespace': namespaceName,
|
'namespace': namespace.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
|
||||||
return resp.repositories.map(findDuplicateRepo);
|
return resp.repositories.map(findDuplicateRepo);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue