Fixes block reordering on my page (#2971).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3194 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
008ad85d10
commit
9d120c872c
|
@ -35,7 +35,6 @@ class MyController < ApplicationController
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
verify :xhr => true,
|
verify :xhr => true,
|
||||||
:session => :page_layout,
|
|
||||||
:only => [:add_block, :remove_block, :order_blocks]
|
:only => [:add_block, :remove_block, :order_blocks]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -109,8 +108,6 @@ class MyController < ApplicationController
|
||||||
def page_layout
|
def page_layout
|
||||||
@user = User.current
|
@user = User.current
|
||||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||||||
session[:page_layout] = @blocks
|
|
||||||
%w(top left right).each {|f| session[:page_layout][f] ||= [] }
|
|
||||||
@block_options = []
|
@block_options = []
|
||||||
BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
|
BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
|
||||||
end
|
end
|
||||||
|
@ -122,10 +119,13 @@ class MyController < ApplicationController
|
||||||
block = params[:block].to_s.underscore
|
block = params[:block].to_s.underscore
|
||||||
(render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
|
(render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
|
||||||
@user = User.current
|
@user = User.current
|
||||||
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
# remove if already present in a group
|
# remove if already present in a group
|
||||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
# add it on top
|
# add it on top
|
||||||
session[:page_layout]['top'].unshift block
|
layout['top'].unshift block
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -133,8 +133,12 @@ class MyController < ApplicationController
|
||||||
# params[:block] : id of the block to remove
|
# params[:block] : id of the block to remove
|
||||||
def remove_block
|
def remove_block
|
||||||
block = params[:block].to_s.underscore
|
block = params[:block].to_s.underscore
|
||||||
|
@user = User.current
|
||||||
# remove block in all groups
|
# remove block in all groups
|
||||||
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,25 +147,20 @@ class MyController < ApplicationController
|
||||||
# params[:list-(top|left|right)] : array of block ids of the group
|
# params[:list-(top|left|right)] : array of block ids of the group
|
||||||
def order_blocks
|
def order_blocks
|
||||||
group = params[:group]
|
group = params[:group]
|
||||||
|
@user = User.current
|
||||||
if group.is_a?(String)
|
if group.is_a?(String)
|
||||||
group_items = (params["list-#{group}"] || []).collect(&:underscore)
|
group_items = (params["list-#{group}"] || []).collect(&:underscore)
|
||||||
if group_items and group_items.is_a? Array
|
if group_items and group_items.is_a? Array
|
||||||
|
layout = @user.pref[:my_page_layout] || {}
|
||||||
# remove group blocks if they are presents in other groups
|
# remove group blocks if they are presents in other groups
|
||||||
%w(top left right).each {|f|
|
%w(top left right).each {|f|
|
||||||
session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
|
layout[f] = (layout[f] || []) - group_items
|
||||||
}
|
}
|
||||||
session[:page_layout][group] = group_items
|
layout[group] = group_items
|
||||||
|
@user.pref[:my_page_layout] = layout
|
||||||
|
@user.pref.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save user's page layout
|
|
||||||
def page_layout_save
|
|
||||||
@user = User.current
|
|
||||||
@user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
|
|
||||||
@user.pref.save
|
|
||||||
session[:page_layout] = nil
|
|
||||||
redirect_to :action => 'page'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,8 +46,7 @@ function removeBlock(block) {
|
||||||
}, :class => 'icon icon-add'
|
}, :class => 'icon icon-add'
|
||||||
%>
|
%>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to l(:button_save), {:action => 'page_layout_save'}, :class => 'icon icon-save' %>
|
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
||||||
<%= link_to l(:button_cancel), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%=l(:label_my_page)%></h2>
|
<h2><%=l(:label_my_page)%></h2>
|
||||||
|
|
|
@ -4,11 +4,10 @@ user_preferences_001:
|
||||||
---
|
---
|
||||||
:my_page_layout:
|
:my_page_layout:
|
||||||
left:
|
left:
|
||||||
- latest_news
|
- latestnews
|
||||||
- documents
|
- documents
|
||||||
right:
|
right:
|
||||||
- issues_assigned_to_me
|
- issuesassignedtome
|
||||||
- issues_reported_by_me
|
|
||||||
top:
|
top:
|
||||||
- calendar
|
- calendar
|
||||||
|
|
||||||
|
@ -16,8 +15,16 @@ user_preferences_001:
|
||||||
user_id: 1
|
user_id: 1
|
||||||
hide_mail: true
|
hide_mail: true
|
||||||
user_preferences_002:
|
user_preferences_002:
|
||||||
others: |+
|
others: |
|
||||||
--- {}
|
---
|
||||||
|
:my_page_layout:
|
||||||
|
left:
|
||||||
|
- latestnews
|
||||||
|
- documents
|
||||||
|
right:
|
||||||
|
- issuesassignedtome
|
||||||
|
top:
|
||||||
|
- calendar
|
||||||
|
|
||||||
id: 2
|
id: 2
|
||||||
user_id: 3
|
user_id: 3
|
||||||
|
|
|
@ -22,7 +22,7 @@ require 'my_controller'
|
||||||
class MyController; def rescue_action(e) raise e end; end
|
class MyController; def rescue_action(e) raise e end; end
|
||||||
|
|
||||||
class MyControllerTest < ActionController::TestCase
|
class MyControllerTest < ActionController::TestCase
|
||||||
fixtures :users, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields
|
fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = MyController.new
|
@controller = MyController.new
|
||||||
|
@ -105,4 +105,28 @@ class MyControllerTest < ActionController::TestCase
|
||||||
assert_redirected_to 'my/account'
|
assert_redirected_to 'my/account'
|
||||||
assert User.try_to_login('jsmith', 'hello')
|
assert User.try_to_login('jsmith', 'hello')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_page_layout
|
||||||
|
get :page_layout
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'page_layout'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_add_block
|
||||||
|
xhr :post, :add_block, :block => 'issuesreportedbyme'
|
||||||
|
assert_response :success
|
||||||
|
assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remove_block
|
||||||
|
xhr :post, :remove_block, :block => 'issuesassignedtome'
|
||||||
|
assert_response :success
|
||||||
|
assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_order_blocks
|
||||||
|
xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
|
||||||
|
assert_response :success
|
||||||
|
assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue