summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-10 04:42:02 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-16 12:52:00 -0400
commit878732b4264eeba0214964da096b6f8c139f6900 (patch)
treee3a81cfadcf608e8b87d37d4d36b59946a78c86c
parent5e0a812669382a18d2688854cb14755078c44eea (diff)
downloadgitlab-ce-878732b4264eeba0214964da096b6f8c139f6900.tar.gz
Add a form field to customize the dashboard preference
cherry-picked
-rw-r--r--app/helpers/preferences_helper.rb21
-rw-r--r--app/views/profiles/preferences/show.html.haml19
-rw-r--r--spec/helpers/preferences_helper_spec.rb20
3 files changed, 58 insertions, 2 deletions
diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb
new file mode 100644
index 00000000000..247be8239c0
--- /dev/null
+++ b/app/helpers/preferences_helper.rb
@@ -0,0 +1,21 @@
+# Helper methods for per-User preferences
+module PreferencesHelper
+ # 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
+end
diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml
index 59df8497805..773a324e1a0 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|
@@ -52,3 +54,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
new file mode 100644
index 00000000000..2a70672ce40
--- /dev/null
+++ b/spec/helpers/preferences_helper_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe PreferencesHelper do
+ 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
+end