Commit 424e7b6326bd00a76e0d29d90cae9f82fa777991
Exists in
master
and in
29 other branches
Merge branch 'stable' into noosfero_0.47.0
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 | 7 | @date = build_date(params[:year], params[:month], params[:day]) |
8 | 8 | |
9 | 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 | 11 | end |
12 | 12 | |
13 | 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 | 15 | end |
16 | 16 | |
17 | 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 | 29 | |
30 | 30 | include EventsHelper |
31 | 31 | |
32 | + def per_page | |
33 | + 20 | |
34 | + end | |
32 | 35 | end | ... | ... |
app/controllers/public/search_controller.rb
... | ... | @@ -99,14 +99,14 @@ class SearchController < PublicController |
99 | 99 | @events = [] |
100 | 100 | if params[:day] || !params[:year] && !params[:month] |
101 | 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 | 104 | end |
105 | 105 | |
106 | 106 | if params[:year] || params[:month] |
107 | 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 | 110 | end |
111 | 111 | |
112 | 112 | @scope = date_range && params[:action] == 'events' ? environment.events.by_range(date_range) : environment.events |
... | ... | @@ -139,7 +139,7 @@ class SearchController < PublicController |
139 | 139 | |
140 | 140 | def events_by_day |
141 | 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 | 143 | render :partial => 'events/events' |
144 | 144 | end |
145 | 145 | |
... | ... | @@ -224,4 +224,8 @@ class SearchController < PublicController |
224 | 224 | @environment.send(klass.name.underscore.pluralize).visible.includes(relations) |
225 | 225 | end |
226 | 226 | |
227 | + def per_page | |
228 | + 20 | |
229 | + end | |
230 | + | |
227 | 231 | end | ... | ... |
app/models/event.rb
... | ... | @@ -38,15 +38,12 @@ class Event < Article |
38 | 38 | named_scope :next_events_from_month, lambda { |date| |
39 | 39 | date_temp = date.strftime("%Y-%m-%d") |
40 | 40 | { :conditions => ["start_date >= ?","#{date_temp}"], |
41 | - :limit => 10, | |
42 | 41 | :order => 'start_date ASC' |
43 | 42 | } |
44 | 43 | } |
45 | 44 | |
46 | 45 | named_scope :by_month, lambda { |date| |
47 | - date_temp = date.strftime("%Y-%m") | |
48 | 46 | { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month], |
49 | - :limit => 10, | |
50 | 47 | :order => 'start_date ASC' |
51 | 48 | } |
52 | 49 | } | ... | ... |
app/views/events/_events.rhtml
features/events.feature
... | ... | @@ -244,3 +244,38 @@ Feature: events |
244 | 244 | Given I am on /profile/josesilva/events/2009/10 |
245 | 245 | When I follow "Oktoberfest" |
246 | 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
... | ... | @@ -3561,9 +3561,10 @@ div#article-parent { |
3561 | 3561 | } |
3562 | 3562 | #agenda .agenda-calendar { |
3563 | 3563 | width: 50%; |
3564 | + display: inline-block; | |
3564 | 3565 | } |
3565 | 3566 | #agenda td, #agenda th { |
3566 | - padding: 15px; | |
3567 | + padding: 10px; | |
3567 | 3568 | padding-right: 0px; |
3568 | 3569 | } |
3569 | 3570 | #agenda .agenda-calendar .previous-month td, #agenda .agenda-calendar .previous-month th, #agenda .agenda-calendar .next-month td, #agenda .agenda-calendar .next-month th { |
... | ... | @@ -3621,26 +3622,25 @@ div#article-parent { |
3621 | 3622 | vertical-align: middle; |
3622 | 3623 | } |
3623 | 3624 | #agenda .agenda-calendar .current-month caption { |
3624 | - margin-bottom: 10px; | |
3625 | + margin: 10px 0px; | |
3625 | 3626 | } |
3626 | 3627 | #agenda #events-of-the-day { |
3627 | - position: absolute; | |
3628 | - left: 50%; | |
3629 | 3628 | width: 45%; |
3630 | - top: 0px; | |
3631 | 3629 | height: 100%; |
3632 | 3630 | padding-left: 20px; |
3631 | + display: inline-block; | |
3632 | + vertical-align: top; | |
3633 | 3633 | } |
3634 | 3634 | #agenda #events-of-the-day #agenda-items { |
3635 | 3635 | display: block; |
3636 | 3636 | overflow: auto; |
3637 | 3637 | overflow-x: hidden; |
3638 | - height: 80%; | |
3638 | + height: 250px; | |
3639 | 3639 | background: white; |
3640 | 3640 | border: none; |
3641 | 3641 | } |
3642 | 3642 | #agenda-toolbar { |
3643 | - float: right; | |
3643 | + text-align: right; | |
3644 | 3644 | font-variant: normal; |
3645 | 3645 | font-weight: normal; |
3646 | 3646 | } |
... | ... | @@ -3663,6 +3663,9 @@ h1#agenda-title { |
3663 | 3663 | display: block; |
3664 | 3664 | margin-top: 10px; |
3665 | 3665 | } |
3666 | +#agenda .pagination { | |
3667 | + margin-top: 15px; | |
3668 | +} | |
3666 | 3669 | /* ==> public/stylesheets/controller_favorite_enterprises.css <== */ |
3667 | 3670 | |
3668 | 3671 | /* ==> @import url(manage_contacts_list.css); <== */ | ... | ... |
test/functional/events_controller_test.rb
... | ... | @@ -38,4 +38,12 @@ class EventsControllerTest < ActionController::TestCase |
38 | 38 | assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{next_month.month}"}, :content => next_month_name |
39 | 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 | 49 | end | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -370,6 +370,14 @@ class SearchControllerTest < ActionController::TestCase |
370 | 370 | assert_equal [ 'upcoming event 1' ], assigns(:searches)[:events][:results].map(&:name) |
371 | 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 | 381 | %w[ people enterprises articles events communities products ].each do |asset| |
374 | 382 | should "render asset-specific template when searching for #{asset}" do |
375 | 383 | get "#{asset}" | ... | ... |