preferences_helper.rb 1.43 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 12
  # Maps `dashboard` values to more user-friendly option text
  DASHBOARD_CHOICES = {
    projects: 'Your Projects (default)',
13 14 15
    stars:    'Starred Projects',
    project_activity: "Your Projects' Activity",
    starred_project_activity: "Starred Projects' Activity"
16
  }.with_indifferent_access.freeze
17

18 19 20
  # Returns an Array usable by a select field for more user-friendly option text
  def dashboard_choices
    defined = User.dashboards
21

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

34 35 36
  def project_view_choices
    [
      ['Readme (default)', :readme],
37 38
      ['Activity view', :activity],
      ['Files view', :files]
39 40 41
    ]
  end

42
  def user_application_theme
43 44 45 46 47
    Gitlab::Themes.for_user(current_user).css_class
  end

  def user_color_scheme
    Gitlab::ColorSchemes.for_user(current_user).css_class
48 49
  end

50 51
  def default_project_view
    current_user ? current_user.project_view : 'readme'
52
  end
53
end