From ad29f61a1c2b2cbba9c6be601d5a3533c71fc472 Mon Sep 17 00:00:00 2001
From: Daniela Feitosa
Date: Mon, 4 Aug 2014 11:43:51 -0300
Subject: [PATCH] [suggestions] Displays categories in common
---
app/controllers/my_profile/friends_controller.rb | 8 +++-----
app/controllers/my_profile/memberships_controller.rb | 8 +++++++-
app/helpers/application_helper.rb | 5 +++++
app/mailers/user_mailer.rb | 2 +-
app/models/person.rb | 7 ++++++-
app/models/profile_suggestion.rb | 20 ++++++++++++++++----
app/views/friends/_profile_list.html.erb | 16 ++++++++++++++++
app/views/friends/index.html.erb | 19 ++++++++++---------
app/views/friends/suggest.html.erb | 4 +---
app/views/memberships/suggest.html.erb | 4 +---
app/views/shared/_profile_list.html.erb | 58 +++++++++++++++++++++++++++++-----------------------------
app/views/user_mailer/profiles_suggestions_email.html.erb | 3 ++-
public/javascripts/application.js | 8 ++++++++
public/stylesheets/application.css | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
test/unit/person_test.rb | 22 ++++++++++++++++++++++
15 files changed, 176 insertions(+), 62 deletions(-)
create mode 100644 app/views/friends/_profile_list.html.erb
diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb
index d200c41..acbdbb3 100644
--- a/app/controllers/my_profile/friends_controller.rb
+++ b/app/controllers/my_profile/friends_controller.rb
@@ -3,7 +3,7 @@ class FriendsController < MyProfileController
protect 'manage_friends', :profile
def index
- @suggestions = profile.suggested_people.limit(per_page/2)
+ @suggestions = profile.profile_suggestions.of_person.includes(:suggestion).limit(per_page)
if is_cache_expired?(profile.manage_friends_cache_key(params))
@friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage])
end
@@ -18,17 +18,15 @@ class FriendsController < MyProfileController
end
def suggest
- @suggestions = profile.suggested_people.paginate(:per_page => per_page, :page => params[:npage])
+ @suggestions = profile.profile_suggestions.of_person.enabled.includes(:suggestion).limit(per_page)
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
+ profile.remove_suggestion(@person)
session[:notice] = _('Suggestion removed')
- redirect_to :action => 'suggest'
end
end
diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb
index 48131cd..91190aa 100644
--- a/app/controllers/my_profile/memberships_controller.rb
+++ b/app/controllers/my_profile/memberships_controller.rb
@@ -40,7 +40,7 @@ class MembershipsController < MyProfileController
end
def suggest
- @suggestions = profile.suggested_communities.paginate(:per_page => 8, :page => params[:npage])
+ @suggestions = profile.profile_suggestions.of_community.includes(:suggestion).limit(per_page)
end
def remove_suggestion
@@ -53,4 +53,10 @@ class MembershipsController < MyProfileController
end
end
+ protected
+
+ def per_page
+ 10
+ end
+
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a955003..dbe33a4 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1419,4 +1419,9 @@ module ApplicationHelper
text_field_tag name, default, options.merge({:id => 'search-input', 'data-asset' => asset})
end
+ def profile_suggestion_categories(suggestion)
+ suggestion.categories.map do |cat|
+ content_tag(:p, content_tag(:span, "#{suggestion.category_label(cat[0])}: #{cat[1]}", :class => suggestion.category_icon(cat[0])))
+ end.join
+ end
end
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 1a79945..93efd25 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -54,7 +54,7 @@ class UserMailer < ActionMailer::Base
content_type: 'text/html',
to: user.email,
from: "#{user.environment.name} <#{user.environment.contact_email}>",
- subject: _("[%s] We have suggestions for your network") % user.environment.name
+ subject: _("[%s] What about grow up your network?") % user.environment.name
)
end
diff --git a/app/models/person.rb b/app/models/person.rb
index 11465cf..82cc97d 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -66,7 +66,7 @@ class Person < Profile
has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
- has_many :profile_suggestions, :foreign_key => :person_id, :dependent => :destroy
+ has_many :profile_suggestions, :foreign_key => :person_id, :order => 'id ASC', :dependent => :destroy
has_many :suggested_people, :through => :profile_suggestions, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true]
has_many :suggested_communities, :through => :profile_suggestions, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true]
@@ -498,6 +498,11 @@ class Person < Profile
person.notifier.reschedule_next_notification_mail
end
+ def remove_suggestion(profile)
+ suggestion = profile_suggestions.find_by_suggestion_id profile.id
+ suggestion.disable if suggestion
+ end
+
protected
def followed_by?(profile)
diff --git a/app/models/profile_suggestion.rb b/app/models/profile_suggestion.rb
index ebeedca..7ddedf6 100644
--- a/app/models/profile_suggestion.rb
+++ b/app/models/profile_suggestion.rb
@@ -2,7 +2,7 @@ class ProfileSuggestion < ActiveRecord::Base
belongs_to :person
belongs_to :suggestion, :class_name => 'Profile', :foreign_key => :suggestion_id
- attr_accessible :person, :suggestion, :suggestion_type, :categories, :similarity, :enabled
+ attr_accessible :person, :suggestion, :suggestion_type, :categories, :enabled
before_create do |profile_suggestion|
profile_suggestion.suggestion_type = self.suggestion.class.to_s
@@ -18,11 +18,15 @@ class ProfileSuggestion < ActiveRecord::Base
end
validates_uniqueness_of :suggestion_id, :scope => [ :person_id ]
+ scope :of_person, :conditions => { :suggestion_type => 'Person' }
+ scope :of_community, :conditions => { :suggestion_type => 'Community' }
+ scope :enabled, :conditions => { :enabled => true }
+ # {:category_type => ['category-icon', 'category-label']}
CATEGORIES = {
- :common_friends => _('Friends in common'),
- :common_communities => _('Communities in common'),
- :common_tags => _('Tags in common')
+ :common_friends => ['menu-people', _('Friends in common')],
+ :common_communities => ['menu-community',_('Communities in common')],
+ :common_tags => ['edit', _('Tags in common')]
}
CATEGORIES.keys.each do |category|
@@ -30,6 +34,14 @@ class ProfileSuggestion < ActiveRecord::Base
attr_accessible category.to_sym
end
+ def category_icon(category)
+ 'icon-' + ProfileSuggestion::CATEGORIES[category][0]
+ end
+
+ def category_label(category)
+ ProfileSuggestion::CATEGORIES[category][1]
+ end
+
RULES = %w[
friends_of_friends
people_with_common_communities
diff --git a/app/views/friends/_profile_list.html.erb b/app/views/friends/_profile_list.html.erb
new file mode 100644
index 0000000..acfd6b2
--- /dev/null
+++ b/app/views/friends/_profile_list.html.erb
@@ -0,0 +1,16 @@
+
+ <% profiles.each do |profile| %>
+ -
+ <%= link_to_profile profile_image(profile) + '
' + profile.short_name,
+ profile.identifier, :class => 'profile-link' %>
+
+ <%= button_without_text :remove, content_tag('span',_('remove')),
+ { :action => 'remove', :id => profile.id },
+ :title => _('remove') %>
+ <%= button_without_text 'menu-mail', content_tag('span',_('contact')),
+ profile.url.merge(:controller => 'contact', :action => 'new', :profile => profile.identifier),
+ :title => _('contact') %>
+
+
+ <% end %>
+
diff --git a/app/views/friends/index.html.erb b/app/views/friends/index.html.erb
index e9daf0b..2611eae 100644
--- a/app/views/friends/index.html.erb
+++ b/app/views/friends/index.html.erb
@@ -20,22 +20,23 @@
<% end %>
<% end %>
- <%= render :partial => 'shared/profile_list', :locals => { :profiles => @friends, :collection => :friends } %>
-
+ <%= render :partial => 'profile_list', :locals => { :profiles => @friends } %>
+
+ <%= pagination_links @friends, :param_name => 'npage' %>
<% end %>
<% unless @suggestions.empty? %>
- <%= _("Friends suggestions") %>
+
+
<%= _("Friends suggestions") %>
- <%= render :partial => 'shared/profile_list', :locals => { :profiles => @suggestions, :collection => :friends_suggestions } %>
+ <%= render :partial => 'shared/profile_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions } %>
- <% button_bar do %>
- <%= link_to _('See more suggestions...'), :action => 'suggest' %>
- <% end %>
+ <% button_bar do %>
+ <%= link_to _('See more suggestions...'), :action => 'suggest' %>
+ <% end %>
+
<% end %>
diff --git a/app/views/friends/suggest.html.erb b/app/views/friends/suggest.html.erb
index 4368dab..a5e3839 100644
--- a/app/views/friends/suggest.html.erb
+++ b/app/views/friends/suggest.html.erb
@@ -13,9 +13,7 @@
<% else %>
- <%= render :partial => 'shared/profile_list', :locals => { :profiles => @suggestions, :collection => :friends_suggestions } %>
-
- <%= pagination_links @suggestions, :param_name => 'npage' %>
+ <%= render :partial => 'shared/profile_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions } %>
<% end %>
diff --git a/app/views/memberships/suggest.html.erb b/app/views/memberships/suggest.html.erb
index 0f6856a..7317d0f 100644
--- a/app/views/memberships/suggest.html.erb
+++ b/app/views/memberships/suggest.html.erb
@@ -13,9 +13,7 @@
<% else %>
- <%= render :partial => 'shared/profile_list', :locals => { :profiles => @suggestions, :collection => :communities_suggestions } %>
+ <%= render :partial => 'shared/profile_list', :locals => { :suggestions => @suggestions, :collection => :communities_suggestions } %>
<% end %>
-
- <%= pagination_links @suggestions, :param_name => 'npage' %>
diff --git a/app/views/shared/_profile_list.html.erb b/app/views/shared/_profile_list.html.erb
index 8549600..a0342c5 100644
--- a/app/views/shared/_profile_list.html.erb
+++ b/app/views/shared/_profile_list.html.erb
@@ -1,38 +1,38 @@
- <% profiles.each do |profile| %>
+ <% suggestions.each do |s| %>
-
- <%= link_to_profile profile_image(profile) + '
' + profile.short_name,
- profile.identifier, :class => 'profile-link' %>
-
- <% if collection == :friends %>
- <%= button_without_text :remove, content_tag('span',_('remove')),
- { :action => 'remove', :id => profile.id },
- :title => _('remove') %>
- <%= button_without_text 'menu-mail', content_tag('span',_('contact')),
- profile.url.merge(:controller => 'contact', :action => 'new', :profile => profile.identifier),
- :title => _('contact') %>
- <% elsif collection == :friends_suggestions %>
- <%= button_without_text :add, content_tag('span',_('add')),
- profile.add_url,
- :class => 'add-friend',
- :title => _('Add friend') %>
- <%= button_without_text :remove, content_tag('span',_('remove')),
- { :action => 'remove_suggestion', :id => profile.identifier },
- :title => _('Remove suggestion'),
- :method => 'post',
- :confirm => _('Are you sure you want to remove this suggestion?') %>
- <% elsif collection == :communities_suggestions %>
- <%= button_without_text :add, content_tag('span',_('join')),
- profile.join_url,
- :class => 'join-community',
- :title => _("Join %s") % profile.name %>
+ <%= link_to_profile profile_image(s.suggestion, :minor) + '
' + s.suggestion.short_name,
+ s.suggestion.identifier, :class => 'profile-link' %>
+ <%= button_without_text :help, content_tag('span',_('info about suggestion')),
+ { :action => '#' },
+ :class => 'explain-suggestion',
+ :title => _('Why this suggestion?') %>
+
+
+ <% if collection == :friends_suggestions %>
+ <%= button_without_text :add, content_tag('span',_('add')),
+ s.suggestion.add_url,
+ :class => 'add-friend',
+ :title => _('Add friend') %>
<%= button_without_text :remove, content_tag('span',_('remove')),
- { :action => 'remove_suggestion', :id => profile.identifier },
+ { :action => 'remove_suggestion', :id => s.suggestion.identifier },
:title => _('Remove suggestion'),
:method => 'post',
:confirm => _('Are you sure you want to remove this suggestion?') %>
- <% end %>
-
+ <% elsif collection == :communities_suggestions %>
+ <%= button_without_text :add, content_tag('span',_('join')),
+ s.suggestion.join_url,
+ :class => 'join-community',
+ :title => _("Join %s") % s.suggestion.name %>
+ <%= button_without_text :remove, content_tag('span',_('remove')),
+ { :action => 'remove_suggestion', :id => s.suggestion.identifier },
+ :title => _('Remove suggestion'),
+ :method => 'post',
+ :confirm => _('Are you sure you want to remove this suggestion?') %>
+ <% end %>
+
<% end %>
diff --git a/app/views/user_mailer/profiles_suggestions_email.html.erb b/app/views/user_mailer/profiles_suggestions_email.html.erb
index ea77df2..7c8486c 100644
--- a/app/views/user_mailer/profiles_suggestions_email.html.erb
+++ b/app/views/user_mailer/profiles_suggestions_email.html.erb
@@ -1,6 +1,7 @@
<%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
-<%= _('We want to give you some suggestions to grow up your network. Check it out!') %>
+<%= _('We want to give you some suggestions to grow up your network.') %>
+
<%= _('Check it out!') %>
<% unless @people_suggestions.empty? %>
<%= _('Friends suggestions:') %>
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index aa7070c..ece5c08 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -1053,6 +1053,14 @@ function showHideTermsOfUse() {
}
}
+jQuery('.profiles-suggestions .explain-suggestion').live('click', function() {
+ var clicked = jQuery(this);
+ jQuery('.profiles-suggestions .extra_info').hide();
+ clicked.toggleClass('active');
+ clicked.next('.extra_info').toggle();
+ return false;
+});
+
jQuery(document).ready(function(){
showHideTermsOfUse();
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index ac0bba9..6c9aae2 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -2131,7 +2131,8 @@ a.button.disabled, input.disabled {
#content .common-profile-list-block .sex-male span, #content .common-profile-list-block .sex-female span, #content .common-profile-list-block .sex-undef span {
display: none;
}
-.common-profile-list-block .extra_info {
+.common-profile-list-block .extra_info,
+.profile-list .extra_info {
font-size: 9px;
opacity: 0.5;
filter: alpha(opacity=50);
@@ -3955,16 +3956,24 @@ h1#agenda-title {
.controller-friends .profile-list li,
.profiles-suggestions .profile-list li {
float: left;
- width: 90px;
+ margin: 5px;
height: 90px;
- max-width: 80px;
max-height: 80px;
- margin: 5px;
padding: 5px;
border: 2px solid transparent;
list-style: none;
position: relative;
}
+.controller-favorite_enterprises .profile-list li,
+.controller-friends .profile-list li {
+ width: 90px;
+ max-width: 80px;
+}
+.profiles-suggestions .profile-list li {
+ width: 76px;
+ max-width: 76px;
+}
+
.controller-favorite_enterprises .profile-list li:hover,
.controller-friends .profile-list li:hover,
.profiles-suggestions .profile-list li:hover {
@@ -4000,12 +4009,22 @@ h1#agenda-title {
.profiles-suggestions .profile-list {
position: relative;
}
+.profiles-suggestions .profile-list .explain-suggestion {
+ position: absolute;
+ top: 7px;
+ left: -5px;
+ z-index: 10;
+}
+#content .profiles-suggestions .profile-list .explain-suggestion.active {
+ border-bottom-color: transparent;
+}
+
.controller-favorite_enterprises .profile-list .controll,
.controller-friends .profile-list .controll,
.profiles-suggestions .profile-list .controll {
position: absolute;
top: 7px;
- right: -10px;
+ right: -5px;
}
.controller-favorite_enterprises .profile-list .controll a,
.controller-friends .profile-list .controll a,
@@ -4024,6 +4043,31 @@ h1#agenda-title {
clear: both;
padding-top: 20px;
}
+
+.profiles-suggestions .profile-list .extra_info {
+ background: url("/images/down-arrow.png") no-repeat scroll center top #eee;
+ border: 1px solid #ccc;
+ left: -66px;
+ min-width: 135px;
+ padding: 5px;
+ position: absolute;
+ top: 29px;
+ opacity: 0.9;
+ z-index: 5;
+}
+
+.profiles-suggestions .profile-list .extra_info p {
+ margin: 0px;
+}
+
+.profiles-suggestions .profile-list .extra_info span {
+ background-position: 4px 50%;
+ background-repeat: no-repeat;
+ display: block;
+ line-height: 20px;
+ padding: 0 0 0 25px;
+}
+
/* ==> public/stylesheets/controller_friends.css <== */
.controller-friends #remove_friend .friend_picture,
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index f117bab..ade740f 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1544,6 +1544,28 @@ class PersonTest < ActiveSupport::TestCase
assert_equal [suggested_community], person.suggested_communities
end
+ should 'disable friend suggestion' do
+ person = create_user('person').person
+ suggested_person = fast_create(Person)
+
+ suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person)
+
+ assert_difference 'person.suggested_people.count', -1 do
+ person.remove_suggestion(suggested_person)
+ end
+ end
+
+ should 'disable community suggestion' do
+ person = create_user('person').person
+ suggested_community = fast_create(Community)
+
+ suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community)
+
+ assert_difference 'person.suggested_communities.count', -1 do
+ person.remove_suggestion(suggested_community)
+ end
+ end
+
should 'return url to people suggestions for a person' do
environment = create_environment('mycolivre.net')
profile = build(Person, :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
--
libgit2 0.21.2