Module: PreferencesHelper

Defined in:
app/helpers/preferences_helper.rb

Overview

Helper methods for per-User preferences

Constant Summary collapse

DASHBOARD_CHOICES =

Maps `dashboard` values to more user-friendly option text

{
  projects: 'Your Projects (default)',
  stars:    'Starred Projects',
  project_activity: "Your Projects' Activity",
  starred_project_activity: "Starred Projects' Activity",
  groups: "Your Groups",
  todos: "Your Todos"
}.with_indifferent_access.freeze

Instance Method Summary collapse

Instance Method Details

#dashboard_choicesObject

Returns an Array usable by a select field for more user-friendly option text


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/preferences_helper.rb', line 21

def dashboard_choices
  defined = User.dashboards

  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}."
  else
    defined.map do |key, _|
      # Use `fetch` so `KeyError` gets raised when a key is missing
      [DASHBOARD_CHOICES.fetch(key), key]
    end
  end
end

#default_project_viewObject


52
53
54
# File 'app/helpers/preferences_helper.rb', line 52

def default_project_view
  current_user ? current_user.project_view : 'readme'
end

#layout_choicesObject


3
4
5
6
7
8
# File 'app/helpers/preferences_helper.rb', line 3

def layout_choices
  [
      ['Fixed', :fixed],
      ['Fluid', :fluid]
  ]
end

#project_view_choicesObject


36
37
38
39
40
41
42
# File 'app/helpers/preferences_helper.rb', line 36

def project_view_choices
  [
    ['Readme (default)', :readme],
    ['Activity view', :activity],
    ['Files view', :files]
  ]
end

#user_application_themeObject


44
45
46
# File 'app/helpers/preferences_helper.rb', line 44

def user_application_theme
  Gitlab::Themes.for_user(current_user).css_class
end

#user_color_schemeObject


48
49
50
# File 'app/helpers/preferences_helper.rb', line 48

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