Commit 8594cee9327339d35dd67660a4f250b9c54cf3d4

Authored by Joenio
2 parents 3a90b4b9 97647ee7

Merge branch 'software_events_block' into 'master'

Software events block

Issue: https://softwarepublico.gov.br/gitlab/softwarepublico/softwarepublico/issues/302

O design do bloco está em: https://softwarepublico.gov.br/gitlab/softwarepublico/noosfero-spb-theme/commits/event_block

See merge request !56
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
... ... @@ -43,7 +43,8 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
43 43 SoftwareHighlightsBlock => { :type => [Environment] },
44 44 SoftwareTabDataBlock => {:type => [Community], :position => 1},
45 45 WikiBlock => {:type => [Community]},
46   - StatisticBlock => { :type => [Community] }
  46 + StatisticBlock => { :type => [Community] },
  47 + SoftwareEventsBlock => { :type => [Community] }
47 48 }
48 49 end
49 50  
... ...
src/noosfero-spb/software_communities/lib/software_events_block.rb 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +class SoftwareEventsBlock < Block
  2 +
  3 + def self.description
  4 + _('Software community events')
  5 + end
  6 +
  7 + def help
  8 + _('This block displays the software community events in a list.')
  9 + end
  10 +
  11 + def content(args={})
  12 + block = self
  13 +
  14 + lambda do |object|
  15 + render(
  16 + :file => 'blocks/software_events',
  17 + :locals => { :block => block }
  18 + )
  19 + end
  20 + end
  21 +
  22 + def cacheable?
  23 + false
  24 + end
  25 +
  26 + def get_events
  27 + today = DateTime.now.beginning_of_day
  28 + self.owner.events.where("end_date >= ?", today).order(:start_date)
  29 + end
  30 +
  31 + def get_events_except event_slug=""
  32 + event_slug = "" if event_slug.nil?
  33 +
  34 + get_events.where("slug NOT IN (?)", event_slug)
  35 + end
  36 +
  37 + def has_events_to_display?
  38 + not get_events.empty?
  39 + end
  40 +
  41 + def should_display_title?
  42 + self.box.position != 1
  43 + end
  44 +end
... ...
src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class SoftwareEventsBlockTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + def setup
  8 + @community = create_community("A new community")
  9 + @software_events_block = SoftwareEventsBlock.new
  10 +
  11 + box = Box.new
  12 + box.position = 1
  13 + box.owner = @community
  14 + box.blocks << @software_events_block
  15 + box.save!
  16 +
  17 + @e1 = Event.new :name=>"Event 1", :body=>"Event 1 body",
  18 + :start_date=>DateTime.now, :end_date=>(DateTime.now + 1.month)
  19 +
  20 + @e2 = Event.new :name=>"Event 2", :body=>"Event 2 body",
  21 + :start_date=>(DateTime.now - 10.days), :end_date=>(DateTime.now + 10.days)
  22 +
  23 + @e3 = Event.new :name=>"Event 3", :body=>"Event 3 body",
  24 + :start_date=>(DateTime.now - 20.days), :end_date=>(DateTime.now - 10.days)
  25 +
  26 + @community.events << @e1
  27 + @community.events << @e2
  28 + @community.events << @e3
  29 + @community.save!
  30 + end
  31 +
  32 + should "give community events that have not yet finished ordered by start date" do
  33 + events = @software_events_block.get_events
  34 +
  35 + assert_equal false, events.include?(@e3)
  36 + assert_equal @e2, events.first
  37 + assert_equal @e1, events.last
  38 + end
  39 +
  40 + should "give community events except by a event with a given slug" do
  41 + events = @software_events_block.get_events_except(@e1.slug)
  42 +
  43 + assert_equal false, events.include?(@e1)
  44 + end
  45 +
  46 + should "tell if there are events to be displayed" do
  47 + assert_equal true, @software_events_block.has_events_to_display?
  48 +
  49 + @community.events.update_all :start_date => (DateTime.now - 2.days),
  50 + :end_date => (DateTime.now - 1.day)
  51 +
  52 + assert_equal false, @software_events_block.has_events_to_display?
  53 + end
  54 +
  55 + should "tell that the block must show the title in other areas that are no the main area" do
  56 + assert_equal false, @software_events_block.should_display_title?
  57 +
  58 + @software_events_block.box.position = 3
  59 + @software_events_block.save!
  60 +
  61 + assert_equal true, @software_events_block.should_display_title?
  62 + end
  63 +end
... ...
src/noosfero-spb/software_communities/views/blocks/_software_events_list_item.html.erb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<div class="software-events-list-item-calendar"></div>
  2 +
  3 +<span class="software-events-list-item-date">
  4 + <%= event.start_date.strftime "%d/%m - " %>
  5 +</span>
  6 +
  7 +<span class="software-events-list-item-title">
  8 + <%= link_to event.title, event.url %>
  9 +</span>
... ...
src/noosfero-spb/software_communities/views/blocks/software_events.html.erb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +<div class="software-community-events-block">
  2 + <% if block.has_events_to_display? %>
  3 + <ul class="software-community-events-list">
  4 +
  5 + <% if block.should_display_title? %>
  6 + <li class="software-events-list-item">
  7 + <span class="software-events-list-item-title">
  8 + <%= block.title %>
  9 + </span>
  10 + </li>
  11 + <% end %>
  12 +
  13 + <% block.get_events_except(params[:page]).each do |event| %>
  14 + <li class="software-events-list-item">
  15 + <%= render :partial=>"blocks/software_events_list_item",
  16 + :locals => {:event => event} %>
  17 + </li>
  18 + <% end %>
  19 +
  20 + </ul>
  21 + <% end %>
  22 +</div>
... ...