]> source.dussan.org Git - redmine.git/commitdiff
If 'Display subprojects issues on main projects' is set to false:
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 27 Mar 2008 18:22:12 +0000 (18:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 27 Mar 2008 18:22:12 +0000 (18:22 +0000)
* do not include subprojects in the issue count of the parent project overview (#939)
* do not include subproject timelogs on the parent project (#848)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1298 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/controllers/timelog_controller.rb
app/models/project.rb

index dbd36f6e41a2c227f356f4376879e56137739893..199b2f0c52ef3e2dde30fbbd67a7a91aecbbc162 100644 (file)
@@ -90,18 +90,20 @@ class ProjectsController < ApplicationController
     @subprojects = @project.active_children
     @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
     @trackers = @project.rolled_up_trackers
+    
+    cond = @project.project_condition(Setting.display_subprojects_issues?)
     Issue.visible_by(User.current) do
       @open_issues_by_tracker = Issue.count(:group => :tracker,
                                             :include => [:project, :status, :tracker],
-                                            :conditions => ["(#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?) and #{IssueStatus.table_name}.is_closed=?", @project.id, @project.id, false])
+                                            :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
       @total_issues_by_tracker = Issue.count(:group => :tracker,
                                             :include => [:project, :status, :tracker],
-                                            :conditions => ["#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?", @project.id, @project.id])
+                                            :conditions => cond)
     end
     TimeEntry.visible_by(User.current) do
       @total_hours = TimeEntry.sum(:hours, 
                                    :include => :project,
-                                   :conditions => ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id]).to_f
+                                   :conditions => cond).to_f
     end
     @key = User.current.rss_key
   end
index d767037eb31d1e93b932ad663191c88d8cb3e7cc..8cfe225d1c9b26b8d0fb773d542455b19388a497 100644 (file)
@@ -72,7 +72,7 @@ class TimelogController < ApplicationController
       sql << " FROM #{TimeEntry.table_name}"
       sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
       sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
-      sql << " WHERE (#{Project.table_name}.id = %s OR #{Project.table_name}.parent_id = %s)" % [@project.id, @project.id]
+      sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
       sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
       sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
       sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
@@ -159,7 +159,7 @@ class TimelogController < ApplicationController
     @from, @to = @to, @from if @from && @to && @from > @to
     
     cond = ARCondition.new
-    cond << (@issue.nil? ? ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id] :
+    cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) :
                            ["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
     
     if @from
index ad2f1fb814be2bf1880901a7f6f3a00051ebfa98..a223b35f0c6b85ccf4df9c6a3c7b30ca9514a6e9 100644 (file)
@@ -124,6 +124,12 @@ class Project < ActiveRecord::Base
     statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))"
   end
   
+  def project_condition(with_subprojects)
+    cond = "#{Project.table_name}.id = #{id}"
+    cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects
+    cond
+  end
+  
   def self.find(*args)
     if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
       project = find_by_identifier(*args)