# HG changeset patch # User Daniel Dourvaris # Date 2019-01-30 20:20:26 # Node ID 3bc8f801125ee18d221d6f928613cefdb853f289 # Parent d273b8e9dbf1bacf6f971681ecbd2178c4313b68 search: new UI for search, and repo group context search - expose search into main NAV - have repo group search filter using new ES lang - show token keys and curretn context when searching - ui updated and consistency fixes diff --git a/rhodecode/apps/_base/__init__.py b/rhodecode/apps/_base/__init__.py --- a/rhodecode/apps/_base/__init__.py +++ b/rhodecode/apps/_base/__init__.py @@ -334,6 +334,13 @@ class RepoGroupAppView(BaseAppView): self.db_repo_group = request.db_repo_group self.db_repo_group_name = self.db_repo_group.group_name + def _get_local_tmpl_context(self, include_app_defaults=True): + _ = self.request.translate + c = super(RepoGroupAppView, self)._get_local_tmpl_context( + include_app_defaults=include_app_defaults) + c.repo_group = self.db_repo_group + return c + def _revoke_perms_on_yourself(self, form_result): _updates = filter(lambda u: self._rhodecode_user.user_id == int(u[0]), form_result['perm_updates']) diff --git a/rhodecode/apps/home/views.py b/rhodecode/apps/home/views.py --- a/rhodecode/apps/home/views.py +++ b/rhodecode/apps/home/views.py @@ -334,6 +334,7 @@ class HomeView(BaseAppView): def _get_default_search_queries(self, search_context, searcher, query): if not searcher: return [] + is_es_6 = searcher.is_es_6 queries = [] @@ -424,12 +425,20 @@ class HomeView(BaseAppView): { 'id': -1, 'value': query, - 'value_display': u'Search for: `{}`'.format(query), + 'value_display': u'Commit search for: `{}`'.format(query), 'type': 'search', 'url': h.route_path('search', _query={'q': query, 'type': 'content'}) - } - ) + }) + queries.append( + { + 'id': -1, + 'value': query, + 'value_display': u'File search for: `{}`'.format(query), + 'type': 'search', + 'url': h.route_path('search', + _query={'q': query, 'type': 'commit'}) + }) return queries diff --git a/rhodecode/apps/search/views.py b/rhodecode/apps/search/views.py --- a/rhodecode/apps/search/views.py +++ b/rhodecode/apps/search/views.py @@ -41,7 +41,7 @@ def perform_search(request, tmpl_context execution_time = '' schema = search_schema.SearchParamsSchema() - + search_tags = [] search_params = {} errors = [] try: @@ -85,6 +85,8 @@ def perform_search(request, tmpl_context finally: searcher.cleanup() + search_tags = searcher.extract_search_tags(search_query) + if not search_result['error']: execution_time = '%s results (%.3f seconds)' % ( search_result['count'], @@ -105,6 +107,7 @@ def perform_search(request, tmpl_context c.cur_query = search_query c.search_type = search_type c.searcher = searcher + c.search_tags = search_tags class SearchView(BaseAppView): diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1495,6 +1495,28 @@ def breadcrumb_repo_link(repo): return literal(' » '.join(path)) +def breadcrumb_repo_group_link(repo_group): + """ + Makes a breadcrumbs path link to repo + + ex:: + group >> subgroup + + :param repo_group: a Repository Group instance + """ + + path = [ + link_to(group.name, + route_path('repo_group_home', repo_group_name=group.group_name)) + for group in repo_group.parents + ] + [ + link_to(repo_group.name, + route_path('repo_group_home', repo_group_name=repo_group.group_name)) + ] + + return literal(' » '.join(path)) + + def format_byte_size_binary(file_size): """ Formats file/folder sizes to standard. diff --git a/rhodecode/lib/index/__init__.py b/rhodecode/lib/index/__init__.py --- a/rhodecode/lib/index/__init__.py +++ b/rhodecode/lib/index/__init__.py @@ -76,6 +76,10 @@ class BaseSearcher(object): def get_handlers(self): return {} + @staticmethod + def extract_search_tags(query): + return [] + def search_config(config, prefix='search.'): _config = {} diff --git a/rhodecode/lib/index/search_utils.py b/rhodecode/lib/index/search_utils.py --- a/rhodecode/lib/index/search_utils.py +++ b/rhodecode/lib/index/search_utils.py @@ -195,63 +195,3 @@ def get_matching_line_offsets(lines, ter matching_lines[line_index] = match_offsets return line_index, matching_lines - - -def lucene_query_parser(): - # from pyparsing lucene_grammar - from pyparsing import ( - Literal, CaselessKeyword, Forward, Regex, QuotedString, Suppress, - Optional, Group, infixNotation, opAssoc, ParserElement, pyparsing_common) - - ParserElement.enablePackrat() - - COLON, LBRACK, RBRACK, LBRACE, RBRACE, TILDE, CARAT = map(Literal, ":[]{}~^") - LPAR, RPAR = map(Suppress, "()") - and_, or_, not_, to_ = map(CaselessKeyword, "AND OR NOT TO".split()) - keyword = and_ | or_ | not_ | to_ - - expression = Forward() - - valid_word = Regex(r'([a-zA-Z0-9*_+.-]|\\[!(){}\[\]^"~*?\\:])+').setName("word") - valid_word.setParseAction( - lambda t: t[0] - .replace('\\\\', chr(127)) - .replace('\\', '') - .replace(chr(127), '\\') - ) - - string = QuotedString('"') - - required_modifier = Literal("+")("required") - prohibit_modifier = Literal("-")("prohibit") - integer = Regex(r"\d+").setParseAction(lambda t: int(t[0])) - proximity_modifier = Group(TILDE + integer("proximity")) - number = pyparsing_common.fnumber() - fuzzy_modifier = TILDE + Optional(number, default=0.5)("fuzzy") - - term = Forward() - field_name = valid_word().setName("fieldname") - incl_range_search = Group(LBRACK + term("lower") + to_ + term("upper") + RBRACK) - excl_range_search = Group(LBRACE + term("lower") + to_ + term("upper") + RBRACE) - range_search = incl_range_search("incl_range") | excl_range_search("excl_range") - boost = (CARAT + number("boost")) - - string_expr = Group(string + proximity_modifier) | string - word_expr = Group(valid_word + fuzzy_modifier) | valid_word - term << (Optional(field_name("field") + COLON) + - (word_expr | string_expr | range_search | Group( - LPAR + expression + RPAR)) + - Optional(boost)) - term.setParseAction(lambda t: [t] if 'field' in t or 'boost' in t else None) - - expression << infixNotation( - term, - [ - (required_modifier | prohibit_modifier, 1, opAssoc.RIGHT), - ((not_ | '!').setParseAction(lambda: "NOT"), 1, opAssoc.RIGHT), - ((and_ | '&&').setParseAction(lambda: "AND"), 2, opAssoc.LEFT), - (Optional(or_ | '||').setParseAction(lambda: "OR"), 2, opAssoc.LEFT), - ] - ) - - return expression diff --git a/rhodecode/public/css/main.less b/rhodecode/public/css/main.less --- a/rhodecode/public/css/main.less +++ b/rhodecode/public/css/main.less @@ -2236,6 +2236,10 @@ h3.files_location{ clear: both; margin: 0 0 @padding; } + + .search-tags { + padding: 5px 0; + } } div.search-feedback-items { diff --git a/rhodecode/public/css/type.less b/rhodecode/public/css/type.less --- a/rhodecode/public/css/type.less +++ b/rhodecode/public/css/type.less @@ -300,6 +300,10 @@ mark, margin-top: @padding; } } + + .repo-group-desc { + padding: 8px 0px 0px 0px; + } } .title-main { diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -281,7 +281,9 @@ function registerRCRoutes() { pyroutes.register('edit_user_group_advanced_sync', '/_admin/user_groups/%(user_group_id)s/edit/advanced/sync', ['user_group_id']); pyroutes.register('user_groups_delete', '/_admin/user_groups/%(user_group_id)s/delete', ['user_group_id']); pyroutes.register('search', '/_admin/search', []); - pyroutes.register('search_repo', '/%(repo_name)s/search', ['repo_name']); + pyroutes.register('search_repo', '/%(repo_name)s/_search', ['repo_name']); + pyroutes.register('search_repo_alt', '/%(repo_name)s/search', ['repo_name']); + pyroutes.register('search_repo_group', '/%(repo_group_name)s/_search', ['repo_group_name']); pyroutes.register('user_profile', '/_profiles/%(username)s', ['username']); pyroutes.register('user_group_profile', '/_profile_user_group/%(user_group_name)s', ['user_group_name']); pyroutes.register('my_account_profile', '/_admin/my_account/profile', []); diff --git a/rhodecode/templates/admin/integrations/new.mako b/rhodecode/templates/admin/integrations/new.mako --- a/rhodecode/templates/admin/integrations/new.mako +++ b/rhodecode/templates/admin/integrations/new.mako @@ -4,17 +4,9 @@ <%def name="breadcrumbs_links()"> %if c.repo: - ${h.link_to('Settings',h.route_path('edit_repo', repo_name=c.repo.repo_name))} - » - ${h.link_to(_('Integrations'),request.route_url(route_name='repo_integrations_home', repo_name=c.repo.repo_name))} + ${_('Settings')} %elif c.repo_group: - ${h.link_to(_('Admin'),h.route_path('admin_home'))} - » - ${h.link_to(_('Repository Groups'),h.route_path('repo_groups'))} - » - ${h.link_to(c.repo_group.group_name,h.route_path('edit_repo_group', repo_group_name=c.repo_group.group_name))} - » - ${h.link_to(_('Integrations'),request.route_url(route_name='repo_group_integrations_home', repo_group_name=c.repo_group.group_name))} + ${_('Settings')} %else: ${h.link_to(_('Admin'),h.route_path('admin_home'))} » diff --git a/rhodecode/templates/admin/repo_groups/repo_group_edit.mako b/rhodecode/templates/admin/repo_groups/repo_group_edit.mako --- a/rhodecode/templates/admin/repo_groups/repo_group_edit.mako +++ b/rhodecode/templates/admin/repo_groups/repo_group_edit.mako @@ -8,26 +8,12 @@ %endif -<%def name="breadcrumbs_links()"> - ${h.link_to(_('Admin'),h.route_path('admin_home'))} - » - ${h.link_to(_('Repository Groups'),h.route_path('repo_groups'))} - %if c.repo_group.parent_group: - » ${h.link_to(c.repo_group.parent_group.name, h.route_path('repo_group_home', repo_group_name=c.repo_group.parent_group.group_name))} - %endif - » ${c.repo_group.name} +<%def name="menu_bar_nav()"> + ${self.menu_items(active='admin')} -<%def name="breadcrumbs_side_links()"> - - - -<%def name="menu_bar_nav()"> - ${self.menu_items(active='admin')} +<%def name="menu_bar_subnav()"> + ${self.repo_group_menu(active='options')} <%def name="main_content()"> @@ -35,10 +21,10 @@ <%def name="main()"> +
- ${self.breadcrumbs()} - ${self.breadcrumbs_side_links()} + ${self.repo_group_page_title(c.repo_group)}
+ diff --git a/rhodecode/templates/admin/repos/repo_edit.mako b/rhodecode/templates/admin/repos/repo_edit.mako --- a/rhodecode/templates/admin/repos/repo_edit.mako +++ b/rhodecode/templates/admin/repos/repo_edit.mako @@ -36,7 +36,7 @@
${self.repo_page_title(c.rhodecode_db_repo)} - ${self.breadcrumbs()} +
@@ -251,7 +251,7 @@