From c47e2ba3715efa61e1e750123d70ca598a912789 Mon Sep 17 00:00:00 2001 From: Moises Machado Date: Thu, 12 Feb 2009 12:15:28 -0300 Subject: [PATCH] ActionItem741: now blocks can be hidden --- app/controllers/box_organizer_controller.rb | 7 +++++++ app/helpers/boxes_helper.rb | 12 ++++++++++-- app/models/block.rb | 11 +++++++++++ public/designs/icons/default/eyes.png | Bin 0 -> 801 bytes public/designs/icons/default/style.css | 1 + public/images/hachure.png | Bin 0 -> 233 bytes public/stylesheets/blocks.css | 9 +++++++++ test/functional/application_controller_test.rb | 13 +++++++++++++ test/functional/profile_design_controller_test.rb | 9 +++++++++ test/unit/block_test.rb | 8 +++++++- test/unit/boxes_helper_test.rb | 24 ++++++++++++++++++++++++ 11 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 public/designs/icons/default/eyes.png create mode 100644 public/images/hachure.png diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index 5de2359..43eeaa9 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -96,6 +96,13 @@ class BoxOrganizerController < ApplicationController end end + def toggle_visibility + @block = boxes_holder.blocks.find(params[:id]) + @block.visible = !@block.visible? + @block.save + redirect_to :action => 'index' + end + protected :boxes_editor? end diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 2261329..28ec885 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -47,7 +47,11 @@ module BoxesHelper end def display_box_content(box, main_content) - box.blocks.map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) + box_decorator.select_blocks(box.blocks).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) + end + + def select_blocks(arr) + arr end def display_block(block, main_content = nil) @@ -59,7 +63,7 @@ module BoxesHelper end options = { - :class => classes = ['block', block.css_class_name ].uniq.join(' '), + :class => classes = ['block', block.css_classes ].uniq.join(' '), :id => "block-#{block.id}" } if ( block.respond_to? 'help' ) @@ -103,6 +107,9 @@ module BoxesHelper def self.block_edit_buttons(block) '' end + def self.select_blocks(arr) + arr.select(&:visible?) + end end # generates a place where you can drop a block and get the block moved to @@ -167,6 +174,7 @@ module BoxesHelper end if !block.main? + buttons << icon_button(:eyes, _('Toggle block visibility'), {:action => 'toggle_visibility', :id => block.id}) buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'}) end diff --git a/app/models/block.rb b/app/models/block.rb index a4fc8ca..f9ba6d4 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -11,6 +11,11 @@ class Block < ActiveRecord::Base belongs_to :box acts_as_having_settings + settings_items :visible, :type => :boolean, :default => true + + def visible? + visible + end # returns the description of the block, used when the user sees a list of # blocks to choose one to include in the design. @@ -63,6 +68,12 @@ class Block < ActiveRecord::Base self.class.name.underscore.gsub('_', '-') end + def css_classes + classes = css_class_name + classes += ' invisible-block' unless visible? + classes + end + def default_title '' end diff --git a/public/designs/icons/default/eyes.png b/public/designs/icons/default/eyes.png new file mode 100644 index 0000000..97b2687 Binary files /dev/null and b/public/designs/icons/default/eyes.png differ diff --git a/public/designs/icons/default/style.css b/public/designs/icons/default/style.css index e1413df..e85723b 100644 --- a/public/designs/icons/default/style.css +++ b/public/designs/icons/default/style.css @@ -35,6 +35,7 @@ .icon-help32off { background-image: url(help-off-32x32-HC.gif) } .icon-spread { background-image: url(mega-phone-HC.gif) } .icon-todo { background-image: url(stock_todo.png) } +.icon-eyes { background-image: url(eyes.png) } .icon-menu- { background-image: url(menu-without-ico-HC.gif) } .icon-menu-home { background-image: url(home-HC.gif) } .icon-menu-blog { background-image: url(blog-HC.gif) } diff --git a/public/images/hachure.png b/public/images/hachure.png new file mode 100644 index 0000000..176275e Binary files /dev/null and b/public/images/hachure.png differ diff --git a/public/stylesheets/blocks.css b/public/stylesheets/blocks.css index 8fc5559..833af4e 100644 --- a/public/stylesheets/blocks.css +++ b/public/stylesheets/blocks.css @@ -7,6 +7,15 @@ border: none; } +.invisible-block { + background: url(../images/hachure.png); +} + +/* ie6 hack */ +.invisible-block a.icon-button { + position: relative; +} + /*********************************************************** * the handles to where you can drag the blocks ***********************************************************/ diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 4e30dbc..e0ffbab 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -424,4 +424,17 @@ class ApplicationControllerTest < Test::Unit::TestCase :descendant => {:tag => 'a', :attributes => { :href => '/admin' }} end + should 'not display invisible blocks' do + @controller.expects(:uses_design_blocks?).returns(true) + p = create_user('test_user').person + @controller.expects(:profile).at_least_once.returns(p) + b = p.blocks[1] + b.expects(:visible).returns(false) + b.save! + + get :index, :profile => p.identifier + + assert_no_tag :tag => 'div', :attributes => {:id => 'block-' + b.id.to_s} + end + end diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index c5e27d0..d58ac19 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -280,4 +280,13 @@ class ProfileDesignControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'input', :attributes => { :id => 'type_blogarchivesblock', :value => 'BlogArchivesBlock' } end + should 'toggle block visibility' do + state = @b1.visible? + get :toggle_visibility, :id => @b1.id, :profile => holder.identifier + block = Block.find(@b1.id) + + assert_equal block, assigns(:block) + assert_equal !state, block.visible? + end + end diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index ef2dab4..eae12a2 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -46,6 +46,12 @@ class BlockTest < Test::Unit::TestCase assert_equal 'my title', b.title end - + should 'have a visible setting' do + b = Block.new + assert b.visible? + b.visible = false + b.save + assert !b.visible? + end end diff --git a/test/unit/boxes_helper_test.rb b/test/unit/boxes_helper_test.rb index 1aece36..4746de6 100644 --- a/test/unit/boxes_helper_test.rb +++ b/test/unit/boxes_helper_test.rb @@ -23,4 +23,28 @@ class BoxesHelperTest < Test::Unit::TestCase assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' end + should 'display invisible block for editing' do + p = create_user('test_user').person + b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] + b.visible = false; b.save! + box = b.box + box.expects(:blocks).returns([b]) + expects(:display_block).with(b, '') + stubs(:block_target).returns('') + with_box_decorator self do + display_box_content(box, '') + end + end + + should 'not display invisible block' do + p = create_user('test_user').person + b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] + b.visible = false; b.save! + box = b.box + box.expects(:blocks).returns([b]) + expects(:display_block).with(b, '').never + stubs(:block_target).returns('') + display_box_content(box, '') + end + end -- libgit2 0.21.2