summaryrefslogtreecommitdiff
path: root/app/helpers/explore_helper.rb
blob: b66c7a69b71f6589386ebf44e8f8864de0e90245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

module ExploreHelper
  def filter_projects_path(options = {})
    exist_opts = {
      sort: params[:sort] || @sort,
      scope: params[:scope],
      group: params[:group],
      tag: params[:tag],
      visibility_level: params[:visibility_level],
      name: params[:name],
      personal: params[:personal],
      archived: params[:archived],
      shared: params[:shared],
      namespace_id: params[:namespace_id]
    }

    options = exist_opts.merge(options).delete_if { |key, value| value.blank? }
    request_path_with_options(options)
  end

  def filter_audit_path(options = {})
    exist_opts = {
      entity_type: params[:entity_type],
      entity_id: params[:entity_id],
      created_before: params[:created_before],
      created_after: params[:created_after],
      sort: params[:sort]
    }
    options = exist_opts.merge(options).delete_if { |key, value| value.blank? }
    request_path_with_options(options)
  end

  def filter_groups_path(options = {})
    request_path_with_options(options)
  end

  def explore_controller?
    controller.class.name.split("::").first == "Explore"
  end

  def explore_nav_links
    @explore_nav_links ||= get_explore_nav_links
  end

  def explore_nav_link?(link)
    explore_nav_links.include?(link)
  end

  def any_explore_nav_link?(links)
    links.any? { |link| explore_nav_link?(link) }
  end

  def public_visibility_restricted?
    Gitlab::CurrentSettings.restricted_visibility_levels&.include? Gitlab::VisibilityLevel::PUBLIC
  end

  private

  def get_explore_nav_links
    [:projects, :groups, :snippets]
  end

  def request_path_with_options(options = {})
    request.path + "?#{options.to_param}"
  end
end