Commit c47e2ba3715efa61e1e750123d70ca598a912789
Committed by
Antonio Terceiro
1 parent
70eccaa3
Exists in
master
and in
22 other branches
ActionItem741: now blocks can be hidden
Showing
11 changed files
with
91 additions
and
3 deletions
Show diff stats
app/controllers/box_organizer_controller.rb
| @@ -96,6 +96,13 @@ class BoxOrganizerController < ApplicationController | @@ -96,6 +96,13 @@ class BoxOrganizerController < ApplicationController | ||
| 96 | end | 96 | end |
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | + def toggle_visibility | ||
| 100 | + @block = boxes_holder.blocks.find(params[:id]) | ||
| 101 | + @block.visible = !@block.visible? | ||
| 102 | + @block.save | ||
| 103 | + redirect_to :action => 'index' | ||
| 104 | + end | ||
| 105 | + | ||
| 99 | protected :boxes_editor? | 106 | protected :boxes_editor? |
| 100 | 107 | ||
| 101 | end | 108 | end |
app/helpers/boxes_helper.rb
| @@ -47,7 +47,11 @@ module BoxesHelper | @@ -47,7 +47,11 @@ module BoxesHelper | ||
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | def display_box_content(box, main_content) | 49 | def display_box_content(box, main_content) |
| 50 | - box.blocks.map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) | 50 | + box_decorator.select_blocks(box.blocks).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) |
| 51 | + end | ||
| 52 | + | ||
| 53 | + def select_blocks(arr) | ||
| 54 | + arr | ||
| 51 | end | 55 | end |
| 52 | 56 | ||
| 53 | def display_block(block, main_content = nil) | 57 | def display_block(block, main_content = nil) |
| @@ -59,7 +63,7 @@ module BoxesHelper | @@ -59,7 +63,7 @@ module BoxesHelper | ||
| 59 | end | 63 | end |
| 60 | 64 | ||
| 61 | options = { | 65 | options = { |
| 62 | - :class => classes = ['block', block.css_class_name ].uniq.join(' '), | 66 | + :class => classes = ['block', block.css_classes ].uniq.join(' '), |
| 63 | :id => "block-#{block.id}" | 67 | :id => "block-#{block.id}" |
| 64 | } | 68 | } |
| 65 | if ( block.respond_to? 'help' ) | 69 | if ( block.respond_to? 'help' ) |
| @@ -103,6 +107,9 @@ module BoxesHelper | @@ -103,6 +107,9 @@ module BoxesHelper | ||
| 103 | def self.block_edit_buttons(block) | 107 | def self.block_edit_buttons(block) |
| 104 | '' | 108 | '' |
| 105 | end | 109 | end |
| 110 | + def self.select_blocks(arr) | ||
| 111 | + arr.select(&:visible?) | ||
| 112 | + end | ||
| 106 | end | 113 | end |
| 107 | 114 | ||
| 108 | # generates a place where you can drop a block and get the block moved to | 115 | # generates a place where you can drop a block and get the block moved to |
| @@ -167,6 +174,7 @@ module BoxesHelper | @@ -167,6 +174,7 @@ module BoxesHelper | ||
| 167 | end | 174 | end |
| 168 | 175 | ||
| 169 | if !block.main? | 176 | if !block.main? |
| 177 | + buttons << icon_button(:eyes, _('Toggle block visibility'), {:action => 'toggle_visibility', :id => block.id}) | ||
| 170 | buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'}) | 178 | buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post'}) |
| 171 | end | 179 | end |
| 172 | 180 |
app/models/block.rb
| @@ -11,6 +11,11 @@ class Block < ActiveRecord::Base | @@ -11,6 +11,11 @@ class Block < ActiveRecord::Base | ||
| 11 | belongs_to :box | 11 | belongs_to :box |
| 12 | 12 | ||
| 13 | acts_as_having_settings | 13 | acts_as_having_settings |
| 14 | + settings_items :visible, :type => :boolean, :default => true | ||
| 15 | + | ||
| 16 | + def visible? | ||
| 17 | + visible | ||
| 18 | + end | ||
| 14 | 19 | ||
| 15 | # returns the description of the block, used when the user sees a list of | 20 | # returns the description of the block, used when the user sees a list of |
| 16 | # blocks to choose one to include in the design. | 21 | # blocks to choose one to include in the design. |
| @@ -63,6 +68,12 @@ class Block < ActiveRecord::Base | @@ -63,6 +68,12 @@ class Block < ActiveRecord::Base | ||
| 63 | self.class.name.underscore.gsub('_', '-') | 68 | self.class.name.underscore.gsub('_', '-') |
| 64 | end | 69 | end |
| 65 | 70 | ||
| 71 | + def css_classes | ||
| 72 | + classes = css_class_name | ||
| 73 | + classes += ' invisible-block' unless visible? | ||
| 74 | + classes | ||
| 75 | + end | ||
| 76 | + | ||
| 66 | def default_title | 77 | def default_title |
| 67 | '' | 78 | '' |
| 68 | end | 79 | end |
801 Bytes
public/designs/icons/default/style.css
| @@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
| 35 | .icon-help32off { background-image: url(help-off-32x32-HC.gif) } | 35 | .icon-help32off { background-image: url(help-off-32x32-HC.gif) } |
| 36 | .icon-spread { background-image: url(mega-phone-HC.gif) } | 36 | .icon-spread { background-image: url(mega-phone-HC.gif) } |
| 37 | .icon-todo { background-image: url(stock_todo.png) } | 37 | .icon-todo { background-image: url(stock_todo.png) } |
| 38 | +.icon-eyes { background-image: url(eyes.png) } | ||
| 38 | .icon-menu- { background-image: url(menu-without-ico-HC.gif) } | 39 | .icon-menu- { background-image: url(menu-without-ico-HC.gif) } |
| 39 | .icon-menu-home { background-image: url(home-HC.gif) } | 40 | .icon-menu-home { background-image: url(home-HC.gif) } |
| 40 | .icon-menu-blog { background-image: url(blog-HC.gif) } | 41 | .icon-menu-blog { background-image: url(blog-HC.gif) } |
233 Bytes
public/stylesheets/blocks.css
| @@ -7,6 +7,15 @@ | @@ -7,6 +7,15 @@ | ||
| 7 | border: none; | 7 | border: none; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | +.invisible-block { | ||
| 11 | + background: url(../images/hachure.png); | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +/* ie6 hack */ | ||
| 15 | +.invisible-block a.icon-button { | ||
| 16 | + position: relative; | ||
| 17 | +} | ||
| 18 | + | ||
| 10 | /*********************************************************** | 19 | /*********************************************************** |
| 11 | * the handles to where you can drag the blocks | 20 | * the handles to where you can drag the blocks |
| 12 | ***********************************************************/ | 21 | ***********************************************************/ |
test/functional/application_controller_test.rb
| @@ -424,4 +424,17 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -424,4 +424,17 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
| 424 | :descendant => {:tag => 'a', :attributes => { :href => '/admin' }} | 424 | :descendant => {:tag => 'a', :attributes => { :href => '/admin' }} |
| 425 | end | 425 | end |
| 426 | 426 | ||
| 427 | + should 'not display invisible blocks' do | ||
| 428 | + @controller.expects(:uses_design_blocks?).returns(true) | ||
| 429 | + p = create_user('test_user').person | ||
| 430 | + @controller.expects(:profile).at_least_once.returns(p) | ||
| 431 | + b = p.blocks[1] | ||
| 432 | + b.expects(:visible).returns(false) | ||
| 433 | + b.save! | ||
| 434 | + | ||
| 435 | + get :index, :profile => p.identifier | ||
| 436 | + | ||
| 437 | + assert_no_tag :tag => 'div', :attributes => {:id => 'block-' + b.id.to_s} | ||
| 438 | + end | ||
| 439 | + | ||
| 427 | end | 440 | end |
test/functional/profile_design_controller_test.rb
| @@ -280,4 +280,13 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -280,4 +280,13 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
| 280 | assert_no_tag :tag => 'input', :attributes => { :id => 'type_blogarchivesblock', :value => 'BlogArchivesBlock' } | 280 | assert_no_tag :tag => 'input', :attributes => { :id => 'type_blogarchivesblock', :value => 'BlogArchivesBlock' } |
| 281 | end | 281 | end |
| 282 | 282 | ||
| 283 | + should 'toggle block visibility' do | ||
| 284 | + state = @b1.visible? | ||
| 285 | + get :toggle_visibility, :id => @b1.id, :profile => holder.identifier | ||
| 286 | + block = Block.find(@b1.id) | ||
| 287 | + | ||
| 288 | + assert_equal block, assigns(:block) | ||
| 289 | + assert_equal !state, block.visible? | ||
| 290 | + end | ||
| 291 | + | ||
| 283 | end | 292 | end |
test/unit/block_test.rb
| @@ -46,6 +46,12 @@ class BlockTest < Test::Unit::TestCase | @@ -46,6 +46,12 @@ class BlockTest < Test::Unit::TestCase | ||
| 46 | assert_equal 'my title', b.title | 46 | assert_equal 'my title', b.title |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | - | 49 | + should 'have a visible setting' do |
| 50 | + b = Block.new | ||
| 51 | + assert b.visible? | ||
| 52 | + b.visible = false | ||
| 53 | + b.save | ||
| 54 | + assert !b.visible? | ||
| 55 | + end | ||
| 50 | 56 | ||
| 51 | end | 57 | end |
test/unit/boxes_helper_test.rb
| @@ -23,4 +23,28 @@ class BoxesHelperTest < Test::Unit::TestCase | @@ -23,4 +23,28 @@ class BoxesHelperTest < Test::Unit::TestCase | ||
| 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' | 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' |
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | + should 'display invisible block for editing' do | ||
| 27 | + p = create_user('test_user').person | ||
| 28 | + b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] | ||
| 29 | + b.visible = false; b.save! | ||
| 30 | + box = b.box | ||
| 31 | + box.expects(:blocks).returns([b]) | ||
| 32 | + expects(:display_block).with(b, '') | ||
| 33 | + stubs(:block_target).returns('') | ||
| 34 | + with_box_decorator self do | ||
| 35 | + display_box_content(box, '') | ||
| 36 | + end | ||
| 37 | + end | ||
| 38 | + | ||
| 39 | + should 'not display invisible block' do | ||
| 40 | + p = create_user('test_user').person | ||
| 41 | + b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] | ||
| 42 | + b.visible = false; b.save! | ||
| 43 | + box = b.box | ||
| 44 | + box.expects(:blocks).returns([b]) | ||
| 45 | + expects(:display_block).with(b, '').never | ||
| 46 | + stubs(:block_target).returns('') | ||
| 47 | + display_box_content(box, '') | ||
| 48 | + end | ||
| 49 | + | ||
| 26 | end | 50 | end |