2015-09-11 14:41:01 +05:30
|
|
|
# Helper methods for per-User preferences
|
|
|
|
module PreferencesHelper
|
2015-10-24 18:46:33 +05:30
|
|
|
def layout_choices
|
|
|
|
[
|
|
|
|
['Fixed', :fixed],
|
|
|
|
['Fluid', :fluid]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
# Maps `dashboard` values to more user-friendly option text
|
|
|
|
DASHBOARD_CHOICES = {
|
|
|
|
projects: 'Your Projects (default)',
|
2015-10-24 18:46:33 +05:30
|
|
|
stars: 'Starred Projects',
|
|
|
|
project_activity: "Your Projects' Activity",
|
2016-06-02 11:05:42 +05:30
|
|
|
starred_project_activity: "Starred Projects' Activity",
|
|
|
|
groups: "Your Groups",
|
|
|
|
todos: "Your Todos"
|
2015-09-11 14:41:01 +05:30
|
|
|
}.with_indifferent_access.freeze
|
|
|
|
|
|
|
|
# Returns an Array usable by a select field for more user-friendly option text
|
|
|
|
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
|
|
|
|
|
|
|
|
def project_view_choices
|
|
|
|
[
|
|
|
|
['Readme (default)', :readme],
|
2015-11-26 14:37:03 +05:30
|
|
|
['Activity view', :activity],
|
|
|
|
['Files view', :files]
|
2015-09-11 14:41:01 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_application_theme
|
2015-09-25 12:07:36 +05:30
|
|
|
Gitlab::Themes.for_user(current_user).css_class
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
def user_color_scheme
|
|
|
|
Gitlab::ColorSchemes.for_user(current_user).css_class
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
def default_project_view
|
2017-01-15 13:20:01 +05:30
|
|
|
return anonymous_project_view unless current_user
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
user_view = current_user.project_view
|
|
|
|
|
|
|
|
if @project.feature_available?(:repository, current_user)
|
|
|
|
user_view
|
|
|
|
elsif user_view == "activity"
|
|
|
|
"activity"
|
|
|
|
elsif @project.wiki_enabled?
|
|
|
|
"wiki"
|
|
|
|
elsif @project.feature_available?(:issues, current_user)
|
|
|
|
"projects/issues/issues"
|
|
|
|
else
|
|
|
|
"customize_workflow"
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2017-01-15 13:20:01 +05:30
|
|
|
|
|
|
|
def anonymous_project_view
|
|
|
|
@project.empty_repo? || !can?(current_user, :download_code, @project) ? 'activity' : 'readme'
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|