preferences_helper.rb 1.51 KB
Newer Older
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

10 11
  # Maps `dashboard` values to more user-friendly option text
  DASHBOARD_CHOICES = {
12 13 14 15 16 17 18 19
    projects: _("Your Projects (default)"),
    stars:    _("Starred Projects"),
    project_activity: _("Your Projects' Activity"),
    starred_project_activity: _("Starred Projects' Activity"),
    groups: _("Your Groups"),
    todos: _("Your Todos"),
    issues: _("Assigned Issues"),
    merge_requests: _("Assigned Merge Requests")
20
  }.with_indifferent_access.freeze
21

22 23 24
  # Returns an Array usable by a select field for more user-friendly option text
  def dashboard_choices
    defined = User.dashboards
25

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

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

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

50 51
  def user_color_scheme
    Gitlab::ColorSchemes.for_user(current_user).css_class
52 53
  end
end