Permalink
Browse files

[#6311] Add user preference to override the pane order

  • Loading branch information...
edavis10 committed Jul 28, 2011
1 parent 0527309 commit a273bd38e625cf28ccb5a92e26d327eafe669ee2
View
@@ -29,13 +29,30 @@ def self.pane_order
end
def self.pane_order_reversed?
- settings.present? &&
- settings['reverse_pane_order'].present? &&
- settings['reverse_pane_order'].to_s == "1"
+ user_preference = check_user_preference_for_pane_order
+
+ if user_preference.nil?
+ settings.present? &&
+ settings['reverse_pane_order'].present? &&
+ settings['reverse_pane_order'].to_s == "1"
+ else
+ # User override
+ return user_preference
+ end
end
private
+ # Can return:
+ # true - yes, reverse
+ # false - no, do not reverse
+ # nil - no preference
+ def self.check_user_preference_for_pane_order
+ if User.current.logged? && User.current.pref.present?
+ User.current.pref.kanban_reverse_pane_order
+ end
+ end
+
def missing_settings(pane, options={})
skip_status = options.delete(:skip_status)
@@ -0,0 +1,3 @@
+<% fields_for :pref, user.pref, :builder => TabularFormBuilder, :lang => current_language do |pref_fields| %>
+<p><%= pref_fields.check_box :kanban_reverse_pane_order %></p>
+<% end %>
View
@@ -75,4 +75,5 @@ en:
label_switch_assignee: "Switch Assignee"
kanban_label_incoming_projects: "Incoming projects"
kanban_label_reverse_pane_order: "Reverse pane order"
+ field_kanban_reverse_pane_order: "Reverse Kanban pane order"
kanban_text_reverse_pane_order_help: "Reverses the workflow so it goes from Right to Left (default is Left to Right)"
View
@@ -9,6 +9,9 @@
Dispatcher.to_prepare :redmine_kanban do
+ require_dependency 'user_preference'
+ UserPreference.send(:include, RedmineKanban::Patches::UserPreferencePatch)
+
require_dependency 'principal'
Principal.send(:include, RedmineKanban::Patches::PrincipalPatch)
require_dependency 'issue'
@@ -93,3 +96,4 @@
:require => :loggedin)
end
+require 'redmine_kanban/hooks/view_my_account_hook'
@@ -0,0 +1,9 @@
+module RedmineKanban
+ module Hooks
+ class ViewMyAccountHook < Redmine::Hook::ViewListener
+
+ render_on(:view_my_account, :partial => 'my/kanban', :layout => false)
+
+ end
+ end
+end
@@ -0,0 +1,28 @@
+module RedmineKanban
+ module Patches
+ module UserPreferencePatch
+ def self.included(base)
+ base.extend(ClassMethods)
+
+ base.send(:include, InstanceMethods)
+ base.class_eval do
+ unloadable
+
+ def kanban_reverse_pane_order
+ self[:kanban_reverse_pane_order]
+ end
+
+ def kanban_reverse_pane_order=(value)
+ self[:kanban_reverse_pane_order] = (value == "1") # convert to bool
+ end
+ end
+ end
+
+ module ClassMethods
+ end
+
+ module InstanceMethods
+ end
+ end
+ end
+end
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/../../../test_helper'
+
+class RedmineKanban::Hooks::ViewMyAccountTest < ActionController::IntegrationTest
+ include Redmine::Hook::Helper
+
+ context "#view_my_account" do
+ setup do
+ configure_plugin
+ @user = User.generate_with_protected!(:login => 'existing', :password => 'existing', :password_confirmation => 'existing')
+ login_as
+ end
+
+ should "allow changing the user's Kanban pane order" do
+ click_link "My account"
+ check "Reverse Kanban pane order"
+ click_button "Save"
+
+ assert_response :success
+ assert_equal true, @user.reload.pref.kanban_reverse_pane_order # check it's forced to bool
+ assert KanbanPane.pane_order_reversed?
+ end
+ end
+end
@@ -21,6 +21,10 @@ class KanbanPaneTest < ActiveSupport::TestCase
end
context "#pane_order_reversed?" do
+ setup do
+ User.current = nil
+ end
+
should 'be false when the pane order reverse setting is not set' do
reconfigure_plugin({'reverse_pane_order' => '0'})
assert !KanbanPane.pane_order_reversed?
@@ -37,8 +41,27 @@ class KanbanPaneTest < ActiveSupport::TestCase
end
context "for users" do
- should 'be true when a user overrides the system setting'
- should 'be falue when a user overrides the system setting'
+ setup do
+ @user = User.generate_with_protected!(:login => 'existing', :password => 'existing', :password_confirmation => 'existing')
+ @preference = @user.pref
+ User.current = @user
+ end
+
+ should 'be true when a user overrides the system setting' do
+ reconfigure_plugin({'reverse_pane_order' => '0'}) # Off
+ @preference.kanban_reverse_pane_order = "1" # On
+ @preference.save
+
+ assert KanbanPane.pane_order_reversed?
+ end
+
+ should 'be falue when a user overrides the system setting' do
+ reconfigure_plugin({'reverse_pane_order' => '1'}) # On
+ @preference.kanban_reverse_pane_order = "0" # Off
+ @preference.save
+
+ assert !KanbanPane.pane_order_reversed?
+ end
end
end
@@ -0,0 +1,6 @@
+require File.dirname(__FILE__) + '/../../../../test_helper'
+
+class RedmineKanban::Patches::UserPreferenceTest < ActionController::TestCase
+
+ should "be tested"
+end

0 comments on commit a273bd3

Please sign in to comment.