comment and cleanup repolistctrl
This commit is contained in:
parent
0aae47fa7c
commit
897cfbefd6
1 changed files with 30 additions and 8 deletions
|
@ -231,14 +231,30 @@ function TutorialCtrl($scope, AngularTour, AngularTourSignals, UserService, Conf
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, ApiService) {
|
function RepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
|
||||||
$scope.namespace = null;
|
$scope.namespace = null;
|
||||||
$scope.page = 1;
|
$scope.page = 1;
|
||||||
$scope.publicPageCount = null;
|
$scope.publicPageCount = null;
|
||||||
|
|
||||||
// Grab user namespaces
|
// When loading the UserService, if the user is logged in, create a list of
|
||||||
|
// relevant namespaces for later collecting relevant repositories.
|
||||||
UserService.load(function() {
|
UserService.load(function() {
|
||||||
var user = UserService.currentUser();
|
var user = UserService.currentUser();
|
||||||
|
if (!user.anonymous) {
|
||||||
|
$scope.namespaces = [user];
|
||||||
|
for (var i = 0; i < user.organizations.length; i++) {
|
||||||
|
$scope.namespaces.push(user.organizations[i]);
|
||||||
|
}
|
||||||
|
//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) {
|
if (!user.anonymous) {
|
||||||
$scope.namespaces = [user];
|
$scope.namespaces = [user];
|
||||||
for (var i = 0; i < user.organizations.length; i++) {
|
for (var i = 0; i < user.organizations.length; i++) {
|
||||||
|
@ -246,8 +262,6 @@ function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, Ap
|
||||||
}
|
}
|
||||||
loadStarredRepos();
|
loadStarredRepos();
|
||||||
loadRepos();
|
loadRepos();
|
||||||
} else {
|
|
||||||
$location.path('signin');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -282,6 +296,7 @@ function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, Ap
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Finds a repository within the list of namespaces attached to $scope.
|
||||||
var findRepoInList = function(repoNamespace, repoName) {
|
var findRepoInList = function(repoNamespace, repoName) {
|
||||||
var namespaceIndex = $scope.namespaces.map(function (n) {
|
var namespaceIndex = $scope.namespaces.map(function (n) {
|
||||||
return n.username || n.name;
|
return n.username || n.name;
|
||||||
|
@ -296,6 +311,8 @@ function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, Ap
|
||||||
return repoIndex != -1 ? namespace.repositories.value[repoIndex] : null;
|
return repoIndex != -1 ? namespace.repositories.value[repoIndex] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a starred repository to the list starred repository list and make
|
||||||
|
// sure it appears starred elsewhere on the page.
|
||||||
var updateReposAfterStar = function(repository) {
|
var updateReposAfterStar = function(repository) {
|
||||||
$scope.starred_repositories.value.push(repository);
|
$scope.starred_repositories.value.push(repository);
|
||||||
|
|
||||||
|
@ -305,6 +322,8 @@ function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, Ap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove a repository from the starred repository list and make sure that
|
||||||
|
// it doesn't appear starred elsewhere on the page.
|
||||||
var updateReposAfterUnstar = function(repository) {
|
var updateReposAfterUnstar = function(repository) {
|
||||||
// Remove from the starred listings
|
// Remove from the starred listings
|
||||||
var index = $scope.starred_repositories.value.map(function(r) {
|
var index = $scope.starred_repositories.value.map(function(r) {
|
||||||
|
@ -332,10 +351,13 @@ function RepoListCtrl($scope, $location, $sanitize, Restangular, UserService, Ap
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Iterate over all of the $scope.namespaces and collect their respective
|
||||||
|
// repositories.
|
||||||
var loadRepos = function() {
|
var loadRepos = function() {
|
||||||
if ($scope.namespaces.length == 0 || $scope.user.anonymous) {
|
if ($scope.namespaces.length == 0 || $scope.user.anonymous) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('load repos called');
|
||||||
|
|
||||||
for (var i = 0; i < $scope.namespaces.length; i++) {
|
for (var i = 0; i < $scope.namespaces.length; i++) {
|
||||||
var namespace = $scope.namespaces[i];
|
var namespace = $scope.namespaces[i];
|
||||||
|
|
Reference in a new issue