2015-06-05 15:53:57 -04:00
|
|
|
# Helper methods for per-User preferences
|
|
|
|
module PreferencesHelper
|
2015-10-05 11:22:47 -04:00
|
|
|
def layout_choices
|
|
|
|
[
|
2015-10-05 12:09:05 -04:00
|
|
|
['Fixed', :fixed],
|
|
|
|
['Fluid', :fluid]
|
2015-10-05 11:22:47 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2015-06-12 20:39:48 -04:00
|
|
|
# Maps `dashboard` values to more user-friendly option text
|
|
|
|
DASHBOARD_CHOICES = {
|
|
|
|
projects: 'Your Projects (default)',
|
2015-09-25 20:04:20 -04:00
|
|
|
stars: 'Starred Projects',
|
|
|
|
project_activity: "Your Projects' Activity",
|
|
|
|
starred_project_activity: "Starred Projects' Activity"
|
2015-06-12 20:39:48 -04:00
|
|
|
}.with_indifferent_access.freeze
|
2015-06-10 04:42:02 -04:00
|
|
|
|
2015-06-12 20:39:48 -04:00
|
|
|
# Returns an Array usable by a select field for more user-friendly option text
|
|
|
|
def dashboard_choices
|
|
|
|
defined = User.dashboards
|
2015-06-10 04:42:02 -04:00
|
|
|
|
2015-06-12 20:39:48 -04:00
|
|
|
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}."
|
2015-06-10 04:42:02 -04:00
|
|
|
else
|
2015-06-12 20:39:48 -04:00
|
|
|
defined.map do |key, _|
|
|
|
|
# Use `fetch` so `KeyError` gets raised when a key is missing
|
|
|
|
[DASHBOARD_CHOICES.fetch(key), key]
|
|
|
|
end
|
2015-06-10 04:42:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-13 12:24:15 -04:00
|
|
|
def project_view_choices
|
|
|
|
[
|
|
|
|
['Readme (default)', :readme],
|
2015-10-01 10:05:20 -04:00
|
|
|
['Activity view', :activity],
|
|
|
|
['Files view', :files]
|
2015-07-13 12:24:15 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2015-06-05 15:53:57 -04:00
|
|
|
def user_application_theme
|
2015-08-26 14:33:44 -04:00
|
|
|
Gitlab::Themes.for_user(current_user).css_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_color_scheme
|
|
|
|
Gitlab::ColorSchemes.for_user(current_user).css_class
|
2015-06-05 15:53:57 -04:00
|
|
|
end
|
|
|
|
|
2015-10-17 13:16:04 -04:00
|
|
|
def default_project_view
|
|
|
|
current_user ? current_user.project_view : 'readme'
|
2015-10-01 10:05:20 -04:00
|
|
|
end
|
2015-06-05 15:53:57 -04:00
|
|
|
end
|