Revert repo single API call change, as it is demonstrably worse from a UX perspective

This commit is contained in:
Joseph Schorr 2015-05-07 13:10:16 -04:00
parent 73193e2ab5
commit d42cf7b42a
3 changed files with 58 additions and 69 deletions

View file

@ -3,10 +3,6 @@
padding-top: 0px; padding-top: 0px;
} }
.repo-list .repo-list-panel.loading {
padding-top: 20px;
}
.repo-list .repo-list-namespaces h4 { .repo-list .repo-list-namespaces h4 {
margin: 6px; margin: 6px;
margin-bottom: 20px; margin-bottom: 20px;

View file

@ -17,46 +17,33 @@
function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService) { function RepoListCtrl($scope, $sanitize, $q, Restangular, UserService, ApiService) {
$scope.namespace = null;
$scope.page = 1;
$scope.publicPageCount = null;
$scope.allRepositories = {}; $scope.allRepositories = {};
$scope.loading = true; $scope.loading = true;
$scope.namespaces = [];
$scope.namespaceMap = {};
// 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 and collect the relevant repositories. // relevant namespaces and collect the relevant repositories.
UserService.updateUserIn($scope, function(user) { UserService.updateUserIn($scope, function(user) {
$scope.loading = false; $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);
};
if (!user.anonymous) { if (!user.anonymous) {
// Add our user to our list of namespaces. // Add our user to our list of namespaces.
addNamespace(user); $scope.namespaces = [{
'name': user.username,
'avatar': user.avatar
}];
// Add each org to our list of namespaces. // Add each org to our list of namespaces.
user.organizations.map(function(org) { user.organizations.map(function(org) {
addNamespace(org); $scope.namespaces.push({
'name': org.name,
'avatar': org.avatar
});
}); });
$scope.starred_repositories = { // Load the repos.
'loading': true, loadStarredRepos();
'value': []
};
// Load the repositories.
loadRepos(); loadRepos();
} }
}); });
@ -75,37 +62,46 @@
} }
}; };
var loadRepos = function() { // Finds a duplicate repo if it exists. If it doesn't, inserts the repo.
if (!$scope.user || $scope.user.anonymous || $scope.loading) { var findDuplicateRepo = function(repo) {
var found = $scope.allRepositories[repo.namespace + '/' + repo.name];
if (found) {
return found;
} else {
$scope.allRepositories[repo.namespace + '/' + repo.name] = repo;
return repo;
}
};
var loadStarredRepos = function() {
if (!$scope.user || $scope.user.anonymous) {
return; return;
} }
var options = { $scope.starred_repositories = ApiService.listStarredReposAsResource().get(function(resp) {
'public': false, return resp.repositories.map(function(repo) {
'sort': true repo = findDuplicateRepo(repo);
}; repo.is_starred = true;
return repo;
});
});
};
$scope.repositoriesResource = ApiService.listReposAsResource().withOptions(options).get(function(resp) { var loadRepos = function() {
for (var i = 0; i < resp.repositories.length; ++i) { if (!$scope.user || $scope.user.anonymous || $scope.namespaces.length == 0) {
var repository = resp.repositories[i]; return;
var namespace = repository.namespace; }
var namespaceInfo = $scope.namespaceMap[namespace];
if (!namespaceInfo) {
continue;
}
namespaceInfo.repositories.value.push(repository); $scope.namespaces.map(function(namespace) {
if (repository.is_starred) { var options = {
$scope.starred_repositories.value.push(repository); 'public': false,
} 'sort': true,
} 'namespace': namespace.name,
};
for (var i = 0; i < $scope.namespaces.length; ++i) { namespace.repositories = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
var namespaceInfo = $scope.namespaces[i]; return resp.repositories.map(findDuplicateRepo);
namespaceInfo.repositories.loading = false; });
}
$scope.starred_repositories.loading = false;
}); });
}; };
} }

View file

@ -51,21 +51,18 @@
</div> </div>
<div class="col-lg-9 col-lg-pull-3 col-md-9 col-md-pull-3 col-sm-12"> <div class="col-lg-9 col-lg-pull-3 col-md-9 col-md-pull-3 col-sm-12">
<div class="repo-list-panel co-main-content-panel" <div class="repo-list-panel co-main-content-panel">
ng-class="repositoriesResource.loading ? 'loading' : ''"> <!-- Starred Repository Listing -->
<div class="resource-view" resource="repositoriesResource" error-message="'Could not load repositories'"> <div class="repo-list-grid" repositories-resource="starred_repositories"
<!-- Starred Repository Listing --> starred="true"
<div class="repo-list-grid" repositories-resource="starred_repositories" star-toggled="starToggled(repository)">
starred="true" </div>
star-toggled="starToggled(repository)">
</div>
<!-- User and Org Repository Listings --> <!-- User and Org Repository Listings -->
<div ng-repeat="namespace in namespaces"> <div ng-repeat="namespace in namespaces">
<div class="repo-list-grid" repositories-resource="namespace.repositories" <div class="repo-list-grid" repositories-resource="namespace.repositories"
starred="false" user="user" namespace="namespace" starred="false" user="user" namespace="namespace"
star-toggled="starToggled(repository)"> star-toggled="starToggled(repository)">
</div>
</div> </div>
</div> </div>
</div> </div>