[Git][noosfero/noosfero][master] 2 commits: favorite_enterprise: track actions to wall
Bráulio Bhavamitra
gitlab at gitlab.com
Tue Aug 11 22:12:11 BRT 2015
Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero
Commits:
db1e4abf by Braulio Bhavamitra at 2015-08-11T22:10:17Z
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
- - - - -
b439f1f7 by Bráulio Bhavamitra at 2015-08-12T01:11:57Z
Merge branch 'favorite-enterprises-actions' into 'master'
favorite_enterprise: track actions to wall
See merge request !498
- - - - -
9 changed files:
- app/helpers/action_tracker_helper.rb
- app/models/enterprise.rb
- app/models/favorite_enterprise_person.rb
- app/models/person.rb
- app/models/profile.rb
- + app/views/profile/_favorite_enterprise.html.erb
- config/initializers/action_tracker.rb
- + db/migrate/20150310132902_add_id_to_favorite_enterprises_people.rb
- db/schema.rb
Changes:
=====================================
app/helpers/action_tracker_helper.rb
=====================================
--- a/app/helpers/action_tracker_helper.rb
+++ b/app/helpers/action_tracker_helper.rb
@@ -85,4 +85,10 @@ module ActionTrackerHelper
}
end
+ def favorite_enterprise_description ta
+ _('favorited enterprise %{title}') % {
+ title: link_to(truncate(ta.get_enterprise_name), ta.get_enterprise_url),
+ }
+ end
+
end
=====================================
app/models/enterprise.rb
=====================================
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -23,7 +23,7 @@ class Enterprise < Organization
has_many :production_costs, :as => :owner
has_many :favorite_enterprise_people
- has_many :fans, through: :favorite_enterprise_people, source: :person
+ has_many :fans, source: :person, through: :favorite_enterprise_people
def product_categories
ProductCategory.by_enterprise(self)
=====================================
app/models/favorite_enterprise_person.rb
=====================================
--- a/app/models/favorite_enterprise_person.rb
+++ b/app/models/favorite_enterprise_person.rb
@@ -1,8 +1,23 @@
class FavoriteEnterprisePerson < ActiveRecord::Base
- self.table_name = :favorite_enteprises_people
+ attr_accessible :person, :enterprise
+
+ track_actions :favorite_enterprise, :after_create, keep_params: [:enterprise_name, :enterprise_url], if: proc{ |f| f.is_trackable? }
belongs_to :enterprise
belongs_to :person
+ protected
+
+ def is_trackable?
+ self.enterprise.public?
+ end
+
+ def enterprise_name
+ self.enterprise.short_name(nil)
+ end
+ def enterprise_url
+ self.enterprise.url
+ end
+
end
=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -81,6 +81,9 @@ roles] }
has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy
+ has_many :favorite_enterprise_people
+ has_many :favorite_enterprises, source: :enterprise, through: :favorite_enterprise_people
+
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'
@@ -315,8 +318,6 @@ roles] }
]
end
- has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people'
-
def email_domain
user && user.email_domain || environment.default_hostname(true)
end
=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -744,7 +744,11 @@ private :generate_url, :url_options
include ActionView::Helpers::TextHelper
def short_name(chars = 40)
if self[:nickname].blank?
- truncate self.name, :length => chars, :omission => '...'
+ if chars
+ truncate self.name, length: chars, omission: '...'
+ else
+ self.name
+ end
else
self[:nickname]
end
=====================================
app/views/profile/_favorite_enterprise.html.erb
=====================================
--- /dev/null
+++ b/app/views/profile/_favorite_enterprise.html.erb
@@ -0,0 +1,15 @@
+<div class='profile-activity-image'>
+ <%= link_to(profile_image(activity.user, :minor), activity.user.url) %>
+</div>
+<div class='profile-activity-description'>
+ <p class='profile-activity-text'>
+ <%= link_to activity.user.short_name(nil), activity.user.url %> <%= describe activity %>
+ </p>
+ <p class='profile-activity-time'><%= time_ago_as_sentence activity.created_at %></p>
+
+ <div class='profile-wall-actions'>
+ <%= 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 %>
+ </div>
+</div>
+
+<div style="clear: both"></div>
=====================================
config/initializers/action_tracker.rb
=====================================
--- a/config/initializers/action_tracker.rb
+++ b/config/initializers/action_tracker.rb
@@ -40,6 +40,9 @@ ActionTrackerConfig.verbs = {
remove_product: {
},
+ favorite_enterprise: {
+ },
+
}
ActionTrackerConfig.current_user = proc do
=====================================
db/migrate/20150310132902_add_id_to_favorite_enterprises_people.rb
=====================================
--- /dev/null
+++ b/db/migrate/20150310132902_add_id_to_favorite_enterprises_people.rb
@@ -0,0 +1,26 @@
+class AddIdToFavoriteEnterprisesPeople < ActiveRecord::Migration
+ def up
+ rename_table :favorite_enteprises_people, :favorite_enterprise_people
+
+ change_table :favorite_enterprise_people do |t|
+ t.timestamps
+ end
+ add_column :favorite_enterprise_people, :id, :primary_key
+
+ add_index :favorite_enterprise_people, [:person_id, :enterprise_id]
+ add_index :favorite_enterprise_people, :person_id
+ add_index :favorite_enterprise_people, :enterprise_id
+ end
+
+ def down
+ rename_table :favorite_enterprise_people, :favorite_enteprises_people
+
+ remove_column :favorite_enteprises_people, :id
+ remove_column :favorite_enteprises_people, :created_at
+ remove_column :favorite_enteprises_people, :updated_at
+
+ remove_index :favorite_enteprises_people, [:person_id, :enterprise_id]
+ remove_index :favorite_enteprises_people, :person_id
+ remove_index :favorite_enteprises_people, :enterprise_id
+ end
+end
=====================================
db/schema.rb
=====================================
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -351,11 +351,17 @@ ActiveRecord::Schema.define(:version => 20150712130827) do
add_index "external_feeds", ["enabled"], :name => "index_external_feeds_on_enabled"
add_index "external_feeds", ["fetched_at"], :name => "index_external_feeds_on_fetched_at"
- create_table "favorite_enteprises_people", :id => false, :force => true do |t|
- t.integer "person_id"
- t.integer "enterprise_id"
+ create_table "favorite_enterprise_people", :force => true do |t|
+ t.integer "person_id"
+ t.integer "enterprise_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
+ add_index "favorite_enterprise_people", ["enterprise_id"], :name => "index_favorite_enterprise_people_on_enterprise_id"
+ add_index "favorite_enterprise_people", ["person_id", "enterprise_id"], :name => "index_favorite_enterprise_people_on_person_id_and_enterprise_id"
+ add_index "favorite_enterprise_people", ["person_id"], :name => "index_favorite_enterprise_people_on_person_id"
+
create_table "friendships", :force => true do |t|
t.integer "person_id"
t.integer "friend_id"
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/ab8d14e6e0d82d9523a95fc6e654ebd2337b6477...b439f1f7e5989e0b970a0eeb5dcaf43d0fcf8a22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150812/0280457c/attachment-0001.html>
More information about the Noosfero-dev
mailing list