Commit fcad091d97e7e03a9f7ea161d4e69389fdc25d21
1 parent
9701ad86
Exists in
master
and in
21 other branches
profile_suggestions: friends suggestions interface
Users can: * add a suggestion as friend * remove a suggestion from list (ActionItem3234)
Showing
7 changed files
with
136 additions
and
31 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
| @@ -3,6 +3,7 @@ class FriendsController < MyProfileController | @@ -3,6 +3,7 @@ class FriendsController < MyProfileController | ||
| 3 | protect 'manage_friends', :profile | 3 | protect 'manage_friends', :profile |
| 4 | 4 | ||
| 5 | def index | 5 | def index |
| 6 | + @suggestions = profile.suggested_people.limit(per_page/2) | ||
| 6 | if is_cache_expired?(profile.manage_friends_cache_key(params)) | 7 | if is_cache_expired?(profile.manage_friends_cache_key(params)) |
| 7 | @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) | 8 | @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) |
| 8 | end | 9 | end |
| @@ -16,6 +17,21 @@ class FriendsController < MyProfileController | @@ -16,6 +17,21 @@ class FriendsController < MyProfileController | ||
| 16 | end | 17 | end |
| 17 | end | 18 | end |
| 18 | 19 | ||
| 20 | + def suggest | ||
| 21 | + @suggestions = profile.suggested_people.paginate(:per_page => per_page, :page => params[:npage]) | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + def remove_suggestion | ||
| 25 | + @person = profile.suggested_people.find_by_identifier(params[:id]) | ||
| 26 | + redirect_to :action => 'suggest' unless @person | ||
| 27 | + if @person && request.post? | ||
| 28 | + suggestion = profile.profile_suggestions.find_by_suggestion_id @person.id | ||
| 29 | + suggestion.disable | ||
| 30 | + session[:notice] = _('Suggestion removed') | ||
| 31 | + redirect_to :action => 'suggest' | ||
| 32 | + end | ||
| 33 | + end | ||
| 34 | + | ||
| 19 | protected | 35 | protected |
| 20 | 36 | ||
| 21 | class << self | 37 | class << self |
| @@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
| 1 | +<ul class="profile-list"> | ||
| 2 | + <% profiles.each do |profile| %> | ||
| 3 | + <li> | ||
| 4 | + <%= link_to_profile profile_image(profile) + '<br/>' + profile.short_name, | ||
| 5 | + profile.identifier, :class => 'profile-link' %> | ||
| 6 | + <div class="controll"> | ||
| 7 | + <% if collection == :friends %> | ||
| 8 | + <%= link_to content_tag('span',_('remove')), | ||
| 9 | + { :action => 'remove', :id => profile.id }, | ||
| 10 | + :class => 'button icon-remove', | ||
| 11 | + :title => _('remove') %> | ||
| 12 | + <%= link_to content_tag('span',_('contact')), | ||
| 13 | + profile.url.merge(:controller => 'contact', :action => 'new', :profile => profile.identifier), | ||
| 14 | + :class => 'button icon-menu-mail', | ||
| 15 | + :title => _('contact') %> | ||
| 16 | + <% elsif collection == :suggestions %> | ||
| 17 | + <%= link_to content_tag('span',_('add')), | ||
| 18 | + profile.add_url, | ||
| 19 | + :class => 'button icon-add add-friend', | ||
| 20 | + :title => _('Add friend') %> | ||
| 21 | + <%= link_to content_tag('span',_('remove')), | ||
| 22 | + { :action => 'remove_suggestion', :id => profile.identifier }, | ||
| 23 | + :class => 'button icon-remove', | ||
| 24 | + :title => _('Remove suggestion'), | ||
| 25 | + :method => 'post', | ||
| 26 | + :confirm => _('Are you sure you want to remove this suggestion?') %> | ||
| 27 | + <% end %> | ||
| 28 | + </div><!-- end class="controll" --> | ||
| 29 | + </li> | ||
| 30 | + <% end %> | ||
| 31 | +</ul> |
app/views/friends/index.html.erb
| @@ -10,38 +10,8 @@ | @@ -10,38 +10,8 @@ | ||
| 10 | <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %> | 10 | <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %> |
| 11 | </em> | 11 | </em> |
| 12 | </p> | 12 | </p> |
| 13 | - <% else %> | ||
| 14 | - <% button_bar do %> | ||
| 15 | - <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> | ||
| 16 | - <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> | ||
| 17 | - <% unless @plugins.dispatch(:remove_invite_friends_button).include?(true) %> | ||
| 18 | - <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'select_address_book') %> | ||
| 19 | - <% end %> | ||
| 20 | - <% end %> | ||
| 21 | <% end %> | 13 | <% end %> |
| 22 | 14 | ||
| 23 | - <ul class="profile-list"> | ||
| 24 | - <% @friends.each do |friend| %> | ||
| 25 | - <li> | ||
| 26 | - <%= link_to_profile profile_image(friend) + '<br/>' + friend.short_name, | ||
| 27 | - friend.identifier, :class => 'profile-link' %> | ||
| 28 | - <div class="controll"> | ||
| 29 | - <%= link_to content_tag('span',_('remove')), | ||
| 30 | - { :action => 'remove', :id => friend.id }, | ||
| 31 | - :class => 'button icon-remove', | ||
| 32 | - :title => _('remove') %> | ||
| 33 | - <%= link_to content_tag('span',_('contact')), | ||
| 34 | - friend.url.merge(:controller => 'contact', :action => 'new', :profile => friend.identifier), | ||
| 35 | - :class => 'button icon-menu-mail', | ||
| 36 | - :title => _('contact') %> | ||
| 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> | ||
| 44 | - | ||
| 45 | <% button_bar do %> | 15 | <% button_bar do %> |
| 46 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> | 16 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> |
| 47 | <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> | 17 | <%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %> |
| @@ -49,7 +19,23 @@ | @@ -49,7 +19,23 @@ | ||
| 49 | <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'select_address_book') %> | 19 | <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'select_address_book') %> |
| 50 | <% end %> | 20 | <% end %> |
| 51 | <% end %> | 21 | <% end %> |
| 22 | + | ||
| 23 | + <%= render :partial => 'profile_list', :locals => { :profiles => @friends, :collection => :friends } %> | ||
| 24 | + <div id='pagination-friends'> | ||
| 25 | + <%= pagination_links @friends, :param_name => 'npage' %> | ||
| 26 | + </div> | ||
| 27 | + | ||
| 28 | +<% end %> | ||
| 29 | + | ||
| 30 | +<% unless @suggestions.empty? %> | ||
| 31 | + <br style="clear:both" /> | ||
| 32 | + <h2><%= _("Friends suggestions") %></h2> | ||
| 33 | + | ||
| 34 | + <%= render :partial => 'profile_list', :locals => { :profiles => @suggestions, :collection => :suggestions } %> | ||
| 35 | + | ||
| 36 | + <% button_bar do %> | ||
| 37 | + <%= link_to _('See more suggestions...'), :action => 'suggest' %> | ||
| 38 | + <% end %> | ||
| 52 | <% end %> | 39 | <% end %> |
| 53 | 40 | ||
| 54 | </div><!-- end id="manage_friends" --> | 41 | </div><!-- end id="manage_friends" --> |
| 55 | - |
| @@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
| 1 | +<h1><%= _("Friends suggestions for %s") % profile.name %></h1> | ||
| 2 | + | ||
| 3 | +<% button_bar do %> | ||
| 4 | + <%= button(:back, _('Go to friends list'), :controller => 'friends') %> | ||
| 5 | +<% end %> | ||
| 6 | + | ||
| 7 | +<% if @suggestions.empty? %> | ||
| 8 | + <p> | ||
| 9 | + <em> | ||
| 10 | + <%= _('You have no suggestions yet.') %> | ||
| 11 | + <%= link_to _('Do you want to see other people in this environment?'), :controller => 'search', :action => 'assets', :asset => 'people' %> | ||
| 12 | + </em> | ||
| 13 | + </p> | ||
| 14 | +<% else %> | ||
| 15 | + | ||
| 16 | + <%= render :partial => 'profile_list', :locals => { :profiles => @suggestions, :collection => :suggestions } %> | ||
| 17 | + | ||
| 18 | + <%= pagination_links @suggestions, :param_name => 'npage' %> | ||
| 19 | +<% end %> | ||
| 20 | +<br style="clear:both" /> |
| @@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
| 1 | +<%= profile_image suggestion, :thumb, :class => 'suggestion_picture' %> | ||
| 2 | + | ||
| 3 | +<p> | ||
| 4 | +<%= _('Are you sure you want to remove %s from your suggestions list?') % suggestion.name %> | ||
| 5 | +</p> | ||
| 6 | + | ||
| 7 | +<%= form_tag do %> | ||
| 8 | + <%= submit_button(:ok, _("Yes, I want to remove %s") % suggestion.name) %> | ||
| 9 | + <%= button(:cancel, _("No"), :action => 'suggest') %> | ||
| 10 | +<% end %> |
test/functional/friends_controller_test.rb
| @@ -70,4 +70,41 @@ class FriendsControllerTest < ActionController::TestCase | @@ -70,4 +70,41 @@ class FriendsControllerTest < ActionController::TestCase | ||
| 70 | assert_no_tag :tag => 'a', :attributes => { :href => "/profile/testuser/invite/friends" } | 70 | assert_no_tag :tag => 'a', :attributes => { :href => "/profile/testuser/invite/friends" } |
| 71 | end | 71 | end |
| 72 | 72 | ||
| 73 | + should 'not display list suggestions button if there is no suggestion' do | ||
| 74 | + get :index, :profile => 'testuser' | ||
| 75 | + assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" } | ||
| 76 | + end | ||
| 77 | + | ||
| 78 | + should 'display link to list suggestions page' do | ||
| 79 | + profile.profile_suggestions.create(:suggestion => friend) | ||
| 80 | + get :index, :profile => 'testuser' | ||
| 81 | + assert_tag :tag => 'a', :content => 'See more suggestions...', :attributes => { :href => "/myprofile/testuser/friends/suggest" } | ||
| 82 | + end | ||
| 83 | + | ||
| 84 | + should 'display people suggestions' do | ||
| 85 | + profile.profile_suggestions.create(:suggestion => friend) | ||
| 86 | + get :suggest, :profile => 'testuser' | ||
| 87 | + assert_tag :tag => 'a', :content => friend.name, :attributes => { :href => "/profile/#{friend.identifier}" } | ||
| 88 | + end | ||
| 89 | + | ||
| 90 | + should 'display button to add friend suggestion' do | ||
| 91 | + profile.profile_suggestions.create(:suggestion => friend) | ||
| 92 | + get :suggest, :profile => 'testuser' | ||
| 93 | + assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" } | ||
| 94 | + end | ||
| 95 | + | ||
| 96 | + should 'display button to remove people suggestion' do | ||
| 97 | + profile.profile_suggestions.create(:suggestion => friend) | ||
| 98 | + get :suggest, :profile => 'testuser' | ||
| 99 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/friends/remove_suggestion/#{friend.identifier}" } | ||
| 100 | + end | ||
| 101 | + | ||
| 102 | + should 'remove suggestion of friend' do | ||
| 103 | + suggestion = profile.profile_suggestions.create(:suggestion => friend) | ||
| 104 | + post :remove_suggestion, :profile => 'testuser', :id => friend.identifier | ||
| 105 | + | ||
| 106 | + assert_redirected_to :action => 'suggest' | ||
| 107 | + assert_equal false, ProfileSuggestion.find(suggestion.id).enabled | ||
| 108 | + end | ||
| 109 | + | ||
| 73 | end | 110 | end |