quick-search: use smart group search when browsing inside a repository group.

- This replaces last part of now disabled quick filter.
This commit is contained in:
Marcin Kuzminski 2018-06-18 15:52:20 +02:00
parent cdb4455415
commit 7ed0451f13
3 changed files with 29 additions and 3 deletions

View file

@ -29,7 +29,7 @@ from rhodecode.lib import helpers as h
from rhodecode.lib.auth import (
LoginRequired, NotAnonymous, HasRepoGroupPermissionAnyDecorator)
from rhodecode.lib.index import searcher_from_config
from rhodecode.lib.utils2 import safe_unicode, str2bool
from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
from rhodecode.lib.ext_json import json
from rhodecode.model.db import (
func, or_, in_filter_generator, Repository, RepoGroup, User, UserGroup)
@ -326,6 +326,20 @@ class HomeView(BaseAppView):
'url': h.route_path(
'search', _query={'q': query})
})
repo_group_id = safe_int(self.request.GET.get('repo_group_id'))
if repo_group_id:
repo_group = RepoGroup.get(repo_group_id)
composed_hint = '{}/{}'.format(repo_group.group_name, query)
show_hint = not query.startswith(repo_group.group_name)
if repo_group and show_hint:
hint = u'Group search: `{}`'.format(composed_hint)
res.append({
'id': -1,
'value': composed_hint,
'value_display': hint,
'type': 'hint',
'url': ""
})
repo_groups = self._get_repo_group_list(query)
for serialized_repo_group in repo_groups:

View file

@ -523,7 +523,10 @@ commit:efced4, to search for commits
var icon = '';
if (searchType === 'search') {
if (searchType === 'hint') {
icon += '<i class="icon-folder-close"></i> ';
}
else if (searchType === 'search') {
icon += '<i class="icon-more"></i> ';
}
else if (searchType === 'repo') {
@ -561,7 +564,12 @@ commit:efced4, to search for commits
};
var handleSelect = function(element, suggestion) {
window.location = suggestion['url'];
if (suggestion.type === "hint") {
// we skip action
$('#main_filter').focus();
} else {
window.location = suggestion['url'];
}
};
var autocompleteMainFilterResult = function (suggestion, originalQuery, queryLowerCase) {
if (queryLowerCase.split(':').length === 2) {
@ -572,6 +580,7 @@ commit:efced4, to search for commits
$('#main_filter').autocomplete({
serviceUrl: pyroutes.url('goto_switcher_data'),
params: {"repo_group_id": templateContext.repo_group_id},
minChars:2,
maxHeight:400,
deferRequestBy: 300, //miliseconds

View file

@ -8,6 +8,9 @@ if hasattr(c, 'rhodecode_db_repo'):
c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type
c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1]
if getattr(c, 'repo_group', None):
c.template_context['repo_group_id'] = c.repo_group.group_id
if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id:
c.template_context['rhodecode_user']['username'] = c.rhodecode_user.username
c.template_context['rhodecode_user']['email'] = c.rhodecode_user.email