Module: PreferencesHelper
- Included in:
- LazyImageTagHelper
- Defined in:
- app/helpers/preferences_helper.rb
Overview
Helper methods for per-User preferences
Instance Method Summary collapse
- #custom_diff_color_classes ⇒ Object
-
#dashboard_choices ⇒ Object
Returns an Array usable by a select field for more user-friendly option text.
- #default_preferred_language_choices ⇒ Object
- #first_day_of_week_choices ⇒ Object
- #first_day_of_week_choices_with_default ⇒ Object
- #integration_views ⇒ Object
- #language_choices ⇒ Object
- #layout_choices ⇒ Object
-
#localized_dashboard_choices ⇒ Object
Maps ‘dashboard` values to more user-friendly option text.
- #project_view_choices ⇒ Object
- #user_application_dark_mode? ⇒ Boolean
- #user_application_theme ⇒ Object
- #user_application_theme_css_filename ⇒ Object
- #user_color_scheme ⇒ Object
- #user_diffs_colors ⇒ Object
- #user_tab_width ⇒ Object
- #user_theme_primary_color ⇒ Object
Instance Method Details
#custom_diff_color_classes ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'app/helpers/preferences_helper.rb', line 97 def custom_diff_color_classes return if request.path == profile_preferences_path classes = [] classes << 'diff-custom-addition-color' if current_user&.diffs_addition_color.presence classes << 'diff-custom-deletion-color' if current_user&.diffs_deletion_color.presence classes end |
#dashboard_choices ⇒ Object
Returns an Array usable by a select field for more user-friendly option text
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/preferences_helper.rb', line 13 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 text: localized_dashboard_choices.fetch(key), value: key } end end |
#default_preferred_language_choices ⇒ Object
115 116 117 118 119 120 121 |
# File 'app/helpers/preferences_helper.rb', line 115 def default_preferred_language_choices ( selectable_locales_with_translation_level( PreferredLanguageSwitcherHelper::SWITCHER_MINIMUM_TRANSLATION_LEVEL).sort, Gitlab::CurrentSettings.default_preferred_language ) end |
#first_day_of_week_choices ⇒ Object
54 55 56 57 58 59 60 |
# File 'app/helpers/preferences_helper.rb', line 54 def first_day_of_week_choices [ [_('Sunday'), 0], [_('Monday'), 1], [_('Saturday'), 6] ] end |
#first_day_of_week_choices_with_default ⇒ Object
62 63 64 |
# File 'app/helpers/preferences_helper.rb', line 62 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 |
#integration_views ⇒ Object
123 124 125 126 127 128 |
# File 'app/helpers/preferences_helper.rb', line 123 def integration_views [].tap do |views| 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 views << { name: 'sourcegraph', 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 end end |
#language_choices ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'app/helpers/preferences_helper.rb', line 106 def language_choices selectable_locales_with_translation_level(Gitlab::I18n::MINIMUM_TRANSLATION_LEVEL).sort.map do |lang, key| { text: lang, value: key } end end |
#layout_choices ⇒ Object
5 6 7 8 9 10 |
# File 'app/helpers/preferences_helper.rb', line 5 def layout_choices [ [s_('Layout|Fixed'), :fixed], [s_('Layout|Fluid'), :fluid] ] end |
#localized_dashboard_choices ⇒ Object
Maps ‘dashboard` values to more user-friendly option text
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/preferences_helper.rb', line 29 def localized_dashboard_choices { projects: _("Your Projects (default)"), stars: _("Starred Projects"), your_activity: _("Your Activity"), project_activity: _("Your Projects' Activity"), starred_project_activity: _("Starred Projects' Activity"), followed_user_activity: _("Followed Users' 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 |
#project_view_choices ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/helpers/preferences_helper.rb', line 45 def project_view_choices [ [s_('ProjectView|Files and Readme (default)'), :files], [s_('ProjectView|Activity'), :activity], [s_('ProjectView|Readme'), :readme], [s_('ProjectView|Wiki'), :wiki] ] end |
#user_application_dark_mode? ⇒ Boolean
70 71 72 |
# File 'app/helpers/preferences_helper.rb', line 70 def user_application_dark_mode? user_application_theme == 'gl-dark' end |
#user_application_theme ⇒ Object
66 67 68 |
# File 'app/helpers/preferences_helper.rb', line 66 def user_application_theme @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class end |
#user_application_theme_css_filename ⇒ Object
74 75 76 |
# File 'app/helpers/preferences_helper.rb', line 74 def user_application_theme_css_filename @user_application_theme_css_filename ||= Gitlab::Themes.for_user(current_user).css_filename end |
#user_color_scheme ⇒ Object
82 83 84 |
# File 'app/helpers/preferences_helper.rb', line 82 def user_color_scheme Gitlab::ColorSchemes.for_user(current_user).css_class end |
#user_diffs_colors ⇒ Object
90 91 92 93 94 95 |
# File 'app/helpers/preferences_helper.rb', line 90 def user_diffs_colors { deletion: current_user&.diffs_deletion_color.presence, addition: current_user&.diffs_addition_color.presence }.compact end |
#user_tab_width ⇒ Object
86 87 88 |
# File 'app/helpers/preferences_helper.rb', line 86 def user_tab_width Gitlab::TabWidth.css_class_for_user(current_user) end |