noosfero | 6 new commits pushed to repository

Antonio Terceiro gitlab at gitlab.com
Tue Jan 20 15:25:08 BRST 2015


Antonio Terceiro pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/5d8f895c64155b3896e19ca353ac61a30b0b4377">5d8f895c</a> by Luciano
Add order option in display_content plugin

Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/1898d13e1592733b3ffd80b38a9b2c2035ea2b9d">1898d13e</a> by Luciano
Add limit option for display_content_plugin when the dinamically option is selected.

Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/8a2de61f4b9fa25001129c6698496f4aa7a40009">8a2de61f</a> by Luciano
Remove article with title "feed" from list of display_content block

Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/0e6f3ccc5b84c5ce9a78bf2071441291b498b431">0e6f3ccc</a> by Luciano
Add suport in javascript of edit display_content_block to subdirectory

Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/53eb5ba1f2ad04667a015b77ea2b1d8c020bc9d7">53eb5ba1</a> by Gabriela Navarro
Extracting style into css file

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/58156aa712fe4d2a4fff7023d6212250bd170223">58156aa7</a> by Antonio Terceiro
Merge branch 'display_content_feature' into 'master'

Display content feature

Adds new render options for display_content_plugin:
  - User can choose type of ordering, recent or oldest.
  - Limit the number of articles showed when dynamically option is checked.

Fix javascript bug path with subdirectory.

See merge request !406

- - - - -


Changes:

=====================================
plugins/display_content/lib/display_content_block.rb
=====================================
--- a/plugins/display_content/lib/display_content_block.rb
+++ b/plugins/display_content/lib/display_content_block.rb
@@ -25,8 +25,10 @@ class DisplayContentBlock < Block
                               {:value => 'abstract', :checked => true}]
   settings_items :display_folder_children, :type => :boolean, :default => true
   settings_items :types, :type => Array, :default => ['TextileArticle', 'TinyMceArticle', 'RawHTMLArticle']
+  settings_items :order_by_recent, :type => :boolean, :default => :true
+  settings_items :limit_to_show, :type => :integer, :default => 6
 
-  attr_accessible :sections, :checked_nodes, :display_folder_children, :types
+  attr_accessible :sections, :checked_nodes, :display_folder_children, :types, :order_by_recent, :limit_to_show
 
   def self.description
     _('Display your contents')
@@ -117,14 +119,22 @@ class DisplayContentBlock < Block
 
   def content(args={})
     block = self
+
     nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) "
     nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children
 
-    docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}], :include => [:profile, :image, :tags])
+    order_string = "published_at"
+    order_string += " DESC" if order_by_recent
+
+    limit_final = [limit_to_show, 0].max
+
+    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)
+    docs = docs.limit(limit_final) if display_folder_children
+
     proc do
       block.block_title(block.title) +
         content_tag('ul', docs.map {|item|
-        if !item.folder?
+        if !item.folder? && item.class != RssFeed
           content_sections = ''
           read_more_section = ''
           tags_section = ''

=====================================
plugins/display_content/public/style.css
=====================================
--- a/plugins/display_content/public/style.css
+++ b/plugins/display_content/public/style.css
@@ -36,3 +36,7 @@
   color: #FFF;
   padding: 2px;
 }
+
+.limit-input {
+  width: 8%;
+}

=====================================
plugins/display_content/test/unit/display_content_block_test.rb
=====================================
--- a/plugins/display_content/test/unit/display_content_block_test.rb
+++ b/plugins/display_content/test/unit/display_content_block_test.rb
@@ -648,4 +648,67 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
     assert_equal [], block.parent_nodes
   end
 
+  should 'show articles in recent order' do
+    profile = create_user('testuser').person
+    Article.delete_all
+    a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :published_at => DateTime.current)
+    a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :published_at => (DateTime.current + 1))
+
+    block = DisplayContentBlock.new
+    block.sections = [{:value => 'title', :checked => true}]
+    block.nodes = [a1.id, a2.id]
+    box = mock()
+    block.stubs(:box).returns(box)
+    box.stubs(:owner).returns(profile)
+
+    block.order_by_recent = true
+
+    a1_index = instance_eval(&block.content).index(a1.name)
+    a2_index = instance_eval(&block.content).index(a2.name)
+
+    assert a2_index < a1_index
+  end
+
+  should 'show articles in oldest order' do
+    profile = create_user('testuser').person
+    Article.delete_all
+    a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :published_at => DateTime.current)
+    a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :published_at => (DateTime.current + 1))
+
+    block = DisplayContentBlock.new
+    block.sections = [{:value => 'title', :checked => true}]
+    block.nodes = [a1.id, a2.id]
+    box = mock()
+    block.stubs(:box).returns(box)
+    box.stubs(:owner).returns(profile)
+
+    block.order_by_recent = false
+
+    a1_index = instance_eval(&block.content).index(a1.name)
+    a2_index = instance_eval(&block.content).index(a2.name)
+
+    assert a1_index < a2_index
+  end
+
+  should 'show articles in recent order with limit option' do
+    profile = create_user('testuser').person
+    Article.delete_all
+    a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :published_at => DateTime.current)
+    a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id, :published_at => (DateTime.current + 1))
+
+    block = DisplayContentBlock.new
+    block.sections = [{:value => 'title', :checked => true}]
+    block.display_folder_children = true
+    box = mock()
+    block.stubs(:box).returns(box)
+    box.stubs(:owner).returns(profile)
+
+    block.order_by_recent = true
+    block.limit_to_show = 1
+
+    a1_index = instance_eval(&block.content).index(a1.name)
+
+    assert a1_index.nil?
+  end
+
 end

=====================================
plugins/display_content/views/box_organizer/_choose_directly.html.erb
=====================================
--- a/plugins/display_content/views/box_organizer/_choose_directly.html.erb
+++ b/plugins/display_content/views/box_organizer/_choose_directly.html.erb
@@ -5,6 +5,10 @@
   <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %>
 </div>
 
+<div id="limit">
+ <%= labelled_text_field(_('Limit:'), "block[limit_to_show]", @block.limit_to_show, :class => "limit-input") %>
+</div>
+
 <script type="text/javascript" >
 
 jQuery_1_8_3("#display_content").jstree({
@@ -13,7 +17,7 @@ jQuery_1_8_3("#display_content").jstree({
      real_checkboxes : true,
      real_checkboxes_names : function (n) { return [("block[checked_nodes[" + n.attr('node_id') + "]]"), 1]; }
    },
-   themes : {"theme" : "classic", "icons" : true, "url": "/plugins/display_content/javascripts/jstree/themes/classic/style.css"},
+   themes : {"theme" : "classic", "icons" : true, "url": "<%= Noosfero.root %>/plugins/display_content/javascripts/jstree/themes/classic/style.css"},
    json_data : {
      ajax : {
          url : '<%= url_for @block.url_params %>',
@@ -27,4 +31,19 @@ jQuery_1_8_3("#display_content").jstree({
 
 jQuery( "#sortable" ).sortable();
 
+function show_limit_field(show){
+  if (show){
+    jQuery("#limit").show();
+  }else {
+    jQuery("#limit").hide();
+  }
+}
+
+jQuery(document).ready(function(){
+  show_limit_field(jQuery("#block_display_folder_children").is(":checked"));
+  jQuery("#block_display_folder_children").click(function(event){
+    show_limit_field(jQuery("#block_display_folder_children").is(":checked"));
+  });
+});
+
 </script>

=====================================
plugins/display_content/views/box_organizer/_display_content_block.html.erb
=====================================
--- a/plugins/display_content/views/box_organizer/_display_content_block.html.erb
+++ b/plugins/display_content/views/box_organizer/_display_content_block.html.erb
@@ -9,7 +9,7 @@
   <% for section in @block.sections do %>
   <tr>
     <td>
-      <%= hidden_field_tag 'block[sections][][value]', section[:value] %> 
+      <%= hidden_field_tag 'block[sections][][value]', section[:value] %>
       <%= check_box_tag 'block[sections][][checked]', section[:value], section[:checked] %>
     </td>
     <td><%= @block.section_name(section[:value]) %></td>
@@ -25,5 +25,8 @@
 
 <%= render_tabs(tabs) %>
 
+<h3> <%= _('Order by:')%> </h3>
+<%= labelled_radio_button(_("Most recent"), "block[order_by_recent]", true, @block.order_by_recent)%>
+<%= labelled_radio_button(_("Most oldest"), "block[order_by_recent]", false, !@block.order_by_recent)%>
 </div>
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150120/3d31e4d5/attachment-0001.html>


More information about the Noosfero-dev mailing list