@@ -140,52 +140,34 class MyController < ApplicationController | |||
|
140 | 140 | # The block is added on top of the page |
|
141 | 141 | # params[:block] : id of the block to add |
|
142 | 142 | def add_block |
|
143 | block = params[:block].to_s.underscore | |
|
144 | if block.present? && Redmine::MyPage.blocks.key?(block) | |
|
145 | @user = User.current | |
|
146 | layout = @user.pref.my_page_layout | |
|
147 | # remove if already present in a group | |
|
148 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
149 | # add it on top | |
|
150 | layout['top'].unshift block | |
|
151 | @user.pref.my_page_layout = layout | |
|
152 | @user.pref.save | |
|
153 | end | |
|
143 | @user = User.current | |
|
144 | @user.pref.add_block params[:block] | |
|
145 | @user.pref.save | |
|
154 | 146 | redirect_to my_page_layout_path |
|
155 | 147 | end |
|
156 | 148 | |
|
157 | 149 | # Remove a block to user's page |
|
158 | 150 | # params[:block] : id of the block to remove |
|
159 | 151 | def remove_block |
|
160 | block = params[:block].to_s.underscore | |
|
161 | 152 | @user = User.current |
|
162 | # remove block in all groups | |
|
163 | layout = @user.pref.my_page_layout | |
|
164 | %w(top left right).each {|f| (layout[f] ||= []).delete block } | |
|
165 | @user.pref.my_page_layout = layout | |
|
153 | @user.pref.remove_block params[:block] | |
|
166 | 154 | @user.pref.save |
|
167 | 155 | redirect_to my_page_layout_path |
|
168 | 156 | end |
|
169 | 157 | |
|
170 | 158 | # Change blocks order on user's page |
|
171 | 159 | # params[:group] : group to order (top, left or right) |
|
172 |
# params[: |
|
|
160 | # params[:blocks] : array of block ids of the group | |
|
173 | 161 | def order_blocks |
|
174 | 162 | group = params[:group] |
|
175 | 163 | @user = User.current |
|
176 | 164 | if group.is_a?(String) |
|
177 | 165 | group_items = (params["blocks"] || []).collect(&:underscore) |
|
178 | 166 | group_items.each {|s| s.sub!(/^block_/, '')} |
|
179 | if group_items and group_items.is_a? Array | |
|
180 | layout = @user.pref.my_page_layout | |
|
181 | # remove group blocks if they are presents in other groups | |
|
182 | %w(top left right).each {|f| | |
|
183 | layout[f] = (layout[f] || []) - group_items | |
|
184 | } | |
|
185 | layout[group] = group_items | |
|
186 | @user.pref.my_page_layout = layout | |
|
187 | @user.pref.save | |
|
188 | end | |
|
167 | # remove group blocks if they are presents in other groups | |
|
168 | group_items.each {|s| @user.pref.remove_block(s)} | |
|
169 | @user.pref.my_page_layout[group] = group_items | |
|
170 | @user.pref.save | |
|
189 | 171 | end |
|
190 | 172 | head 200 |
|
191 | 173 | end |
@@ -90,4 +90,22 class UserPreference < ActiveRecord::Base | |||
|
90 | 90 | def my_page_layout=(arg) |
|
91 | 91 | self[:my_page_layout] = arg |
|
92 | 92 | end |
|
93 | ||
|
94 | def remove_block(block) | |
|
95 | block = block.to_s.underscore | |
|
96 | %w(top left right).each do |f| | |
|
97 | (my_page_layout[f] ||= []).delete(block) | |
|
98 | end | |
|
99 | my_page_layout | |
|
100 | end | |
|
101 | ||
|
102 | def add_block(block) | |
|
103 | block = block.to_s.underscore | |
|
104 | return unless Redmine::MyPage.blocks.key?(block) | |
|
105 | ||
|
106 | remove_block(block) | |
|
107 | # add it on top | |
|
108 | my_page_layout['top'] ||= [] | |
|
109 | my_page_layout['top'].unshift(block) | |
|
110 | end | |
|
93 | 111 | end |
General Comments 0
You need to be logged in to leave comments.
Login now