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
# Show user's page
def page
@user = User.current
@groups = @user.pref.my_page_groups
@blocks = @user.pref.my_page_layout
end
......@@ -178,14 +179,8 @@ class MyController < ApplicationController
# params[:blocks] : array of block ids of the group
def order_blocks
@user = User.current
group = params[:group].to_s
if %w(top left right).include? group
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
@user.pref.order_blocks params[:group], params[:blocks]
@user.pref.save
head 200
end
end
......@@ -88,6 +88,14 @@ class UserPreference < ActiveRecord::Base
def textarea_font; self[:textarea_font] 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
self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
end
......@@ -110,10 +118,12 @@ class UserPreference < ActiveRecord::Base
end
# Removes block from the user page layout
# Example:
# preferences.remove_block('news')
def remove_block(block)
block = block.to_s.underscore
%w(top left right).each do |f|
(my_page_layout[f] ||= []).delete(block)
my_page_layout.keys.each do |group|
my_page_layout[group].delete(block)
end
my_page_layout
end
......@@ -126,9 +136,22 @@ class UserPreference < ActiveRecord::Base
return unless Redmine::MyPage.valid_block?(block, my_page_layout.values.flatten)
remove_block(block)
# add it on top
my_page_layout['top'] ||= []
my_page_layout['top'].unshift(block)
# add it to the first group
group = my_page_groups.first
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
def update_block_settings(block, settings)
......
......@@ -8,17 +8,11 @@
<h2><%=l(:label_my_page)%></h2>
<div id="my-page">
<div id="list-top" class="block-receiver">
<%= render_blocks(@blocks['top'], @user) %>
</div>
<div id="list-left" class="splitcontentleft block-receiver">
<%= render_blocks(@blocks['left'], @user) %>
</div>
<div id="list-right" class="splitcontentright block-receiver">
<%= render_blocks(@blocks['right'], @user) %>
</div>
<% @groups.each do |group| %>
<div id="list-<%= group %>" class="block-receiver">
<%= render_blocks(@blocks[group], @user) %>
</div>
<% end %>
</div>
<%= context_menu %>
......@@ -26,7 +20,7 @@
<%= javascript_tag do %>
$(document).ready(function(){
$('#block-select').val('');
$('#list-top, #list-left, #list-right').sortable({
$('.block-receiver').sortable({
connectWith: '.block-receiver',
tolerance: 'pointer',
handle: '.sort-handle',
......
......@@ -19,6 +19,8 @@ module Redmine
module MyPage
include Redmine::I18n
CORE_GROUPS = ['top', 'left', 'right']
CORE_BLOCKS = {
'issuesassignedtome' => {:label => :label_assigned_to_me_issues},
'issuesreportedbyme' => {:label => :label_reported_issues},
......@@ -30,6 +32,10 @@ module Redmine
'timelog' => {:label => :label_spent_time}
}
def self.groups
CORE_GROUPS.dup.freeze
end
# Returns the available blocks
def self.blocks
CORE_BLOCKS.merge(additional_blocks).freeze
......
......@@ -428,8 +428,8 @@ div.square {
.message .contextual { margin-top: 0; }
.splitcontent {overflow:auto;}
.splitcontentleft{float:left; width:49%;}
.splitcontentright{float:right; width:49%;}
.splitcontentleft, #list-left {float:left; width:49%;}
.splitcontentright, #list-right {float:right; width:49%;}
form {display: inline;}
input, select {vertical-align: middle; margin-top: 1px; margin-bottom: 1px;}
input[type="submit"] { -webkit-appearance: button; }
......
......@@ -217,11 +217,11 @@
display: none;
}
.splitcontentleft {
.splitcontentleft, #list-left {
width: 100%;
}
.splitcontentright {
.splitcontentright, #list-right {
width: 100%;
}
......
......@@ -411,9 +411,23 @@ class MyControllerTest < Redmine::ControllerTest
end
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_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
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