diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/helpers/search_helper.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r-- | app/helpers/search_helper.rb | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 5ad65c59a2e..4e3b6aad8cc 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -3,28 +3,6 @@ module SearchHelper SEARCH_PERMITTED_PARAMS = [:search, :scope, :project_id, :group_id, :repository_ref, :snippets].freeze - def search_autocomplete_opts(term) - return unless current_user - - resources_results = [ - groups_autocomplete(term), - projects_autocomplete(term) - ].flatten - - search_pattern = Regexp.new(Regexp.escape(term), "i") - - generic_results = project_autocomplete + default_autocomplete + help_autocomplete - generic_results.concat(default_autocomplete_admin) if current_user.admin? - generic_results.select! { |result| result[:label] =~ search_pattern } - - [ - resources_results, - generic_results - ].flatten.uniq do |item| - item[:label] - end - end - def search_entries_info(collection, scope, term) return if collection.to_a.empty? @@ -95,91 +73,6 @@ module SearchHelper private - # Autocomplete results for various settings pages - def default_autocomplete - [ - { category: "Settings", label: _("User settings"), url: profile_path }, - { category: "Settings", label: _("SSH Keys"), url: profile_keys_path }, - { category: "Settings", label: _("Dashboard"), url: root_path } - ] - end - - # Autocomplete results for settings pages, for admins - def default_autocomplete_admin - [ - { category: "Settings", label: _("Admin Section"), url: admin_root_path } - ] - end - - # Autocomplete results for internal help pages - def help_autocomplete - [ - { category: "Help", label: _("API Help"), url: help_page_path("api/README") }, - { category: "Help", label: _("Markdown Help"), url: help_page_path("user/markdown") }, - { category: "Help", label: _("Permissions Help"), url: help_page_path("user/permissions") }, - { category: "Help", label: _("Public Access Help"), url: help_page_path("public_access/public_access") }, - { category: "Help", label: _("Rake Tasks Help"), url: help_page_path("raketasks/README") }, - { category: "Help", label: _("SSH Keys Help"), url: help_page_path("ssh/README") }, - { category: "Help", label: _("System Hooks Help"), url: help_page_path("system_hooks/system_hooks") }, - { category: "Help", label: _("Webhooks Help"), url: help_page_path("user/project/integrations/webhooks") }, - { category: "Help", label: _("Workflow Help"), url: help_page_path("workflow/README") } - ] - end - - # Autocomplete results for the current project, if it's defined - def project_autocomplete - if @project && @project.repository.root_ref - ref = @ref || @project.repository.root_ref - - [ - { category: "In this project", label: _("Files"), url: project_tree_path(@project, ref) }, - { category: "In this project", label: _("Commits"), url: project_commits_path(@project, ref) }, - { category: "In this project", label: _("Network"), url: project_network_path(@project, ref) }, - { category: "In this project", label: _("Graph"), url: project_graph_path(@project, ref) }, - { category: "In this project", label: _("Issues"), url: project_issues_path(@project) }, - { category: "In this project", label: _("Merge Requests"), url: project_merge_requests_path(@project) }, - { category: "In this project", label: _("Milestones"), url: project_milestones_path(@project) }, - { category: "In this project", label: _("Snippets"), url: project_snippets_path(@project) }, - { category: "In this project", label: _("Members"), url: project_project_members_path(@project) }, - { category: "In this project", label: _("Wiki"), url: project_wikis_path(@project) } - ] - else - [] - end - end - - # Autocomplete results for the current user's groups - # rubocop: disable CodeReuse/ActiveRecord - def groups_autocomplete(term, limit = 5) - current_user.authorized_groups.order_id_desc.search(term).limit(limit).map do |group| - { - category: "Groups", - id: group.id, - label: "#{search_result_sanitize(group.full_name)}", - url: group_path(group), - avatar_url: group.avatar_url || '' - } - end - end - # rubocop: enable CodeReuse/ActiveRecord - - # Autocomplete results for the current user's projects - # rubocop: disable CodeReuse/ActiveRecord - def projects_autocomplete(term, limit = 5) - current_user.authorized_projects.order_id_desc.search_by_title(term) - .sorted_by_stars_desc.non_archived.limit(limit).map do |p| - { - category: "Projects", - id: p.id, - value: "#{search_result_sanitize(p.name)}", - label: "#{search_result_sanitize(p.full_name)}", - url: project_path(p), - avatar_url: p.avatar_url || '' - } - end - end - # rubocop: enable CodeReuse/ActiveRecord - def search_result_sanitize(str) Sanitize.clean(str) end |