Commit db1e4abf17405f1cbfdce30e89498e542f5c0e86

Authored by Braulio Bhavamitra
1 parent ab8d14e6

favorite_enterprise: track actions to wall

The id was necessary for the has_many :through. Also add indexes and
timestamps and fix typo on table name
app/helpers/action_tracker_helper.rb
@@ -85,4 +85,10 @@ module ActionTrackerHelper @@ -85,4 +85,10 @@ module ActionTrackerHelper
85 } 85 }
86 end 86 end
87 87
  88 + def favorite_enterprise_description ta
  89 + _('favorited enterprise %{title}') % {
  90 + title: link_to(truncate(ta.get_enterprise_name), ta.get_enterprise_url),
  91 + }
  92 + end
  93 +
88 end 94 end
app/models/enterprise.rb
@@ -23,7 +23,7 @@ class Enterprise < Organization @@ -23,7 +23,7 @@ class Enterprise < Organization
23 has_many :production_costs, :as => :owner 23 has_many :production_costs, :as => :owner
24 24
25 has_many :favorite_enterprise_people 25 has_many :favorite_enterprise_people
26 - has_many :fans, through: :favorite_enterprise_people, source: :person 26 + has_many :fans, source: :person, through: :favorite_enterprise_people
27 27
28 def product_categories 28 def product_categories
29 ProductCategory.by_enterprise(self) 29 ProductCategory.by_enterprise(self)
app/models/favorite_enterprise_person.rb
1 class FavoriteEnterprisePerson < ActiveRecord::Base 1 class FavoriteEnterprisePerson < ActiveRecord::Base
2 2
3 - self.table_name = :favorite_enteprises_people 3 + attr_accessible :person, :enterprise
  4 +
  5 + track_actions :favorite_enterprise, :after_create, keep_params: [:enterprise_name, :enterprise_url], if: proc{ |f| f.is_trackable? }
4 6
5 belongs_to :enterprise 7 belongs_to :enterprise
6 belongs_to :person 8 belongs_to :person
7 9
  10 + protected
  11 +
  12 + def is_trackable?
  13 + self.enterprise.public?
  14 + end
  15 +
  16 + def enterprise_name
  17 + self.enterprise.short_name(nil)
  18 + end
  19 + def enterprise_url
  20 + self.enterprise.url
  21 + end
  22 +
8 end 23 end
app/models/person.rb
@@ -81,6 +81,9 @@ roles] } @@ -81,6 +81,9 @@ roles] }
81 81
82 has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy 82 has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy
83 83
  84 + has_many :favorite_enterprise_people
  85 + has_many :favorite_enterprises, source: :enterprise, through: :favorite_enterprise_people
  86 +
84 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' 87 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
85 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' 88 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
86 89
@@ -315,8 +318,6 @@ roles] } @@ -315,8 +318,6 @@ roles] }
315 ] 318 ]
316 end 319 end
317 320
318 - has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people'  
319 -  
320 def email_domain 321 def email_domain
321 user && user.email_domain || environment.default_hostname(true) 322 user && user.email_domain || environment.default_hostname(true)
322 end 323 end
app/models/profile.rb
@@ -744,7 +744,11 @@ private :generate_url, :url_options @@ -744,7 +744,11 @@ private :generate_url, :url_options
744 include ActionView::Helpers::TextHelper 744 include ActionView::Helpers::TextHelper
745 def short_name(chars = 40) 745 def short_name(chars = 40)
746 if self[:nickname].blank? 746 if self[:nickname].blank?
747 - truncate self.name, :length => chars, :omission => '...' 747 + if chars
  748 + truncate self.name, length: chars, omission: '...'
  749 + else
  750 + self.name
  751 + end
748 else 752 else
749 self[:nickname] 753 self[:nickname]
750 end 754 end
app/views/profile/_favorite_enterprise.html.erb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +<div class='profile-activity-image'>
  2 + <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
  3 +</div>
  4 +<div class='profile-activity-description'>
  5 + <p class='profile-activity-text'>
  6 + <%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>
  7 + </p>
  8 + <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p>
  9 +
  10 + <div class='profile-wall-actions'>
  11 + <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %>
  12 + </div>
  13 +</div>
  14 +
  15 +<div style="clear: both"></div>
config/initializers/action_tracker.rb
@@ -40,6 +40,9 @@ ActionTrackerConfig.verbs = { @@ -40,6 +40,9 @@ ActionTrackerConfig.verbs = {
40 remove_product: { 40 remove_product: {
41 }, 41 },
42 42
  43 + favorite_enterprise: {
  44 + },
  45 +
43 } 46 }
44 47
45 ActionTrackerConfig.current_user = proc do 48 ActionTrackerConfig.current_user = proc do
db/migrate/20150310132902_add_id_to_favorite_enterprises_people.rb 0 → 100644
@@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
  1 +class AddIdToFavoriteEnterprisesPeople < ActiveRecord::Migration
  2 + def up
  3 + rename_table :favorite_enteprises_people, :favorite_enterprise_people
  4 +
  5 + change_table :favorite_enterprise_people do |t|
  6 + t.timestamps
  7 + end
  8 + add_column :favorite_enterprise_people, :id, :primary_key
  9 +
  10 + add_index :favorite_enterprise_people, [:person_id, :enterprise_id]
  11 + add_index :favorite_enterprise_people, :person_id
  12 + add_index :favorite_enterprise_people, :enterprise_id
  13 + end
  14 +
  15 + def down
  16 + rename_table :favorite_enterprise_people, :favorite_enteprises_people
  17 +
  18 + remove_column :favorite_enteprises_people, :id
  19 + remove_column :favorite_enteprises_people, :created_at
  20 + remove_column :favorite_enteprises_people, :updated_at
  21 +
  22 + remove_index :favorite_enteprises_people, [:person_id, :enterprise_id]
  23 + remove_index :favorite_enteprises_people, :person_id
  24 + remove_index :favorite_enteprises_people, :enterprise_id
  25 + end
  26 +end
@@ -351,11 +351,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150712130827) do @@ -351,11 +351,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150712130827) do
351 add_index "external_feeds", ["enabled"], :name => "index_external_feeds_on_enabled" 351 add_index "external_feeds", ["enabled"], :name => "index_external_feeds_on_enabled"
352 add_index "external_feeds", ["fetched_at"], :name => "index_external_feeds_on_fetched_at" 352 add_index "external_feeds", ["fetched_at"], :name => "index_external_feeds_on_fetched_at"
353 353
354 - create_table "favorite_enteprises_people", :id => false, :force => true do |t|  
355 - t.integer "person_id"  
356 - t.integer "enterprise_id" 354 + create_table "favorite_enterprise_people", :force => true do |t|
  355 + t.integer "person_id"
  356 + t.integer "enterprise_id"
  357 + t.datetime "created_at"
  358 + t.datetime "updated_at"
357 end 359 end
358 360
  361 + add_index "favorite_enterprise_people", ["enterprise_id"], :name => "index_favorite_enterprise_people_on_enterprise_id"
  362 + add_index "favorite_enterprise_people", ["person_id", "enterprise_id"], :name => "index_favorite_enterprise_people_on_person_id_and_enterprise_id"
  363 + add_index "favorite_enterprise_people", ["person_id"], :name => "index_favorite_enterprise_people_on_person_id"
  364 +
359 create_table "friendships", :force => true do |t| 365 create_table "friendships", :force => true do |t|
360 t.integer "person_id" 366 t.integer "person_id"
361 t.integer "friend_id" 367 t.integer "friend_id"