Commit e5dba6d0f2b73f34c1fd2332295c02084cbb812e
Committed by
Antonio Terceiro
1 parent
a03dc433
Exists in
master
and in
22 other branches
ActionItem989: added pagination and cache to manage_friends
Showing
7 changed files
with
61 additions
and
37 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
| @@ -5,7 +5,9 @@ class FriendsController < MyProfileController | @@ -5,7 +5,9 @@ class FriendsController < MyProfileController | ||
| 5 | protect 'manage_friends', :profile | 5 | protect 'manage_friends', :profile |
| 6 | 6 | ||
| 7 | def index | 7 | def index |
| 8 | - @friends = profile.friends | 8 | + if is_cache_expired?(profile.manage_friends_cache_key(params)) |
| 9 | + @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) | ||
| 10 | + end | ||
| 9 | end | 11 | end |
| 10 | 12 | ||
| 11 | def add | 13 | def add |
| @@ -23,7 +25,6 @@ class FriendsController < MyProfileController | @@ -23,7 +25,6 @@ class FriendsController < MyProfileController | ||
| 23 | def remove | 25 | def remove |
| 24 | @friend = profile.friends.find(params[:id]) | 26 | @friend = profile.friends.find(params[:id]) |
| 25 | if request.post? && params[:confirmation] | 27 | if request.post? && params[:confirmation] |
| 26 | - expire_fragment(:action => 'friends', :controller => 'profile', :profile => profile.identifier) | ||
| 27 | profile.remove_friend(@friend) | 28 | profile.remove_friend(@friend) |
| 28 | redirect_to :action => 'index' | 29 | redirect_to :action => 'index' |
| 29 | end | 30 | end |
| @@ -106,4 +107,9 @@ class FriendsController < MyProfileController | @@ -106,4 +107,9 @@ class FriendsController < MyProfileController | ||
| 106 | end | 107 | end |
| 107 | end | 108 | end |
| 108 | 109 | ||
| 110 | + protected | ||
| 111 | + | ||
| 112 | + def per_page | ||
| 113 | + 10 | ||
| 114 | + end | ||
| 109 | end | 115 | end |
app/helpers/friends_helper.rb
| @@ -4,4 +4,10 @@ module FriendsHelper | @@ -4,4 +4,10 @@ module FriendsHelper | ||
| 4 | options.merge!({:action => 'invite', :import => 1, :wizard => true}) | 4 | options.merge!({:action => 'invite', :import => 1, :wizard => true}) |
| 5 | link_to text, options | 5 | link_to text, options |
| 6 | end | 6 | end |
| 7 | + | ||
| 8 | + def pagination_links(collection, options={}) | ||
| 9 | + options = {:prev_label => '« ' + _('Previous'), :next_label => _('Next') + ' »'}.merge(options) | ||
| 10 | + will_paginate(collection, options) | ||
| 11 | + end | ||
| 12 | + | ||
| 7 | end | 13 | end |
app/views/friends/index.rhtml
| @@ -2,47 +2,52 @@ | @@ -2,47 +2,52 @@ | ||
| 2 | 2 | ||
| 3 | <h1><%= __("%s's friends") % profile.name %></h1> | 3 | <h1><%= __("%s's friends") % profile.name %></h1> |
| 4 | 4 | ||
| 5 | -<% if @friends.empty? %> | ||
| 6 | -<p> | ||
| 7 | -<em> | ||
| 8 | - <%= __('You have no friends yet.') %> | ||
| 9 | - <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %> | ||
| 10 | -</em> | ||
| 11 | -</p> | ||
| 12 | -<% else %> | ||
| 13 | - <% button_bar do %> | ||
| 14 | - <%= button(:back, _('Go back'), :controller => 'profile_editor') %> | ||
| 15 | - <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> | ||
| 16 | - <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %> | 5 | +<% cache_timeout(profile.manage_friends_cache_key(params), 4.hours.from_now) do %> |
| 6 | + <% if @friends.empty? %> | ||
| 7 | + <p> | ||
| 8 | + <em> | ||
| 9 | + <%= __('You have no friends yet.') %> | ||
| 10 | + <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %> | ||
| 11 | + </em> | ||
| 12 | + </p> | ||
| 13 | + <% else %> | ||
| 14 | + <% button_bar do %> | ||
| 15 | + <%= button(:back, _('Go back'), :controller => 'profile_editor') %> | ||
| 16 | + <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> | ||
| 17 | + <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %> | ||
| 18 | + <% end %> | ||
| 17 | <% end %> | 19 | <% end %> |
| 18 | -<% end %> | ||
| 19 | 20 | ||
| 20 | -<ul class="profile-list"> | ||
| 21 | - <% @friends.each do |friend| %> | ||
| 22 | - <li> | ||
| 23 | - <%= link_to_profile profile_image(friend) + '<br/>' + friend.name, | ||
| 24 | - friend.identifier, :class => 'profile-link' %> | ||
| 25 | - <div class="controll"> | ||
| 26 | - <%= link_to content_tag('span',_('remove')), | ||
| 27 | - { :action => 'remove', :id => friend.id }, | ||
| 28 | - :class => 'button icon-delete', | ||
| 29 | - :title => _('remove'), | ||
| 30 | - :help => __('Clicking on this button will remove your friend relation with %s.') % friend.name %> | ||
| 31 | - <%= link_to content_tag('span',_('contact')), | ||
| 32 | - friend.url.merge(:controller => 'contact', :action => 'new'), | ||
| 33 | - :class => 'button icon-menu-mail', | ||
| 34 | - :title => _('contact'), | ||
| 35 | - :help => __('Clicking on this button will let you send a message to %s.') % friend.name %> | ||
| 36 | - </div><!-- end class="controll" --> | ||
| 37 | - </li> | ||
| 38 | - <% end %> | ||
| 39 | -</ul> | 21 | + <ul class="profile-list"> |
| 22 | + <% @friends.each do |friend| %> | ||
| 23 | + <li> | ||
| 24 | + <%= link_to_profile profile_image(friend) + '<br/>' + friend.short_name, | ||
| 25 | + friend.identifier, :class => 'profile-link' %> | ||
| 26 | + <div class="controll"> | ||
| 27 | + <%= link_to content_tag('span',_('remove')), | ||
| 28 | + { :action => 'remove', :id => friend.id }, | ||
| 29 | + :class => 'button icon-delete', | ||
| 30 | + :title => _('remove'), | ||
| 31 | + :help => __('Clicking on this button will remove your friend relation with %s.') % friend.name %> | ||
| 32 | + <%= link_to content_tag('span',_('contact')), | ||
| 33 | + friend.url.merge(:controller => 'contact', :action => 'new'), | ||
| 34 | + :class => 'button icon-menu-mail', | ||
| 35 | + :title => _('contact'), | ||
| 36 | + :help => __('Clicking on this button will let you send a message to %s.') % friend.name %> | ||
| 37 | + </div><!-- end class="controll" --> | ||
| 38 | + </li> | ||
| 39 | + <% end %> | ||
| 40 | + </ul> | ||
| 41 | + <div id='pagination-friends'> | ||
| 42 | + <%= pagination_links @friends, :param_name => 'npage' %> | ||
| 43 | + </div> | ||
| 40 | 44 | ||
| 41 | <% button_bar do %> | 45 | <% button_bar do %> |
| 42 | <%= button(:back, _('Go back'), :controller => 'profile_editor') %> | 46 | <%= button(:back, _('Go back'), :controller => 'profile_editor') %> |
| 43 | <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> | 47 | <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> |
| 44 | <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %> | 48 | <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %> |
| 45 | <% end %> | 49 | <% end %> |
| 50 | +<% end %> | ||
| 46 | 51 | ||
| 47 | </div><!-- end id="manage_friends" --> | 52 | </div><!-- end id="manage_friends" --> |
| 48 | 53 |
public/stylesheets/controller_friends.css
| 1 | 1 | ||
| 2 | @import url(manage_contacts_list.css); | 2 | @import url(manage_contacts_list.css); |
| 3 | +@import url(pagination.css); | ||
| 3 | 4 | ||
| 4 | #remove_friend .friend_picture { | 5 | #remove_friend .friend_picture { |
| 5 | float: left; | 6 | float: left; |
| @@ -17,3 +18,7 @@ | @@ -17,3 +18,7 @@ | ||
| 17 | border: 1px solid #999; | 18 | border: 1px solid #999; |
| 18 | margin: 5px 0px; | 19 | margin: 5px 0px; |
| 19 | } | 20 | } |
| 21 | + | ||
| 22 | +#pagination-friends .pagination span { | ||
| 23 | + display: inline; | ||
| 24 | +} |
public/stylesheets/manage_contacts_list.css
| @@ -29,6 +29,7 @@ | @@ -29,6 +29,7 @@ | ||
| 29 | text-decoration: none; | 29 | text-decoration: none; |
| 30 | text-align: center; | 30 | text-align: center; |
| 31 | display: block; | 31 | display: block; |
| 32 | + font-size: 11px; | ||
| 32 | } | 33 | } |
| 33 | .profile-list a.profile-link:hover { | 34 | .profile-list a.profile-link:hover { |
| 34 | color: #FFF; | 35 | color: #FFF; |
test/functional/friends_controller_test.rb
| @@ -67,6 +67,7 @@ class FriendsControllerTest < Test::Unit::TestCase | @@ -67,6 +67,7 @@ class FriendsControllerTest < Test::Unit::TestCase | ||
| 67 | post :remove, :id => friend.id, :confirmation => '1' | 67 | post :remove, :id => friend.id, :confirmation => '1' |
| 68 | assert_redirected_to :action => 'index' | 68 | assert_redirected_to :action => 'index' |
| 69 | end | 69 | end |
| 70 | + assert_equal friend, Profile.find(friend.id) | ||
| 70 | end | 71 | end |
| 71 | 72 | ||
| 72 | should 'display find people button' do | 73 | should 'display find people button' do |
test/unit/friendship_test.rb
| @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
| 3 | class FriendshipTest < Test::Unit::TestCase | 3 | class FriendshipTest < Test::Unit::TestCase |
| 4 | 4 | ||
| 5 | should 'connect a person to another' do | 5 | should 'connect a person to another' do |
| 6 | - p1 = Person.new(:environment => Environment.default) | ||
| 7 | - p2 = Person.new(:environment => Environment.default) | 6 | + p1 = create_user('person_test').person |
| 7 | + p2 = create_user('person_test_2').person | ||
| 8 | 8 | ||
| 9 | f = Friendship.new | 9 | f = Friendship.new |
| 10 | assert_raise ActiveRecord::AssociationTypeMismatch do | 10 | assert_raise ActiveRecord::AssociationTypeMismatch do |