BigW Consortium Gitlab

preferences_helper.rb 1.21 KB
Newer Older
1 2
# Helper methods for per-User preferences
module PreferencesHelper
3 4 5 6 7
  # Maps `dashboard` values to more user-friendly option text
  DASHBOARD_CHOICES = {
    projects: 'Your Projects (default)',
    stars:    'Starred Projects'
  }.with_indifferent_access.freeze
8

9 10 11
  # Returns an Array usable by a select field for more user-friendly option text
  def dashboard_choices
    defined = User.dashboards
12

13 14 15 16
    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}."
17
    else
18 19 20 21
      defined.map do |key, _|
        # Use `fetch` so `KeyError` gets raised when a key is missing
        [DASHBOARD_CHOICES.fetch(key), key]
      end
22 23 24
    end
  end

25 26 27 28 29 30 31
  def project_view_choices
    [
      ['Readme (default)', :readme],
      ['Activity view', :activity]
    ]
  end

32
  def user_application_theme
33 34 35 36 37
    Gitlab::Themes.for_user(current_user).css_class
  end

  def user_color_scheme
    Gitlab::ColorSchemes.for_user(current_user).css_class
38 39
  end

40 41 42 43
  def prefer_readme?
    !current_user ||
      current_user.project_view == 'readme'
  end
44
end