diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index da07102..10c92bd 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -6,6 +6,7 @@ class ProfileController < PublicController before_filter :login_required, :only => [:add, :join, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity, :send_mail] helper TagsHelper + helper ActionTrackerHelper protect 'send_mail_to_members', :profile, :only => [:send_mail] diff --git a/app/helpers/action_tracker_helper.rb b/app/helpers/action_tracker_helper.rb new file mode 100644 index 0000000..b1b05af --- /dev/null +++ b/app/helpers/action_tracker_helper.rb @@ -0,0 +1,70 @@ +module ActionTrackerHelper + + def create_article_description ta + _('published an article: %{title}') % { title: link_to(truncate(ta.get_name), ta.get_url) } + end + + def new_friendship_description ta + n_('has made 1 new friend:
%{name}', 'has made %{num} new friends:
%{name}', ta.get_friend_name.size) % { + num: ta.get_friend_name.size, + name: ta.collect_group_with_index(:friend_name) do |n,i| + link_to image_tag(ta.get_friend_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), + ta.get_friend_url[i], title: n + end.join + } + end + + def join_community_description ta + n_('has joined 1 community:
%{name}', 'has joined %{num} communities:
%{name}', ta.get_resource_name.size) % { + num: ta.get_resource_name.size, + name: ta.collect_group_with_index(:resource_name) do |n,i| + link_to image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), + ta.get_resource_url[i], title: n + end.join + } + end + + def add_member_in_community_description ta + _('has joined the community.') + end + + def upload_image_description ta + total = ta.get_view_url.size + (n_('uploaded 1 image', 'uploaded %d images', total) % total) + + tag(:br) + + ta.collect_group_with_index(:thumbnail_path) do |t,i| + if total == 1 + link_to image_tag(t), ta.get_view_url[i], class: 'upimg' + else + pos = total-i; + morethen2 = pos>2 ? 'morethen2' : '' + morethen5 = pos>5 ? 'morethen5' : '' + t = t.gsub(/(.*)(display)(.*)/, '\\1thumb\\3') + + link_to ' '.html_safe, ta.get_view_url[i], + style: "background-image:url(#{t})", + class: "upimg pos#{pos} #{morethen2} #{morethen5}" + end + end.reverse.join + + if total <= 5 then ''.html_safe else content_tag :span, '…'.html_safe, + class: 'more', onclick: "this.parentNode.className+=' show-all'" end + + tag(:br, style: 'clear: both') + end + + def reply_scrap_description ta + _('sent a message to %{receiver}:
"%{message}"') % { + receiver: link_to(ta.get_receiver_name, ta.get_receiver_url), + message: auto_link_urls(ta.get_content) + } + end + + alias :leave_scrap_description :reply_scrap_description + alias :reply_scrap_on_self_description :reply_scrap_description + + def leave_scrap_to_self_description ta + _('wrote:
"%{text}"') % { + text: auto_link_urls(ta.get_content) + } + end + +end diff --git a/app/models/person_notifier.rb b/app/models/person_notifier.rb index 9cb0d53..fc0ba01 100644 --- a/app/models/person_notifier.rb +++ b/app/models/person_notifier.rb @@ -76,7 +76,8 @@ class PersonNotifier class Mailer < ActionMailer::Base - add_template_helper(ApplicationHelper) + helper ApplicationHelper + helper ActionTrackerHelper def session {:theme => nil} diff --git a/app/views/person_notifier/mailer/_default_activity.html.erb b/app/views/person_notifier/mailer/_default_activity.html.erb index c1bd5c1..05d3528 100644 --- a/app/views/person_notifier/mailer/_default_activity.html.erb +++ b/app/views/person_notifier/mailer/_default_activity.html.erb @@ -4,7 +4,10 @@

- <%= link_to activity.user.name, activity.user.url %> <%= describe activity %> + + <%= link_to activity.user.name, activity.user.url %> + <%= describe activity %> + <%= time_ago_in_words(activity.created_at) %>

diff --git a/config/initializers/action_tracker.rb b/config/initializers/action_tracker.rb index c35809d..7ef594a 100644 --- a/config/initializers/action_tracker.rb +++ b/config/initializers/action_tracker.rb @@ -2,64 +2,33 @@ require 'noosfero/i18n' # ActionTracker plugin stuff -@reply_scrap_description = proc { _('sent a message to %{receiver}:
"%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } - ActionTrackerConfig.verbs = { - :create_article => { - :description => proc { _('published an article: %{title}') % { :title => '{{link_to(truncate(ta.get_name), ta.get_url)}}' } } + create_article: { }, - :new_friendship => { - :description => proc { n_('has made 1 new friend:
%{name}', 'has made %{num} new friends:
%{name}', get_friend_name.size) % { :num => get_friend_name.size, :name => '{{ta.collect_group_with_index(:friend_name){ |n,i| link_to(image_tag(ta.get_friend_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), ta.get_friend_url[i], :title => n)}.join}}' } }, - :type => :groupable + new_friendship: { + type: :groupable }, - :join_community => { - :description => proc { n_('has joined 1 community:
%{name}', 'has joined %{num} communities:
%{name}', get_resource_name.size) % { :num => get_resource_name.size, :name => '{{ta.collect_group_with_index(:resource_name){ |n,i| link_to(image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), ta.get_resource_url[i], :title => n)}.join}}' } }, - :type => :groupable + join_community: { + type: :groupable }, - :add_member_in_community => { - :description => proc { _('has joined the community.') }, + add_member_in_community: { }, - :upload_image => { - :description => proc do - total = get_view_url.size - n_('uploaded 1 image', 'uploaded %d images', total) % total + - '
{{'+ - 'ta.collect_group_with_index(:thumbnail_path) { |t,i|' + - " if ( #{total} == 1 );" + - ' link_to( image_tag(t), ta.get_view_url[i], :class => \'upimg\' );' + - ' else;' + - " pos = #{total}-i;" + - ' morethen2 = pos>2 ? \'morethen2\' : \'\';' + - ' morethen5 = pos>5 ? \'morethen5\' : \'\';' + - ' t = t.gsub(/(.*)(display)(.*)/, \'\\1thumb\\3\');' + - ' link_to( \' \', ta.get_view_url[i],' + - ' :style => "background-image:url(#{t})",' + - ' :class => "upimg pos#{pos} #{morethen2} #{morethen5}" );' + - ' end' + - '}.reverse.join}}' + - ( total > 5 ? - '' + - '…' : '' ) + - '
' - end, - :type => :groupable + upload_image: { + type: :groupable }, - :leave_scrap => { - :description => @reply_scrap_description + leave_scrap: { }, - :leave_scrap_to_self => { - :description => proc { _('wrote:
"%{text}"') % { :text => "{{auto_link_urls(ta.get_content)}}" } } + leave_scrap_to_self: { }, - :reply_scrap_on_self => { - :description => @reply_scrap_description + reply_scrap_on_self: { }, } diff --git a/test/unit/person_notifier_test.rb b/test/unit/person_notifier_test.rb index 59c93b4..4de6806 100644 --- a/test/unit/person_notifier_test.rb +++ b/test/unit/person_notifier_test.rb @@ -162,23 +162,31 @@ class PersonNotifierTest < ActiveSupport::TestCase ActionTrackerConfig.verb_names.each do |verb| should "render notification for verb #{verb}" do - action = mock() - action.stubs(:verb).returns(verb) - action.stubs(:user).returns(@member) - action.stubs(:created_at).returns(DateTime.now) - action.stubs(:target).returns(fast_create(Forum)) - action.stubs(:comments_count).returns(0) - action.stubs(:comments).returns([]) - action.stubs(:params).returns({'name' => 'home', 'url' => '/', 'lead' => ''}) - action.stubs(:get_url).returns('') - - notifications = [] - notifications.stubs(:find).returns([action]) - Person.any_instance.stubs(:tracked_notifications).returns(notifications) - - notify - sent = ActionMailer::Base.deliveries.last - assert_no_match /cannot render notification for #{verb}/, sent.body.to_s + @member.tracked_notifications = [] + + a = @member.tracked_notifications.build + a.verb = verb + a.user = @member + a.created_at = @member.notifier.notify_from + 1.day + a.target = fast_create(Forum) + a.comments_count = 0 + a.params = { + 'name' => 'home', 'url' => '/', 'lead' => '', + 'receiver_url' => '/', 'content' => 'nothing', + 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'], + 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'], + 'view_url'=> ['/'], 'thumbnail_path' => ['1'], + } + a.get_url = '' + a.save! + n = @member.action_tracker_notifications.build + n.action_tracker = a + n.profile = @member + n.save! + + assert_nothing_raised do + notify + end end end diff --git a/vendor/plugins/action_tracker/lib/action_tracker.rb b/vendor/plugins/action_tracker/lib/action_tracker.rb index 24ce96a..5d4ff67 100644 --- a/vendor/plugins/action_tracker/lib/action_tracker.rb +++ b/vendor/plugins/action_tracker/lib/action_tracker.rb @@ -8,21 +8,21 @@ module ActionTracker base.send :user_stamp, ActionTracker::Record base.send :extend, ClassMethods end - + module ClassMethods def track_actions_after(verb, options = {}, &block) track_actions_by_time(verb, :after, options, &block) end - + def track_actions_before(verb, options = {}, &block) track_actions_by_time(verb, :before, options, &block) end - + def track_actions(verb, options = {}, &block) track_actions_by_time(verb, ActionTrackerConfig.default_filter_time, options, &block) end - + def track_actions_by_time(verb, time, options = {}, &block) keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all send("#{time}_filter", options) do |x| @@ -32,7 +32,7 @@ module ActionTracker send :include, InstanceMethods end end - + module InstanceMethods def save_action_for_verb(verb, keep_params = :all) if keep_params.is_a? Array @@ -62,7 +62,7 @@ module ActionTracker def self.included(base) base.send :extend, ClassMethods end - + module ClassMethods def track_actions(verb, callback, options = {}, &block) keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all @@ -78,11 +78,11 @@ module ActionTracker send :include, InstanceMethods end end - + module InstanceMethods def time_spent_doing(verb, conditions = {}) time = 0 - tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| + tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| time += t.updated_at - t.created_at end time.to_f @@ -124,13 +124,7 @@ module ActionTracker module ViewHelper def describe(ta) - "".tap do |result| - if ta.is_a?(ActionTracker::Record) - result << ta.description.gsub(/\{\{(.*?)\}\}/) { eval $1 } - else - result << "" - end - end + send "#{ta.verb}_description", ta if ta.is_a? ActionTracker::Record end end -- libgit2 0.21.2