From ac6da245d710953fe1f015f29600b9afc8182194 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 11 Nov 2013 11:12:19 -0300 Subject: [PATCH] Organize type selection at context content block --- plugins/context_content/lib/context_content_block.rb | 16 +++++++++++++++- plugins/context_content/test/unit/context_content_block_test.rb | 34 ++++++++++++++++++++++++++++++++-- plugins/context_content/views/box_organizer/_context_content_block.rhtml | 20 ++++++++++++++++---- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/plugins/context_content/lib/context_content_block.rb b/plugins/context_content/lib/context_content_block.rb index de449e9..ce2ca40 100644 --- a/plugins/context_content/lib/context_content_block.rb +++ b/plugins/context_content/lib/context_content_block.rb @@ -18,7 +18,21 @@ class ContextContentBlock < Block end def available_content_types - @available_content_types ||= [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) + @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) + checked_types = types.map {|t| t.constantize} + checked_types + (@available_content_types - checked_types) + end + + def first_content_types + available_content_types.first(first_types_count) + end + + def more_content_types + available_content_types.drop(first_types_count) + end + + def first_types_count + [2, types.length].max end def types=(new_types) diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb index 8c72e88..a7a439c 100644 --- a/plugins/context_content/test/unit/context_content_block_test.rb +++ b/plugins/context_content/test/unit/context_content_block_test.rb @@ -84,8 +84,37 @@ class ContextContentBlockTest < ActiveSupport::TestCase assert_equal nil, @block.contents(folder) end + should 'return available content types with checked types first' do + @block.types = ['TinyMceArticle', 'Folder'] + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], @block.available_content_types + end + should 'return available content types' do - assert_equal [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed], @block.available_content_types + @block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], @block.available_content_types + end + + should 'return first 2 content types' do + assert_equal 2, @block.first_content_types.length + end + + should 'return all but first 2 content types' do + assert_equal @block.available_content_types.length - 2, @block.more_content_types.length + end + + should 'return 2 as default value for first_types_count' do + assert_equal 2, @block.first_types_count + end + + should 'return types length if it has more than 2 selected types' do + @block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal 3, @block.first_types_count + end + + should 'return selected types at first_content_types' do + @block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal [UploadedFile, Event, Folder], @block.first_content_types + assert_equal @block.available_content_types - [UploadedFile, Event, Folder], @block.more_content_types end should 'include plugin content at available content types' do @@ -93,7 +122,8 @@ class ContextContentBlockTest < ActiveSupport::TestCase class SomePlugin; def content_types; SomePluginContent end end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) - assert_equal [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types + @block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types end should 'display thumbnail for image content' do diff --git a/plugins/context_content/views/box_organizer/_context_content_block.rhtml b/plugins/context_content/views/box_organizer/_context_content_block.rhtml index 29f752e..5c98787 100644 --- a/plugins/context_content/views/box_organizer/_context_content_block.rhtml +++ b/plugins/context_content/views/box_organizer/_context_content_block.rhtml @@ -4,8 +4,20 @@ <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> -

Display content types:

- <% @block.available_content_types.each do |type| %> - <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> - <% end %> +
+ <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> +
+ <% @block.first_content_types.each do |type| %> + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> + <% end %> + <% if !@block.more_content_types.empty? %> + <%= _('more') %> + <% end %> + +
+
-- libgit2 0.21.2