Commit 4596ef428b44dd63c720a6d38c3f9f2417545653

Authored by Dylan Guedes
1 parent 6e677d68

Adds Follower concern and follow methods

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
app/models/concerns/follower.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +module Follower
  2 + extend ActiveSupport::Concern
  3 +
  4 + def follow(profile, circles)
  5 + circles = [circles] unless circles.is_a?(Array)
  6 + circles.each do |new_circle|
  7 + ProfileFollower.create(profile: profile, circle: new_circle)
  8 + end
  9 + end
  10 +
  11 + def follows?(profile)
  12 + return false if profile.nil?
  13 + profile.followed_by?(self)
  14 + end
  15 +
  16 +end
... ...
app/models/external_person.rb
... ... @@ -3,6 +3,7 @@ class ExternalPerson &lt; ActiveRecord::Base
3 3  
4 4 include Human
5 5 include ProfileEntity
  6 + include Follower
6 7  
7 8 has_many :circles, as: :person
8 9 validates_uniqueness_of :identifier, scope: :source
... ... @@ -196,7 +197,7 @@ class ExternalPerson &lt; ActiveRecord::Base
196 197 build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join:
197 198 nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '',
198 199 friends_cache_key: '', manage_friends_cache_key: '',
199   - relationships_cache_key: '', is_member_of?: false, follows?: false,
  200 + relationships_cache_key: '', is_member_of?: false,
200 201 each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false,
201 202 leave: nil, last_notification: nil, notification_time: 0, notifier: nil,
202 203 remove_suggestion: nil, allow_invitation_from?: false
... ... @@ -255,7 +256,7 @@ class ExternalPerson &lt; ActiveRecord::Base
255 256 may_display_field_to?: true, may_display_location_to?: true, public_fields:
256 257 {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
257 258 true, remove_from_suggestion_list: nil, layout_template: 'default',
258   - is_admin?: false, add_friend: false, follows?: false, is_a_friend?: false,
  259 + is_admin?: false, add_friend: false, is_a_friend?: false,
259 260 already_request_friendship?: false
260 261 }
261 262  
... ... @@ -278,13 +279,6 @@ class ExternalPerson &lt; ActiveRecord::Base
278 279 super
279 280 end
280 281  
281   - def follow(profile, circles)
282   - circles = [circles] unless circles.is_a?(Array)
283   - circles.each do |new_circle|
284   - ProfileFollower.create(profile: profile, circle: new_circle)
285   - end
286   - end
287   -
288 282 private
289 283  
290 284 def generate_derivated_methods(methods)
... ...
app/models/person.rb
... ... @@ -2,6 +2,7 @@
2 2 class Person < Profile
3 3  
4 4 include Human
  5 + include Follower
5 6  
6 7 attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website, :following_articles
7 8  
... ... @@ -181,13 +182,6 @@ class Person &lt; Profile
181 182 end
182 183 end
183 184  
184   - def follow(profile, circles)
185   - circles = [circles] unless circles.is_a?(Array)
186   - circles.each do |new_circle|
187   - ProfileFollower.create(profile: profile, circle: new_circle)
188   - end
189   - end
190   -
191 185 def update_profile_circles(profile, new_circles)
192 186 profile_circles = ProfileFollower.with_profile(profile).with_follower(self).map(&:circle)
193 187 circles_to_add = new_circles - profile_circles
... ... @@ -492,11 +486,6 @@ class Person &lt; Profile
492 486 profile.members.include?(self)
493 487 end
494 488  
495   - def follows?(profile)
496   - return false if profile.nil?
497   - profile.followed_by?(self)
498   - end
499   -
500 489 def each_friend(offset=0)
501 490 while friend = self.friends.order(:id).offset(offset).first
502 491 yield friend
... ...
app/views/blocks/profile_info_actions/_common.html.erb
1 1 <li><%= report_abuse(profile, :button) %></li>
2 2 <% if logged_in? && (user != profile) && profile.allow_followers? %>
3 3 <li>
4   - <% follow = profile.followed_by user %>
  4 + <% follow = user.follows?(profile) %>
5 5 <%= button(:unfollow, content_tag('span', _('Unfollow')), {:profile => profile.identifier, :controller => 'profile', :action => 'unfollow'}, :method => :post, :id => 'action-unfollow', :title => _("Unfollow"), :style => follow ? "" : "display: none;") %>
6 6 <%= button(:ok, content_tag('span', _('Follow')), {:profile => profile.identifier, :controller => 'profile', :action => 'find_profile_circles'}, :id => 'action-follow', :title => _("Follow"), :style => follow ? "display: none;" : "") %>
7 7 <div id="circles-container" style="display: none;">
... ...
app/views/profile/_profile_comment_form.html.erb
... ... @@ -10,7 +10,7 @@
10 10 :rows => 1,
11 11 :class => 'submit-with-keypress',
12 12 :title => _('Leave your comment'),
13   - :onfocus => ("if(this.value==this.title){this.value='';this.style.color='#000'};this.style.backgroundImage='url(" + profile_icon(current_person, :icon, false) + ")'" if logged_in?),
  13 + :onfocus => ("if(this.value==this.title){this.value='';this.style.color='#000'};this.style.backgroundImage='url(" + profile_icon(current_person, :icon, false).to_s + ")'" if logged_in?),
14 14 :onblur => ("if(this.value==''){this.value=this.title;this.style.color='#ccc'};this.style.backgroundImage='none'" if logged_in?),
15 15 :value => _('Leave your comment'),
16 16 :style => 'color: #ccc' %>
... ...