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;
}
.repo-list .repo-list-panel.loading {
padding-top: 20px;
}
.repo-list .repo-list-namespaces h4 {
margin: 6px;
margin-bottom: 20px;

View file

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

View file

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