Commit cd91600715b9d2bd483b670ed051c92031f936cb
1 parent
46095aa0
Exists in
master
and in
29 other branches
Adding support to choose which attributes will be displayed
Showing
5 changed files
with
92 additions
and
3 deletions
Show diff stats
plugins/display_content/lib/display_content_block.rb
@@ -2,6 +2,7 @@ class DisplayContentBlock < Block | @@ -2,6 +2,7 @@ class DisplayContentBlock < Block | ||
2 | 2 | ||
3 | settings_items :nodes, :type => Array, :default => [] | 3 | settings_items :nodes, :type => Array, :default => [] |
4 | settings_items :parent_nodes, :type => Array, :default => [] | 4 | settings_items :parent_nodes, :type => Array, :default => [] |
5 | + settings_items :chosen_attributes, :type => Array, :default => ['title'] | ||
5 | 6 | ||
6 | def self.description | 7 | def self.description |
7 | _('Display your contents') | 8 | _('Display your contents') |
@@ -41,8 +42,9 @@ class DisplayContentBlock < Block | @@ -41,8 +42,9 @@ class DisplayContentBlock < Block | ||
41 | block_title(title) + | 42 | block_title(title) + |
42 | content_tag('ul', docs.map {|item| | 43 | content_tag('ul', docs.map {|item| |
43 | content_tag('li', | 44 | content_tag('li', |
44 | - link_to(h(item.title), item.url) + "<br/>" + | ||
45 | - content_tag('div', item.abstract ,:class => 'lead') | 45 | + (display_attribute?('title') ? content_tag('div', link_to(h(item.title), item.url), :class => 'title') : '') + |
46 | + (display_attribute?('abstract') ? content_tag('div', item.abstract ,:class => 'lead') : '') + | ||
47 | + (display_attribute?('body') ? content_tag('div', item.body ,:class => 'body') : '') | ||
46 | ) | 48 | ) |
47 | }.join("\n")) | 49 | }.join("\n")) |
48 | 50 | ||
@@ -59,6 +61,10 @@ class DisplayContentBlock < Block | @@ -59,6 +61,10 @@ class DisplayContentBlock < Block | ||
59 | params | 61 | params |
60 | end | 62 | end |
61 | 63 | ||
64 | + def display_attribute?(attr) | ||
65 | + chosen_attributes.include?(attr) | ||
66 | + end | ||
67 | + | ||
62 | protected | 68 | protected |
63 | 69 | ||
64 | def holder | 70 | def holder |
plugins/display_content/lib/display_content_plugin.rb
@@ -20,6 +20,11 @@ class DisplayContentPlugin < Noosfero::Plugin | @@ -20,6 +20,11 @@ class DisplayContentPlugin < Noosfero::Plugin | ||
20 | false | 20 | false |
21 | end | 21 | end |
22 | 22 | ||
23 | + #FIXME make this test | ||
24 | + def stylesheet? | ||
25 | + true | ||
26 | + end | ||
27 | + | ||
23 | def js_files | 28 | def js_files |
24 | ['/javascripts/jstree/_lib/jquery-1.8.3.js', '/javascripts/jstree/jquery.jstree.js'] | 29 | ['/javascripts/jstree/_lib/jquery-1.8.3.js', '/javascripts/jstree/jquery.jstree.js'] |
25 | end | 30 | end |
plugins/display_content/test/unit/display_content_block_test.rb
@@ -559,13 +559,14 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -559,13 +559,14 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
559 | assert_match /.*<a.*>#{a2.title}<\/a>/, block.content | 559 | assert_match /.*<a.*>#{a2.title}<\/a>/, block.content |
560 | end | 560 | end |
561 | 561 | ||
562 | - should 'list links for all articles lead defined in nodes' do | 562 | + should 'list content for all articles lead defined in nodes' do |
563 | profile = create_user('testuser').person | 563 | profile = create_user('testuser').person |
564 | Article.delete_all | 564 | Article.delete_all |
565 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') | 565 | a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') |
566 | a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') | 566 | a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') |
567 | 567 | ||
568 | block = DisplayContentBlock.new | 568 | block = DisplayContentBlock.new |
569 | + block.chosen_attributes = ['abstract'] | ||
569 | block.nodes = [a1.id, a2.id] | 570 | block.nodes = [a1.id, a2.id] |
570 | box = mock() | 571 | box = mock() |
571 | block.stubs(:box).returns(box) | 572 | block.stubs(:box).returns(box) |
@@ -612,4 +613,63 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | @@ -612,4 +613,63 @@ class DisplayContentBlockTest < ActiveSupport::TestCase | ||
612 | assert_equal params, block.url_params | 613 | assert_equal params, block.url_params |
613 | end | 614 | end |
614 | 615 | ||
616 | + should 'show title if defined by user' do | ||
617 | + profile = create_user('testuser').person | ||
618 | + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | ||
619 | + | ||
620 | + block = DisplayContentBlock.new | ||
621 | + block.nodes = [a.id] | ||
622 | + block.chosen_attributes = ['title'] | ||
623 | + box = mock() | ||
624 | + block.stubs(:box).returns(box) | ||
625 | + box.stubs(:owner).returns(profile) | ||
626 | + | ||
627 | + assert_match /.*<a.*>#{a.title}<\/a>/, block.content | ||
628 | + end | ||
629 | + | ||
630 | + should 'show abstract if defined by user' do | ||
631 | + profile = create_user('testuser').person | ||
632 | + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'some abstract') | ||
633 | + | ||
634 | + block = DisplayContentBlock.new | ||
635 | + block.nodes = [a.id] | ||
636 | + block.chosen_attributes = ['abstract'] | ||
637 | + box = mock() | ||
638 | + block.stubs(:box).returns(box) | ||
639 | + box.stubs(:owner).returns(profile) | ||
640 | + | ||
641 | + assert_match /#{a.abstract}/, block.content | ||
642 | + end | ||
643 | + | ||
644 | + should 'show body if defined by user' do | ||
645 | + profile = create_user('testuser').person | ||
646 | + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') | ||
647 | + | ||
648 | + block = DisplayContentBlock.new | ||
649 | + block.nodes = [a.id] | ||
650 | + block.chosen_attributes = ['body'] | ||
651 | + box = mock() | ||
652 | + block.stubs(:box).returns(box) | ||
653 | + box.stubs(:owner).returns(profile) | ||
654 | + | ||
655 | + assert_match /#{a.body}/, block.content | ||
656 | + end | ||
657 | + | ||
658 | + should 'display_attribute be true for title by default' do | ||
659 | + profile = create_user('testuser').person | ||
660 | + | ||
661 | + block = DisplayContentBlock.new | ||
662 | + | ||
663 | + assert block.display_attribute?('title') | ||
664 | + end | ||
665 | + | ||
666 | + should 'display_attribute be true if the attribute was chosen' do | ||
667 | + profile = create_user('testuser').person | ||
668 | + | ||
669 | + block = DisplayContentBlock.new | ||
670 | + block.chosen_attributes = ['body'] | ||
671 | + | ||
672 | + assert block.display_attribute?('body') | ||
673 | + end | ||
674 | + | ||
615 | end | 675 | end |
plugins/display_content/views/box_organizer/_display_content_block.rhtml
1 | +<div id="display_content_plugin"> | ||
2 | + | ||
3 | +<h3> <%= _('Choose which attributes should be displayed:') %> </h3> | ||
4 | +<ul class='display_attributes'> | ||
5 | + <li> <%= _('Title: ')%> <%= check_box_tag "block[chosen_attributes][]", 'title', @block.display_attribute?('title') %> </li> | ||
6 | + <li> <%= _('Abstract: ')%> <%= check_box_tag "block[chosen_attributes][]", 'abstract', @block.display_attribute?('abstract') %> </li> | ||
7 | + <li> <%= _('Body: ')%> <%= check_box_tag "block[chosen_attributes][]", 'body', @block.display_attribute?('body') %> </li> | ||
8 | +</ul> | ||
9 | + | ||
10 | +<h3> <%= _('Choose which content should be displayed:') %> </h3> | ||
1 | <div id="display_content"> | 11 | <div id="display_content"> |
2 | </div> | 12 | </div> |
3 | 13 | ||
@@ -22,3 +32,4 @@ jQuery_1_8_3("#display_content").jstree({ | @@ -22,3 +32,4 @@ jQuery_1_8_3("#display_content").jstree({ | ||
22 | }); | 32 | }); |
23 | 33 | ||
24 | </script> | 34 | </script> |
35 | +</div> |