]> source.dussan.org Git - redmine.git/commitdiff
On the calendar, the gantt and in the Tracker filter on the issue list, only active...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 16 Jan 2008 21:27:48 +0000 (21:27 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 16 Jan 2008 21:27:48 +0000 (21:27 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1071 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/models/project.rb
app/models/query.rb
app/models/tracker.rb
test/fixtures/projects_trackers.yml
test/fixtures/trackers.yml
test/functional/projects_controller_test.rb
test/unit/project_test.rb

index 2ae742dfa46b87233d228db0619cbbc8a15c79cd..6add8585ba6b479c548bb01af6c67f7dac6955a2 100644 (file)
@@ -418,7 +418,7 @@ class ProjectsController < ApplicationController
   end
   
   def calendar
-    @trackers = Tracker.find(:all, :order => 'position')
+    @trackers = @project.rolled_up_trackers
     retrieve_selected_tracker_ids(@trackers)
     
     if params[:year] and params[:year].to_i > 1900
@@ -445,7 +445,7 @@ class ProjectsController < ApplicationController
   end  
 
   def gantt
-    @trackers = Tracker.find(:all, :order => 'position')
+    @trackers = @project.rolled_up_trackers
     retrieve_selected_tracker_ids(@trackers)
     
     if params[:year] and params[:year].to_i >0
index 60a7a84a46b04123c1d530fa6b8fc2bfde6b7ff3..0e7f8284cfde26be64a0a325f8d501ea27d578c5 100644 (file)
@@ -146,6 +146,15 @@ class Project < ActiveRecord::Base
     children.select {|child| child.active?}
   end
   
+  # Returns an array of the trackers used by the project and its sub projects
+  def rolled_up_trackers
+    @rolled_up_trackers ||=
+      Tracker.find(:all, :include => :projects,
+                         :select => "DISTINCT #{Tracker.table_name}.*",
+                         :conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id],
+                         :order => "#{Tracker.table_name}.position")
+  end
+  
   # Deletes all project's members
   def delete_all_members
     Member.delete_all(['project_id = ?', id])
index 09dc0d5818300c35ae2960a39fd92439292a43b2..3a1b5a19eeb870d8a57393012e180939984e4d7f 100644 (file)
@@ -132,8 +132,11 @@ class Query < ActiveRecord::Base
   
   def available_filters
     return @available_filters if @available_filters
+    
+    trackers = project.nil? ? Tracker.find(:all, :order => 'position') : project.rolled_up_trackers
+    
     @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },       
-                           "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },                                                                                                                
+                           "tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },                                                                                                                
                            "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
                            "subject" => { :type => :text, :order => 8 },  
                            "created_on" => { :type => :date_past, :order => 9 },                        
index 8d864774725f988585ed9f9d3ec1c211d92289f2..07253a2279e4eb7c52e9bf5ce1b2c84435574389 100644 (file)
@@ -19,6 +19,7 @@ class Tracker < ActiveRecord::Base
   before_destroy :check_integrity  
   has_many :issues
   has_many :workflows, :dependent => :delete_all
+  has_and_belongs_to_many :projects
   has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
   acts_as_list
 
index cfca5b22822837aa0776d31b7cc4f59250267469..8eb7d85abd4c9b62e482e0014b2161a23bd877e8 100644 (file)
@@ -14,9 +14,6 @@ projects_trackers_002:
 projects_trackers_014: 
   project_id: 5
   tracker_id: 2
-projects_trackers_003: 
-  project_id: 1
-  tracker_id: 3
 projects_trackers_015: 
   project_id: 5
   tracker_id: 3
@@ -29,9 +26,6 @@ projects_trackers_005:
 projects_trackers_006: 
   project_id: 2
   tracker_id: 3
-projects_trackers_007: 
-  project_id: 3
-  tracker_id: 1
 projects_trackers_008: 
   project_id: 3
   tracker_id: 2
index d4ea34ac8bfa4dc4242cda04fb27d20a208c7d53..2643e8d1a9acb50e2e3fd8a26eeb002dfe4b8b85 100644 (file)
@@ -3,11 +3,14 @@ trackers_001:
   name: Bug\r
   id: 1\r
   is_in_chlog: true\r
+  position: 1\r
 trackers_002: \r
   name: Feature request\r
   id: 2\r
   is_in_chlog: true\r
+  position: 2\r
 trackers_003: \r
   name: Support request\r
   id: 3\r
   is_in_chlog: false\r
+  position: 3\r
index 896f590740d8f0494d03395db1f21b51da9e36c3..f19aa774867ef974e2c5b1d44b4cd1b2f36b6d48 100644 (file)
@@ -112,10 +112,10 @@ class ProjectsControllerTest < Test::Unit::TestCase
   
   def test_move_issues_to_another_tracker
     @request.session[:user_id] = 1
-    post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3
+    post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2
     assert_redirected_to 'projects/ecookbook/issues'
-    assert_equal 3, Issue.find(1).tracker_id
-    assert_equal 3, Issue.find(2).tracker_id
+    assert_equal 2, Issue.find(1).tracker_id
+    assert_equal 2, Issue.find(2).tracker_id
   end
   \r
   def test_list_files\r
index 62ba2b02d21770cec00737be3b26e89a89d8b139..b05b7b09f05c455b5a9153641c5cfc32c921e08b 100644 (file)
@@ -18,7 +18,7 @@
 require File.dirname(__FILE__) + '/../test_helper'\r
 \r
 class ProjectTest < Test::Unit::TestCase\r
-  fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles\r
+  fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers\r
 \r
   def setup\r
     @ecookbook = Project.find(1)\r
@@ -112,6 +112,20 @@ class ProjectTest < Test::Unit::TestCase
     sub.parent = Project.find(2)\r
     assert !sub.save\r
   end\r
+  \r
+  def test_rolled_up_trackers\r
+    parent = Project.find(1)\r
+    child = parent.children.find(3)\r
+  \r
+    assert_equal [1, 2], parent.tracker_ids\r
+    assert_equal [2, 3], child.tracker_ids\r
+    \r
+    assert_kind_of Tracker, parent.rolled_up_trackers.first\r
+    assert_equal Tracker.find(1), parent.rolled_up_trackers.first\r
+    \r
+    assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)\r
+    assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)\r
+  end\r
 \r
   def test_issues_status_changes\r
     journals = @ecookbook.issues_status_changes 3.days.ago.to_date, Date.today\r