Commit 84475efd266f295fd4e63250493cb6ea329ee185

Authored by Leandro Santos
1 parent 0e391d12

refactoring block store view

app/helpers/box_organizer_helper.rb
1 module BoxOrganizerHelper 1 module BoxOrganizerHelper
2 2
  3 + def max_number_of_blocks_per_line
  4 + 7
  5 + end
  6 +
3 def icon_selector(icon = 'no-ico') 7 def icon_selector(icon = 'no-ico')
4 render :partial => 'icon_selector', :locals => { :icon => icon } 8 render :partial => 'icon_selector', :locals => { :icon => icon }
5 end 9 end
@@ -10,4 +14,4 @@ module BoxOrganizerHelper @@ -10,4 +14,4 @@ module BoxOrganizerHelper
10 end 14 end
11 end 15 end
12 16
13 -end  
14 \ No newline at end of file 17 \ No newline at end of file
  18 +end
app/models/block.rb
@@ -139,10 +139,6 @@ class Block < ActiveRecord::Base @@ -139,10 +139,6 @@ class Block < ActiveRecord::Base
139 "/images/icon_block.png" 139 "/images/icon_block.png"
140 end 140 end
141 141
142 - def self.position  
143 - [1,2,3]  
144 - end  
145 -  
146 # Returns the content to be used for this block. 142 # Returns the content to be used for this block.
147 # 143 #
148 # This method can return several types of objects: 144 # This method can return several types of objects:
app/views/box_organizer/index.html.erb
@@ -7,24 +7,24 @@ @@ -7,24 +7,24 @@
7 <%= button(:back, _('Back to control panel'), :controller => (profile.nil? ? 'admin_panel': 'profile_editor')) %> 7 <%= button(:back, _('Back to control panel'), :controller => (profile.nil? ? 'admin_panel': 'profile_editor')) %>
8 <% end %> 8 <% end %>
9 9
10 -<% cont = 0 %>  
11 -<% i = 0 %> 10 +<% n_blocks_in_line = 0 %>
  11 +<% last_block = @blocks.last %>
12 12
13 <div id="block-types-container"> 13 <div id="block-types-container">
14 <div id="block-types"> 14 <div id="block-types">
15 15
16 <% @blocks.each do |block| %> 16 <% @blocks.each do |block| %>
17 17
18 - <% if cont == 0 && i < @blocks.length %> 18 + <% if n_blocks_in_line == 0 %>
19 <div class="block-types-group"> 19 <div class="block-types-group">
20 <% end %> 20 <% end %>
21 21
22 - <% cont += 1 %> 22 + <% n_blocks_in_line += 1 %>
23 23
24 <div id="block-<%=block.name%>" class="block-type <%= block.name.to_css_class %> drag"> 24 <div id="block-<%=block.name%>" class="block-type <%= block.name.to_css_class %> drag">
25 <div class="button-bar"> 25 <div class="button-bar">
26 <%= link_to content_tag('span', _('Help on this block')), 26 <%= link_to content_tag('span', _('Help on this block')),
27 - {:controller => 'environment_design', :action => 'show_block_type_info', :type => block.name}, 27 + {:action => 'show_block_type_info', :type => block.name},
28 :class => "button icon-button icon-help colorbox", 28 :class => "button icon-button icon-help colorbox",
29 :title => _('Help on this block') %> 29 :title => _('Help on this block') %>
30 <br style="clear: left"> 30 <br style="clear: left">
@@ -37,13 +37,11 @@ @@ -37,13 +37,11 @@
37 37
38 <%= draggable_element("block-#{block.name}", :revert => true) %> 38 <%= draggable_element("block-#{block.name}", :revert => true) %>
39 39
40 - <% if cont == 7 || i == (@blocks.length - 1) %>  
41 - <% cont = 0 %> 40 + <% if n_blocks_in_line == max_number_of_blocks_per_line || last_block == block %>
  41 + <% n_blocks_in_line = 0 %>
42 </div> 42 </div>
43 <% end %> 43 <% end %>
44 44
45 - <% i += 1 %>  
46 -  
47 <% end %> 45 <% end %>
48 46
49 </div> 47 </div>
test/functional/environment_design_controller_test.rb
@@ -352,4 +352,21 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase @@ -352,4 +352,21 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
352 assert_equal json_response, [] 352 assert_equal json_response, []
353 end 353 end
354 354
  355 + should 'display all available blocks in groups' do
  356 + login_as(create_admin_user(Environment.default))
  357 + get :index
  358 + assert_select 'div.block-types-group', 3
  359 +
  360 + assert_select 'div.block-types-group' do |elements|
  361 + assert_select 'div.block-type', 15
  362 + end
  363 + end
  364 +
  365 + should 'paginate the block store with 7 elements per line' do
  366 + assert_equal 15, @controller.available_blocks.length
  367 + login_as(create_admin_user(Environment.default))
  368 + get :index
  369 + assert_select 'div.block-types-group', 3, "something wrong happens with the pagination of the block store"
  370 + end
  371 +
355 end 372 end
test/unit/box_organizer_helper_test.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +# encoding: UTF-8
  2 +require File.dirname(__FILE__) + '/../test_helper'
  3 +
  4 +class BoxOrganizerHelperTest < ActiveSupport::TestCase
  5 +
  6 + include BoxOrganizerHelper
  7 +
  8 + should 'max number of blocks be 7' do
  9 + assert_equal 7, max_number_of_blocks_per_line
  10 + end
  11 +
  12 +end