diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb
index 43894bd..0a70611 100644
--- a/app/controllers/my_profile/friends_controller.rb
+++ b/app/controllers/my_profile/friends_controller.rb
@@ -5,7 +5,9 @@ class FriendsController < MyProfileController
protect 'manage_friends', :profile
def index
- @friends = profile.friends
+ if is_cache_expired?(profile.manage_friends_cache_key(params))
+ @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage])
+ end
end
def add
@@ -23,7 +25,6 @@ class FriendsController < MyProfileController
def remove
@friend = profile.friends.find(params[:id])
if request.post? && params[:confirmation]
- expire_fragment(:action => 'friends', :controller => 'profile', :profile => profile.identifier)
profile.remove_friend(@friend)
redirect_to :action => 'index'
end
@@ -106,4 +107,9 @@ class FriendsController < MyProfileController
end
end
+ protected
+
+ def per_page
+ 10
+ end
end
diff --git a/app/helpers/friends_helper.rb b/app/helpers/friends_helper.rb
index 40edf26..a2fd2c3 100644
--- a/app/helpers/friends_helper.rb
+++ b/app/helpers/friends_helper.rb
@@ -4,4 +4,10 @@ module FriendsHelper
options.merge!({:action => 'invite', :import => 1, :wizard => true})
link_to text, options
end
+
+ def pagination_links(collection, options={})
+ options = {:prev_label => '« ' + _('Previous'), :next_label => _('Next') + ' »'}.merge(options)
+ will_paginate(collection, options)
+ end
+
end
diff --git a/app/views/friends/index.rhtml b/app/views/friends/index.rhtml
index 2887f1d..b58d34d 100644
--- a/app/views/friends/index.rhtml
+++ b/app/views/friends/index.rhtml
@@ -2,47 +2,52 @@
<%= __("%s's friends") % profile.name %>
-<% if @friends.empty? %>
-
-
- <%= __('You have no friends yet.') %>
- <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %>
-
-
-<% else %>
- <% button_bar do %>
- <%= button(:back, _('Go back'), :controller => 'profile_editor') %>
- <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
- <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %>
+<% cache_timeout(profile.manage_friends_cache_key(params), 4.hours.from_now) do %>
+ <% if @friends.empty? %>
+
+
+ <%= __('You have no friends yet.') %>
+ <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %>
+
+
+ <% else %>
+ <% button_bar do %>
+ <%= button(:back, _('Go back'), :controller => 'profile_editor') %>
+ <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
+ <%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %>
+ <% end %>
<% end %>
-<% end %>
-
- <% @friends.each do |friend| %>
- -
- <%= link_to_profile profile_image(friend) + '
' + friend.name,
- friend.identifier, :class => 'profile-link' %>
-
- <%= link_to content_tag('span',_('remove')),
- { :action => 'remove', :id => friend.id },
- :class => 'button icon-delete',
- :title => _('remove'),
- :help => __('Clicking on this button will remove your friend relation with %s.') % friend.name %>
- <%= link_to content_tag('span',_('contact')),
- friend.url.merge(:controller => 'contact', :action => 'new'),
- :class => 'button icon-menu-mail',
- :title => _('contact'),
- :help => __('Clicking on this button will let you send a message to %s.') % friend.name %>
-
-
- <% end %>
-
+
+ <% @friends.each do |friend| %>
+ -
+ <%= link_to_profile profile_image(friend) + '
' + friend.short_name,
+ friend.identifier, :class => 'profile-link' %>
+
+ <%= link_to content_tag('span',_('remove')),
+ { :action => 'remove', :id => friend.id },
+ :class => 'button icon-delete',
+ :title => _('remove'),
+ :help => __('Clicking on this button will remove your friend relation with %s.') % friend.name %>
+ <%= link_to content_tag('span',_('contact')),
+ friend.url.merge(:controller => 'contact', :action => 'new'),
+ :class => 'button icon-menu-mail',
+ :title => _('contact'),
+ :help => __('Clicking on this button will let you send a message to %s.') % friend.name %>
+
+
+ <% end %>
+
+
<% button_bar do %>
<%= button(:back, _('Go back'), :controller => 'profile_editor') %>
<%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
<%= button(:search, _('Invite people from my e-mail contacts'), :action => 'invite') %>
<% end %>
+<% end %>
diff --git a/public/stylesheets/controller_friends.css b/public/stylesheets/controller_friends.css
index 9e90f16..2e940e4 100644
--- a/public/stylesheets/controller_friends.css
+++ b/public/stylesheets/controller_friends.css
@@ -1,5 +1,6 @@
@import url(manage_contacts_list.css);
+@import url(pagination.css);
#remove_friend .friend_picture {
float: left;
@@ -17,3 +18,7 @@
border: 1px solid #999;
margin: 5px 0px;
}
+
+#pagination-friends .pagination span {
+ display: inline;
+}
diff --git a/public/stylesheets/manage_contacts_list.css b/public/stylesheets/manage_contacts_list.css
index 58b7411..2d4c96f 100644
--- a/public/stylesheets/manage_contacts_list.css
+++ b/public/stylesheets/manage_contacts_list.css
@@ -29,6 +29,7 @@
text-decoration: none;
text-align: center;
display: block;
+ font-size: 11px;
}
.profile-list a.profile-link:hover {
color: #FFF;
diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb
index 251bf3f..53f892f 100644
--- a/test/functional/friends_controller_test.rb
+++ b/test/functional/friends_controller_test.rb
@@ -67,6 +67,7 @@ class FriendsControllerTest < Test::Unit::TestCase
post :remove, :id => friend.id, :confirmation => '1'
assert_redirected_to :action => 'index'
end
+ assert_equal friend, Profile.find(friend.id)
end
should 'display find people button' do
diff --git a/test/unit/friendship_test.rb b/test/unit/friendship_test.rb
index f1b52da..5365cac 100644
--- a/test/unit/friendship_test.rb
+++ b/test/unit/friendship_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper'
class FriendshipTest < Test::Unit::TestCase
should 'connect a person to another' do
- p1 = Person.new(:environment => Environment.default)
- p2 = Person.new(:environment => Environment.default)
+ p1 = create_user('person_test').person
+ p2 = create_user('person_test_2').person
f = Friendship.new
assert_raise ActiveRecord::AssociationTypeMismatch do
--
libgit2 0.21.2