From f9eaeaf4512d02a2bc790feb434f20b04afb1b19 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 29 Oct 2016 08:10:19 +0000 Subject: [PATCH] Adds helpers for rendering my page blocks. git-svn-id: http://svn.redmine.org/redmine/trunk@15927 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/my_helper.rb | 35 ++++++++++++++++++++++++++++++ app/views/my/_block.html.erb | 10 --------- app/views/my/page.html.erb | 21 +++--------------- app/views/my/page_layout.html.erb | 15 +++---------- public/stylesheets/application.css | 4 ++++ 5 files changed, 45 insertions(+), 40 deletions(-) delete mode 100644 app/views/my/_block.html.erb diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb index 4942d7e04..c7cf53499 100644 --- a/app/helpers/my_helper.rb +++ b/app/helpers/my_helper.rb @@ -18,6 +18,41 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module MyHelper + # Renders the blocks + def render_blocks(blocks, user, options={}) + s = ''.html_safe + + if blocks.present? + blocks.each do |block| + content = render_block_content(block, user) + if content.present? + if options[:edit] + close = link_to("", {:action => "remove_block", :block => block}, :method => 'post', :class => "close-icon") + content = close + content_tag('div', content, :class => 'handle') + end + + s << content_tag('div', content, :class => "mypage-box", :id => "block-#{block}") + end + end + end + s + end + + # Renders a single block content + def render_block_content(block, user) + unless MyController::BLOCKS.keys.include?(block) + Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") + return + end + + begin + render(:partial => "my/blocks/#{block}", :locals => {:user => user}) + rescue ActionView::MissingTemplate + Rails.logger.warn("Template missing for block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") + return nil + end + end + def calendar_items(startdt, enddt) Issue.visible. where(:project_id => User.current.projects.map(&:id)). diff --git a/app/views/my/_block.html.erb b/app/views/my/_block.html.erb deleted file mode 100644 index 813eb2b88..000000000 --- a/app/views/my/_block.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
- -
- <%= link_to "", {:action => "remove_block", :block => block_name}, :method => 'post', :class => "close-icon" %> -
- -
- <%= render :partial => "my/blocks/#{block_name}", :locals => { :user => user } %> -
-
diff --git a/app/views/my/page.html.erb b/app/views/my/page.html.erb index 819dddeaf..87c6e4c56 100644 --- a/app/views/my/page.html.erb +++ b/app/views/my/page.html.erb @@ -5,30 +5,15 @@

<%=l(:label_my_page)%>

- <% @blocks['top'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> -
- <%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %> -
- <% end if @blocks['top'] %> + <%= render_blocks(@blocks['top'], @user) %>
- <% @blocks['left'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> -
- <%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %> -
- <% end if @blocks['left'] %> + <%= render_blocks(@blocks['left'], @user) %>
- <% @blocks['right'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> -
- <%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %> -
- <% end if @blocks['right'] %> + <%= render_blocks(@blocks['right'], @user) %>
<%= context_menu issues_context_menu_path %> diff --git a/app/views/my/page_layout.html.erb b/app/views/my/page_layout.html.erb index 4a60d97e1..70bf835fb 100644 --- a/app/views/my/page_layout.html.erb +++ b/app/views/my/page_layout.html.erb @@ -14,24 +14,15 @@

<%=l(:label_my_page)%>

- <% @blocks['top'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> - <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> - <% end if @blocks['top'] %> + <%= render_blocks(@blocks['top'], @user, :edit => true) %>
- <% @blocks['left'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> - <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> - <% end if @blocks['left'] %> + <%= render_blocks(@blocks['left'], @user, :edit => true) %>
- <% @blocks['right'].each do |b| - next unless MyController::BLOCKS.keys.include? b %> - <%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %> - <% end if @blocks['right'] %> + <%= render_blocks(@blocks['right'], @user, :edit => true) %>
<%= javascript_tag "initMyPageSortable('top', '#{ escape_javascript url_for(:action => "order_blocks", :group => "top") }');" %> diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 34559cffb..6ec614edf 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1077,6 +1077,10 @@ div.wiki img {vertical-align:middle; max-width:100%;} color:#505050; line-height:1.5em; } +.mypage-box .close-icon { + float:right; + z-index:500; +} .handle {cursor: move;} -- 2.39.5