2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
[
|
2021-05-09 20:10:37 -04:00
|
|
|
['Fixed', :fixed],
|
|
|
|
['Fluid', :fluid]
|
2015-10-05 11:22:47 -04:00
|
|
|
]
|
|
|
|
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
|
2018-10-12 10:10:34 -04:00
|
|
|
dashboards = User.dashboards.keys
|
2015-06-10 04:42:02 -04:00
|
|
|
|
2018-10-12 10:10:34 -04:00
|
|
|
validate_dashboard_choices!(dashboards)
|
|
|
|
dashboards -= excluded_dashboard_choices
|
|
|
|
|
|
|
|
dashboards.map do |key|
|
|
|
|
# Use `fetch` so `KeyError` gets raised when a key is missing
|
2020-04-21 11:21:10 -04:00
|
|
|
[localized_dashboard_choices.fetch(key), key]
|
2015-06-10 04:42:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
# 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"),
|
2021-03-03 13:11:16 -05:00
|
|
|
followed_user_activity: _("Followed Users' Activity"),
|
2020-04-21 11:21:10 -04:00
|
|
|
groups: _("Your Groups"),
|
|
|
|
todos: _("Your To-Do List"),
|
|
|
|
issues: _("Assigned Issues"),
|
2021-04-08 11:09:06 -04:00
|
|
|
merge_requests: _("Assigned merge requests"),
|
2020-04-21 11:21:10 -04:00
|
|
|
operations: _("Operations Dashboard")
|
|
|
|
}.with_indifferent_access.freeze
|
|
|
|
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
|
|
|
|
|
2018-11-06 16:16:49 -05:00
|
|
|
def first_day_of_week_choices
|
|
|
|
[
|
2018-11-13 13:38:26 -05:00
|
|
|
[_('Sunday'), 0],
|
2019-02-24 00:42:22 -05:00
|
|
|
[_('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
|
|
|
|
|
2017-09-11 11:44:42 -04:00
|
|
|
def user_application_theme
|
|
|
|
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
|
|
|
|
end
|
|
|
|
|
2020-09-25 17:09:51 -04:00
|
|
|
def user_application_theme_css_filename
|
|
|
|
@user_application_theme_css_filename ||= Gitlab::Themes.for_user(current_user).css_filename
|
2020-09-02 14:10:40 -04:00
|
|
|
end
|
|
|
|
|
2021-06-09 14:11:25 -04:00
|
|
|
def user_theme_primary_color
|
|
|
|
Gitlab::Themes.for_user(current_user).primary_color
|
|
|
|
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
|
2018-10-12 10:10:34 -04:00
|
|
|
|
2020-02-06 07:10:29 -05:00
|
|
|
def user_tab_width
|
|
|
|
Gitlab::TabWidth.css_class_for_user(current_user)
|
|
|
|
end
|
|
|
|
|
2019-02-20 17:58:53 -05:00
|
|
|
def language_choices
|
2020-07-06 05:09:20 -04:00
|
|
|
options_for_select(
|
2021-05-09 20:10:37 -04:00
|
|
|
selectable_locales_with_translation_level.sort,
|
2020-07-06 05:09:20 -04:00
|
|
|
current_user.preferred_language
|
|
|
|
)
|
2019-02-20 17:58:53 -05:00
|
|
|
end
|
|
|
|
|
2020-09-16 14:09:47 -04:00
|
|
|
def integration_views
|
|
|
|
[].tap do |views|
|
2021-05-26 08:10:41 -04:00
|
|
|
views << { name: 'gitpod', message: gitpod_enable_description, message_url: gitpod_url_placeholder, help_link: help_page_path('integration/gitpod.md') } if Gitlab::CurrentSettings.gitpod_enabled
|
2020-11-13 13:09:11 -05:00
|
|
|
views << { name: 'sourcegraph', message: sourcegraph_url_message, message_url: Gitlab::CurrentSettings.sourcegraph_url, help_link: help_page_path('user/profile/preferences.md', anchor: 'sourcegraph') } if Gitlab::Sourcegraph.feature_available? && Gitlab::CurrentSettings.sourcegraph_enabled
|
2020-09-16 14:09:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-12 10:10:34 -04:00
|
|
|
private
|
|
|
|
|
2021-05-26 08:10:41 -04:00
|
|
|
def gitpod_url_placeholder
|
|
|
|
Gitlab::CurrentSettings.gitpod_url.presence || 'https://gitpod.io/'
|
|
|
|
end
|
|
|
|
|
2018-10-12 10:10:34 -04:00
|
|
|
# Ensure that anyone adding new options updates `DASHBOARD_CHOICES` too
|
|
|
|
def validate_dashboard_choices!(user_dashboards)
|
2020-04-21 11:21:10 -04:00
|
|
|
if user_dashboards.size != localized_dashboard_choices.size
|
2018-10-12 10:10:34 -04:00
|
|
|
raise "`User` defines #{user_dashboards.size} dashboard choices," \
|
2020-04-21 11:21:10 -04:00
|
|
|
" but `localized_dashboard_choices` defined #{localized_dashboard_choices.size}."
|
2018-10-12 10:10:34 -04:00
|
|
|
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
|
2021-05-09 20:10:37 -04:00
|
|
|
|
|
|
|
def selectable_locales_with_translation_level
|
|
|
|
Gitlab::I18n.selectable_locales.map do |code, language|
|
|
|
|
[
|
|
|
|
s_("i18n|%{language} (%{percent_translated}%% translated)") % {
|
|
|
|
language: language,
|
|
|
|
percent_translated: Gitlab::I18n.percentage_translated_for(code)
|
|
|
|
},
|
|
|
|
code
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2015-06-05 15:53:57 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
PreferencesHelper.prepend_mod_with('PreferencesHelper')
|