Commit 251e6e4367119941bcec2eb845ae99809b6c8b45
Exists in
web_steps_improvements
and in
7 other branches
Merge branch 'display-content-translation' into 'master'
display_content plugin: Filter content by locale Show posts and content based on locale and replaces post with its translation. See merge request !835
Showing
3 changed files
with
67 additions
and
2 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
@@ -26,9 +26,10 @@ class DisplayContentBlock < Block | @@ -26,9 +26,10 @@ class DisplayContentBlock < Block | ||
26 | settings_items :display_folder_children, :type => :boolean, :default => true | 26 | settings_items :display_folder_children, :type => :boolean, :default => true |
27 | settings_items :types, :type => Array, :default => ['TextileArticle', 'TinyMceArticle', 'RawHTMLArticle'] | 27 | settings_items :types, :type => Array, :default => ['TextileArticle', 'TinyMceArticle', 'RawHTMLArticle'] |
28 | settings_items :order_by_recent, :type => :boolean, :default => :true | 28 | settings_items :order_by_recent, :type => :boolean, :default => :true |
29 | + settings_items :content_with_translations, :type => :boolean, :default => :true | ||
29 | settings_items :limit_to_show, :type => :integer, :default => 6 | 30 | settings_items :limit_to_show, :type => :integer, :default => 6 |
30 | 31 | ||
31 | - attr_accessible :sections, :checked_nodes, :display_folder_children, :types, :order_by_recent, :limit_to_show | 32 | + attr_accessible :sections, :checked_nodes, :display_folder_children, :types, :order_by_recent, :limit_to_show, :content_with_translations |
32 | 33 | ||
33 | def self.description | 34 | def self.description |
34 | _('Display your contents') | 35 | _('Display your contents') |
@@ -129,8 +130,14 @@ class DisplayContentBlock < Block | @@ -129,8 +130,14 @@ class DisplayContentBlock < Block | ||
129 | limit_final = [limit_to_show, 0].max | 130 | limit_final = [limit_to_show, 0].max |
130 | 131 | ||
131 | docs = owner.articles.order(order_string).where(["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}]).includes(:profile, :image, :tags) | 132 | docs = owner.articles.order(order_string).where(["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}]).includes(:profile, :image, :tags) |
133 | + | ||
132 | docs = docs.limit(limit_final) if display_folder_children | 134 | docs = docs.limit(limit_final) if display_folder_children |
133 | 135 | ||
136 | + if content_with_translations | ||
137 | + docs = docs.native_translations | ||
138 | + docs.replace docs.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | ||
139 | + end | ||
140 | + | ||
134 | proc do | 141 | proc do |
135 | block.block_title(block.title) + | 142 | block.block_title(block.title) + |
136 | content_tag('ul', docs.map {|item| | 143 | content_tag('ul', docs.map {|item| |
plugins/display_content/test/unit/display_content_block_test.rb
@@ -711,4 +711,59 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -711,4 +711,59 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
711 | assert a1_index.nil? | 711 | assert a1_index.nil? |
712 | end | 712 | end |
713 | 713 | ||
714 | + should 'show only articles with current locale translation' do | ||
715 | + FastGettext.stubs(:locale).returns('pt') | ||
716 | + profile = create_user('testuser').person | ||
717 | + Article.delete_all | ||
718 | + | ||
719 | + en_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article', :language => 'en') | ||
720 | + en_article2 = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article 2', :language => 'en') | ||
721 | + | ||
722 | + pt_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'pt_article', :language => 'pt') | ||
723 | + | ||
724 | + block = DisplayContentBlock.new | ||
725 | + block.sections = [{:value => 'title', :checked => true}] | ||
726 | + block.content_with_translations = true | ||
727 | + block.limit_to_show = 2 | ||
728 | + | ||
729 | + box = mock() | ||
730 | + block.stubs(:box).returns(box) | ||
731 | + box.stubs(:owner).returns(profile) | ||
732 | + | ||
733 | + assert_nil instance_eval(&block.content).index(en_article.name) | ||
734 | + assert_nil instance_eval(&block.content).index(en_article2.name) | ||
735 | + assert instance_eval(&block.content).index(pt_article.name).present? | ||
736 | + | ||
737 | + FastGettext.stubs(:locale).returns('en') | ||
738 | + | ||
739 | + assert instance_eval(&block.content).index(en_article.name).present? | ||
740 | + assert instance_eval(&block.content).index(en_article2.name).present? | ||
741 | + assert_nil instance_eval(&block.content).index(pt_article.name) | ||
742 | + end | ||
743 | + | ||
744 | + should 'replace article with its translation' do | ||
745 | + FastGettext.stubs(:locale).returns('pt') | ||
746 | + profile = create_user('testuser').person | ||
747 | + Article.delete_all | ||
748 | + | ||
749 | + en_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'en_article', :language => 'en') | ||
750 | + pt_article = fast_create(TextileArticle, :profile_id => profile.id, :name => 'pt_article', :language => 'pt', :translation_of_id => en_article) | ||
751 | + | ||
752 | + block = DisplayContentBlock.new | ||
753 | + block.sections = [{:value => 'title', :checked => true}] | ||
754 | + block.content_with_translations = true | ||
755 | + block.limit_to_show = 2 | ||
756 | + | ||
757 | + box = mock() | ||
758 | + block.stubs(:box).returns(box) | ||
759 | + box.stubs(:owner).returns(profile) | ||
760 | + | ||
761 | + assert_nil instance_eval(&block.content).index(en_article.name) | ||
762 | + assert instance_eval(&block.content).index(pt_article.name).present? | ||
763 | + | ||
764 | + FastGettext.stubs(:locale).returns('en') | ||
765 | + | ||
766 | + assert instance_eval(&block.content).index(en_article.name).present? | ||
767 | + assert_nil instance_eval(&block.content).index(pt_article.name) | ||
768 | + end | ||
714 | end | 769 | end |
plugins/display_content/views/box_organizer/_display_content_block.html.erb
@@ -28,5 +28,8 @@ | @@ -28,5 +28,8 @@ | ||
28 | <h3> <%= _('Order by:')%> </h3> | 28 | <h3> <%= _('Order by:')%> </h3> |
29 | <%= labelled_radio_button(_("Most recent"), "block[order_by_recent]", true, @block.order_by_recent)%> | 29 | <%= labelled_radio_button(_("Most recent"), "block[order_by_recent]", true, @block.order_by_recent)%> |
30 | <%= labelled_radio_button(_("Most oldest"), "block[order_by_recent]", false, !@block.order_by_recent)%> | 30 | <%= labelled_radio_button(_("Most oldest"), "block[order_by_recent]", false, !@block.order_by_recent)%> |
31 | -</div> | ||
32 | 31 | ||
32 | +<h3> <%= _('Translations:')%> </h3> | ||
33 | +<%= labelled_check_box(_('List only translated content'), 'block[content_with_translations]', true) %> | ||
34 | + | ||
35 | +</div> |