debian-mirror-gitlab/app/helpers/preferences_helper.rb

92 lines
2.5 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
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 = {
2018-05-09 12:01:36 +05:30
projects: _("Your Projects (default)"),
stars: _("Starred Projects"),
project_activity: _("Your Projects' Activity"),
starred_project_activity: _("Starred Projects' Activity"),
groups: _("Your Groups"),
2019-09-30 21:07:59 +05:30
todos: _("Your To-Do List"),
2018-05-09 12:01:36 +05:30
issues: _("Assigned Issues"),
2018-12-13 13:39:08 +05:30
merge_requests: _("Assigned Merge Requests"),
operations: _("Operations Dashboard")
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
2018-12-13 13:39:08 +05:30
dashboards = User.dashboards.keys
2015-09-11 14:41:01 +05:30
2018-12-13 13:39:08 +05:30
validate_dashboard_choices!(dashboards)
dashboards -= excluded_dashboard_choices
dashboards.map do |key|
# Use `fetch` so `KeyError` gets raised when a key is missing
[DASHBOARD_CHOICES.fetch(key), key]
2015-09-11 14:41:01 +05:30
end
end
def project_view_choices
[
2017-08-17 22:00:37 +05:30
['Files and Readme (default)', :files],
2018-03-17 18:26:18 +05:30
['Activity', :activity],
['Readme', :readme]
2015-09-11 14:41:01 +05:30
]
end
2019-03-02 22:35:43 +05:30
def first_day_of_week_choices
[
[_('Sunday'), 0],
2019-07-07 11:18:12 +05:30
[_('Monday'), 1],
[_('Saturday'), 6]
2019-03-02 22:35:43 +05:30
]
end
def first_day_of_week_choices_with_default
first_day_of_week_choices.unshift([_('System default (%{default})') % { default: default_first_day_of_week }, nil])
end
2018-03-17 18:26:18 +05:30
def user_application_theme
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
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
2018-12-13 13:39:08 +05:30
2019-07-07 11:18:12 +05:30
def language_choices
Gitlab::I18n::AVAILABLE_LANGUAGES.map { |value, label| [label, value] }
end
2018-12-13 13:39:08 +05:30
private
# Ensure that anyone adding new options updates `DASHBOARD_CHOICES` too
def validate_dashboard_choices!(user_dashboards)
if user_dashboards.size != DASHBOARD_CHOICES.size
raise "`User` defines #{user_dashboards.size} dashboard choices," \
" but `DASHBOARD_CHOICES` defined #{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-03-02 22:35:43 +05:30
def default_first_day_of_week
first_day_of_week_choices.rassoc(Gitlab::CurrentSettings.first_day_of_week).first
end
2015-09-11 14:41:01 +05:30
end
2019-12-04 20:38:33 +05:30
PreferencesHelper.prepend_if_ee('EE::PreferencesHelper')