Commit fe3ebd1c23f8b3e022fbba2e663a78ae3e29175c
1 parent
a349f151
Exists in
master
and in
28 other branches
Added pagination on events
agenda_improvements: Changed the limit to show the events Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luiz Matos <luizff.matos@gmail.com> (ActionItem3048)
Showing
8 changed files
with
78 additions
and
18 deletions
Show diff stats
app/controllers/public/events_controller.rb
| @@ -7,11 +7,11 @@ class EventsController < PublicController | @@ -7,11 +7,11 @@ class EventsController < PublicController | ||
| 7 | @date = build_date(params[:year], params[:month], params[:day]) | 7 | @date = build_date(params[:year], params[:month], params[:day]) |
| 8 | 8 | ||
| 9 | if !params[:year] && !params[:month] && !params[:day] | 9 | if !params[:year] && !params[:month] && !params[:day] |
| 10 | - @events = profile.events.next_events_from_month(@date) | 10 | + @events = profile.events.next_events_from_month(@date).paginate(:per_page => per_page, :page => params[:page]) |
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | if params[:year] || params[:month] | 13 | if params[:year] || params[:month] |
| 14 | - @events = profile.events.by_month(@date) | 14 | + @events = profile.events.by_month(@date).paginate(:per_page => per_page, :page => params[:page]) |
| 15 | end | 15 | end |
| 16 | 16 | ||
| 17 | events_in_range = profile.events.by_range((@date - 1.month).at_beginning_of_month .. (@date + 1.month).at_end_of_month) | 17 | events_in_range = profile.events.by_range((@date - 1.month).at_beginning_of_month .. (@date + 1.month).at_end_of_month) |
| @@ -29,4 +29,7 @@ class EventsController < PublicController | @@ -29,4 +29,7 @@ class EventsController < PublicController | ||
| 29 | 29 | ||
| 30 | include EventsHelper | 30 | include EventsHelper |
| 31 | 31 | ||
| 32 | + def per_page | ||
| 33 | + 20 | ||
| 34 | + end | ||
| 32 | end | 35 | end |
app/controllers/public/search_controller.rb
| @@ -99,14 +99,14 @@ class SearchController < PublicController | @@ -99,14 +99,14 @@ class SearchController < PublicController | ||
| 99 | @events = [] | 99 | @events = [] |
| 100 | if params[:day] || !params[:year] && !params[:month] | 100 | if params[:day] || !params[:year] && !params[:month] |
| 101 | @events = @category ? | 101 | @events = @category ? |
| 102 | - environment.events.by_day(@date).in_category(Category.find(@category_id)) : | ||
| 103 | - environment.events.by_day(@date) | 102 | + environment.events.by_day(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : |
| 103 | + environment.events.by_day(@date).paginate(:per_page => per_page, :page => params[:page]) | ||
| 104 | end | 104 | end |
| 105 | 105 | ||
| 106 | if params[:year] || params[:month] | 106 | if params[:year] || params[:month] |
| 107 | @events = @category ? | 107 | @events = @category ? |
| 108 | - environment.events.by_month(@date).in_category(Category.find(@category_id)) : | ||
| 109 | - environment.events.by_month(@date) | 108 | + environment.events.by_month(@date).in_category(Category.find(@category_id)).paginate(:per_page => per_page, :page => params[:page]) : |
| 109 | + environment.events.by_month(@date).paginate(:per_page => per_page, :page => params[:page]) | ||
| 110 | end | 110 | end |
| 111 | 111 | ||
| 112 | @scope = date_range && params[:action] == 'events' ? environment.events.by_range(date_range) : environment.events | 112 | @scope = date_range && params[:action] == 'events' ? environment.events.by_range(date_range) : environment.events |
| @@ -139,7 +139,7 @@ class SearchController < PublicController | @@ -139,7 +139,7 @@ class SearchController < PublicController | ||
| 139 | 139 | ||
| 140 | def events_by_day | 140 | def events_by_day |
| 141 | @date = build_date(params[:year], params[:month], params[:day]) | 141 | @date = build_date(params[:year], params[:month], params[:day]) |
| 142 | - @events = environment.events.by_day(@date) | 142 | + @events = environment.events.by_day(@date).paginate(:per_page => per_page, :page => params[:page]) |
| 143 | render :partial => 'events/events' | 143 | render :partial => 'events/events' |
| 144 | end | 144 | end |
| 145 | 145 | ||
| @@ -224,4 +224,8 @@ class SearchController < PublicController | @@ -224,4 +224,8 @@ class SearchController < PublicController | ||
| 224 | @environment.send(klass.name.underscore.pluralize).visible.includes(relations) | 224 | @environment.send(klass.name.underscore.pluralize).visible.includes(relations) |
| 225 | end | 225 | end |
| 226 | 226 | ||
| 227 | + def per_page | ||
| 228 | + 20 | ||
| 229 | + end | ||
| 230 | + | ||
| 227 | end | 231 | end |
app/models/event.rb
| @@ -38,15 +38,12 @@ class Event < Article | @@ -38,15 +38,12 @@ class Event < Article | ||
| 38 | named_scope :next_events_from_month, lambda { |date| | 38 | named_scope :next_events_from_month, lambda { |date| |
| 39 | date_temp = date.strftime("%Y-%m-%d") | 39 | date_temp = date.strftime("%Y-%m-%d") |
| 40 | { :conditions => ["start_date >= ?","#{date_temp}"], | 40 | { :conditions => ["start_date >= ?","#{date_temp}"], |
| 41 | - :limit => 10, | ||
| 42 | :order => 'start_date ASC' | 41 | :order => 'start_date ASC' |
| 43 | } | 42 | } |
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | named_scope :by_month, lambda { |date| | 45 | named_scope :by_month, lambda { |date| |
| 47 | - date_temp = date.strftime("%Y-%m") | ||
| 48 | { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month], | 46 | { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month], |
| 49 | - :limit => 10, | ||
| 50 | :order => 'start_date ASC' | 47 | :order => 'start_date ASC' |
| 51 | } | 48 | } |
| 52 | } | 49 | } |
app/views/events/_events.rhtml
features/events.feature
| @@ -244,3 +244,38 @@ Feature: events | @@ -244,3 +244,38 @@ Feature: events | ||
| 244 | Given I am on /profile/josesilva/events/2009/10 | 244 | Given I am on /profile/josesilva/events/2009/10 |
| 245 | When I follow "Oktoberfest" | 245 | When I follow "Oktoberfest" |
| 246 | Then I should see "Oktoberfest" | 246 | Then I should see "Oktoberfest" |
| 247 | + | ||
| 248 | + Scenario: list events paginated for a specific profile for the month | ||
| 249 | + Given I am logged in as admin | ||
| 250 | + And the following users | ||
| 251 | + | login | | ||
| 252 | + | josemanuel | | ||
| 253 | + And I am logged in as "josemanuel" | ||
| 254 | + And the following events | ||
| 255 | + | owner | name | start_date | | ||
| 256 | + | josemanuel | Event 5 | 2009-10-12 | | ||
| 257 | + | josemanuel | Event 3 | 2009-10-15 | | ||
| 258 | + | josemanuel | Test Event | 2009-10-15 | | ||
| 259 | + | josemanuel | Oktoberfest | 2009-10-19 | | ||
| 260 | + | josemanuel | WikiSym | 2009-10-21 | | ||
| 261 | + | josemanuel | Free Software | 2009-10-22 | | ||
| 262 | + | josemanuel | Rachel Birthday | 2009-10-23 | | ||
| 263 | + | josemanuel | Manuel Birthday | 2009-10-24 | | ||
| 264 | + | josemanuel | Michelle Birthday | 2009-10-25 | | ||
| 265 | + | josemanuel | Lecture Allien 10 | 2009-10-26 | | ||
| 266 | + | josemanuel | Lecture Allien 11 | 2009-10-26 | | ||
| 267 | + | josemanuel | Lecture Allien 12 | 2009-10-26 | | ||
| 268 | + | josemanuel | Lecture Allien 13 | 2009-10-26 | | ||
| 269 | + | josemanuel | Lecture Allien 14 | 2009-10-26 | | ||
| 270 | + | josemanuel | Lecture Allien 15 | 2009-10-26 | | ||
| 271 | + | josemanuel | Lecture Allien 16 | 2009-10-26 | | ||
| 272 | + | josemanuel | Lecture Allien 17 | 2009-10-26 | | ||
| 273 | + | josemanuel | Lecture Allien 18 | 2009-10-26 | | ||
| 274 | + | josemanuel | Lecture Allien 19 | 2009-10-26 | | ||
| 275 | + | josemanuel | Lecture Allien 20 | 2009-10-26 | | ||
| 276 | + | josemanuel | Party On | 2009-10-27 | | ||
| 277 | + | ||
| 278 | + When I am on /profile/josemanuel/events/2009/10 | ||
| 279 | + Then I should not see "Party On" within "#agenda-items" | ||
| 280 | + When I follow "Next" | ||
| 281 | + Then I should see "Party On" within "#agenda-items" |
public/stylesheets/application.css
| @@ -3578,9 +3578,10 @@ div#article-parent { | @@ -3578,9 +3578,10 @@ div#article-parent { | ||
| 3578 | } | 3578 | } |
| 3579 | #agenda .agenda-calendar { | 3579 | #agenda .agenda-calendar { |
| 3580 | width: 50%; | 3580 | width: 50%; |
| 3581 | + display: inline-block; | ||
| 3581 | } | 3582 | } |
| 3582 | #agenda td, #agenda th { | 3583 | #agenda td, #agenda th { |
| 3583 | - padding: 15px; | 3584 | + padding: 10px; |
| 3584 | padding-right: 0px; | 3585 | padding-right: 0px; |
| 3585 | } | 3586 | } |
| 3586 | #agenda .agenda-calendar .previous-month td, #agenda .agenda-calendar .previous-month th, #agenda .agenda-calendar .next-month td, #agenda .agenda-calendar .next-month th { | 3587 | #agenda .agenda-calendar .previous-month td, #agenda .agenda-calendar .previous-month th, #agenda .agenda-calendar .next-month td, #agenda .agenda-calendar .next-month th { |
| @@ -3638,26 +3639,25 @@ div#article-parent { | @@ -3638,26 +3639,25 @@ div#article-parent { | ||
| 3638 | vertical-align: middle; | 3639 | vertical-align: middle; |
| 3639 | } | 3640 | } |
| 3640 | #agenda .agenda-calendar .current-month caption { | 3641 | #agenda .agenda-calendar .current-month caption { |
| 3641 | - margin-bottom: 10px; | 3642 | + margin: 10px 0px; |
| 3642 | } | 3643 | } |
| 3643 | #agenda #events-of-the-day { | 3644 | #agenda #events-of-the-day { |
| 3644 | - position: absolute; | ||
| 3645 | - left: 50%; | ||
| 3646 | width: 45%; | 3645 | width: 45%; |
| 3647 | - top: 0px; | ||
| 3648 | height: 100%; | 3646 | height: 100%; |
| 3649 | padding-left: 20px; | 3647 | padding-left: 20px; |
| 3648 | + display: inline-block; | ||
| 3649 | + vertical-align: top; | ||
| 3650 | } | 3650 | } |
| 3651 | #agenda #events-of-the-day #agenda-items { | 3651 | #agenda #events-of-the-day #agenda-items { |
| 3652 | display: block; | 3652 | display: block; |
| 3653 | overflow: auto; | 3653 | overflow: auto; |
| 3654 | overflow-x: hidden; | 3654 | overflow-x: hidden; |
| 3655 | - height: 80%; | 3655 | + height: 250px; |
| 3656 | background: white; | 3656 | background: white; |
| 3657 | border: none; | 3657 | border: none; |
| 3658 | } | 3658 | } |
| 3659 | #agenda-toolbar { | 3659 | #agenda-toolbar { |
| 3660 | - float: right; | 3660 | + text-align: right; |
| 3661 | font-variant: normal; | 3661 | font-variant: normal; |
| 3662 | font-weight: normal; | 3662 | font-weight: normal; |
| 3663 | } | 3663 | } |
| @@ -3680,6 +3680,9 @@ h1#agenda-title { | @@ -3680,6 +3680,9 @@ h1#agenda-title { | ||
| 3680 | display: block; | 3680 | display: block; |
| 3681 | margin-top: 10px; | 3681 | margin-top: 10px; |
| 3682 | } | 3682 | } |
| 3683 | +#agenda .pagination { | ||
| 3684 | + margin-top: 15px; | ||
| 3685 | +} | ||
| 3683 | /* ==> public/stylesheets/controller_favorite_enterprises.css <== */ | 3686 | /* ==> public/stylesheets/controller_favorite_enterprises.css <== */ |
| 3684 | 3687 | ||
| 3685 | /* ==> @import url(manage_contacts_list.css); <== */ | 3688 | /* ==> @import url(manage_contacts_list.css); <== */ |
test/functional/events_controller_test.rb
| @@ -38,4 +38,12 @@ class EventsControllerTest < ActionController::TestCase | @@ -38,4 +38,12 @@ class EventsControllerTest < ActionController::TestCase | ||
| 38 | assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{next_month.month}"}, :content => next_month_name | 38 | assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{next_month.month}"}, :content => next_month_name |
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | + should 'see the events paginated' do | ||
| 42 | + 30.times do |i| | ||
| 43 | + profile.events << Event.new(:name => "Lesson #{i}", :start_date => Date.today) | ||
| 44 | + end | ||
| 45 | + get :events, :profile => profile.identifier | ||
| 46 | + assert_equal 20, assigns(:events).count | ||
| 47 | + end | ||
| 48 | + | ||
| 41 | end | 49 | end |
test/functional/search_controller_test.rb
| @@ -370,6 +370,14 @@ class SearchControllerTest < ActionController::TestCase | @@ -370,6 +370,14 @@ class SearchControllerTest < ActionController::TestCase | ||
| 370 | assert_equal [ 'upcoming event 1' ], assigns(:searches)[:events][:results].map(&:name) | 370 | assert_equal [ 'upcoming event 1' ], assigns(:searches)[:events][:results].map(&:name) |
| 371 | end | 371 | end |
| 372 | 372 | ||
| 373 | + should 'see the events paginated' do | ||
| 374 | + 30.times do |i| | ||
| 375 | + create_event(person, :name => "Event #{i}", :start_date => Date.today) | ||
| 376 | + end | ||
| 377 | + get :events | ||
| 378 | + assert_equal 20, assigns(:events).count | ||
| 379 | + end | ||
| 380 | + | ||
| 373 | %w[ people enterprises articles events communities products ].each do |asset| | 381 | %w[ people enterprises articles events communities products ].each do |asset| |
| 374 | should "render asset-specific template when searching for #{asset}" do | 382 | should "render asset-specific template when searching for #{asset}" do |
| 375 | get "#{asset}" | 383 | get "#{asset}" |