star status shown in normal repo listings

This commit is contained in:
Jimmy Zelinskie 2014-12-30 15:07:14 -05:00
parent 17751eced9
commit 8464b54ad9
5 changed files with 27 additions and 12 deletions

View file

@ -112,6 +112,8 @@ class RepositoryList(ApiResource):
username = None
if get_authenticated_user() and args['private']:
username = get_authenticated_user().username
starred_repos = model.get_user_starred_repositories(get_authenticated_user())
star_lookup = set([repo.id for repo in starred_repos])
response = {}
@ -124,6 +126,16 @@ class RepositoryList(ApiResource):
repo_query = model.get_visible_repositories(username, limit=args['limit'], page=args['page'],
include_public=args['public'], sort=args['sort'],
namespace=args['namespace'])
def repo_view(repo_obj):
repo = {
'namespace': repo_obj.namespace_user.username,
'name': repo_obj.name,
'description': repo_obj.description,
'is_public': repo_obj.visibility.name == 'public',
}
if get_authenticated_user():
repo['is_starred'] = repo_obj.id in star_lookup
return repo
response['repositories'] = [repo_view(repo) for repo in repo_query
if (repo.visibility.name == 'public' or
@ -133,15 +145,6 @@ class RepositoryList(ApiResource):
return response
def repo_view(repo_obj):
return {
'namespace': repo_obj.namespace_user.username,
'name': repo_obj.name,
'description': repo_obj.description,
'is_public': repo_obj.visibility.name == 'public',
}
@resource('/v1/repository/<repopath:repository>')
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
class Repository(RepositoryParamResource):

View file

@ -15,7 +15,6 @@ from endpoints.api import (ApiResource, nickname, resource, validate_json_reques
from endpoints.api.subscribe import subscribe
from endpoints.common import common_login
from endpoints.api.team import try_accept_invite
from endpoints.api.repository import repo_view
from data import model
from data.billing import get_plan
@ -702,6 +701,14 @@ class StarredRepositoryList(ApiResource):
starred_repos = list(model.get_user_starred_repositories(get_authenticated_user(),
page=page,
limit=limit))
def repo_view(repo_obj):
return {
'namespace': repo_obj.namespace_user.username,
'name': repo_obj.name,
'description': repo_obj.description,
'is_public': repo_obj.visibility.name == 'public',
}
return {'repositories': [repo_view(repo) for repo in starred_repos]}
@require_scope(scopes.READ_REPO)

View file

@ -262,8 +262,10 @@ function RepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
};
ApiService.createStar(data).then(function(result) {
loadStarredRepos();
loadRepos();
}, function(result) {
loadStarredRepos();
loadRepos();
});
};
@ -273,8 +275,10 @@ function RepoListCtrl($scope, $sanitize, Restangular, UserService, ApiService) {
};
ApiService.deleteStar(null, data).then(function(result) {
loadStarredRepos();
loadRepos();
}, function(result) {
loadStarredRepos();
loadRepos();
});
};

View file

@ -96,7 +96,7 @@
<div class="row">
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12" ng-repeat="repository in namespace.repositories.value">
<div class="panel panel-default">
<div class="panel-body">
<div class="panel-body" ng-class="repository.is_starred ? 'starred' : ''">
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 repo-panel-title-row">
<span class="repo-icon repo-circle no-background" repo="repository"></span>
@ -106,7 +106,8 @@
</a>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<i class="star-icon fa fa-star-o" ng-click="starRepo(repository)"></i>
<i ng-if="repository.is_starred" class="star-icon starred fa fa-star" ng-click="unstarRepo(repository)"></i>
<i ng-if="!repository.is_starred" class="star-icon fa fa-star-o" ng-click="starRepo(repository)"></i>
</div>
</div>
<!-- The description automatically gets put in a <p> which adds margin that throws off our .repo-panel padding -->

Binary file not shown.