summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-29 10:10:31 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-29 10:10:31 +0000
commit8b86d5158e50d27de68a3c69c12b06e1af0deb52 (patch)
tree724ac0a770438aa579d94a77b6855361a329274c
parent6ef3ecc030cfc744244bb15db2f2ef0eb46ed439 (diff)
downloadredmine-8b86d5158e50d27de68a3c69c12b06e1af0deb52.tar.gz
redmine-8b86d5158e50d27de68a3c69c12b06e1af0deb52.zip
Moves blocks definition to Redmine::MyPage.
git-svn-id: http://svn.redmine.org/redmine/trunk@15930 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/my_controller.rb37
-rw-r--r--app/helpers/my_helper.rb11
-rw-r--r--app/models/user_preference.rb8
-rw-r--r--app/views/my/page_layout.html.erb9
-rw-r--r--lib/redmine/my_page.rb62
-rw-r--r--lib/redmine/views/my_page/block.rb32
-rw-r--r--test/functional/my_controller_test.rb2
7 files changed, 93 insertions, 68 deletions
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 73ac2222c..6e328c270 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -27,19 +27,6 @@ class MyController < ApplicationController
helper :users
helper :custom_fields
- BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
- 'issuesreportedbyme' => :label_reported_issues,
- 'issueswatched' => :label_watched_issues,
- 'news' => :label_news_latest,
- 'calendar' => :label_calendar,
- 'documents' => :label_document_plural,
- 'timelog' => :label_spent_time
- }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
-
- DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
- 'right' => ['issuesreportedbyme']
- }.freeze
-
def index
page
render :action => 'page'
@@ -48,7 +35,7 @@ class MyController < ApplicationController
# Show user's page
def page
@user = User.current
- @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
+ @blocks = @user.pref.my_page_layout
end
# Edit user's account
@@ -146,13 +133,7 @@ class MyController < ApplicationController
# User's page layout configuration
def page_layout
@user = User.current
- @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
- @block_options = []
- BLOCKS.each do |k, v|
- unless @blocks.values.flatten.include?(k)
- @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
- end
- end
+ @blocks = @user.pref.my_page_layout
end
# Add a block to user's page
@@ -160,14 +141,14 @@ class MyController < ApplicationController
# params[:block] : id of the block to add
def add_block
block = params[:block].to_s.underscore
- if block.present? && BLOCKS.key?(block)
+ if block.present? && Redmine::MyPage.blocks.key?(block)
@user = User.current
- layout = @user.pref[:my_page_layout] || {}
+ layout = @user.pref.my_page_layout
# remove if already present in a group
%w(top left right).each {|f| (layout[f] ||= []).delete block }
# add it on top
layout['top'].unshift block
- @user.pref[:my_page_layout] = layout
+ @user.pref.my_page_layout = layout
@user.pref.save
end
redirect_to my_page_layout_path
@@ -179,9 +160,9 @@ class MyController < ApplicationController
block = params[:block].to_s.underscore
@user = User.current
# remove block in all groups
- layout = @user.pref[:my_page_layout] || {}
+ layout = @user.pref.my_page_layout
%w(top left right).each {|f| (layout[f] ||= []).delete block }
- @user.pref[:my_page_layout] = layout
+ @user.pref.my_page_layout = layout
@user.pref.save
redirect_to my_page_layout_path
end
@@ -196,13 +177,13 @@ class MyController < ApplicationController
group_items = (params["blocks"] || []).collect(&:underscore)
group_items.each {|s| s.sub!(/^block_/, '')}
if group_items and group_items.is_a? Array
- layout = @user.pref[:my_page_layout] || {}
+ layout = @user.pref.my_page_layout
# remove group blocks if they are presents in other groups
%w(top left right).each {|f|
layout[f] = (layout[f] || []) - group_items
}
layout[group] = group_items
- @user.pref[:my_page_layout] = layout
+ @user.pref.my_page_layout = layout
@user.pref.save
end
end
diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb
index 23e738977..b3e4e02b7 100644
--- a/app/helpers/my_helper.rb
+++ b/app/helpers/my_helper.rb
@@ -40,7 +40,7 @@ module MyHelper
# Renders a single block content
def render_block_content(block, user)
- unless MyController::BLOCKS.keys.include?(block)
+ unless Redmine::MyPage.blocks.key?(block)
Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
return
end
@@ -53,6 +53,15 @@ module MyHelper
end
end
+ def block_select_tag(user)
+ disabled = user.pref.my_page_layout.values.flatten
+ options = content_tag('option')
+ Redmine::MyPage.block_options.each do |label, block|
+ options << content_tag('option', label, :value => block, :disabled => disabled.include?(block))
+ end
+ content_tag('select', options, :id => "block-select")
+ end
+
def calendar_items(startdt, enddt)
Issue.visible.
where(:project_id => User.current.projects.map(&:id)).
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 4a07e990c..bf54e5a5b 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -82,4 +82,12 @@ class UserPreference < ActiveRecord::Base
def textarea_font; self[:textarea_font] end
def textarea_font=(value); self[:textarea_font]=value; end
+
+ def my_page_layout
+ self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
+ end
+
+ def my_page_layout=(arg)
+ self[:my_page_layout] = arg
+ end
end
diff --git a/app/views/my/page_layout.html.erb b/app/views/my/page_layout.html.erb
index 70bf835fb..690aa25a8 100644
--- a/app/views/my/page_layout.html.erb
+++ b/app/views/my/page_layout.html.erb
@@ -1,12 +1,9 @@
<div class="contextual">
-<% if @block_options.present? %>
- <%= form_tag({:action => "add_block"}, :id => "block-form") do %>
+
+<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
<%= label_tag('block-select', l(:label_my_page_block)) %>:
- <%= select_tag 'block',
- content_tag('option') + options_for_select(@block_options),
- :id => "block-select" %>
+ <%= block_select_tag(@user) %>
<%= link_to l(:button_add), '#', :onclick => '$("#block-form").submit()', :class => 'icon icon-add' %>
- <% end %>
<% end %>
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
</div>
diff --git a/lib/redmine/my_page.rb b/lib/redmine/my_page.rb
new file mode 100644
index 000000000..0c11459e4
--- /dev/null
+++ b/lib/redmine/my_page.rb
@@ -0,0 +1,62 @@
+# Redmine - project management software
+# Copyright (C) 2006-2016 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module Redmine
+ module MyPage
+ include Redmine::I18n
+
+ CORE_BLOCKS = {
+ 'issuesassignedtome' => :label_assigned_to_me_issues,
+ 'issuesreportedbyme' => :label_reported_issues,
+ 'issueswatched' => :label_watched_issues,
+ 'news' => :label_news_latest,
+ 'calendar' => :label_calendar,
+ 'documents' => :label_document_plural,
+ 'timelog' => :label_spent_time
+ }
+
+ # Returns the available blocks
+ def self.blocks
+ CORE_BLOCKS.merge(additional_blocks).freeze
+ end
+
+ def self.block_options
+ options = []
+ blocks.each do |k, v|
+ options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
+ end
+ options
+ end
+
+ # Returns the additional blocks that are defined by plugin partials
+ def self.additional_blocks
+ @@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
+ name = File.basename(file).split('.').first.gsub(/^_/, '')
+ h[name] = name.to_sym
+ h
+ end
+ end
+
+ # Returns the default layout for My Page
+ def self.default_layout
+ {
+ 'left' => ['issuesassignedtome'],
+ 'right' => ['issuesreportedbyme']
+ }
+ end
+ end
+end
diff --git a/lib/redmine/views/my_page/block.rb b/lib/redmine/views/my_page/block.rb
deleted file mode 100644
index 07398d788..000000000
--- a/lib/redmine/views/my_page/block.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# Redmine - project management software
-# Copyright (C) 2006-2016 Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-module Redmine
- module Views
- module MyPage
- module Block
- def self.additional_blocks
- @@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
- name = File.basename(file).split('.').first.gsub(/^_/, '')
- h[name] = name.to_sym
- h
- end
- end
- end
- end
- end
-end
diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb
index 41d9171b7..b64b311a2 100644
--- a/test/functional/my_controller_test.rb
+++ b/test/functional/my_controller_test.rb
@@ -52,7 +52,7 @@ class MyControllerTest < Redmine::ControllerTest
end
def test_page_with_all_blocks
- blocks = MyController::BLOCKS.keys
+ blocks = Redmine::MyPage.blocks.keys
preferences = User.find(2).pref
preferences[:my_page_layout] = {'top' => blocks}
preferences.save!