Changed looking for my page blocks to not happen at class

load time
pull/408/head
Sebastian Schuster 11 years ago
parent 9ace5fd0b2
commit 512ce70af0
  1. 13
      app/controllers/my_controller.rb
  2. 6
      app/views/my/page.html.erb
  3. 6
      app/views/my/page_layout.html.erb
  4. 2
      features/step_definitions/my_page_steps.rb

@ -18,13 +18,13 @@ class MyController < ApplicationController
menu_item :account, :only => [:account]
menu_item :password, :only => [:password]
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_work_packages,
DEFAULT_BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_work_packages,
'issuesreportedbyme' => :label_reported_work_packages,
'issueswatched' => :label_watched_work_packages,
'news' => :label_news_latest,
'calendar' => :label_calendar,
'timelog' => :label_spent_time
}.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
}.freeze
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
'right' => ['issuesreportedbyme']
@ -33,6 +33,11 @@ class MyController < ApplicationController
verify :xhr => true,
:only => [:add_block, :remove_block, :order_blocks]
def self.available_blocks
@available_blocks ||= DEFAULT_BLOCKS.merge(Redmine::Views::MyPage::Block.additional_blocks)
end
# Show user's page
def index
@user = User.current
@ -131,7 +136,7 @@ class MyController < ApplicationController
@user = User.current
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
@block_options = []
BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
MyController.available_blocks.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
end
# Add a block to user's page
@ -139,7 +144,7 @@ class MyController < ApplicationController
# params[:block] : id of the block to add
def add_block
block = params[:block].to_s.underscore
(render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
(render :nothing => true; return) unless block && (MyController.available_blocks.keys.include? block)
@user = User.current
layout = @user.pref[:my_page_layout] || {}
# remove if already present in a group

@ -19,7 +19,7 @@ See doc/COPYRIGHT.rdoc for more details.
<div id="list-top">
<% @blocks['top'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<div class="mypage-box">
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
</div>
@ -28,7 +28,7 @@ See doc/COPYRIGHT.rdoc for more details.
<div id="list-left" class="splitcontentleft">
<% @blocks['left'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<div class="mypage-box">
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
</div>
@ -37,7 +37,7 @@ See doc/COPYRIGHT.rdoc for more details.
<div id="list-right" class="splitcontentright">
<% @blocks['right'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<div class="mypage-box">
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
</div>

@ -66,21 +66,21 @@ function removeBlock(block) {
<div id="list-top" class="block-receiver">
<% @blocks['top'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
<% end if @blocks['top'] %>
</div>
<div id="list-left" class="splitcontentleft block-receiver">
<% @blocks['left'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
<% end if @blocks['left'] %>
</div>
<div id="list-right" class="splitcontentright block-receiver">
<% @blocks['right'].each do |b|
next unless MyController::BLOCKS.keys.include? b %>
next unless MyController.available_blocks.keys.include? b %>
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
<% end if @blocks['right'] %>
</div>

@ -26,7 +26,7 @@ Then(/^I should see the widget "([^"]*)"$/) do |arg|
end
Then /^"(.+)" should be disabled in the my page available widgets drop down$/ do |widget_name|
option_name = MyController::BLOCKS.detect{|k, v| I18n.t(v) == widget_name}.first.dasherize
option_name = MyController.available_blocks.detect{|k, v| I18n.t(v) == widget_name}.first.dasherize
steps %Q{Then the "block-select" drop-down should have the following options disabled:
| #{option_name} |}

Loading…
Cancel
Save