convert more to acts_as_journalized

This commit is contained in:
Tim Felgentreff 2010-07-15 21:10:05 +02:00
parent 2d282f8deb
commit 2ec2405b32
6 changed files with 29 additions and 30 deletions

View File

@ -25,22 +25,26 @@ class Attachment < ActiveRecord::Base
validates_length_of :filename, :maximum => 255 validates_length_of :filename, :maximum => 255
validates_length_of :disk_filename, :maximum => 255 validates_length_of :disk_filename, :maximum => 255
acts_as_event :title => :filename, acts_as_journalized :event_title => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}} :event_url => (Proc.new do |o|
{ :controller => 'attachments', :action => 'download',
:id => o.id, :filename => o.filename }
end),
:activity_type => 'files',
:activity_permission => :view_files,
:activity_find_options => {:select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
" AND #{Attachment.table_name}.container_type = 'Version' " +
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Version.table_name}.project_id " +
" OR ( #{Attachment.table_name}.container_id = #{Project.table_name}.id " +
" AND #{Attachment.table_name}.container_type = 'Project' ) " }
acts_as_activity_provider :type => 'files', acts_as_activity :type => 'documents',
:permission => :view_files, :permission => :view_documents,
:author_key => :author_id, :find_options => {:select => "#{Attachment.table_name}.*",
:find_options => {:select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Document.table_name} ON (#{Document.table_name}.id = #{Attachment.table_name}.container_id" +
:joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + " AND #{Attachment.table_name}.container_type='Document') " +
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )"} "LEFT JOIN #{Project.table_name} ON (#{Project.table_name}.id = #{Document.table_name}.project_id)" }
acts_as_activity_provider :type => 'documents',
:permission => :view_documents,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
cattr_accessor :storage_path cattr_accessor :storage_path
@@storage_path = "#{RAILS_ROOT}/files" @@storage_path = "#{RAILS_ROOT}/files"

View File

@ -28,7 +28,7 @@ class Changeset < ActiveRecord::Base
:event_datetime => :committed_on, :event_datetime => :committed_on,
:event_url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}}, :event_url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}},
:activity_timestamp => "#{table_name}.committed_on", :activity_timestamp => "#{table_name}.committed_on",
:activity_author_key => :user_id :activity_find_options => {:include => [:user, {:repository => :project}]}
acts_as_searchable :columns => 'comments', acts_as_searchable :columns => 'comments',
:include => {:repository => :project}, :include => {:repository => :project},

View File

@ -37,9 +37,7 @@ class Issue < ActiveRecord::Base
acts_as_watchable acts_as_watchable
acts_as_journalized :event_title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"}, acts_as_journalized :event_title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
:event_type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }, :event_type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
:activity_find_options => {:include => [:project, :author, :tracker]},
:activity_author_key => :author_id
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
:include => [:project, :journals], :include => [:project, :journals],

View File

@ -29,8 +29,7 @@ class TimeEntry < ActiveRecord::Base
acts_as_journalized :event_title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, acts_as_journalized :event_title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
:event_url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project, :issue_id => o.issue}}, :event_url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project, :issue_id => o.issue}},
:event_author => :user, :event_author => :user,
:event_description => :comments, :event_description => :comments
:activity_timestamp => "#{table_name}.created_on"
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
validates_numericality_of :hours, :allow_nil => true, :message => :invalid validates_numericality_of :hours, :allow_nil => true, :message => :invalid

View File

@ -1,11 +1,9 @@
class Meeting < ActiveRecord::Base class Meeting < ActiveRecord::Base
belongs_to :project belongs_to :project
acts_as_event :title => Proc.new {|o| "#{o.scheduled_on} Meeting"}, acts_as_journalized :event_title => Proc.new {|o| "#{o.scheduled_on} Meeting"},
:datetime => :scheduled_on, :event_datetime => :scheduled_on,
:author => nil, :event_author => nil,
:url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o.id}} :event_url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o.id}}
:activity_timestamp => 'scheduled_on'
acts_as_activity_provider :timestamp => 'scheduled_on',
:find_options => { :include => :project }
end end

View File

@ -181,7 +181,7 @@ Redmine::MenuManager.map :project_menu do |menu|
end end
Redmine::Activity.map do |activity| Redmine::Activity.map do |activity|
activity.register :issues, :class_name => %w(Issue Journal) activity.register :issues, :class_name => 'Issue'
activity.register :changesets activity.register :changesets
activity.register :news activity.register :news
activity.register :documents, :class_name => %w(Document Attachment) activity.register :documents, :class_name => %w(Document Attachment)