gitlab-org--gitlab-foss/app/helpers/preferences_helper.rb

101 lines
2.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Helper methods for per-User preferences
module PreferencesHelper
def layout_choices
[
['Fixed', :fixed],
['Fluid', :fluid]
]
end
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
dashboards = User.dashboards.keys
validate_dashboard_choices!(dashboards)
dashboards -= excluded_dashboard_choices
dashboards.map do |key|
# Use `fetch` so `KeyError` gets raised when a key is missing
[localized_dashboard_choices.fetch(key), key]
end
end
# Maps `dashboard` values to more user-friendly option text
def localized_dashboard_choices
{
projects: _("Your Projects (default)"),
stars: _("Starred Projects"),
project_activity: _("Your Projects' Activity"),
starred_project_activity: _("Starred Projects' Activity"),
groups: _("Your Groups"),
todos: _("Your To-Do List"),
issues: _("Assigned Issues"),
merge_requests: _("Assigned Merge Requests"),
operations: _("Operations Dashboard")
}.with_indifferent_access.freeze
end
def project_view_choices
[
['Files and Readme (default)', :files],
2017-10-16 16:21:51 -04:00
['Activity', :activity],
['Readme', :readme]
]
end
2018-11-06 16:16:49 -05:00
def first_day_of_week_choices
[
2018-11-13 13:38:26 -05:00
[_('Sunday'), 0],
[_('Monday'), 1],
[_('Saturday'), 6]
2018-11-06 16:16:49 -05:00
]
end
2018-11-13 13:38:26 -05:00
def first_day_of_week_choices_with_default
2019-01-10 16:06:42 -05:00
first_day_of_week_choices.unshift([_('System default (%{default})') % { default: default_first_day_of_week }, nil])
2018-11-13 13:38:26 -05:00
end
def user_application_theme
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
end
def user_color_scheme
Gitlab::ColorSchemes.for_user(current_user).css_class
end
def user_tab_width
Gitlab::TabWidth.css_class_for_user(current_user)
end
2019-02-20 17:58:53 -05:00
def language_choices
options_for_select(
Gitlab::I18n::AVAILABLE_LANGUAGES.map(&:reverse).sort,
current_user.preferred_language
)
2019-02-20 17:58:53 -05:00
end
private
# Ensure that anyone adding new options updates `DASHBOARD_CHOICES` too
def validate_dashboard_choices!(user_dashboards)
if user_dashboards.size != localized_dashboard_choices.size
raise "`User` defines #{user_dashboards.size} dashboard choices," \
" but `localized_dashboard_choices` defined #{localized_dashboard_choices.size}."
end
end
# List of dashboard choice to be excluded from CE.
# EE would override this.
def excluded_dashboard_choices
['operations']
end
2019-02-06 11:49:39 -05:00
def default_first_day_of_week
first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first
end
end
PreferencesHelper.prepend_if_ee('EE::PreferencesHelper')