Commit 727baee629102e3a91144f309371d1c445c6bb88

Authored by Daniela Feitosa
1 parent cf24fb79

Added visibility to action trackers

app/controllers/public/profile_controller.rb
... ... @@ -224,7 +224,11 @@ class ProfileController < PublicController
224 224 begin
225 225 raise if !can_edit_profile
226 226 activity = ActionTracker::Record.find(params[:activity_id])
227   - activity.destroy
  227 + if params[:only_hide]
  228 + activity.update_attribute(:visible, false)
  229 + else
  230 + activity.destroy
  231 + end
228 232 render :text => _('Activity successfully removed.')
229 233 rescue
230 234 render :text => _('You could not remove this activity')
... ...
app/models/comment.rb
... ... @@ -80,7 +80,10 @@ class Comment < ActiveRecord::Base
80 80 Comment::Notifier.deliver_mail(comment)
81 81 end
82 82  
83   - comment.article.activity.increment!(:comments_count) if comment.source.kind_of?(Article) && comment.article.activity
  83 + if comment.source.kind_of?(Article) && comment.article.activity
  84 + comment.article.activity.increment!(:comments_count)
  85 + comment.article.activity.update_attribute(:visible, true)
  86 + end
84 87 end
85 88  
86 89 after_destroy do |comment|
... ...
app/views/profile/_create_article.rhtml
... ... @@ -11,6 +11,6 @@
11 11 <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p>
12 12 <div class='profile-wall-actions'>
13 13 <%= link_to _('Comment'), "#reply_content_#{activity.id}" %>
14   - <%= link_to_remote(content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id}, :confirm => _('Are you sure?'), :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %>
  14 + <%= link_to_remote(content_tag(:span, _('Remove')), :url =>{:action => 'remove_activity', :activity_id => activity.id, :only_hide => true}, :confirm => _('Are you sure?'), :update => "profile-activity-item-#{activity.id}") if logged_in? && current_person == @profile %>
15 15 </div>
16 16 </div>
... ...
app/views/profile/_profile_activities_scraps.rhtml
1 1 <% activities.each do |a| %>
2 2 <% activity = a.klass.constantize.find(a.id) %>
3 3 <% if activity.kind_of?(ActionTracker::Record) %>
4   - <%= render :partial => 'profile_activity', :locals => {:activity => activity} %>
  4 + <%= render :partial => 'profile_activity', :locals => {:activity => activity} if activity.visible? %>
5 5 <% else %>
6 6 <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %>
7 7 <% end %>
... ...
db/schema.rb
... ... @@ -30,6 +30,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120307200651) do
30 30 t.datetime "created_at"
31 31 t.datetime "updated_at"
32 32 t.integer "comments_count", :default => 0
  33 + t.boolean "visible", :default => true
33 34 end
34 35  
35 36 add_index "action_tracker", ["target_id", "target_type"], :name => "index_action_tracker_on_dispatcher_id_and_dispatcher_type"
... ...