diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-04 17:17:47 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-04 17:17:47 +0000 |
commit | 88a3a351d08b5446317c1813cf2b966aa5f716fb (patch) | |
tree | 169a31dda9d70770d0c63337e93c6f1b27617851 /app/models/user_preference.rb | |
parent | b9ee00a8c8ba2fe2b32eb33d299d4764ebc2968b (diff) | |
download | redmine-88a3a351d08b5446317c1813cf2b966aa5f716fb.tar.gz redmine-88a3a351d08b5446317c1813cf2b966aa5f716fb.zip |
Don't hardcode the groups on My page.
git-svn-id: http://svn.redmine.org/redmine/trunk@16475 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/user_preference.rb')
-rw-r--r-- | app/models/user_preference.rb | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 836ad3978..861cf9323 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -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) |