From 507d3fb973b88e1feaa31c3beacdb3c05cdb815c Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 4 Mar 2015 15:54:47 -0500 Subject: [PATCH] fix repos not loading when signed in on repo list --- static/directives/repo-list-grid.html | 9 ++-- static/js/pages/repo-list.js | 65 +++++++++++++-------------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/static/directives/repo-list-grid.html b/static/directives/repo-list-grid.html index ea22b7cb4..223027c62 100644 --- a/static/directives/repo-list-grid.html +++ b/static/directives/repo-list-grid.html @@ -6,13 +6,10 @@ Starred -
+
- {{ namespace.username }} -
- diff --git a/static/js/pages/repo-list.js b/static/js/pages/repo-list.js index a71b19a90..dae52e501 100644 --- a/static/js/pages/repo-list.js +++ b/static/js/pages/repo-list.js @@ -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); }); - } + }); }; }