diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb
index 21f812b..d200c41 100644
--- a/app/controllers/my_profile/friends_controller.rb
+++ b/app/controllers/my_profile/friends_controller.rb
@@ -3,6 +3,7 @@ class FriendsController < MyProfileController
protect 'manage_friends', :profile
def index
+ @suggestions = profile.suggested_people.limit(per_page/2)
if is_cache_expired?(profile.manage_friends_cache_key(params))
@friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage])
end
@@ -16,6 +17,21 @@ class FriendsController < MyProfileController
end
end
+ def suggest
+ @suggestions = profile.suggested_people.paginate(:per_page => per_page, :page => params[:npage])
+ end
+
+ def remove_suggestion
+ @person = profile.suggested_people.find_by_identifier(params[:id])
+ redirect_to :action => 'suggest' unless @person
+ if @person && request.post?
+ suggestion = profile.profile_suggestions.find_by_suggestion_id @person.id
+ suggestion.disable
+ session[:notice] = _('Suggestion removed')
+ redirect_to :action => 'suggest'
+ end
+ end
+
protected
class << self
diff --git a/app/views/friends/_profile_list.html.erb b/app/views/friends/_profile_list.html.erb
new file mode 100644
index 0000000..1a68d17
--- /dev/null
+++ b/app/views/friends/_profile_list.html.erb
@@ -0,0 +1,31 @@
+
+ <% profiles.each do |profile| %>
+ -
+ <%= link_to_profile profile_image(profile) + '
' + profile.short_name,
+ profile.identifier, :class => 'profile-link' %>
+
+ <% if collection == :friends %>
+ <%= link_to content_tag('span',_('remove')),
+ { :action => 'remove', :id => profile.id },
+ :class => 'button icon-remove',
+ :title => _('remove') %>
+ <%= link_to content_tag('span',_('contact')),
+ profile.url.merge(:controller => 'contact', :action => 'new', :profile => profile.identifier),
+ :class => 'button icon-menu-mail',
+ :title => _('contact') %>
+ <% elsif collection == :suggestions %>
+ <%= link_to content_tag('span',_('add')),
+ profile.add_url,
+ :class => 'button icon-add add-friend',
+ :title => _('Add friend') %>
+ <%= link_to content_tag('span',_('remove')),
+ { :action => 'remove_suggestion', :id => profile.identifier },
+ :class => 'button icon-remove',
+ :title => _('Remove suggestion'),
+ :method => 'post',
+ :confirm => _('Are you sure you want to remove this suggestion?') %>
+ <% end %>
+
+
+ <% end %>
+
diff --git a/app/views/friends/index.html.erb b/app/views/friends/index.html.erb
index 94bed84..df4a19a 100644
--- a/app/views/friends/index.html.erb
+++ b/app/views/friends/index.html.erb
@@ -10,38 +10,8 @@
<%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %>
- <% else %>
- <% button_bar do %>
- <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
- <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
- <% unless @plugins.dispatch(:remove_invite_friends_button).include?(true) %>
- <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'select_address_book') %>
- <% end %>
- <% end %>
<% 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-remove',
- :title => _('remove') %>
- <%= link_to content_tag('span',_('contact')),
- friend.url.merge(:controller => 'contact', :action => 'new', :profile => friend.identifier),
- :class => 'button icon-menu-mail',
- :title => _('contact') %>
-
-
- <% end %>
-
-
-
<% button_bar do %>
<%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
<%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
@@ -49,7 +19,23 @@
<%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'select_address_book') %>
<% end %>
<% end %>
+
+ <%= render :partial => 'profile_list', :locals => { :profiles => @friends, :collection => :friends } %>
+
+
+<% end %>
+
+<% unless @suggestions.empty? %>
+
+ <%= _("Friends suggestions") %>
+
+ <%= render :partial => 'profile_list', :locals => { :profiles => @suggestions, :collection => :suggestions } %>
+
+ <% button_bar do %>
+ <%= link_to _('See more suggestions...'), :action => 'suggest' %>
+ <% end %>
<% end %>
-
diff --git a/app/views/friends/remove_suggestion.html.erb b/app/views/friends/remove_suggestion.html.erb
new file mode 100644
index 0000000..ebfdd78
--- /dev/null
+++ b/app/views/friends/remove_suggestion.html.erb
@@ -0,0 +1,5 @@
+
+
<%= _('Removing suggestion for friend: %s') % @person.name %>
+
+ <%= render :partial => 'shared/remove_suggestion', :locals => { :suggestion => @person } %>
+
diff --git a/app/views/friends/suggest.html.erb b/app/views/friends/suggest.html.erb
new file mode 100644
index 0000000..30d0436
--- /dev/null
+++ b/app/views/friends/suggest.html.erb
@@ -0,0 +1,20 @@
+<%= _("Friends suggestions for %s") % profile.name %>
+
+<% button_bar do %>
+ <%= button(:back, _('Go to friends list'), :controller => 'friends') %>
+<% end %>
+
+<% if @suggestions.empty? %>
+
+
+ <%= _('You have no suggestions yet.') %>
+ <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %>
+
+
+<% else %>
+
+ <%= render :partial => 'profile_list', :locals => { :profiles => @suggestions, :collection => :suggestions } %>
+
+ <%= pagination_links @suggestions, :param_name => 'npage' %>
+<% end %>
+
diff --git a/app/views/shared/_remove_suggestion.html.erb b/app/views/shared/_remove_suggestion.html.erb
new file mode 100644
index 0000000..34466c8
--- /dev/null
+++ b/app/views/shared/_remove_suggestion.html.erb
@@ -0,0 +1,10 @@
+<%= profile_image suggestion, :thumb, :class => 'suggestion_picture' %>
+
+
+<%= _('Are you sure you want to remove %s from your suggestions list?') % suggestion.name %>
+
+
+<%= form_tag do %>
+ <%= submit_button(:ok, _("Yes, I want to remove %s") % suggestion.name) %>
+ <%= button(:cancel, _("No"), :action => 'suggest') %>
+<% end %>
diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb
index c692e85..e04fa6f 100644
--- a/test/functional/friends_controller_test.rb
+++ b/test/functional/friends_controller_test.rb
@@ -70,4 +70,41 @@ class FriendsControllerTest < ActionController::TestCase
assert_no_tag :tag => 'a', :attributes => { :href => "/profile/testuser/invite/friends" }
end
+ should 'not display list suggestions button if there is no suggestion' do
+ get :index, :profile => 'testuser'
+ assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" }
+ end
+
+ should 'display link to list suggestions page' do
+ profile.profile_suggestions.create(:suggestion => friend)
+ get :index, :profile => 'testuser'
+ assert_tag :tag => 'a', :content => 'See more suggestions...', :attributes => { :href => "/myprofile/testuser/friends/suggest" }
+ end
+
+ should 'display people suggestions' do
+ profile.profile_suggestions.create(:suggestion => friend)
+ get :suggest, :profile => 'testuser'
+ assert_tag :tag => 'a', :content => friend.name, :attributes => { :href => "/profile/#{friend.identifier}" }
+ end
+
+ should 'display button to add friend suggestion' do
+ profile.profile_suggestions.create(:suggestion => friend)
+ get :suggest, :profile => 'testuser'
+ assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" }
+ end
+
+ should 'display button to remove people suggestion' do
+ profile.profile_suggestions.create(:suggestion => friend)
+ get :suggest, :profile => 'testuser'
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/friends/remove_suggestion/#{friend.identifier}" }
+ end
+
+ should 'remove suggestion of friend' do
+ suggestion = profile.profile_suggestions.create(:suggestion => friend)
+ post :remove_suggestion, :profile => 'testuser', :id => friend.identifier
+
+ assert_redirected_to :action => 'suggest'
+ assert_equal false, ProfileSuggestion.find(suggestion.id).enabled
+ end
+
end
--
libgit2 0.21.2