Commit af25f7a4ec4269ab53804a99c1e7ff60d5fa6a93
1 parent
37e8561e
Exists in
master
and in
27 other branches
[event_plugin] displaying profile events
Also: - By default, list only future events - Replacing strings describing the number of days left/past to the event - Removed br tags and added margin on elements from edit block view - Only display option "Show all environment events" if there's another option - Fixed tests See merge request !400
Showing
6 changed files
with
55 additions
and
47 deletions
Show diff stats
plugins/event/lib/event_plugin/event_block.rb
| ... | ... | @@ -5,7 +5,7 @@ class EventPlugin::EventBlock < Block |
| 5 | 5 | |
| 6 | 6 | settings_items :all_env_events, :type => :boolean, :default => false |
| 7 | 7 | settings_items :limit, :type => :integer, :default => 4 |
| 8 | - settings_items :future_only, :type => :boolean, :default => false | |
| 8 | + settings_items :future_only, :type => :boolean, :default => true | |
| 9 | 9 | settings_items :date_distance_limit, :type => :integer, :default => 0 |
| 10 | 10 | |
| 11 | 11 | def self.description |
| ... | ... | @@ -17,15 +17,12 @@ class EventPlugin::EventBlock < Block |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | def events_source |
| 20 | - unless all_env_events | |
| 21 | - if self.owner.kind_of? Environment | |
| 22 | - return self.owner | |
| 23 | - elsif environment.portal_community | |
| 24 | - return environment.portal_community | |
| 25 | - end | |
| 20 | + return environment if all_env_events | |
| 21 | + if self.owner.kind_of? Environment | |
| 22 | + environment.portal_community ? environment.portal_community : environment | |
| 23 | + else | |
| 24 | + self.owner | |
| 26 | 25 | end |
| 27 | - | |
| 28 | - environment | |
| 29 | 26 | end |
| 30 | 27 | |
| 31 | 28 | def events(user = nil) |
| ... | ... | @@ -65,15 +62,15 @@ class EventPlugin::EventBlock < Block |
| 65 | 62 | def human_time_left(days_left) |
| 66 | 63 | months_left = (days_left/30.0).round |
| 67 | 64 | if days_left <= -60 |
| 68 | - n_('Started one month ago.', 'Started %d months ago.', -months_left) % -months_left | |
| 65 | + n_('One month ago', '%d months ago', -months_left) % -months_left | |
| 69 | 66 | elsif days_left < 0 |
| 70 | - n_('Started one day ago.', 'Started %d days ago.', -days_left) % -days_left | |
| 67 | + n_('Yesterday', '%d days ago', -days_left) % -days_left | |
| 71 | 68 | elsif days_left == 0 |
| 72 | - _("I happens today.") | |
| 69 | + _("Today") | |
| 73 | 70 | elsif days_left < 60 |
| 74 | - n_('One day left to start.', '%d days left to start.', days_left) % days_left | |
| 71 | + n_('Tomorrow', '%d days left to start', days_left) % days_left | |
| 75 | 72 | else |
| 76 | - n_('One month left to start.', '%d months left to start.', months_left) % months_left | |
| 73 | + n_('One month left to start', '%d months left to start', months_left) % months_left | |
| 77 | 74 | end |
| 78 | 75 | end |
| 79 | 76 | ... | ... |
plugins/event/public/style.css
| ... | ... | @@ -119,6 +119,11 @@ |
| 119 | 119 | background: #D4D4D4; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | +.event-plugin_event-block .event .week-day, | |
| 123 | +.event-plugin_event-block .event .year { | |
| 124 | + display: none; | |
| 125 | +} | |
| 126 | + | |
| 122 | 127 | .event-plugin_event-block .event .duration { |
| 123 | 128 | display: block; |
| 124 | 129 | } |
| ... | ... | @@ -184,3 +189,8 @@ |
| 184 | 189 | .msie8 #content .event-plugin_event-block .event .days-left { |
| 185 | 190 | float: left; |
| 186 | 191 | } |
| 192 | + | |
| 193 | +.event-plugin-config-tip { | |
| 194 | + display: block; | |
| 195 | + margin-bottom: 3px; | |
| 196 | +} | ... | ... |
plugins/event/test/functional/event_block_test.rb
| ... | ... | @@ -42,17 +42,17 @@ class HomeControllerTest < ActionController::TestCase |
| 42 | 42 | should 'see event duration' do |
| 43 | 43 | @e1a.slug = 'event1a' |
| 44 | 44 | @e1a.start_date = Date.today |
| 45 | - @e1a.end_date = Date.tomorrow | |
| 45 | + @e1a.end_date = Date.today + 1.day | |
| 46 | 46 | @e1a.save! |
| 47 | 47 | get :index |
| 48 | - assert_select ev + 'time.duration[itemprop="endDate"]', '+1 day' | |
| 48 | + assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/ | |
| 49 | 49 | |
| 50 | 50 | @e1a.slug = 'event1a' |
| 51 | 51 | @e1a.start_date = Date.today |
| 52 | - @e1a.end_date = Date.tomorrow+1 | |
| 52 | + @e1a.end_date = Date.today + 2.day | |
| 53 | 53 | @e1a.save! |
| 54 | 54 | get :index |
| 55 | - assert_select ev + 'time.duration[itemprop="endDate"]', '+2 days' | |
| 55 | + assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/ | |
| 56 | 56 | end |
| 57 | 57 | |
| 58 | 58 | should 'not see event duration for one day events' do | ... | ... |
plugins/event/test/unit/event_block_test.rb
| ... | ... | @@ -19,7 +19,7 @@ class EventPlugin::EventBlockTest < ActiveSupport::TestCase |
| 19 | 19 | :start_date => Date.today-30) |
| 20 | 20 | |
| 21 | 21 | box = fast_create(Box, :owner_id => @p1) |
| 22 | - @block = EventPlugin::EventBlock.new(:limit => 99, :box => box) | |
| 22 | + @block = EventPlugin::EventBlock.new(:limit => 99, :future_only => false, :box => box) | |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | def set_portal(env, portal) |
| ... | ... | @@ -78,9 +78,7 @@ class EventPlugin::EventBlockTest < ActiveSupport::TestCase |
| 78 | 78 | end |
| 79 | 79 | |
| 80 | 80 | should 'say human left time for an event' do |
| 81 | - one_day = @block.human_time_left(Date.tomorrow - Date.today) | |
| 82 | - | |
| 83 | - assert_match /One day left/, one_day | |
| 81 | + assert_match /Tomorrow/, @block.human_time_left(1) | |
| 84 | 82 | assert_match /5 days left/, @block.human_time_left(5) |
| 85 | 83 | assert_match /30 days left/, @block.human_time_left(30) |
| 86 | 84 | assert_match /2 months left/, @block.human_time_left(60) |
| ... | ... | @@ -88,13 +86,15 @@ class EventPlugin::EventBlockTest < ActiveSupport::TestCase |
| 88 | 86 | end |
| 89 | 87 | |
| 90 | 88 | should 'say human past time for an event' do |
| 91 | - one_day = @block.human_time_left(Date.yesterday - Date.today) | |
| 89 | + assert_match /Yesterday/, @block.human_time_left(-1) | |
| 90 | + assert_match /5 days ago/, @block.human_time_left(-5) | |
| 91 | + assert_match /30 days ago/, @block.human_time_left(-30) | |
| 92 | + assert_match /2 months ago/, @block.human_time_left(-60) | |
| 93 | + assert_match /3 months ago/, @block.human_time_left(-85) | |
| 94 | + end | |
| 92 | 95 | |
| 93 | - assert_match /One day past/, one_day | |
| 94 | - assert_match /5 days past/, @block.human_time_left(-5) | |
| 95 | - assert_match /30 days past/, @block.human_time_left(-30) | |
| 96 | - assert_match /2 months past/, @block.human_time_left(-60) | |
| 97 | - assert_match /3 months past/, @block.human_time_left(-85) | |
| 96 | + should 'say human present time for an event' do | |
| 97 | + assert_match /Today/, @block.human_time_left(0) | |
| 98 | 98 | end |
| 99 | 99 | |
| 100 | 100 | should 'write formatable data in html' do | ... | ... |
plugins/event/views/blocks/event.html.erb
| 1 | 1 | <%= block_title(block.title) %> |
| 2 | 2 | |
| 3 | 3 | <ul class="events"> |
| 4 | - <% block.events(@user).map do |event| %> | |
| 4 | + <% block.events(user).map do |event| %> | |
| 5 | 5 | <% days_left = ( event.start_date - Date.today ).round %> |
| 6 | 6 | <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event"> |
| 7 | 7 | <%= render( | ... | ... |
plugins/event/views/profile_design/event_plugin/_event_block.html.erb
| 1 | 1 | <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 4) %> |
| 2 | 2 | |
| 3 | -<%= labelled_check_box(_('Show all environment events'), "block[all_env_events]", "1", @block.all_env_events) %> | |
| 4 | -<br> | |
| 5 | -<small><%= | |
| 6 | - if @profile | |
| 7 | - if @profile.person? | |
| 8 | - _("(Don't check to show only your events)") | |
| 9 | - else | |
| 10 | - _("(Don't check to show only %s events)") % @profile.name | |
| 11 | - end | |
| 12 | - elsif environment.portal_community | |
| 13 | - _("(Don't check to show only the environment events)") | |
| 14 | - end | |
| 15 | -%></small> | |
| 16 | -<br> | |
| 3 | +<% unless @block.owner.kind_of?(Environment) && !@block.owner.portal_community %> | |
| 4 | + <%= labelled_check_box(_('Show all environment events'), "block[all_env_events]", "1", @block.all_env_events) %> | |
| 17 | 5 | |
| 18 | -<%= labelled_form_field _('Limit of days to display'), | |
| 19 | - text_field(:block, :date_distance_limit, :size => 4) %> | |
| 20 | -<small>(<%=_('Only show events on this limit of days.')%>)</small> | |
| 21 | -<br><br> | |
| 6 | + <small class='event-plugin-config-tip'> | |
| 7 | + <%= if @block.owner.kind_of?(Profile) | |
| 8 | + if @block.owner.person? | |
| 9 | + _("(Don't check to show only your events)") | |
| 10 | + else | |
| 11 | + _("(Don't check to show only %s events)") % @profile.name | |
| 12 | + end | |
| 13 | + elsif environment.portal_community | |
| 14 | + _("(Don't check to show only %s events)") % link_to(environment.portal_community.name, environment.portal_community.url) | |
| 15 | + end | |
| 16 | + %> | |
| 17 | + </small> | |
| 18 | +<% end %> | |
| 22 | 19 | |
| 23 | 20 | <%= labelled_check_box(_('Only show future events'), "block[future_only]", "1", @block.future_only) %> |
| 21 | + | |
| 22 | +<%= labelled_form_field _('Limit of days to display'), | |
| 23 | + text_field(:block, :date_distance_limit, :size => 4) %> | |
| 24 | +<small class='event-plugin-config-tip'>(<%=_('Only show events in this interval of days.')%>)</small> | ... | ... |