Commit 9372126ab1bb1f7d85cc2ebf17eb5fabd49880bd

Authored by Daniela Feitosa
1 parent 9cc4340d

[suggestions] Some enhancements

Added title on links
Moved logic from view to model
Added conditions to avoid displaying empty lists
Removed code duplication on js
app/helpers/application_helper.rb
... ... @@ -1424,7 +1424,7 @@ module ApplicationHelper
1424 1424  
1425 1425 def profile_suggestion_profile_connections(suggestion)
1426 1426 profiles = suggestion.profile_connections.first(4).map do |profile|
1427   - link_to(profile_image(profile, :icon), profile.url, :class => 'profile-suggestion-connection-icon', :title => profile.name)
  1427 + link_to(profile_image(profile, :icon, :title => profile.name), profile.url, :class => 'profile-suggestion-connection-icon')
1428 1428 end
1429 1429  
1430 1430 controller_target = suggestion.suggestion_type == 'Person' ? :friends : :memberships
... ... @@ -1446,7 +1446,7 @@ module ApplicationHelper
1446 1446 title = tags.join
1447 1447  
1448 1448 controller_target = suggestion.suggestion_type == 'Person' ? :friends : :memberships
1449   - tags << ' ' + link_to('...', {:controller => controller_target, :action => :connections, :id => suggestion.suggestion_id}, :class => 'more-tag-connections') if suggestion.tag_connections.count > 4
  1449 + tags << ' ' + link_to('...', {:controller => controller_target, :action => :connections, :id => suggestion.suggestion_id}, :class => 'more-tag-connections', :title => _('See all connections')) if suggestion.tag_connections.count > 4
1450 1450  
1451 1451 if tags.present?
1452 1452 content_tag(:div, tags.join, :class => 'tag-connections', :title => title)
... ...
app/models/communities_block.rb
... ... @@ -22,6 +22,7 @@ class CommunitiesBlock &lt; ProfileListBlock
22 22 def footer
23 23 owner = self.owner
24 24 suggestions = self.suggestions
  25 + return '' unless owner.kind_of?(Profile) || owner.kind_of?(Environment)
25 26 proc do
26 27 render :file => 'blocks/communities', :locals => { :owner => owner, :suggestions => suggestions }
27 28 end
... ...
app/views/blocks/communities.html.erb
... ... @@ -2,11 +2,9 @@
2 2 <%= link_to s_('communities|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %>
3 3 <% elsif owner.kind_of?(Environment) %>
4 4 <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %>
5   -<% else %>
6   - ''
7 5 <% end %>
8 6  
9   -<% if user == profile && suggestions && !suggestions.empty? %>
  7 +<% if user && user == profile && suggestions && !suggestions.empty? %>
10 8 <div class='suggestions-block common-profile-list-block'>
11 9 <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>
12 10 <div class='profiles-suggestions'>
... ...
app/views/shared/_profile_connections.html.erb
1   -<h2><%= _("Profiles in common:") if profiles.present? %></h2>
2   -<div class="list-profile-connections">
3   - <ul class="profile-list">
4   - <% profiles.each do |profile| %>
5   - <li>
6   - <%= link_to_profile profile_image(profile) + '<br/>' + profile.short_name,
7   - profile.identifier, :class => 'profile-link' %>
8   - </li>
9   - <% end %>
10   - </ul>
11   -</div>
12   -
13   -<br style="clear:both" />
  1 +<% if profiles.present? %>
  2 + <h2><%= _("Profiles in common:") %></h2>
  3 + <div class="list-profile-connections">
  4 + <ul class="profile-list">
  5 + <% profiles.each do |profile| %>
  6 + <li>
  7 + <%= link_to_profile profile_image(profile) + '<br/>' + profile.short_name,
  8 + profile.identifier, :class => 'profile-link' %>
  9 + </li>
  10 + <% end %>
  11 + </ul>
  12 + </div>
  13 + <br style="clear:both" />
  14 +<% end %>
14 15  
15   -<h2><%= _("Tags in common:") if tags.present? %></h2>
  16 +<% if tags.present? %>
  17 + <h2><%= _("Tags in common:") %></h2>
16 18 <ul>
17 19 <% tags.each do |tag| %>
18 20 <li><%= tag.name %></li>
19 21 <% end %>
20 22 </ul>
  23 +<% end %>
... ...
app/views/shared/_profile_suggestions_list.html.erb
... ... @@ -10,14 +10,22 @@
10 10 <ul class="profile-list">
11 11 <% suggestions.each do |s| %>
12 12 <li>
13   - <%= link_to_profile profile_image(s.suggestion, :minor),
  13 + <%= link_to_profile profile_image(s.suggestion, :minor, :title => s.suggestion.short_name),
14 14 s.suggestion.identifier, :class => 'profile-link' %>
15 15 <% if collection == :friends_suggestions %>
16   - <%= link_to _('Add %s') % s.suggestion.short_name,
17   - s.suggestion.add_url, :class => 'accept-suggestion' %>
  16 + <%= link_to '+ %s' % s.suggestion.short_name,
  17 + s.suggestion.add_url,
  18 + :class => 'accept-suggestion',
  19 + :title => _('Add suggestion'),
  20 + :remote => true
  21 + %>
18 22 <% elsif collection == :communities_suggestions %>
19   - <%= link_to _('Join %s') % s.suggestion.name,
20   - s.suggestion.add_url, :class => 'accept-suggestion' %>
  23 + <%= link_to '+ %s' % s.suggestion.name,
  24 + s.suggestion.join_url,
  25 + :class => 'accept-suggestion',
  26 + :title => _('Add suggestion'),
  27 + :remote => true
  28 + %>
21 29 <% end %>
22 30 <div class='extra_info'>
23 31 <%= profile_suggestion_profile_connections(s) %>
... ... @@ -29,13 +37,17 @@
29 37 { :controller => 'friends', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page },
30 38 :class => 'remove-suggestion',
31 39 :title => _('Remove suggestion'),
32   - :confirm => _('Are you sure you want to remove this suggestion?') %>
  40 + :confirm => _('Are you sure you want to remove this suggestion?'),
  41 + :remote => true
  42 + %>
33 43 <% elsif collection == :communities_suggestions %>
34 44 <%= link_to 'x',
35 45 { :controller => 'memberships', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page },
36 46 :class => 'remove-suggestion',
37 47 :title => _('Remove suggestion'),
38   - :confirm => _('Are you sure you want to remove this suggestion?') %>
  48 + :confirm => _('Are you sure you want to remove this suggestion?'),
  49 + :remote => true
  50 + %>
39 51 <% end %>
40 52 </div><!-- end class="controll" -->
41 53 </li>
... ...
public/javascripts/add-and-join.js
... ... @@ -121,30 +121,29 @@ jQuery(function($) {
121 121 })
122 122  
123 123 $(".remove-suggestion").live('click', function(){
124   - clicked = $(this)
125   - url = clicked.attr("href");
126   - loading_for_button(this);
127   - $.post(url, function(data){
128   - clicked.fadeOut();
129   - clicked.parents('.profiles-suggestions').html(data);
130   - });
131   - return false;
  124 + clicked = $(this);
  125 + removeSuggestionFromList(clicked);
132 126 })
133 127  
134   - /* After adding a suggestion need to remove it from list */
135 128 $(".accept-suggestion").live('click', function(){
136 129 clicked = $(this)
137 130 loading_for_button(this);
138 131 url = clicked.attr("href");
139   - remove_suggestion = clicked.parents('li').find('.remove-suggestion');
140   - remove_url = remove_suggestion.attr('href')
141   - $.post(remove_url, function(suggestions_data){
142   - remove_suggestion.parents('.profiles-suggestions').html(suggestions_data);
143   - $.post(url, function(add_data){
144   - clicked.parents('li').fadeOut();
145   - });
  132 + removeSuggestionFromList(clicked.parents('li').find('.remove-suggestion'));
  133 + $.post(url, function(add_data){
  134 + clicked.parents('li').fadeOut();
146 135 });
147 136 return false;
148 137 })
149 138  
150 139 });
  140 +
  141 +/* Used after clicking on remove and after adding a suggestion */
  142 +function removeSuggestionFromList( element ) {
  143 + url = element.attr("href");
  144 + loading_for_button(element);
  145 + jQuery.post(url, function(data){
  146 + element.fadeOut();
  147 + element.parents('.profiles-suggestions').html(data);
  148 + });
  149 +}
... ...
public/stylesheets/application.css
... ... @@ -1688,12 +1688,11 @@ a.button.disabled, input.disabled {
1688 1688 #content .communities-block .block-footer-content .profiles-suggestions a.accept-suggestion,
1689 1689 #content .communities-block .block-footer-content .profiles-suggestions a.remove-suggestion {
1690 1690 position: relative;
1691   - z-index: 5;
1692 1691 }
1693 1692  
1694 1693 #content .block-footer-content .profiles-suggestions a.accept-suggestion {
1695 1694 padding-bottom: 3px;
1696   - display: inline-block;
  1695 + display: block;
1697 1696 color: #333;
1698 1697 font-size: 11px
1699 1698 }
... ...
test/functional/friends_controller_test.rb
... ... @@ -75,16 +75,10 @@ class FriendsControllerTest &lt; ActionController::TestCase
75 75 assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" }
76 76 end
77 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 78 should 'display people suggestions' do
85 79 profile.profile_suggestions.create(:suggestion => friend)
86 80 get :suggest, :profile => 'testuser'
87   - assert_tag :tag => 'a', :content => friend.name, :attributes => { :href => "/profile/#{friend.identifier}" }
  81 + assert_tag :tag => 'a', :content => "+ #{friend.name}", :attributes => { :href => "/profile/#{friend.identifier}/add" }
88 82 end
89 83  
90 84 should 'display button to add friend suggestion' do
... ... @@ -96,14 +90,14 @@ class FriendsControllerTest &lt; ActionController::TestCase
96 90 should 'display button to remove people suggestion' do
97 91 profile.profile_suggestions.create(:suggestion => friend)
98 92 get :suggest, :profile => 'testuser'
99   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/friends/remove_suggestion/#{friend.identifier}" }
  93 + assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/friends\/remove_suggestion\/#{friend.identifier}/ }
100 94 end
101 95  
102 96 should 'remove suggestion of friend' do
103 97 suggestion = profile.profile_suggestions.create(:suggestion => friend)
104 98 post :remove_suggestion, :profile => 'testuser', :id => friend.identifier
105 99  
106   - assert_redirected_to :action => 'suggest'
  100 + assert_response :success
107 101 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled
108 102 end
109 103  
... ...
test/functional/memberships_controller_test.rb
... ... @@ -340,7 +340,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
340 340 community = fast_create(Community)
341 341 profile.profile_suggestions.create(:suggestion => community)
342 342 get :suggest, :profile => 'testuser'
343   - assert_tag :tag => 'a', :content => community.name, :attributes => { :href => "/profile/#{community.identifier}" }
  343 + assert_tag :tag => 'a', :content => "+ #{community.name}", :attributes => { :href => "/profile/#{community.identifier}/join" }
344 344 end
345 345  
346 346 should 'display button to join on community suggestion' do
... ... @@ -354,7 +354,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
354 354 community = fast_create(Community)
355 355 profile.profile_suggestions.create(:suggestion => community)
356 356 get :suggest, :profile => 'testuser'
357   - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/remove_suggestion/#{community.identifier}" }
  357 + assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/memberships\/remove_suggestion\/#{community.identifier}/ }
358 358 end
359 359  
360 360 should 'remove suggestion of community' do
... ... @@ -362,7 +362,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
362 362 suggestion = profile.profile_suggestions.create(:suggestion => community)
363 363 post :remove_suggestion, :profile => 'testuser', :id => community.identifier
364 364  
365   - assert_redirected_to :action => 'suggest'
  365 + assert_response :success
366 366 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled
367 367 end
368 368  
... ...
test/unit/communities_block_test.rb
... ... @@ -27,30 +27,30 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
27 27 assert_same list, block.profiles
28 28 end
29 29  
30   - should 'link to all communities of profile' do
  30 + should 'support profile as block owner' do
31 31 profile = Profile.new
32   - profile.expects(:identifier).returns("theprofile")
33 32  
34 33 block = CommunitiesBlock.new
35   - block.expects(:owner).returns(profile)
  34 + block.expects(:owner).returns(profile).at_least_once
36 35  
37   - expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'communities')
  36 + self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => profile, :suggestions => block.suggestions })
38 37 instance_eval(&block.footer)
39 38 end
40 39  
41   - should 'support environment as owner' do
  40 + should 'support environment as block owner' do
42 41 env = Environment.default
43 42 block = CommunitiesBlock.new
44   - block.expects(:owner).returns(env)
45   -
46   - expects(:link_to).with('View all', :controller => "search", :action => 'communities')
  43 + block.expects(:owner).returns(env).at_least_once
47 44  
  45 + self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => env, :suggestions => block.suggestions })
48 46 instance_eval(&block.footer)
49 47 end
50 48  
51 49 should 'give empty footer on unsupported owner type' do
52 50 block = CommunitiesBlock.new
53   - block.expects(:owner).returns(1)
  51 + block.expects(:owner).returns(1).at_least_once
  52 +
  53 + self.expects(:render).with(anything).never
54 54 assert_equal '', block.footer
55 55 end
56 56  
... ...