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.
- #dashboard_value ⇒ Object
- #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
dashboardvalues to more user-friendly option text. -
#localized_dashboard_choices_for_user ⇒ Object
Maps
dashboardvalues to more user-friendly option text for current user. - #project_view_choices ⇒ Object
- #time_display_format_choices ⇒ Object
- #user_application_color_mode ⇒ Object
- #user_application_dark_mode? ⇒ Boolean
- #user_application_light_mode? ⇒ Boolean
- #user_application_system_mode? ⇒ Boolean
- #user_application_theme ⇒ Object
- #user_color_scheme ⇒ Object
- #user_dark_color_scheme ⇒ Object
- #user_diffs_colors ⇒ Object
- #user_light_color_scheme ⇒ Object
- #user_tab_width ⇒ Object
- #user_theme_primary_color(dark = false) ⇒ Object
Instance Method Details
#custom_diff_color_classes ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'app/helpers/preferences_helper.rb', line 149 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/preferences_helper.rb', line 23 def dashboard_choices dashboards = User.dashboards.keys validate_dashboard_choices!(dashboards) dashboards -= excluded_dashboard_choices dashboards -= ['homepage'] unless Feature.enabled?(:personal_homepage, current_user) # Move homepage to first position if it's available # For homepage rollout with flipped mapping, homepage becomes their default (value 0) dashboards.unshift('homepage') if dashboards.delete('homepage') dashboards.map do |key| { # Use `fetch` so `KeyError` gets raised when a key is missing text: localized_dashboard_choices_for_user.fetch(key), value: key } end end |
#dashboard_value ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/preferences_helper.rb', line 12 def dashboard_value # For homepage rollout with flipped mapping, show the effective preference # that matches what they actually see, not the raw database value if current_user.should_use_flipped_dashboard_mapping_for_rollout? current_user.effective_dashboard_for_routing else current_user.dashboard end end |
#default_preferred_language_choices ⇒ Object
167 168 169 170 171 172 173 |
# File 'app/helpers/preferences_helper.rb', line 167 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
84 85 86 87 88 89 90 |
# File 'app/helpers/preferences_helper.rb', line 84 def first_day_of_week_choices [ [_('Sunday'), 0], [_('Monday'), 1], [_('Saturday'), 6] ] end |
#first_day_of_week_choices_with_default ⇒ Object
96 97 98 |
# File 'app/helpers/preferences_helper.rb', line 96 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
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/preferences_helper.rb', line 175 def integration_views [].tap do |views| if Gitlab::CurrentSettings.gitpod_enabled views << { name: 'gitpod', message: gitpod_enable_description, message_url: gitpod_url_placeholder, help_link: help_page_path('integration/gitpod.md') } end if Gitlab::CurrentSettings.sourcegraph_enabled views << { name: 'sourcegraph', message: , message_url: Gitlab::CurrentSettings.sourcegraph_url, help_link: help_page_path( 'user/profile/preferences.md', anchor: 'integrate-your-gitlab-instance-with-sourcegraph' ) } end views << extensions_marketplace_view end.compact end |
#language_choices ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'app/helpers/preferences_helper.rb', line 158 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/preferences_helper.rb', line 55 def localized_dashboard_choices { projects: _("Your Contributed Projects (default)"), stars: _("Starred Projects"), member_projects: _("Member 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: _("Merge request homepage"), operations: _("Operations Dashboard"), homepage: _("Personal homepage"), assigned_merge_requests: _("Assigned merge requests"), review_merge_requests: _("Merge request reviews") }.compact.with_indifferent_access.freeze end |
#localized_dashboard_choices_for_user ⇒ Object
Maps dashboard values to more user-friendly option text for current user
45 46 47 48 49 50 51 52 |
# File 'app/helpers/preferences_helper.rb', line 45 def localized_dashboard_choices_for_user return localized_dashboard_choices unless current_user.should_use_flipped_dashboard_mapping_for_rollout? localized_dashboard_choices.dup.tap do |choices| choices[:projects] = _("Your Contributed Projects") choices[:homepage] = _("Personal homepage (default)") end.freeze end |
#project_view_choices ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'app/helpers/preferences_helper.rb', line 75 def project_view_choices [ [s_('ProjectView|Files and Readme (default)'), :files], [s_('ProjectView|Activity'), :activity], [s_('ProjectView|Readme'), :readme], [s_('ProjectView|Wiki'), :wiki] ] end |
#time_display_format_choices ⇒ Object
92 93 94 |
# File 'app/helpers/preferences_helper.rb', line 92 def time_display_format_choices UserPreference.time_display_formats end |
#user_application_color_mode ⇒ Object
104 105 106 |
# File 'app/helpers/preferences_helper.rb', line 104 def user_application_color_mode @user_color_mode ||= Gitlab::ColorModes.for_user(current_user).css_class end |
#user_application_dark_mode? ⇒ Boolean
112 113 114 |
# File 'app/helpers/preferences_helper.rb', line 112 def user_application_dark_mode? user_application_color_mode == 'gl-dark' end |
#user_application_light_mode? ⇒ Boolean
108 109 110 |
# File 'app/helpers/preferences_helper.rb', line 108 def user_application_light_mode? user_application_color_mode == 'gl-light' end |
#user_application_system_mode? ⇒ Boolean
116 117 118 |
# File 'app/helpers/preferences_helper.rb', line 116 def user_application_system_mode? user_application_color_mode == 'gl-system' end |
#user_application_theme ⇒ Object
100 101 102 |
# File 'app/helpers/preferences_helper.rb', line 100 def user_application_theme @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class end |
#user_color_scheme ⇒ Object
126 127 128 |
# File 'app/helpers/preferences_helper.rb', line 126 def user_color_scheme Gitlab::ColorSchemes.for_user(current_user).css_class end |
#user_dark_color_scheme ⇒ Object
134 135 136 |
# File 'app/helpers/preferences_helper.rb', line 134 def user_dark_color_scheme Gitlab::ColorSchemes.dark_for_user(current_user).css_class end |
#user_diffs_colors ⇒ Object
142 143 144 145 146 147 |
# File 'app/helpers/preferences_helper.rb', line 142 def user_diffs_colors { deletion: current_user&.diffs_deletion_color.presence, addition: current_user&.diffs_addition_color.presence }.compact end |
#user_light_color_scheme ⇒ Object
130 131 132 |
# File 'app/helpers/preferences_helper.rb', line 130 def user_light_color_scheme Gitlab::ColorSchemes.light_for_user(current_user).css_class end |
#user_tab_width ⇒ Object
138 139 140 |
# File 'app/helpers/preferences_helper.rb', line 138 def user_tab_width Gitlab::TabWidth.css_class_for_user(current_user) end |