[Git][noosfero/noosfero][master] 2 commits: comment_paragraph: add option to display all environment discussions
Leandro Nunes
gitlab at mg.gitlab.com
Tue Dec 6 16:03:57 BRST 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
3ad66806 by Victor Costa at 2016-12-02T10:51:24-03:00
comment_paragraph: add option to display all environment discussions
- - - - -
c2fa63c6 by Leandro Nunes at 2016-12-06T18:03:53+00:00
Merge branch 'discussion-block' into 'master'
comment_paragraph: add option to display all environment discussions
See merge request !1061
- - - - -
3 changed files:
- plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
- plugins/comment_paragraph/test/unit/discussion_block_test.rb
- plugins/comment_paragraph/views/box_organizer/comment_paragraph_plugin/_discussion_block.html.erb
Changes:
=====================================
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
=====================================
--- a/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
+++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
@@ -3,8 +3,9 @@ class CommentParagraphPlugin::DiscussionBlock < Block
settings_items :presentation_mode, :type => String, :default => 'title_only'
settings_items :total_items, :type => Integer, :default => 5
settings_items :discussion_status, :type => Integer
+ settings_items :use_portal_community, :type => :boolean, :default => false
- attr_accessible :presentation_mode, :total_items, :discussion_status
+ attr_accessible :presentation_mode, :total_items, :discussion_status, :use_portal_community
VALID_CONTENT = ['CommentParagraphPlugin::Discussion']
@@ -22,6 +23,7 @@ class CommentParagraphPlugin::DiscussionBlock < Block
def discussions
current_time = Time.now
+ return [] if holder.blank?
discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date ASC, created_at DESC').limit(self.total_items)
case discussion_status
when STATUS_NOT_OPENED
@@ -37,9 +39,8 @@ class CommentParagraphPlugin::DiscussionBlock < Block
def holder
return nil if self.box.nil? || self.box.owner.nil?
- if self.box.owner.kind_of?(Environment)
- return nil if self.box.owner.portal_community.nil?
- self.box.owner.portal_community
+ if environment_owner?
+ use_portal_community ? self.box.owner.portal_community : self.box.owner
else
self.box.owner
end
@@ -56,4 +57,8 @@ class CommentParagraphPlugin::DiscussionBlock < Block
def display_api_content_by_default?
false
end
+
+ def environment_owner?
+ self.box.owner.kind_of?(Environment)
+ end
end
=====================================
plugins/comment_paragraph/test/unit/discussion_block_test.rb
=====================================
--- a/plugins/comment_paragraph/test/unit/discussion_block_test.rb
+++ b/plugins/comment_paragraph/test/unit/discussion_block_test.rb
@@ -24,20 +24,21 @@ class DiscussionBlockTest < ActiveSupport::TestCase
assert_nil b.holder
end
- should 'holder be nil if there is no portal community in environment' do
+ should 'holder be the environment if there is no portal community in environment' do
b = CommentParagraphPlugin::DiscussionBlock.new
environment.boxes<< Box.new
b.box = environment.boxes.last
assert_nil environment.portal_community
- assert_nil b.holder
+ assert_equal environment, b.holder
end
- should 'holder be the portal community for environments blocks' do
+ should 'holder be the portal community for environments blocks when use_portal_community is true' do
community = fast_create(Community)
environment.portal_community= community
environment.save!
environment.boxes<< Box.new
b = CommentParagraphPlugin::DiscussionBlock.new
+ b.use_portal_community = true
b.box = environment.boxes.last
assert_equal environment.portal_community, b.holder
end
@@ -66,6 +67,11 @@ class DiscussionBlockTest < ActiveSupport::TestCase
assert_equal enterprise, b.holder
end
+ should 'discussions be empty when holder is nil' do
+ b = CommentParagraphPlugin::DiscussionBlock.new
+ assert b.discussions.blank?
+ end
+
should 'discussions return only discussion articles' do
community = fast_create(Community)
community.boxes << Box.new
=====================================
plugins/comment_paragraph/views/box_organizer/comment_paragraph_plugin/_discussion_block.html.erb
=====================================
--- a/plugins/comment_paragraph/views/box_organizer/comment_paragraph_plugin/_discussion_block.html.erb
+++ b/plugins/comment_paragraph/views/box_organizer/comment_paragraph_plugin/_discussion_block.html.erb
@@ -26,3 +26,6 @@ labelled_form_field(_('Choose how the content should be displayed'),
@block.total_items, :size => 3, :maxlength => 5)
)
%>
+<% if @block.environment_owner? %>
+ <%= labelled_check_box(_('Display only discussions from portal community'), 'block[use_portal_community]', true, @block.use_portal_community, :id => 'checkbox-use-portal-community') %>
+<% end %>
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/3aa953a12645a36622ec20a5234f0ed09c1501b3...c2fa63c64415cbbc037a1b87b3dbe7cf7ac93a09
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20161206/4229d1c3/attachment-0001.html>
More information about the Noosfero-dev
mailing list