Read about our upcoming Code of Conduct on this issue

preferences_helper.rb 1.41 KB
Newer Older
Robert Speicher's avatar
Robert Speicher committed
1
2
# Helper methods for per-User preferences
module PreferencesHelper
3
4
  def layout_choices
    [
5
6
        ['Fixed', :fixed],
        ['Fluid', :fluid]
7
8
9
    ]
  end

Robert Speicher's avatar
Robert Speicher committed
10
11
12
  # Maps `dashboard` values to more user-friendly option text
  DASHBOARD_CHOICES = {
    projects: 'Your Projects (default)',
13
14
    stars:    'Starred Projects',
    project_activity: "Your Projects' Activity",
15
16
17
    starred_project_activity: "Starred Projects' Activity",
    groups: "Your Groups",
    todos: "Your Todos"
Robert Speicher's avatar
Robert Speicher committed
18
  }.with_indifferent_access.freeze
19

Robert Speicher's avatar
Robert Speicher committed
20
21
22
  # Returns an Array usable by a select field for more user-friendly option text
  def dashboard_choices
    defined = User.dashboards
23

Robert Speicher's avatar
Robert Speicher committed
24
25
    if defined.size != DASHBOARD_CHOICES.size
      # Ensure that anyone adding new options updates this method too
26
      raise "`User` defines #{defined.size} dashboard choices," \
Robert Speicher's avatar
Robert Speicher committed
27
        " but `DASHBOARD_CHOICES` defined #{DASHBOARD_CHOICES.size}."
28
    else
Robert Speicher's avatar
Robert Speicher committed
29
30
31
32
      defined.map do |key, _|
        # Use `fetch` so `KeyError` gets raised when a key is missing
        [DASHBOARD_CHOICES.fetch(key), key]
      end
33
34
35
    end
  end

36
37
  def project_view_choices
    [
38
      ['Files and Readme (default)', :files],
39
40
      ['Activity', :activity],
      ['Readme', :readme]
41
42
43
    ]
  end

44
45
46
47
  def user_application_theme
    @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
  end

48
49
  def user_color_scheme
    Gitlab::ColorSchemes.for_user(current_user).css_class
Robert Speicher's avatar
Robert Speicher committed
50
51
  end
end