Commit 8100e1efa9b9499ff8ef319d571956add96c434f

Authored by Fabio Teixeira
Committed by Tallys Martins
1 parent 878fa51b

Add block with tabs to colab data insertion

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/software_communities_plugin.rb
... ... @@ -40,7 +40,8 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
40 40 CategoriesAndTagsBlock => { :type => [Community] },
41 41 CategoriesSoftwareBlock => { :type => [Environment] },
42 42 SearchCatalogBlock => { :type => [Environment] },
43   - SoftwareHighlightsBlock => { :type => [Environment] }
  43 + SoftwareHighlightsBlock => { :type => [Environment] },
  44 + SoftwareTabDataBlock => {:type => [Community], :position => 1}
44 45 }
45 46 end
46 47  
... ...
lib/software_tab_data_block.rb 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +class SoftwareTabDataBlock < Block
  2 + attr_accessible :show_name, :displayed_blog
  3 +
  4 + settings_items :show_name, :type => :boolean, :default => false
  5 + settings_items :displayed_blog, :type => :integer, :default => 0
  6 +
  7 + TOTAL_POSTS_DYSPLAYED = 5
  8 +
  9 + def self.description
  10 + _('Software Tab Data')
  11 + end
  12 +
  13 + def help
  14 + _('This block is used by colab to insert data into Noosfero')
  15 + end
  16 +
  17 + def content(args={})
  18 + block = self
  19 +
  20 + lambda do |object|
  21 + render(
  22 + :file => 'blocks/software_tab_data',
  23 + :locals => {
  24 + :block => block
  25 + }
  26 + )
  27 + end
  28 + end
  29 +
  30 + def blogs
  31 + self.owner.blogs
  32 + end
  33 +
  34 + def actual_blog
  35 + # As :displayed_blog default value is 0, it falls to the first one
  36 + blogs.find_by_id(self.displayed_blog) || blogs.first
  37 + end
  38 +
  39 + def posts
  40 + blog = actual_blog
  41 +
  42 + if blog and (not blog.posts.empty?)
  43 + blog.posts.limit(TOTAL_POSTS_DYSPLAYED)
  44 + else
  45 + []
  46 + end
  47 + end
  48 +end
... ...
test/unit/software_tab_data_block_test.rb 0 → 100644
... ... @@ -0,0 +1,66 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class SoftwareTabDataBlockTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + def setup
  8 + @software_info = create_software_info("A new Software")
  9 + @software_info.save!
  10 +
  11 + @soft_community = @software_info.community
  12 +
  13 + @soft_community.blogs << Blog.new(:name=>"First blog")
  14 + @soft_community.blogs << Blog.new(:name=>"Second blog")
  15 + @soft_community.save!
  16 +
  17 + SoftwareTabDataBlock.any_instance.stubs(:owner).returns(@soft_community)
  18 + end
  19 +
  20 + should "get its owner blogs" do
  21 + assert_equal @soft_community.blogs, SoftwareTabDataBlock.new.blogs
  22 + end
  23 +
  24 + should "actual_blog get the first blog if it is not defined" do
  25 + assert_equal @soft_community.blogs.first, SoftwareTabDataBlock.new.actual_blog
  26 + end
  27 +
  28 + should "actual_blog get the defined community blog" do
  29 + last_blog = @soft_community.blogs.last
  30 + soft_tab_data = create_software_tab_data_block(last_blog)
  31 +
  32 + assert_equal last_blog, soft_tab_data.actual_blog
  33 + end
  34 +
  35 + should "get the actual_blog posts" do
  36 + last_blog = @soft_community.blogs.last
  37 + soft_tab_data = create_software_tab_data_block(last_blog)
  38 + craete_sample_posts(last_blog, 2)
  39 +
  40 + assert_equal last_blog.posts.first.id, soft_tab_data.posts.first.id
  41 + assert_equal last_blog.posts.last.id, soft_tab_data.posts.last.id
  42 + end
  43 +
  44 + should "limit the number of posts" do
  45 + last_blog = @soft_community.blogs.last
  46 + soft_tab_data = create_software_tab_data_block(last_blog)
  47 + craete_sample_posts(last_blog, 6)
  48 +
  49 + assert_equal SoftwareTabDataBlock::TOTAL_POSTS_DYSPLAYED, soft_tab_data.posts.count
  50 + end
  51 +
  52 + private
  53 +
  54 + def create_software_tab_data_block blog
  55 + soft_tab_data = SoftwareTabDataBlock.new
  56 + soft_tab_data.displayed_blog = blog.id
  57 + soft_tab_data
  58 + end
  59 +
  60 + def craete_sample_posts blog, quantity=1
  61 + quantity.times do |number|
  62 + TinyMceArticle.create! :name=>"Simple post #{number}", :body=>"Simple post #{number}",
  63 + :parent=> blog, :profile=>@soft_community
  64 + end
  65 + end
  66 +end
... ...
views/blocks/_software_tab_blog.html.erb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<div id="article" class="blog">
  2 + <div class="article-body article-body-blog">
  3 + <% if block.posts.empty? %>
  4 + <div class="software-blog-post-empty">
  5 + <%= _("This community has no posts in its blog") %>
  6 + </div>
  7 + <% else %>
  8 + <div class="blog-posts">
  9 + <%= list_posts(block.posts, format: "compact", paginate: false) %>
  10 + </div>
  11 +
  12 + <div class="read-more">
  13 + <%= link_to _("Read more"), block.actual_blog.url %>
  14 + </div>
  15 + <% end %>
  16 + </div>
  17 +</div>
... ...
views/blocks/software_tab_data.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<div id="block-community-tabs">
  2 + <% tabs = [] %>
  3 + <% tabs << {:title => _("Activity"), :id => 'activity-tab', :content => ""} %>
  4 + <% tabs << {:title => _("Discussions"), :id => 'discussions-tab', :content => ""} %>
  5 + <% tabs << {:title => _("Blog"), :id => 'blog-tab', :content => (render partial: "blocks/software_tab_blog", :locals => {block: block})} %>
  6 + <% tabs << {:title => _("Wiki"), :id => 'wiki-tab', :content => ""} %>
  7 + <% tabs << {:title => _("Repository Feed"), :id => 'repository-feed-tab', :content => ""} %>
  8 +
  9 + <%= render_tabs(tabs) %>
  10 +</div>
... ...
views/box_organizer/_software_tab_data_block.html.erb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<br />
  2 +
  3 +<% if not @block.blogs.empty? %>
  4 + <label for="block_displayed_blog">
  5 + <%= _("Which blog should have its posts displayed: ")%>
  6 + </label>
  7 +
  8 + <br />
  9 +
  10 + <%= select_tag 'block[displayed_blog]', options_from_collection_for_select(@block.blogs, :id, :name, @block.actual_blog.id) %>
  11 +<% else %>
  12 + <div class="software-blog-empty">
  13 + <h2> <%= _("This community has no blogs") %> </h2>
  14 + </div>
  15 +<% end %>
... ...