BigW Consortium Gitlab

preferences_helper.rb 1.48 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
    stars:    'Starred Projects',
    project_activity: "Your Projects' Activity",
15 16 17
    starred_project_activity: "Starred Projects' Activity",
    groups: "Your Groups",
    todos: "Your Todos"
18
  }.with_indifferent_access.freeze
19

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

24 25 26 27
    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}."
28
    else
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 38
  def project_view_choices
    [
      ['Readme (default)', :readme],
39 40
      ['Activity view', :activity],
      ['Files view', :files]
41 42 43
    ]
  end

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

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

52 53
  def default_project_view
    current_user ? current_user.project_view : 'readme'
54
  end
55
end