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",
|
2016-03-24 06:12:45 -04:00
|
|
|
starred_project_activity: "Starred Projects' Activity",
|
|
|
|
groups: "Your Groups",
|
|
|
|
todos: "Your Todos"
|
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
|
2016-11-30 02:34:29 -05:00
|
|
|
raise "`User` defines #{defined.size} dashboard choices," \
|
2015-06-12 20:39:48 -04:00
|
|
|
" 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
|
|
|
|
[
|
2017-03-06 15:49:31 -05:00
|
|
|
['Files and Readme (default)', :files],
|
2017-10-16 16:21:51 -04:00
|
|
|
['Activity', :activity],
|
|
|
|
['Readme', :readme]
|
2015-07-13 12:24:15 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2017-09-11 11:44:42 -04:00
|
|
|
def user_application_theme
|
|
|
|
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
|
|
|
|
end
|
|
|
|
|
2015-08-26 14:33:44 -04:00
|
|
|
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
|
2016-11-16 13:20:05 -05:00
|
|
|
return anonymous_project_view unless current_user
|
2016-09-16 15:15:39 -04:00
|
|
|
|
|
|
|
user_view = current_user.project_view
|
|
|
|
|
2017-04-07 18:21:16 -04:00
|
|
|
if can?(current_user, :download_code, @project)
|
2016-09-16 15:15:39 -04:00
|
|
|
user_view
|
|
|
|
elsif user_view == "activity"
|
|
|
|
"activity"
|
2017-11-21 12:58:42 -05:00
|
|
|
elsif can?(current_user, :read_wiki, @project)
|
2016-09-16 15:15:39 -04:00
|
|
|
"wiki"
|
|
|
|
elsif @project.feature_available?(:issues, current_user)
|
|
|
|
"projects/issues/issues"
|
|
|
|
else
|
|
|
|
"customize_workflow"
|
|
|
|
end
|
2015-10-01 10:05:20 -04:00
|
|
|
end
|
2016-11-11 17:57:23 -05:00
|
|
|
|
2016-11-16 13:20:05 -05:00
|
|
|
def anonymous_project_view
|
2017-04-06 10:52:15 -04:00
|
|
|
if !@project.empty_repo? && can?(current_user, :download_code, @project)
|
|
|
|
'files'
|
|
|
|
else
|
|
|
|
'activity'
|
|
|
|
end
|
2016-11-11 17:57:23 -05:00
|
|
|
end
|
2015-06-05 15:53:57 -04:00
|
|
|
end
|