Commit 7e2ac2d57d7a9f384036eb19c2814410db6d71a6

Authored by Victor Costa
2 parents e83ed4e9 e6562b97

Merge branch 'AI3279-new_block_store' into stable

app/controllers/box_organizer_controller.rb
@@ -3,7 +3,7 @@ class BoxOrganizerController < ApplicationController @@ -3,7 +3,7 @@ class BoxOrganizerController < ApplicationController
3 before_filter :login_required 3 before_filter :login_required
4 4
5 def index 5 def index
6 - @available_blocks = available_blocks.uniq 6 + @available_blocks = available_blocks.uniq.sort_by(&:pretty_name)
7 end 7 end
8 8
9 def move_block 9 def move_block
app/helpers/boxes_helper.rb
@@ -193,7 +193,7 @@ module BoxesHelper @@ -193,7 +193,7 @@ module BoxesHelper
193 if block.nil? or modifiable?(block) 193 if block.nil? or modifiable?(block)
194 draggable_id = "encodeURIComponent(jQuery(ui.draggable).attr('id'))" 194 draggable_id = "encodeURIComponent(jQuery(ui.draggable).attr('id'))"
195 draggable_type = "encodeURIComponent(jQuery(ui.draggable).attr('data-block-type'))" 195 draggable_type = "encodeURIComponent(jQuery(ui.draggable).attr('data-block-type'))"
196 - content_tag('div', _('Drop Here'), :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover', :with => "'type='+"+draggable_type+"+'&id=' + "+draggable_id, :activeClass => 'block-target-active') 196 + content_tag('div', _('Drop Here'), :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover', :with => "'type='+"+draggable_type+"+'&id=' + "+draggable_id, :activeClass => 'block-target-active', :tolerance => 'pointer')
197 else 197 else
198 "" 198 ""
199 end 199 end
app/views/box_organizer/index.html.erb
@@ -8,9 +8,10 @@ @@ -8,9 +8,10 @@
8 <% end %> 8 <% end %>
9 9
10 <div id="block-store"> 10 <div id="block-store">
  11 + <input type="text" id="block-store-filter" placeholder="<%= _('Filter blocks') %>" title="<%= _('Filter blocks') %>">
11 <div id="block-types"> 12 <div id="block-types">
12 <% @available_blocks.each do |block| %> 13 <% @available_blocks.each do |block| %>
13 - <div id="block-<%= block.name.to_css_class %>" class="block-type <%= block.name.to_css_class %>" data-block-type="<%= block.name %>"> 14 + <div id="block-<%= block.name.to_css_class %>" class="block-type <%= block.name.to_css_class %>" data-block-type="<%= block.name %>" data-block-name="<%= block.pretty_name %>">
14 <div class="button-bar"> 15 <div class="button-bar">
15 <%= modal_button 'help', _('Help on this block'), 16 <%= modal_button 'help', _('Help on this block'),
16 {:action => 'show_block_type_info', :type => block.name}, 17 {:action => 'show_block_type_info', :type => block.name},
plugins/container_block/public/style.css
@@ -60,3 +60,6 @@ @@ -60,3 +60,6 @@
60 #box-organizer.shadow .container-block-plugin_container-block { 60 #box-organizer.shadow .container-block-plugin_container-block {
61 opacity: 1; 61 opacity: 1;
62 } 62 }
  63 +#content #box-organizer .container-block-plugin_container-block {
  64 + padding-top: 20px;
  65 +}
public/javascripts/block-store.js
  1 +function filterBlocks() {
  2 + jQuery('#block-store #block-types').slick('slickFilter', function() {
  3 + var name = $(this).data('block-name');
  4 + var filter = $('#block-store #block-store-filter').val();
  5 + return name.toLowerCase().indexOf(filter.toLowerCase()) > -1;
  6 + });
  7 +}
  8 +
1 function cloneDraggableBlock(el, blockIcon) { 9 function cloneDraggableBlock(el, blockIcon) {
2 el.addClass('ui-draggable-dragging'); 10 el.addClass('ui-draggable-dragging');
3 return blockIcon; 11 return blockIcon;
@@ -13,29 +21,30 @@ function stopDragBlock() { @@ -13,29 +21,30 @@ function stopDragBlock() {
13 } 21 }
14 22
15 function initBlockStore() { 23 function initBlockStore() {
  24 + jQuery('#block-store').show();
16 var store = jQuery('#block-store #block-types').slick({ 25 var store = jQuery('#block-store #block-types').slick({
17 - infinite: true, 26 + infinite: false,
18 dots: true, 27 dots: true,
19 draggable: false, 28 draggable: false,
20 respondTo: 'slider', 29 respondTo: 'slider',
21 slidesToShow: 7, 30 slidesToShow: 7,
22 - slidesToScroll: 4, 31 + slidesToScroll: 6,
23 responsive: [ 32 responsive: [
24 { 33 {
25 breakpoint: 2048, 34 breakpoint: 2048,
26 settings: { 35 settings: {
27 slidesToShow: 10, 36 slidesToShow: 10,
28 - slidesToScroll: 4, 37 + slidesToScroll: 9,
29 } 38 }
30 }, 39 },
31 { 40 {
32 breakpoint: 1024, 41 breakpoint: 1024,
33 settings: { 42 settings: {
34 slidesToShow: 8, 43 slidesToShow: 8,
35 - slidesToScroll: 4, 44 + slidesToScroll: 7,
36 } 45 }
37 } 46 }
38 ] 47 ]
39 }); 48 });
40 - jQuery('#block-store').show(); 49 + jQuery('#block-store #block-store-filter').keyup(filterBlocks);
41 } 50 }
public/stylesheets/block-store.css
@@ -27,6 +27,13 @@ @@ -27,6 +27,13 @@
27 /************************************************ 27 /************************************************
28 * block store styles 28 * block store styles
29 ************************************************/ 29 ************************************************/
  30 +#block-store #block-store-filter {
  31 + float: right;
  32 + margin-bottom: 8px;
  33 +}
  34 +#block-store #block-types {
  35 + clear: both;
  36 +}
30 #block-store { 37 #block-store {
31 display: none; 38 display: none;
32 } 39 }
test/functional/profile_design_controller_test.rb
@@ -362,6 +362,12 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -362,6 +362,12 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
362 assert_tag :tag => 'a', :content => 'Back to control panel' 362 assert_tag :tag => 'a', :content => 'Back to control panel'
363 end 363 end
364 364
  365 + should 'display avaliable blocks in alphabetical order' do
  366 + @controller.stubs(:available_blocks).returns([TagsBlock, ArticleBlock])
  367 + get :index, :profile => 'designtestuser'
  368 + assert_equal assigns(:available_blocks), [ArticleBlock, TagsBlock]
  369 + end
  370 +
365 should 'not allow products block if environment do not let' do 371 should 'not allow products block if environment do not let' do
366 env = Environment.default 372 env = Environment.default
367 env.disable('products_for_enterprises') 373 env.disable('products_for_enterprises')