diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 04873b9bd00037ebb2cb05a5867d8661faddb06c..c67a34270ff2569976a4933a36db9d6cc9d0c4c9 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -20,6 +20,25 @@ module PreferencesHelper COLOR_SCHEMES.freeze end + # Populates the dashboard preference select field with more user-friendly + # values. + def dashboard_choices + orig = User.dashboards.keys + + choices = [ + ['Projects (default)', orig[0]], + ['Starred Projects', orig[1]] + ] + + if orig.size != choices.size + # Assure that anyone adding new options updates this method too + raise RuntimeError, "`User` defines #{orig.size} dashboard choices," + + " but #{__method__} defined #{choices.size}" + else + choices + end + end + def user_application_theme theme = Gitlab::Themes.by_id(current_user.try(:theme_id)) theme.css_class diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index 680c0930bbab8aa2c32cb05e027f9da04953825e..8f7c57c12bbf6fca0167a5b16da9652134424a0e 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -1,8 +1,10 @@ -- page_title "Design" +- page_title 'Preferences' %h3.page-title = page_title %p.light - Appearance settings will be saved to your profile and made available across all devices. + These settings allow you to customize the appearance and behavior of the site. + They are saved with your account and will persist to any device you use to + access the site. %hr = form_for @user, url: profile_preferences_path, remote: true, method: :put, html: {class: 'js-preferences-form'} do |f| @@ -25,3 +27,16 @@ .preview= image_tag "#{color_scheme}-scheme-preview.png" = f.radio_button :color_scheme_id, color_scheme_id = color_scheme.tr('-_', ' ').titleize + + .panel.panel-default + .panel-heading + Behavior + .panel-body + .form-group + = f.label :dashboard, class: 'control-label' + .col-sm-10 + = f.select :dashboard, dashboard_choices, {}, class: 'form-control' + %p.help-block.hint + This setting allows you to customize the default Dashboard page. + .panel-footer + = f.submit 'Save', class: 'btn btn-save' diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index 095b016e6ec26ce57921ac6b29da5e162dfcc5f1..e8d8c4ceb87c9481b7ad540082f364a3507cda81 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -30,6 +30,23 @@ describe PreferencesHelper do end end + describe 'dashboard_choices' do + it 'raises an exception when defined choices may be missing' do + dashboards = User.dashboards + expect(User).to receive(:dashboards). + and_return(dashboards.merge(foo: 'foo')) + + expect { dashboard_choices }.to raise_error + end + + it 'provides better option descriptions' do + choices = dashboard_choices + + expect(choices[0]).to eq ['Projects (default)', 'projects'] + expect(choices[1]).to eq ['Starred Projects', 'stars'] + end + end + describe 'user_color_scheme_class' do context 'with current_user is nil' do it 'should return a string' do