Commit 8d5373b906dfc7a67bdadef13ae01b2287bb4706

Authored by Rodrigo Souto
2 parents bd4954d3 9b3332e5

Merge commit 'refs/merge-requests/413' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/413
Showing 36 changed files with 880 additions and 16 deletions   Show diff stats
app/helpers/boxes_helper.rb
... ... @@ -102,14 +102,16 @@ module BoxesHelper
102 102  
103 103 result = filter_html(result, block)
104 104  
105   - box_decorator.block_target(block.box, block) +
106   - content_tag('div',
107   - content_tag('div',
  105 + content_tag('div',
  106 + box_decorator.block_target(block.box, block) +
  107 + content_tag('div',
108 108 content_tag('div',
109   - result + footer_content + box_decorator.block_edit_buttons(block),
110   - :class => 'block-inner-2'),
111   - :class => 'block-inner-1'),
112   - options) +
  109 + content_tag('div',
  110 + result + footer_content + box_decorator.block_edit_buttons(block),
  111 + :class => 'block-inner-2'),
  112 + :class => 'block-inner-1'),
  113 + options),
  114 + :class => 'block-outer') +
113 115 box_decorator.block_handle(block)
114 116 end
115 117  
... ...
app/models/article_block.rb
... ... @@ -49,8 +49,8 @@ class ArticleBlock < Block
49 49 end
50 50  
51 51 def available_articles
52   - return [] if self.box.nil? or self.box.owner.nil?
53   - self.box.owner.kind_of?(Environment) ? self.box.owner.portal_community.articles : self.box.owner.articles
  52 + return [] if self.owner.nil?
  53 + self.owner.kind_of?(Environment) ? self.owner.portal_community.articles : self.owner.articles
54 54 end
55 55  
56 56 def posts_per_page
... ...
app/models/box.rb
... ... @@ -3,12 +3,15 @@ class Box < ActiveRecord::Base
3 3 acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\''
4 4 has_many :blocks, :dependent => :destroy, :order => 'position'
5 5  
  6 + include Noosfero::Plugin::HotSpot
  7 +
6 8 def environment
7 9 owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil
8 10 end
9 11  
10 12 def acceptable_blocks
11   - to_css_class_name central? ? Box.acceptable_center_blocks : Box.acceptable_side_blocks
  13 + blocks = central? ? Box.acceptable_center_blocks + plugins.dispatch(:extra_blocks, :position => 1) : Box.acceptable_side_blocks + plugins.dispatch(:extra_blocks, :position => [2, 3])
  14 + to_css_class_name(blocks)
12 15 end
13 16  
14 17 def central?
... ...
app/views/box_organizer/_article_block.rhtml
1 1 <div class="article-block-edition">
2   -<% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %>
  2 +<% if @block.owner.kind_of?(Environment) and @block.owner.portal_community.nil? %>
3 3 <p id="no_portal_community">
4 4 <%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %>
5 5 </p>
... ...
config/initializers/plugins.rb
... ... @@ -6,3 +6,9 @@ require &#39;noosfero/plugin/mailer_base&#39;
6 6 require 'noosfero/plugin/settings'
7 7 require 'noosfero/plugin/spammable'
8 8 Noosfero::Plugin.init_system if $NOOSFERO_LOAD_PLUGINS
  9 +
  10 +if Rails.env == 'development' && $NOOSFERO_LOAD_PLUGINS
  11 + ActionController::Base.send(:prepend_before_filter) do |controller|
  12 + Noosfero::Plugin.init_system
  13 + end
  14 +end
... ...
plugins/container_block/controllers/admin/container_block_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class ContainerBlockPluginAdminController < AdminController
  2 +
  3 + include ContainerBlockPluginController
  4 +
  5 +end
... ...
plugins/container_block/controllers/container_block_plugin_controller.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +module ContainerBlockPluginController
  2 +
  3 + def saveWidths
  4 + container = boxes_holder.blocks.find(params[:id])
  5 + pairs = params[:widths].split('|')
  6 + settings = container.children_settings
  7 + pairs.each do |pair|
  8 + id, width = pair.split(',')
  9 + settings[id.to_i] = {:width => width.to_i}
  10 + end
  11 + container.children_settings = settings
  12 + container.save!
  13 +
  14 + render :text => _('Block successfully saved.')
  15 + end
  16 +
  17 +end
... ...
plugins/container_block/controllers/myprofile/container_block_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class ContainerBlockPluginMyprofileController < MyProfileController
  2 +
  3 + include ContainerBlockPluginController
  4 +
  5 +end
... ...
plugins/container_block/lib/container_block.rb 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +class ContainerBlock < Block
  2 +
  3 + after_create :create_box
  4 + after_destroy :destroy_children
  5 +
  6 + settings_items :container_box_id, :type => Integer, :default => nil
  7 + settings_items :children_settings, :type => Hash, :default => {}
  8 +
  9 + def self.description
  10 + _('Container')
  11 + end
  12 +
  13 + def help
  14 + _('This block acts as a container for another blocks')
  15 + end
  16 +
  17 + def layout_template
  18 + nil
  19 + end
  20 +
  21 + def destroy_children
  22 + blocks.destroy_all
  23 + end
  24 +
  25 + def create_box
  26 + box = Box.create!(:owner => self)
  27 + settings[:container_box_id] = box.id
  28 + save!
  29 + end
  30 +
  31 + def container_box
  32 + Box.find(container_box_id)
  33 + end
  34 +
  35 + def block_classes=(classes)
  36 + classes.each { |c| block = c.constantize.create!(:box => container_box) } if classes
  37 + end
  38 +
  39 + def blocks
  40 + container_box.blocks
  41 + end
  42 +
  43 + def child_width(child_id)
  44 + children_settings[child_id][:width] if children_settings[child_id]
  45 + end
  46 +
  47 + def content(args={})
  48 + block = self
  49 + lambda do
  50 + render :file => 'blocks/container.rhtml', :locals => {:block => block}
  51 + end
  52 + end
  53 +
  54 +end
... ...
plugins/container_block/lib/container_block_array.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +module ContainerBlockArray
  2 +
  3 + def blocks_with_container_block_plugin(reload = false)
  4 + blocks = blocks_without_container_block_plugin(reload)
  5 + blocks.each { |block| blocks.concat(block.blocks) if block.kind_of?(ContainerBlock) }
  6 + end
  7 +
  8 + def self.included(base)
  9 + base.class_eval do
  10 + alias_method_chain :blocks, :container_block_plugin
  11 + end
  12 + end
  13 +
  14 +end
... ...
plugins/container_block/lib/container_block_plugin.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class ContainerBlockPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "Container Block Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that add a container block.")
  9 + end
  10 +
  11 + def self.extra_blocks
  12 + { ContainerBlock => {} }
  13 + end
  14 +
  15 + def stylesheet?
  16 + true
  17 + end
  18 +
  19 +end
... ...
plugins/container_block/lib/ext/block.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require_dependency 'block'
  2 +
  3 +class Block
  4 +
  5 + def owner_with_container_block_plugin
  6 + owner = owner_without_container_block_plugin
  7 + owner.kind_of?(ContainerBlock) ? owner.owner : owner
  8 + end
  9 +
  10 + alias_method_chain :owner, :container_block_plugin
  11 +
  12 +end
... ...
plugins/container_block/lib/ext/environment.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +require_dependency 'environment'
  2 +
  3 +class Environment
  4 +
  5 + include ContainerBlockArray
  6 +
  7 +end
... ...
plugins/container_block/lib/ext/profile.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +require_dependency 'profile'
  2 +
  3 +class Profile
  4 +
  5 + include ContainerBlockArray
  6 +
  7 +end
... ...
plugins/container_block/public/images/handle_e.png 0 → 100644

458 Bytes

plugins/container_block/public/images/handle_w.png 0 → 100644

505 Bytes

plugins/container_block/public/images/scalable/handle.svg 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<!-- Created with Inkscape (http://www.inkscape.org/) -->
  3 +
  4 +<svg
  5 + xmlns:dc="http://purl.org/dc/elements/1.1/"
  6 + xmlns:cc="http://creativecommons.org/ns#"
  7 + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  8 + xmlns:svg="http://www.w3.org/2000/svg"
  9 + xmlns="http://www.w3.org/2000/svg"
  10 + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  11 + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  12 + width="210mm"
  13 + height="297mm"
  14 + id="svg2"
  15 + version="1.1"
  16 + inkscape:version="0.48.1 r9760"
  17 + sodipodi:docname="Novo documento 1">
  18 + <defs
  19 + id="defs4" />
  20 + <sodipodi:namedview
  21 + id="base"
  22 + pagecolor="#ffffff"
  23 + bordercolor="#666666"
  24 + borderopacity="1.0"
  25 + inkscape:pageopacity="0.0"
  26 + inkscape:pageshadow="2"
  27 + inkscape:zoom="0.35"
  28 + inkscape:cx="1290.448"
  29 + inkscape:cy="359.98856"
  30 + inkscape:document-units="px"
  31 + inkscape:current-layer="layer1"
  32 + showgrid="false"
  33 + showguides="true"
  34 + inkscape:guide-bbox="true"
  35 + inkscape:window-width="1600"
  36 + inkscape:window-height="825"
  37 + inkscape:window-x="0"
  38 + inkscape:window-y="24"
  39 + inkscape:window-maximized="1" />
  40 + <metadata
  41 + id="metadata7">
  42 + <rdf:RDF>
  43 + <cc:Work
  44 + rdf:about="">
  45 + <dc:format>image/svg+xml</dc:format>
  46 + <dc:type
  47 + rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
  48 + <dc:title></dc:title>
  49 + </cc:Work>
  50 + </rdf:RDF>
  51 + </metadata>
  52 + <g
  53 + inkscape:label="Camada 1"
  54 + inkscape:groupmode="layer"
  55 + id="layer1">
  56 + <path
  57 + style="fill:#b7b7b7;fill-opacity:0.8627451;stroke:#040400;stroke-width:30;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
  58 + d="m 188,288.93362 154.85715,0 c 0,0 -49.16601,97.1789 -54.28571,225.99999 -4.76678,119.94091 53.75423,244.90317 54.28571,241.71431 l -154.85715,0 z"
  59 + id="rect2988"
  60 + inkscape:connector-curvature="0"
  61 + sodipodi:nodetypes="ccsccc"
  62 + inkscape:export-filename="/home/00838716598/participa/noosfero/plugins/container_block/public/images/handle_e.png"
  63 + inkscape:export-xdpi="5.2851791"
  64 + inkscape:export-ydpi="5.2851791" />
  65 + <path
  66 + style="fill:#737373;fill-opacity:0.8627451;stroke:#040400;stroke-width:30;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
  67 + d="m 448.57143,289.79464 c 0,0 -49.16155,97.17891 -54.28125,226 -1.03249,25.97926 0.92026,52.18412 4.59375,77.28125 8.75453,44.36315 22.00361,91.09021 31.90625,123.375 9.12115,24.76788 16.62682,40.25755 17.65625,41.0625 l 0.125,0 96.84375,0 0,-467.71875 -96.84375,0 z"
  68 + id="use3761"
  69 + inkscape:connector-curvature="0"
  70 + inkscape:export-xdpi="5"
  71 + inkscape:export-ydpi="5"
  72 + inkscape:export-filename="/home/00838716598/participa/noosfero/plugins/container_block/public/images/handle_w.png" />
  73 + </g>
  74 +</svg>
... ...
plugins/container_block/public/style.css 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +#content .boxes .container-block .container_block_child, .container-block .block-outer {
  2 + display: inline-block;
  3 + vertical-align: top;
  4 + margin-left: -2px;
  5 + margin-right: -2px;
  6 +}
  7 +
  8 +.container-block .block-target {
  9 + clear: both;
  10 +}
  11 +
  12 +.container-block .block-target[id^='end-of-box-'] {
  13 + display: none;
  14 +}
  15 +
  16 +#content .boxes .container-block .block .icon-down, #content .boxes .container-block .block .icon-down-disabled {
  17 + background-image: url(/designs/icons/default/Tango/16x16/actions/go-next.png);
  18 +}
  19 +
  20 +#content .boxes .container-block .block .icon-up, #content .boxes .container-block .block .icon-up-disabled {
  21 + background-image: url(/designs/icons/default/Tango/16x16/actions/go-previous.png);
  22 +}
  23 +
  24 +#content .boxes .container-block .block {
  25 + outline-offset: -2px;
  26 +}
  27 +
  28 +#content .boxes .container-block .block .ui-resizable-handle {
  29 + width: 10px;
  30 + height: 28px;
  31 + z-index: 0;
  32 +}
  33 +
  34 +#content .boxes .container-block .block .ui-resizable-e {
  35 + right: -2px;
  36 + background-image: url(/plugins/container_block/images/handle_e.png);
  37 +}
  38 +
  39 +#content .boxes .container-block .block .ui-resizable-w {
  40 + left: -2px;
  41 + background-image: url(/plugins/container_block/images/handle_w.png);
  42 +}
  43 +
  44 +.container-block .button-bar .icon-resize {
  45 + background-image: url(/designs/icons/default/Tango/16x16/actions/view-fullscreen.png);
  46 +}
... ...
plugins/container_block/test/functional/container_block_environment_design_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class EnvironmentDesignController
  5 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  6 + def rescue_action(e)
  7 + raise e
  8 + end
  9 +end
  10 +
  11 +class EnvironmentDesignControllerTest < ActionController::TestCase
  12 +
  13 + def setup
  14 + Environment.delete_all
  15 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  16 + @environment.enabled_plugins = ['ContainerBlock']
  17 + @environment.save!
  18 +
  19 + user = create_user('testinguser')
  20 + @environment.add_admin(user.person)
  21 + login_as(user.login)
  22 +
  23 + @block = ContainerBlock.create!(:box => @environment.boxes.first)
  24 + end
  25 +
  26 + should 'be able to edit ContainerBlock' do
  27 + get :edit, :id => @block.id
  28 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  29 + end
  30 +
  31 + should 'be able to save ContainerBlock' do
  32 + get :edit, :id => @block.id
  33 + post :save, :id => @block.id, :block => {:title => 'Container' }
  34 + @block.reload
  35 + assert_equal 'Container', @block.title
  36 + end
  37 +
  38 + should 'display container children' do
  39 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  40 + get :index
  41 + assert_tag :div, :attributes => { :id => "block-#{c1.id}" }
  42 + end
  43 +
  44 + should 'display hidden children of container block' do
  45 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never')
  46 + get :index
  47 + assert_tag :div, :attributes => { :id => "block-#{c1.id}", :class => 'block raw-html-block invisible-block' }
  48 + end
  49 +
  50 + should 'display button to save widths of container children' do
  51 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  52 + get :index
  53 + assert_tag :a, :attributes => { :class => "button icon-save container_block_save" }
  54 + end
  55 +
  56 + should 'move child of container block to another box' do
  57 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  58 + get :move_block, :id => c1.id, :target => "end-of-box-#{@environment.boxes.last.id}"
  59 + assert_equal @environment.boxes.last, c1.reload.box
  60 + end
  61 +
  62 + should 'move block to inside of a container block' do
  63 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  64 + c2 = RawHTMLBlock.create!(:box => @environment.boxes.last, :html => 'child2 content')
  65 + get :move_block, :id => c2.id, :target => "before-block-#{c1.id}"
  66 + assert_equal @block.container_box, c2.reload.box
  67 + end
  68 +
  69 + should 'move down a container block child' do
  70 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  71 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  72 + get :move_block_down, :id => c1.id
  73 + assert_equal [c2, c1], @block.blocks
  74 + end
  75 +
  76 + should 'move up a container block child' do
  77 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  78 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  79 + get :move_block_up, :id => c2.id
  80 + assert_equal [c2, c1], @block.blocks
  81 + end
  82 +
  83 +end
... ...
plugins/container_block/test/functional/container_block_home_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +# Re-raise errors caught by the controller.
  4 +class HomeController
  5 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  6 + def rescue_action(e)
  7 + raise e
  8 + end
  9 +end
  10 +
  11 +class HomeControllerTest < ActionController::TestCase
  12 +
  13 + def setup
  14 + Environment.delete_all
  15 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  16 + @environment.enabled_plugins = ['ContainerBlock']
  17 + @environment.save!
  18 +
  19 + user = create_user('testinguser')
  20 + @environment.add_admin(user.person)
  21 + login_as(user.login)
  22 +
  23 + box = Box.create!(:owner => @environment)
  24 + @block = ContainerBlock.create!(:box => box)
  25 +
  26 + @environment.boxes = [box]
  27 + end
  28 +
  29 + should 'display ContainerBlock' do
  30 + get :index
  31 + assert_tag :div, :attributes => { :class => 'block container-block' }
  32 + end
  33 +
  34 + should 'display container children' do
  35 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  36 + c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content')
  37 + get :index
  38 + assert_tag :div, :attributes => { :id => "block-#{c1.id}" }
  39 + assert_tag :div, :attributes => { :id => "block-#{c2.id}" }
  40 + end
  41 +
  42 + should 'display style tags for container children' do
  43 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content')
  44 + @block.children_settings = { c1.id => {:width => "123"} }
  45 + @block.save!
  46 + get :index
  47 + assert_match /#block-#{c1.id} \{ width: 123px; \}/, @response.body
  48 + end
  49 +
  50 + should 'do not display hidden children of container' do
  51 + c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never')
  52 + get :index
  53 + assert_no_tag :div, :attributes => { :id => "block-#{c1.id}" }
  54 + end
  55 +
  56 + should 'do not display button to save widths of container children' do
  57 + get :index
  58 + assert_no_tag :a, :attributes => { :class => "button icon-save container_block_save" }
  59 + end
  60 +
  61 +end
... ...
plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginAdminControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + Environment.delete_all
  7 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  8 + @environment.enabled_plugins = ['ContainerBlock']
  9 + @environment.save!
  10 +
  11 + user = create_user('testinguser')
  12 + @environment.add_admin(user.person)
  13 + login_as(user.login)
  14 +
  15 + @block = ContainerBlock.create!(:box => @environment.boxes.first)
  16 + @child1 = Block.create!(:box => @block.container_box)
  17 + @child2 = Block.create!(:box => @block.container_box)
  18 + end
  19 +
  20 + should 'save widths of container block children' do
  21 + xhr :post, :saveWidths, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  22 + assert_response 200
  23 + assert_equal 'Block successfully saved.', @response.body
  24 + @block.reload
  25 + assert_equal 100, @block.child_width(@child1.id)
  26 + assert_equal 200, @block.child_width(@child2.id)
  27 + end
  28 +
  29 +end
... ...
plugins/container_block/test/functional/container_block_plugin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,47 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginControllerTest < ActionController::TestCase
  4 +
  5 + include ContainerBlockPluginController
  6 +
  7 + def setup
  8 + Environment.delete_all
  9 + @environment = Environment.new(:name => 'testenv', :is_default => true)
  10 + @environment.enabled_plugins = ['ContainerBlock']
  11 + @environment.save!
  12 +
  13 + user = create_user('testinguser')
  14 + @environment.add_admin(user.person)
  15 + login_as(user.login)
  16 +
  17 + @block = ContainerBlock.create!(:box => @environment.boxes.first)
  18 + @child1 = Block.create!(:box => @block.container_box)
  19 + @child2 = Block.create!(:box => @block.container_box)
  20 + @environment = Environment.find(@environment.id)
  21 + stubs(:boxes_holder).returns(@environment)
  22 + @params = {}
  23 + end
  24 +
  25 + attr_reader :params
  26 +
  27 + should 'save widths of container block children' do
  28 + @params = {:id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"}
  29 + expects(:render).with(:text => 'Block successfully saved.')
  30 + saveWidths
  31 + @block.reload
  32 + assert_equal 100, @block.child_width(@child1.id)
  33 + assert_equal 200, @block.child_width(@child2.id)
  34 + end
  35 +
  36 + should 'do not change child width that is not passed in widths param' do
  37 + @block.children_settings = {@child2.id => {:width => 200}}
  38 + @block.save!
  39 + @params = {:id => @block.id, :widths => "#{@child1.id},100"}
  40 + expects(:render).with(:text => 'Block successfully saved.')
  41 + saveWidths
  42 + @block.reload
  43 + assert_equal 100, @block.child_width(@child1.id)
  44 + assert_equal 200, @block.child_width(@child2.id)
  45 + end
  46 +
  47 +end
... ...
plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginMyprofileControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + user = create_user('testinguser')
  7 + login_as(user.login)
  8 +
  9 + @profile = fast_create(Community)
  10 + @profile.add_admin(user.person)
  11 + @box = Box.new(:owner => @profile)
  12 +
  13 + @block = ContainerBlock.create!(:box => @box)
  14 + @child1 = Block.create!(:box => @block.container_box)
  15 + @child2 = Block.create!(:box => @block.container_box)
  16 + end
  17 +
  18 + should 'save widths of container block children' do
  19 + xhr :post, :saveWidths, :profile => @profile.identifier, :id => @block.id, :widths => "#{@child1.id},100|#{@child2.id},200"
  20 + assert_response 200
  21 + assert_equal 'Block successfully saved.', @response.body
  22 + @block.reload
  23 + assert_equal 100, @block.child_width(@child1.id)
  24 + assert_equal 200, @block.child_width(@child2.id)
  25 + end
  26 +
  27 +end
... ...
plugins/container_block/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
... ...
plugins/container_block/test/unit/block_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class BlockTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = fast_create(Environment)
  7 + @box = Box.create!(:owner => @environment)
  8 + @container = ContainerBlock.create!(:box => @box)
  9 + end
  10 +
  11 + should 'return environment box if block owner is not a ContainerBlock' do
  12 + block = Block.create!(:box => @box)
  13 + assert_equal @box, block.box
  14 + end
  15 +
  16 + should 'return container box if block owner is a ContainerBlock' do
  17 + block = Block.create!(:box => @container.container_box)
  18 + assert_equal @container.container_box, block.box
  19 + end
  20 +
  21 + should 'return block owner if block onwer is not a ContainerBlock' do
  22 + block = Block.create!(:box => @box)
  23 + assert_equal @environment, block.owner
  24 + end
  25 +
  26 + should 'return environment as owner if block onwer is a ContainerBlock' do
  27 + block = Block.create!(:box => @container.container_box)
  28 + assert_equal @environment, block.owner
  29 + end
  30 +
  31 +end
... ...
plugins/container_block/test/unit/container_block_array_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockArrayTest < ActiveSupport::TestCase
  4 +
  5 + attr_reader :blocks
  6 +
  7 + include ContainerBlockArray
  8 +
  9 + def setup
  10 + @blocks = []
  11 +
  12 + @environment = fast_create(Environment)
  13 + @container_box = Box.new(:owner => @environment)
  14 + @container = ContainerBlock.new(:box => @container_box)
  15 + end
  16 +
  17 + should 'return blocks as usual' do
  18 + @blocks << Block.new
  19 + assert_equal @blocks, blocks_without_container_block_plugin
  20 + end
  21 +
  22 + should 'return blocks and container block children' do
  23 + @container.save!
  24 + @container_box.blocks << Block.new
  25 + @blocks.concat([Block.new, @container])
  26 + assert_equal @blocks + @container.blocks, blocks_without_container_block_plugin
  27 + end
  28 +
  29 +end
... ...
plugins/container_block/test/unit/container_block_plugin_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @plugin = ContainerBlockPlugin.new
  7 + end
  8 +
  9 + should 'has a name' do
  10 + assert !ContainerBlockPlugin.plugin_name.blank?
  11 + end
  12 +
  13 + should 'has a description' do
  14 + assert !ContainerBlockPlugin.plugin_description.blank?
  15 + end
  16 +
  17 + should 'add a block' do
  18 + assert_equal [ContainerBlock], ContainerBlockPlugin.extra_blocks.keys
  19 + end
  20 +
  21 + should 'has stylesheet' do
  22 + assert @plugin.stylesheet?
  23 + end
  24 +
  25 +end
... ...
plugins/container_block/test/unit/container_block_test.rb 0 → 100644
... ... @@ -0,0 +1,85 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ContainerBlockTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @block = ContainerBlock.new
  7 + end
  8 +
  9 + should 'describe yourself' do
  10 + assert !ContainerBlock.description.blank?
  11 + end
  12 +
  13 + should 'has a help' do
  14 + assert !@block.help.blank?
  15 + end
  16 +
  17 + should 'create a box on save' do
  18 + @block.save!
  19 + assert @block.container_box_id
  20 + end
  21 +
  22 + should 'return created box' do
  23 + @block.save!
  24 + assert @block.container_box
  25 + end
  26 +
  27 + should 'create new blocks when receive block classes' do
  28 + Block.destroy_all
  29 + @block.save!
  30 + @block.block_classes = ['Block']
  31 + assert_equal 2, Block.count
  32 + assert_equal Block, Block.last.class
  33 + end
  34 +
  35 + should 'do not create blocks when nothing is passed as block classes' do
  36 + Block.destroy_all
  37 + @block.save!
  38 + @block.block_classes = []
  39 + assert_equal 1, Block.count
  40 + end
  41 +
  42 + should 'do not create blocks when nil is passed as block classes' do
  43 + Block.destroy_all
  44 + @block.save!
  45 + @block.block_classes = nil
  46 + assert_equal 1, Block.count
  47 + end
  48 +
  49 + should 'return a list of blocks associated with the container block' do
  50 + Block.destroy_all
  51 + @block.save!
  52 + @block.block_classes = ['Block', 'Block']
  53 + assert_equal [Block, Block], @block.blocks.map(&:class)
  54 + end
  55 +
  56 + should 'return child width' do
  57 + @block.children_settings = {1 => {:width => 10} }
  58 + @block.save!
  59 + assert_equal 10, @block.child_width(1)
  60 + end
  61 +
  62 + should 'return nil in width if child do not exists' do
  63 + @block.children_settings = {2 => {:width => 10} }
  64 + @block.save!
  65 + assert_equal nil, @block.child_width(1)
  66 + end
  67 +
  68 + should 'return nil at layout_templat' do
  69 + assert_equal nil, @block.layout_template
  70 + end
  71 +
  72 + should 'return children blocks that have container box as box' do
  73 + @block.save!
  74 + child = Block.create!(:box_id => @block.container_box.id)
  75 + assert_equal [child], @block.blocks
  76 + end
  77 +
  78 + should 'destroy chilrend when container is removed' do
  79 + @block.save!
  80 + child = Block.create!(:box_id => @block.container_box.id)
  81 + @block.destroy
  82 + assert !Block.exists?(child.id)
  83 + end
  84 +
  85 +end
... ...
plugins/container_block/test/unit/environment_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class EnvironmentTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @environment = fast_create(Environment)
  7 +
  8 + @box = Box.create!(:owner => @environment)
  9 + @block = Block.create!(:box => @box)
  10 +
  11 + @container = ContainerBlock.create!(:box => @box)
  12 + end
  13 +
  14 + should 'return blocks as usual' do
  15 + assert_equal [@block, @container], @environment.blocks
  16 + end
  17 +
  18 + should 'return blocks with container children' do
  19 + child = Block.create!(:box => @container.container_box)
  20 + assert_equal [@block, @container, child], @environment.blocks
  21 + end
  22 +
  23 + should 'return block with id at find method' do
  24 + assert_equal @block, @environment.blocks.find(@block.id)
  25 + end
  26 +
  27 + should 'return child block with id at find method' do
  28 + child = Block.create!(:box => @container.container_box)
  29 + assert_equal child, @environment.blocks.find(child.id)
  30 + end
  31 +
  32 +end
... ...
plugins/container_block/test/unit/profile_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ProfileTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Profile)
  7 +
  8 + @box = Box.create!(:owner => @profile)
  9 + @block = Block.create!(:box => @box)
  10 +
  11 + @container = ContainerBlock.create!(:box => @box)
  12 + end
  13 +
  14 + should 'return blocks as usual' do
  15 + assert_equal [@block, @container], @profile.blocks
  16 + end
  17 +
  18 + should 'return blocks with container children' do
  19 + child = Block.create!(:box => @container.container_box)
  20 + assert_equal [@block, @container, child], @profile.blocks
  21 + end
  22 +
  23 + should 'return block with id at find method' do
  24 + assert_equal @block, @profile.blocks.find(@block.id)
  25 + end
  26 +
  27 + should 'return child block with id at find method' do
  28 + child = Block.create!(:box => @container.container_box)
  29 + assert_equal child, @profile.blocks.find(child.id)
  30 + end
  31 +
  32 +end
... ...
plugins/container_block/views/blocks/container.rhtml 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +<% edit_mode = @controller.send(:boxes_editor?) && @controller.send(:uses_design_blocks?) %>
  2 +<% box_decorator = edit_mode ? self : BoxesHelper::DontMoveBlocks %>
  3 +
  4 +
  5 +<div class="box" id="box-<%= block.container_box.id %>">
  6 + <%= display_box_content(block.container_box, nil) %>
  7 + <div class="clear"></div>
  8 +</div>
  9 +<div class="clear"></div>
  10 +
  11 +<style>
  12 + <% box_decorator.select_blocks(block.blocks, { :article => @page, :request_path => request.path, :locale => locale }).each do |child| %>
  13 + #block-<%=block.id%> #block-<%=child.id%> { width: <%= block.child_width(child.id) %>px; }
  14 + <% end %>
  15 +</style>
  16 +
  17 +<% if edit_mode %>
  18 + <div class="button-bar">
  19 + <a href="#" onclick="toggleMoveContainerChildren(<%= block.id %>, <%= block.container_box.id %>); return false;" class="button icon-resize"></a>
  20 + <%= link_to_remote '', :url => { :controller => @controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id },
  21 + :with => "containerChildrenWidth(#{block.id}, #{block.container_box.id})",
  22 + :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}" },
  23 + :loading => "open_loading(DEFAULT_LOADING_MESSAGE);",
  24 + :loaded => "close_loading();",
  25 + :complete => "display_notice(request.responseText);"%>
  26 + </div>
  27 +
  28 + <script>
  29 + function toggleMoveContainerChildren(container, box) {
  30 + var div = jQuery('#box-'+box+' > .block-outer > .block');
  31 + var targetDiv = jQuery('#box-'+box+' .block-outer .block-target');
  32 + if(div.is('.ui-resizable')) {
  33 + targetDiv.show();
  34 + div.find("a").die("click");
  35 + div.resizable('destroy');
  36 + } else {
  37 + targetDiv.hide();
  38 + div.find("a").live("click", function(e) {
  39 + e.preventDefault();
  40 + });
  41 + div.resizable({
  42 + handles: 'e, w',
  43 + containment: '#block-'+container+' .block-inner-2',
  44 + resize: function( event, ui ) {
  45 + ui.element.height('auto');
  46 + }
  47 + });
  48 + }
  49 + }
  50 +
  51 + function containerChildrenWidth(container, box) {
  52 + widths = "";
  53 + jQuery('#box-'+box+' > .block-outer > .block').each(function(i) {
  54 + childId = jQuery(this).attr('id').match(/block-(\d+)/)[1];
  55 + widths+=childId+","+jQuery(this).width()+"|";
  56 + });
  57 + return "widths="+widths;
  58 + }
  59 + </script>
  60 +<% end %>
... ...
plugins/container_block/views/box_organizer/_container_block.rhtml 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<br/>
  2 +<ul id="links">
  3 + <% @block.blocks.each do |block| %>
  4 + <li>
  5 + <%= block.class.name %>
  6 + </li>
  7 + <% end %>
  8 +</ul>
  9 +
  10 +<%= link_to_function(_('New block'), nil, :class => 'button icon-add with-text') { |page|
  11 + page.insert_html :bottom, 'links', content_tag('li',select_tag('block[block_classes][]',
  12 + options_for_select( @controller.available_blocks.each_with_index.map {|b,i| [b.name, b.name] } ))) } %>
  13 +
  14 +<br/><br/>
... ...
plugins/container_block/views/environment_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer
0 2 \ No newline at end of file
... ...
plugins/container_block/views/profile_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer
0 2 \ No newline at end of file
... ...
plugins/display_content/lib/display_content_block.rb
... ... @@ -68,12 +68,12 @@ class DisplayContentBlock &lt; Block
68 68 protected
69 69  
70 70 def holder
71   - return nil if self.box.nil? || self.box.owner.nil?
72   - if self.box.owner.kind_of?(Environment)
73   - return nil if self.box.owner.portal_community.nil?
74   - self.box.owner.portal_community
  71 + return nil if self.box.nil? || self.owner.nil?
  72 + if self.owner.kind_of?(Environment)
  73 + return nil if self.owner.portal_community.nil?
  74 + self.owner.portal_community
75 75 else
76   - self.box.owner
  76 + self.owner
77 77 end
78 78 end
79 79  
... ...
test/unit/box_test.rb
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2  
3 3 class BoxTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
  7 + end
  8 +
4 9 should 'retrieve environment based on owner' do
5 10 profile = fast_create(Profile)
6 11 box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile')
... ... @@ -84,4 +89,34 @@ class BoxTest &lt; ActiveSupport::TestCase
84 89 assert blocks.include?('tags-block')
85 90 end
86 91  
  92 + should 'list plugin block as allowed for box at position 1' do
  93 + class SomePlugin < Noosfero::Plugin
  94 + def self.extra_blocks
  95 + { PluginBlock => {:position => 1} }
  96 + end
  97 + end
  98 + class PluginBlock < Block
  99 + def self.to_s; 'plugin-block'; end
  100 + end
  101 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
  102 +
  103 + blocks = Box.new(:position => 1).acceptable_blocks
  104 + assert blocks.include?('plugin-block')
  105 + end
  106 +
  107 + should 'list plugin block as allowed for box at position 2' do
  108 + class SomePlugin < Noosfero::Plugin
  109 + def self.extra_blocks
  110 + { PluginBlock => {:position => 2} }
  111 + end
  112 + end
  113 + class PluginBlock < Block
  114 + def self.to_s; 'plugin-block'; end
  115 + end
  116 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new])
  117 +
  118 + blocks = Box.new(:position => 2).acceptable_blocks
  119 + assert blocks.include?('plugin-block')
  120 + end
  121 +
87 122 end
... ...