[Git][noosfero/noosfero][master] 2 commits: adding fixed articles to discussion block

Rodrigo Souto gitlab at mg.gitlab.com
Tue Oct 23 12:03:36 BRST 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
7a653445 by Leandro Nunes dos Santos at 2018-10-21T13:22:45Z
adding fixed articles to discussion block

- - - - -
e83be027 by Rodrigo Souto at 2018-10-23T14:03:33Z
Merge branch 'add-fixed-article-to-discussion-block' into 'master'

adding fixed articles to discussion block

See merge request noosfero/noosfero!1631
- - - - -


2 changed files:

- plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
- plugins/comment_paragraph/test/unit/discussion_block_test.rb


Changes:

=====================================
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion_block.rb
=====================================
@@ -2,10 +2,12 @@ class CommentParagraphPlugin::DiscussionBlock < Block
 
   settings_items :presentation_mode, :type => String, :default => 'title_only'
   settings_items :total_items, :type => Integer, :default => 5
+  settings_items :fixed_documents_ids, :type => Array, :default => []
   settings_items :discussion_status, :type => Integer
   settings_items :use_portal_community, :type => :boolean, :default => false
+  # settings_items :limit, :type => :integer, :default => 5
 
-  attr_accessible :presentation_mode, :total_items, :discussion_status, :use_portal_community
+  attr_accessible :presentation_mode, :discussion_status, :use_portal_community
 
   VALID_CONTENT = ['CommentParagraphPlugin::Discussion']
 
@@ -22,9 +24,13 @@ class CommentParagraphPlugin::DiscussionBlock < Block
   end
 
   def discussions
+    amount = self.total_items - self.fixed_documents_ids.length
+    if(amount <= 0 )
+      return [];
+    end
     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)
+    discussions = holder.articles.where(type: VALID_CONTENT).order('start_date ASC, end_date ASC, created_at DESC').limit(amount)
     case discussion_status
     when STATUS_NOT_OPENED
       discussions = discussions.where("start_date > ?", current_time)
@@ -37,6 +43,10 @@ class CommentParagraphPlugin::DiscussionBlock < Block
     discussions
   end
 
+  def fixed_documents
+    holder.articles.where(type: VALID_CONTENT, id: self.fixed_documents_ids).order('start_date ASC, end_date ASC, created_at DESC')
+  end
+
   def holder
     return nil if self.box.nil? || self.box.owner.nil?
     if environment_owner?
@@ -51,7 +61,17 @@ class CommentParagraphPlugin::DiscussionBlock < Block
   end
 
   def api_content(params = {})
-    {:articles => Api::Entities::ArticleBase.represent(self.discussions)}.as_json
+    {
+      articles: Api::Entities::ArticleBase.represent(self.discussions),
+      fixed_documents: Api::Entities::ArticleBase.represent(self.fixed_documents),
+      total_items: self.total_items
+    }.as_json
+  end
+
+  def api_content= params
+    super
+    self.total_items= params[:total_items]
+    self.fixed_documents_ids= params[:fixed_documents_ids]
   end
 
   def display_api_content_by_default?


=====================================
plugins/comment_paragraph/test/unit/discussion_block_test.rb
=====================================
@@ -239,6 +239,20 @@ class DiscussionBlockViewTest < ActionView::TestCase
     assert_equivalent [a2.id, a1.id], b.api_content['articles'].map {|a| a[:id]}
   end
 
+  should 'return fixed_documents in api_content' do
+    community = fast_create(Community)
+    community.boxes << Box.new
+    b = CommentParagraphPlugin::DiscussionBlock.new
+    b.box = community.boxes.last
+    b.save
+    a1 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
+    b.fixed_documents_ids = [a1.id]
+    fast_create(Event, :profile_id => community.id)
+    fast_create(TextArticle, :profile_id => community.id)
+    a2 = fast_create(CommentParagraphPlugin::Discussion, :profile_id => community.id)
+    assert_equivalent [a1.id], b.api_content['fixed_documents'].map {|a| a[:id]}
+  end
+
   should 'sort discussions by start_date, end_date and created_at' do
     community = fast_create(Community)
     community.boxes << Box.new



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/5b06b2c52c5a574b31650f4452bec5a3d0688e84...e83be0272b01eac1abcf5de75540bcb3710d06bc

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/5b06b2c52c5a574b31650f4452bec5a3d0688e84...e83be0272b01eac1abcf5de75540bcb3710d06bc
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20181023/941b9b08/attachment-0001.html>


More information about the Noosfero-dev mailing list