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,7 +1424,7 @@ module ApplicationHelper
1424 1424
1425 def profile_suggestion_profile_connections(suggestion) 1425 def profile_suggestion_profile_connections(suggestion)
1426 profiles = suggestion.profile_connections.first(4).map do |profile| 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 end 1428 end
1429 1429
1430 controller_target = suggestion.suggestion_type == 'Person' ? :friends : :memberships 1430 controller_target = suggestion.suggestion_type == 'Person' ? :friends : :memberships
@@ -1446,7 +1446,7 @@ module ApplicationHelper @@ -1446,7 +1446,7 @@ module ApplicationHelper
1446 title = tags.join 1446 title = tags.join
1447 1447
1448 controller_target = suggestion.suggestion_type == 'Person' ? :friends : :memberships 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 if tags.present? 1451 if tags.present?
1452 content_tag(:div, tags.join, :class => 'tag-connections', :title => title) 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,6 +22,7 @@ class CommunitiesBlock &lt; ProfileListBlock
22 def footer 22 def footer
23 owner = self.owner 23 owner = self.owner
24 suggestions = self.suggestions 24 suggestions = self.suggestions
  25 + return '' unless owner.kind_of?(Profile) || owner.kind_of?(Environment)
25 proc do 26 proc do
26 render :file => 'blocks/communities', :locals => { :owner => owner, :suggestions => suggestions } 27 render :file => 'blocks/communities', :locals => { :owner => owner, :suggestions => suggestions }
27 end 28 end
app/views/blocks/communities.html.erb
@@ -2,11 +2,9 @@ @@ -2,11 +2,9 @@
2 <%= link_to s_('communities|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %> 2 <%= link_to s_('communities|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %>
3 <% elsif owner.kind_of?(Environment) %> 3 <% elsif owner.kind_of?(Environment) %>
4 <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %> 4 <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %>
5 -<% else %>  
6 - ''  
7 <% end %> 5 <% end %>
8 6
9 -<% if user == profile && suggestions && !suggestions.empty? %> 7 +<% if user && user == profile && suggestions && !suggestions.empty? %>
10 <div class='suggestions-block common-profile-list-block'> 8 <div class='suggestions-block common-profile-list-block'>
11 <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> 9 <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4>
12 <div class='profiles-suggestions'> 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 <ul> 18 <ul>
17 <% tags.each do |tag| %> 19 <% tags.each do |tag| %>
18 <li><%= tag.name %></li> 20 <li><%= tag.name %></li>
19 <% end %> 21 <% end %>
20 </ul> 22 </ul>
  23 +<% end %>
app/views/shared/_profile_suggestions_list.html.erb
@@ -10,14 +10,22 @@ @@ -10,14 +10,22 @@
10 <ul class="profile-list"> 10 <ul class="profile-list">
11 <% suggestions.each do |s| %> 11 <% suggestions.each do |s| %>
12 <li> 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 s.suggestion.identifier, :class => 'profile-link' %> 14 s.suggestion.identifier, :class => 'profile-link' %>
15 <% if collection == :friends_suggestions %> 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 <% elsif collection == :communities_suggestions %> 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 <% end %> 29 <% end %>
22 <div class='extra_info'> 30 <div class='extra_info'>
23 <%= profile_suggestion_profile_connections(s) %> 31 <%= profile_suggestion_profile_connections(s) %>
@@ -29,13 +37,17 @@ @@ -29,13 +37,17 @@
29 { :controller => 'friends', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page }, 37 { :controller => 'friends', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page },
30 :class => 'remove-suggestion', 38 :class => 'remove-suggestion',
31 :title => _('Remove suggestion'), 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 <% elsif collection == :communities_suggestions %> 43 <% elsif collection == :communities_suggestions %>
34 <%= link_to 'x', 44 <%= link_to 'x',
35 { :controller => 'memberships', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page }, 45 { :controller => 'memberships', :action => 'remove_suggestion', :id => s.suggestion.identifier, :per_page => per_page },
36 :class => 'remove-suggestion', 46 :class => 'remove-suggestion',
37 :title => _('Remove suggestion'), 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 <% end %> 51 <% end %>
40 </div><!-- end class="controll" --> 52 </div><!-- end class="controll" -->
41 </li> 53 </li>
public/javascripts/add-and-join.js
@@ -121,30 +121,29 @@ jQuery(function($) { @@ -121,30 +121,29 @@ jQuery(function($) {
121 }) 121 })
122 122
123 $(".remove-suggestion").live('click', function(){ 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 $(".accept-suggestion").live('click', function(){ 128 $(".accept-suggestion").live('click', function(){
136 clicked = $(this) 129 clicked = $(this)
137 loading_for_button(this); 130 loading_for_button(this);
138 url = clicked.attr("href"); 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 return false; 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,12 +1688,11 @@ a.button.disabled, input.disabled {
1688 #content .communities-block .block-footer-content .profiles-suggestions a.accept-suggestion, 1688 #content .communities-block .block-footer-content .profiles-suggestions a.accept-suggestion,
1689 #content .communities-block .block-footer-content .profiles-suggestions a.remove-suggestion { 1689 #content .communities-block .block-footer-content .profiles-suggestions a.remove-suggestion {
1690 position: relative; 1690 position: relative;
1691 - z-index: 5;  
1692 } 1691 }
1693 1692
1694 #content .block-footer-content .profiles-suggestions a.accept-suggestion { 1693 #content .block-footer-content .profiles-suggestions a.accept-suggestion {
1695 padding-bottom: 3px; 1694 padding-bottom: 3px;
1696 - display: inline-block; 1695 + display: block;
1697 color: #333; 1696 color: #333;
1698 font-size: 11px 1697 font-size: 11px
1699 } 1698 }
test/functional/friends_controller_test.rb
@@ -75,16 +75,10 @@ class FriendsControllerTest &lt; ActionController::TestCase @@ -75,16 +75,10 @@ class FriendsControllerTest &lt; ActionController::TestCase
75 assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" } 75 assert_no_tag :tag => 'a', :content => 'Suggest friends', :attributes => { :href => "/myprofile/testuser/friends/suggest" }
76 end 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 should 'display people suggestions' do 78 should 'display people suggestions' do
85 profile.profile_suggestions.create(:suggestion => friend) 79 profile.profile_suggestions.create(:suggestion => friend)
86 get :suggest, :profile => 'testuser' 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 end 82 end
89 83
90 should 'display button to add friend suggestion' do 84 should 'display button to add friend suggestion' do
@@ -96,14 +90,14 @@ class FriendsControllerTest &lt; ActionController::TestCase @@ -96,14 +90,14 @@ class FriendsControllerTest &lt; ActionController::TestCase
96 should 'display button to remove people suggestion' do 90 should 'display button to remove people suggestion' do
97 profile.profile_suggestions.create(:suggestion => friend) 91 profile.profile_suggestions.create(:suggestion => friend)
98 get :suggest, :profile => 'testuser' 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 end 94 end
101 95
102 should 'remove suggestion of friend' do 96 should 'remove suggestion of friend' do
103 suggestion = profile.profile_suggestions.create(:suggestion => friend) 97 suggestion = profile.profile_suggestions.create(:suggestion => friend)
104 post :remove_suggestion, :profile => 'testuser', :id => friend.identifier 98 post :remove_suggestion, :profile => 'testuser', :id => friend.identifier
105 99
106 - assert_redirected_to :action => 'suggest' 100 + assert_response :success
107 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled 101 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled
108 end 102 end
109 103
test/functional/memberships_controller_test.rb
@@ -340,7 +340,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -340,7 +340,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
340 community = fast_create(Community) 340 community = fast_create(Community)
341 profile.profile_suggestions.create(:suggestion => community) 341 profile.profile_suggestions.create(:suggestion => community)
342 get :suggest, :profile => 'testuser' 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 end 344 end
345 345
346 should 'display button to join on community suggestion' do 346 should 'display button to join on community suggestion' do
@@ -354,7 +354,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -354,7 +354,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
354 community = fast_create(Community) 354 community = fast_create(Community)
355 profile.profile_suggestions.create(:suggestion => community) 355 profile.profile_suggestions.create(:suggestion => community)
356 get :suggest, :profile => 'testuser' 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 end 358 end
359 359
360 should 'remove suggestion of community' do 360 should 'remove suggestion of community' do
@@ -362,7 +362,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -362,7 +362,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
362 suggestion = profile.profile_suggestions.create(:suggestion => community) 362 suggestion = profile.profile_suggestions.create(:suggestion => community)
363 post :remove_suggestion, :profile => 'testuser', :id => community.identifier 363 post :remove_suggestion, :profile => 'testuser', :id => community.identifier
364 364
365 - assert_redirected_to :action => 'suggest' 365 + assert_response :success
366 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled 366 assert_equal false, ProfileSuggestion.find(suggestion.id).enabled
367 end 367 end
368 368
test/unit/communities_block_test.rb
@@ -27,30 +27,30 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -27,30 +27,30 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
27 assert_same list, block.profiles 27 assert_same list, block.profiles
28 end 28 end
29 29
30 - should 'link to all communities of profile' do 30 + should 'support profile as block owner' do
31 profile = Profile.new 31 profile = Profile.new
32 - profile.expects(:identifier).returns("theprofile")  
33 32
34 block = CommunitiesBlock.new 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 instance_eval(&block.footer) 37 instance_eval(&block.footer)
39 end 38 end
40 39
41 - should 'support environment as owner' do 40 + should 'support environment as block owner' do
42 env = Environment.default 41 env = Environment.default
43 block = CommunitiesBlock.new 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 instance_eval(&block.footer) 46 instance_eval(&block.footer)
49 end 47 end
50 48
51 should 'give empty footer on unsupported owner type' do 49 should 'give empty footer on unsupported owner type' do
52 block = CommunitiesBlock.new 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 assert_equal '', block.footer 54 assert_equal '', block.footer
55 end 55 end
56 56