Code improvement in ProjectsController#activity (Nicolas Chuche)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@650 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-08-16 21:23:54 +00:00
parent 446889b3f0
commit a7033c8bac
1 changed files with 3 additions and 12 deletions

View File

@ -472,15 +472,13 @@ class ProjectsController < ApplicationController
@date_from = Date.civil(@year, @month, 1) @date_from = Date.civil(@year, @month, 1)
@date_to = @date_from >> 1 @date_to = @date_from >> 1
@events_by_day = {} @events_by_day = Hash.new { |h,k| h[k] = [] }
unless params[:show_issues] == "0" unless params[:show_issues] == "0"
@project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i| @project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_issues = 1 @show_issues = 1
@ -488,7 +486,6 @@ class ProjectsController < ApplicationController
unless params[:show_news] == "0" unless params[:show_news] == "0"
@project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i| @project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_news = 1 @show_news = 1
@ -497,9 +494,8 @@ class ProjectsController < ApplicationController
unless params[:show_files] == "0" unless params[:show_files] == "0"
Attachment.find(:all, :select => "#{Attachment.table_name}.*", Attachment.find(:all, :select => "#{Attachment.table_name}.*",
:joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id",
:conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to], :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
:include => :author ).each { |i| :include => :author ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_files = 1 @show_files = 1
@ -507,14 +503,12 @@ class ProjectsController < ApplicationController
unless params[:show_documents] == "0" unless params[:show_documents] == "0"
@project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i| @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
Attachment.find(:all, :select => "attachments.*", Attachment.find(:all, :select => "attachments.*",
:joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id",
:conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to], :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
:include => :author ).each { |i| :include => :author ).each { |i|
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_documents = 1 @show_documents = 1
@ -533,8 +527,6 @@ class ProjectsController < ApplicationController
def i.created_on def i.created_on
self.updated_on self.updated_on
end end
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_wiki_edits = 1 @show_wiki_edits = 1
@ -545,7 +537,6 @@ class ProjectsController < ApplicationController
def i.created_on def i.created_on
self.committed_on self.committed_on
end end
@events_by_day[i.created_on.to_date] ||= []
@events_by_day[i.created_on.to_date] << i @events_by_day[i.created_on.to_date] << i
} }
@show_changesets = 1 @show_changesets = 1