@@ -35,7 +35,6 class MyController < ApplicationController | |||
|
35 | 35 | }.freeze |
|
36 | 36 | |
|
37 | 37 | verify :xhr => true, |
|
38 | :session => :page_layout, | |
|
39 | 38 | :only => [:add_block, :remove_block, :order_blocks] |
|
40 | 39 | |
|
41 | 40 | def index |
@@ -109,8 +108,6 class MyController < ApplicationController | |||
|
109 | 108 | def page_layout |
|
110 | 109 | @user = User.current |
|
111 | 110 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
|
112 | session[:page_layout] = @blocks | |
|
113 | %w(top left right).each {|f| session[:page_layout][f] ||= [] } | |
|
114 | 111 | @block_options = [] |
|
115 | 112 | BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} |
|
116 | 113 | end |
@@ -122,10 +119,13 class MyController < ApplicationController | |||
|
122 | 119 | block = params[:block].to_s.underscore |
|
123 | 120 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) |
|
124 | 121 | @user = User.current |
|
122 | layout = @user.pref[:my_page_layout] || {} | |
|
125 | 123 | # remove if already present in a group |
|
126 |
%w(top left right).each {|f| ( |
|
|
124 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
127 | 125 | # add it on top |
|
128 |
|
|
|
126 | layout['top'].unshift block | |
|
127 | @user.pref[:my_page_layout] = layout | |
|
128 | @user.pref.save | |
|
129 | 129 | render :partial => "block", :locals => {:user => @user, :block_name => block} |
|
130 | 130 | end |
|
131 | 131 | |
@@ -133,8 +133,12 class MyController < ApplicationController | |||
|
133 | 133 | # params[:block] : id of the block to remove |
|
134 | 134 | def remove_block |
|
135 | 135 | block = params[:block].to_s.underscore |
|
136 | @user = User.current | |
|
136 | 137 | # remove block in all groups |
|
137 | %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } | |
|
138 | layout = @user.pref[:my_page_layout] || {} | |
|
139 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
140 | @user.pref[:my_page_layout] = layout | |
|
141 | @user.pref.save | |
|
138 | 142 | render :nothing => true |
|
139 | 143 | end |
|
140 | 144 | |
@@ -143,25 +147,20 class MyController < ApplicationController | |||
|
143 | 147 | # params[:list-(top|left|right)] : array of block ids of the group |
|
144 | 148 | def order_blocks |
|
145 | 149 | group = params[:group] |
|
150 | @user = User.current | |
|
146 | 151 | if group.is_a?(String) |
|
147 | 152 | group_items = (params["list-#{group}"] || []).collect(&:underscore) |
|
148 | 153 | if group_items and group_items.is_a? Array |
|
154 | layout = @user.pref[:my_page_layout] || {} | |
|
149 | 155 | # remove group blocks if they are presents in other groups |
|
150 | 156 | %w(top left right).each {|f| |
|
151 |
|
|
|
157 | layout[f] = (layout[f] || []) - group_items | |
|
152 | 158 | } |
|
153 |
|
|
|
159 | layout[group] = group_items | |
|
160 | @user.pref[:my_page_layout] = layout | |
|
161 | @user.pref.save | |
|
154 | 162 | end |
|
155 | 163 | end |
|
156 | 164 | render :nothing => true |
|
157 | 165 | end |
|
158 | ||
|
159 | # Save user's page layout | |
|
160 | def page_layout_save | |
|
161 | @user = User.current | |
|
162 | @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout] | |
|
163 | @user.pref.save | |
|
164 | session[:page_layout] = nil | |
|
165 | redirect_to :action => 'page' | |
|
166 | end | |
|
167 | 166 | end |
@@ -46,8 +46,7 function removeBlock(block) { | |||
|
46 | 46 | }, :class => 'icon icon-add' |
|
47 | 47 | %> |
|
48 | 48 | <% end %> |
|
49 |
<%= link_to l(:button_ |
|
|
50 | <%= link_to l(:button_cancel), {:action => 'page'}, :class => 'icon icon-cancel' %> | |
|
49 | <%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %> | |
|
51 | 50 | </div> |
|
52 | 51 | |
|
53 | 52 | <h2><%=l(:label_my_page)%></h2> |
@@ -4,11 +4,10 user_preferences_001: | |||
|
4 | 4 | --- |
|
5 | 5 | :my_page_layout: |
|
6 | 6 | left: |
|
7 |
- latest |
|
|
7 | - latestnews | |
|
8 | 8 | - documents |
|
9 | 9 | right: |
|
10 |
- issues |
|
|
11 | - issues_reported_by_me | |
|
10 | - issuesassignedtome | |
|
12 | 11 | top: |
|
13 | 12 | - calendar |
|
14 | 13 | |
@@ -16,9 +15,17 user_preferences_001: | |||
|
16 | 15 | user_id: 1 |
|
17 | 16 | hide_mail: true |
|
18 | 17 | user_preferences_002: |
|
19 |
others: | |
|
|
20 |
--- |
|
|
21 | ||
|
18 | others: | | |
|
19 | --- | |
|
20 | :my_page_layout: | |
|
21 | left: | |
|
22 | - latestnews | |
|
23 | - documents | |
|
24 | right: | |
|
25 | - issuesassignedtome | |
|
26 | top: | |
|
27 | - calendar | |
|
28 | ||
|
22 | 29 | id: 2 |
|
23 | 30 | user_id: 3 |
|
24 | 31 | hide_mail: false No newline at end of file |
@@ -22,7 +22,7 require 'my_controller' | |||
|
22 | 22 | class MyController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class MyControllerTest < ActionController::TestCase |
|
25 | fixtures :users, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields | |
|
25 | fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields | |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = MyController.new |
@@ -105,4 +105,28 class MyControllerTest < ActionController::TestCase | |||
|
105 | 105 | assert_redirected_to 'my/account' |
|
106 | 106 | assert User.try_to_login('jsmith', 'hello') |
|
107 | 107 | end |
|
108 | ||
|
109 | def test_page_layout | |
|
110 | get :page_layout | |
|
111 | assert_response :success | |
|
112 | assert_template 'page_layout' | |
|
113 | end | |
|
114 | ||
|
115 | def test_add_block | |
|
116 | xhr :post, :add_block, :block => 'issuesreportedbyme' | |
|
117 | assert_response :success | |
|
118 | assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme') | |
|
119 | end | |
|
120 | ||
|
121 | def test_remove_block | |
|
122 | xhr :post, :remove_block, :block => 'issuesassignedtome' | |
|
123 | assert_response :success | |
|
124 | assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome') | |
|
125 | end | |
|
126 | ||
|
127 | def test_order_blocks | |
|
128 | xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews'] | |
|
129 | assert_response :success | |
|
130 | assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] | |
|
131 | end | |
|
108 | 132 | end |
General Comments 0
You need to be logged in to leave comments.
Login now