From 1a86a1c3e44736a789b070700649101caad749c1 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Wed, 21 Oct 2015 12:15:22 -0200 Subject: [PATCH] Do not list the event in its event page --- src/noosfero-spb/software_communities/lib/software_communities_plugin.rb | 2 +- src/noosfero-spb/software_communities/lib/software_events_block.rb | 20 ++++++++++++++++---- src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb | 51 ++++++++++++++++++++++++++++++++++++++------------- src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb | 2 +- src/noosfero-spb/software_communities/views/blocks/software_events.html.erb | 27 ++++++++++++++++++--------- 5 files changed, 74 insertions(+), 28 deletions(-) diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb index 8b685bb..c546163 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb @@ -44,7 +44,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin SoftwareTabDataBlock => {:type => [Community], :position => 1}, WikiBlock => {:type => [Community]}, StatisticBlock => { :type => [Community] }, - SoftwareEventsBlock => { :type => [Community], :position => 1 } + SoftwareEventsBlock => { :type => [Community] } } end diff --git a/src/noosfero-spb/software_communities/lib/software_events_block.rb b/src/noosfero-spb/software_communities/lib/software_events_block.rb index 8d2eb89..a028d5c 100644 --- a/src/noosfero-spb/software_communities/lib/software_events_block.rb +++ b/src/noosfero-spb/software_communities/lib/software_events_block.rb @@ -9,14 +9,12 @@ class SoftwareEventsBlock < Block end def content(args={}) - events = community_events - block = self lambda do |object| render( :file => 'blocks/software_events', - :locals => { :block => block, :events => events } + :locals => { :block => block } ) end end @@ -25,8 +23,22 @@ class SoftwareEventsBlock < Block false end - def community_events + def get_events today = DateTime.now.beginning_of_day self.owner.events.where("end_date >= ?", today).order(:start_date) end + + def get_events_except event_slug="" + event_slug = "" if event_slug.nil? + + get_events.where("slug NOT IN (?)", event_slug) + end + + def has_events_to_display? + not get_events.empty? + end + + def should_display_title? + self.box.position != 1 + end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb index 290c8f1..e0403b0 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb @@ -9,30 +9,55 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase @software_events_block = SoftwareEventsBlock.new box = Box.new + box.position = 1 box.owner = @community box.blocks << @software_events_block box.save! - end - - should "give community events that have not yet finished ordered by start date" do - assert_equal true, @software_events_block.community_events.empty? - e1 = Event.new :name=>"Event 1", :body=>"Event 1 body", + @e1 = Event.new :name=>"Event 1", :body=>"Event 1 body", :start_date=>DateTime.now, :end_date=>(DateTime.now + 1.month) - e2 = Event.new :name=>"Event 2", :body=>"Event 2 body", + @e2 = Event.new :name=>"Event 2", :body=>"Event 2 body", :start_date=>(DateTime.now - 10.days), :end_date=>(DateTime.now + 10.days) - e3 = Event.new :name=>"Event 3", :body=>"Event 3 body", + @e3 = Event.new :name=>"Event 3", :body=>"Event 3 body", :start_date=>(DateTime.now - 20.days), :end_date=>(DateTime.now - 10.days) - @community.events << e1 - @community.events << e2 - @community.events << e3 + @community.events << @e1 + @community.events << @e2 + @community.events << @e3 @community.save! + end + + should "give community events that have not yet finished ordered by start date" do + events = @software_events_block.get_events + + assert_equal false, events.include?(@e3) + assert_equal @e2, events.first + assert_equal @e1, events.last + end + + should "give community events except by a event with a given slug" do + events = @software_events_block.get_events_except(@e1.slug) + + assert_equal false, events.include?(@e1) + end + + should "tell if there are events to be displayed" do + assert_equal true, @software_events_block.has_events_to_display? + + @community.events.update_all :start_date => (DateTime.now - 2.days), + :end_date => (DateTime.now - 1.day) + + assert_equal false, @software_events_block.has_events_to_display? + end + + should "tell that the block must show the title in other areas that are no the main area" do + assert_equal false, @software_events_block.should_display_title? + + @software_events_block.box.position = 3 + @software_events_block.save! - assert_equal false, @software_events_block.community_events.include?(e3) - assert_equal e2, @software_events_block.community_events.first - assert_equal e1, @software_events_block.community_events.last + assert_equal true, @software_events_block.should_display_title? end end diff --git a/src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb b/src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb index 6994ded..6a1624b 100644 --- a/src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb +++ b/src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb @@ -1,4 +1,4 @@ - +
<%= event.start_date.strftime "%d/%m - " %> diff --git a/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb b/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb index 13802ce..65dec68 100644 --- a/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb +++ b/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb @@ -1,13 +1,22 @@
- <% if not events.empty? %> + <% if block.has_events_to_display? %> +
    -
      - <% events.each do |event| %> -
    • - <%= render :partial=>"blocks/software_events_list_item", - :locals => {:event => event} %> -
    • - <% end %> -
    + <% if block.should_display_title? %> +
  • + + <%= block.title %> + +
  • + <% end %> + + <% block.get_events_except(params[:page]).each do |event| %> +
  • + <%= render :partial=>"blocks/software_events_list_item", + :locals => {:event => event} %> +
  • + <% end %> + +
<% end %>
-- libgit2 0.21.2