File: explore_helper.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (50 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download
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
# 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]
    }

    exist_opts[:language] = params[:language]

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

  def public_visibility_restricted?
    Gitlab::VisibilityLevel.public_visibility_restricted?
  end

  def projects_filter_items
    [
      { value: _('Any'), text: _('Any'), href: filter_projects_path(visibility_level: nil) },
      *Gitlab::VisibilityLevel.options.keys.map do |key|
        {
          value: key,
          text: key,
          href: filter_projects_path(visibility_level: Gitlab::VisibilityLevel.options[key])
        }
      end
    ]
  end

  def projects_filter_selected(visibility_level)
    visibility_level.present? ? visibility_level_label(visibility_level.to_i) : _('Any')
  end

  private

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