Add ability to search for repos by their full path
This commit is contained in:
parent
76d9cbc14f
commit
d09c402675
3 changed files with 19 additions and 5 deletions
|
@ -110,9 +110,22 @@ def get_visible_repositories(username=None):
|
|||
|
||||
|
||||
def get_matching_repositories(repo_term, username=None):
|
||||
namespace_term = repo_term
|
||||
name_term = repo_term
|
||||
|
||||
visible = get_visible_repositories(username)
|
||||
search_clauses = (Repository.name ** ('%' + repo_term + '%') |
|
||||
Repository.namespace ** ('%' + repo_term + '%'))
|
||||
|
||||
search_clauses = (Repository.name ** ('%' + name_term + '%') |
|
||||
Repository.namespace ** ('%' + namespace_term + '%'))
|
||||
|
||||
# Handle the case where the user has already entered a namespace path.
|
||||
if repo_term.find('/') > 0:
|
||||
parts = repo_term.split('/', 1)
|
||||
namespace_term = '/'.join(parts[:-1])
|
||||
name_term = parts[-1]
|
||||
|
||||
search_clauses = (Repository.name ** ('%' + name_term + '%') &
|
||||
Repository.namespace ** ('%' + namespace_term + '%'))
|
||||
|
||||
final = visible.where(search_clauses).limit(10)
|
||||
return list(final)
|
||||
|
|
|
@ -67,8 +67,9 @@ def create_repo_api():
|
|||
pass
|
||||
|
||||
|
||||
@app.route('/api/repository/find/<prefix>', methods=['GET'])
|
||||
def match_repos_api(prefix):
|
||||
@app.route('/api/find/repository', methods=['GET'])
|
||||
def match_repos_api():
|
||||
prefix = request.args.get('query', '')
|
||||
def repo_view(repo):
|
||||
return {
|
||||
'namespace': repo.namespace,
|
||||
|
|
|
@ -43,7 +43,7 @@ function HeaderCtrl($scope, UserService) {
|
|||
$('#repoSearch').typeahead({
|
||||
name: 'repositories',
|
||||
remote: {
|
||||
url: '/api/repository/find/%QUERY',
|
||||
url: '/api/find/repository?query=%QUERY',
|
||||
filter: function(data) {
|
||||
var datums = [];
|
||||
for (var i = 0; i < data.repositories.length; ++i) {
|
||||
|
|
Reference in a new issue