Commit f36c32d1 authored by jplang's avatar jplang

Don't hardcode the groups on My page.

git-svn-id: https://svn.redmine.org/redmine/trunk@16475 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent dcb9cade
...@@ -37,6 +37,7 @@ class MyController < ApplicationController ...@@ -37,6 +37,7 @@ class MyController < ApplicationController
# Show user's page # Show user's page
def page def page
@user = User.current @user = User.current
@groups = @user.pref.my_page_groups
@blocks = @user.pref.my_page_layout @blocks = @user.pref.my_page_layout
end end
...@@ -178,14 +179,8 @@ class MyController < ApplicationController ...@@ -178,14 +179,8 @@ class MyController < ApplicationController
# params[:blocks] : array of block ids of the group # params[:blocks] : array of block ids of the group
def order_blocks def order_blocks
@user = User.current @user = User.current
group = params[:group].to_s @user.pref.order_blocks params[:group], params[:blocks]
if %w(top left right).include? group @user.pref.save
group_items = (params[:blocks] || []).collect(&:underscore)
# remove group blocks if they are presents in other groups
group_items.each {|s| @user.pref.remove_block(s)}
@user.pref.my_page_layout[group] = group_items
@user.pref.save
end
head 200 head 200
end end
end end
...@@ -88,6 +88,14 @@ class UserPreference < ActiveRecord::Base ...@@ -88,6 +88,14 @@ class UserPreference < ActiveRecord::Base
def textarea_font; self[:textarea_font] end def textarea_font; self[:textarea_font] end
def textarea_font=(value); self[:textarea_font]=value; end def textarea_font=(value); self[:textarea_font]=value; end
# Returns the names of groups that are displayed on user's page
# Example:
# preferences.my_page_groups
# # => ['top', 'left, 'right']
def my_page_groups
Redmine::MyPage.groups
end
def my_page_layout def my_page_layout
self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
end end
...@@ -110,10 +118,12 @@ class UserPreference < ActiveRecord::Base ...@@ -110,10 +118,12 @@ class UserPreference < ActiveRecord::Base
end end
# Removes block from the user page layout # Removes block from the user page layout
# Example:
# preferences.remove_block('news')
def remove_block(block) def remove_block(block)
block = block.to_s.underscore block = block.to_s.underscore
%w(top left right).each do |f| my_page_layout.keys.each do |group|
(my_page_layout[f] ||= []).delete(block) my_page_layout[group].delete(block)
end end
my_page_layout my_page_layout
end end
...@@ -126,9 +136,22 @@ class UserPreference < ActiveRecord::Base ...@@ -126,9 +136,22 @@ class UserPreference < ActiveRecord::Base
return unless Redmine::MyPage.valid_block?(block, my_page_layout.values.flatten) return unless Redmine::MyPage.valid_block?(block, my_page_layout.values.flatten)
remove_block(block) remove_block(block)
# add it on top # add it to the first group
my_page_layout['top'] ||= [] group = my_page_groups.first
my_page_layout['top'].unshift(block) my_page_layout[group] ||= []
my_page_layout[group].unshift(block)
end
# Sets the block order for the given group.
# Example:
# preferences.order_blocks('left', ['issueswatched', 'news'])
def order_blocks(group, blocks)
group = group.to_s
if Redmine::MyPage.groups.include?(group) && blocks.present?
blocks = blocks.map(&:underscore) & my_page_layout.values.flatten
blocks.each {|block| remove_block(block)}
my_page_layout[group] = blocks
end
end end
def update_block_settings(block, settings) def update_block_settings(block, settings)
......
...@@ -8,17 +8,11 @@ ...@@ -8,17 +8,11 @@
<h2><%=l(:label_my_page)%></h2> <h2><%=l(:label_my_page)%></h2>
<div id="my-page"> <div id="my-page">
<div id="list-top" class="block-receiver"> <% @groups.each do |group| %>
<%= render_blocks(@blocks['top'], @user) %> <div id="list-<%= group %>" class="block-receiver">
</div> <%= render_blocks(@blocks[group], @user) %>
</div>
<div id="list-left" class="splitcontentleft block-receiver"> <% end %>
<%= render_blocks(@blocks['left'], @user) %>
</div>
<div id="list-right" class="splitcontentright block-receiver">
<%= render_blocks(@blocks['right'], @user) %>
</div>
</div> </div>
<%= context_menu %> <%= context_menu %>
...@@ -26,7 +20,7 @@ ...@@ -26,7 +20,7 @@
<%= javascript_tag do %> <%= javascript_tag do %>
$(document).ready(function(){ $(document).ready(function(){
$('#block-select').val(''); $('#block-select').val('');
$('#list-top, #list-left, #list-right').sortable({ $('.block-receiver').sortable({
connectWith: '.block-receiver', connectWith: '.block-receiver',
tolerance: 'pointer', tolerance: 'pointer',
handle: '.sort-handle', handle: '.sort-handle',
......
...@@ -19,6 +19,8 @@ module Redmine ...@@ -19,6 +19,8 @@ module Redmine
module MyPage module MyPage
include Redmine::I18n include Redmine::I18n
CORE_GROUPS = ['top', 'left', 'right']
CORE_BLOCKS = { CORE_BLOCKS = {
'issuesassignedtome' => {:label => :label_assigned_to_me_issues}, 'issuesassignedtome' => {:label => :label_assigned_to_me_issues},
'issuesreportedbyme' => {:label => :label_reported_issues}, 'issuesreportedbyme' => {:label => :label_reported_issues},
...@@ -30,6 +32,10 @@ module Redmine ...@@ -30,6 +32,10 @@ module Redmine
'timelog' => {:label => :label_spent_time} 'timelog' => {:label => :label_spent_time}
} }
def self.groups
CORE_GROUPS.dup.freeze
end
# Returns the available blocks # Returns the available blocks
def self.blocks def self.blocks
CORE_BLOCKS.merge(additional_blocks).freeze CORE_BLOCKS.merge(additional_blocks).freeze
......
...@@ -428,8 +428,8 @@ div.square { ...@@ -428,8 +428,8 @@ div.square {
.message .contextual { margin-top: 0; } .message .contextual { margin-top: 0; }
.splitcontent {overflow:auto;} .splitcontent {overflow:auto;}
.splitcontentleft{float:left; width:49%;} .splitcontentleft, #list-left {float:left; width:49%;}
.splitcontentright{float:right; width:49%;} .splitcontentright, #list-right {float:right; width:49%;}
form {display: inline;} form {display: inline;}
input, select {vertical-align: middle; margin-top: 1px; margin-bottom: 1px;} input, select {vertical-align: middle; margin-top: 1px; margin-bottom: 1px;}
input[type="submit"] { -webkit-appearance: button; } input[type="submit"] { -webkit-appearance: button; }
......
...@@ -217,11 +217,11 @@ ...@@ -217,11 +217,11 @@
display: none; display: none;
} }
.splitcontentleft { .splitcontentleft, #list-left {
width: 100%; width: 100%;
} }
.splitcontentright { .splitcontentright, #list-right {
width: 100%; width: 100%;
} }
......
...@@ -411,9 +411,23 @@ class MyControllerTest < Redmine::ControllerTest ...@@ -411,9 +411,23 @@ class MyControllerTest < Redmine::ControllerTest
end end
def test_order_blocks def test_order_blocks
xhr :post, :order_blocks, :group => 'left', 'blocks' => ['documents', 'calendar', 'latestnews'] pref = User.find(2).pref
pref.my_page_layout = {'left' => ['news', 'calendar','documents']}
pref.save!
xhr :post, :order_blocks, :group => 'left', :blocks => ['documents', 'calendar', 'news']
assert_response :success assert_response :success
assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left'] assert_equal ['documents', 'calendar', 'news'], User.find(2).pref.my_page_layout['left']
end
def test_move_block
pref = User.find(2).pref
pref.my_page_layout = {'left' => ['news','documents'], 'right' => ['calendar']}
pref.save!
xhr :post, :order_blocks, :group => 'left', :blocks => ['news', 'calendar', 'documents']
assert_response :success
assert_equal({'left' => ['news', 'calendar', 'documents'], 'right' => []}, User.find(2).pref.my_page_layout)
end end
def test_reset_rss_key_with_existing_key def test_reset_rss_key_with_existing_key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment