def initialize_available_filters
add_available_filter "status_id",
- :type => :list_status, :values => lambda { IssueStatus.sorted.collect{|s| [s.name, s.id.to_s] } }
+ :type => :list_status, :values => lambda { issue_statuses }
add_available_filter("project_id",
:type => :list, :values => lambda { project_values }
@shared_versions = nil
@rolled_up_versions = nil
@rolled_up_trackers = nil
+ @rolled_up_statuses = nil
@rolled_up_custom_fields = nil
@all_issue_custom_fields = nil
@all_time_entry_custom_fields = nil
sorted
end
+ def rolled_up_statuses
+ issue_status_ids = WorkflowTransition.
+ where(:tracker_id => trackers).
+ distinct.
+ pluck(:old_status_id, :new_status_id).
+ flatten.
+ uniq
+
+ IssueStatus.where(:id => issue_status_ids).sorted
+ end
+
# Closes open and locked project versions that are completed
def close_completed_versions
Version.transaction do
Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
end
+ # Returns a scope of issue statuses that are available as columns for filters
+ def issue_statuses
+ if project
+ statuses = project.rolled_up_statuses
+ else
+ statuses = IssueStatus.all.sorted
+ end
+ statuses.collect{|s| [s.name, s.id.to_s]}
+ end
+
# Returns a scope of issue custom fields that are available as columns or filters
def issue_custom_fields
if project
assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
end
+ def test_rolled_up_statuses
+ project = Project.find(1)
+
+ WorkflowTransition.delete_all
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+ assert_kind_of IssueStatus, project.rolled_up_statuses.first
+ assert_equal IssueStatus.find(1), project.rolled_up_statuses.first
+
+ assert_equal [1, 2, 3, 4], project.rolled_up_statuses.collect(&:id)
+ end
+
test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do
parent = Project.generate!
parent.trackers = Tracker.find([1, 2])
issues = find_issues_with_query(query)
assert_equal [1, 2, 5, 11, 12, 13], issues.map(&:id).sort
end
+
+ def test_issue_statuses_should_return_only_statuses_used_by_that_project
+ query = IssueQuery.new(:name => '_', :project => Project.find(1))
+ query.filters = {'status_id' => {:operator => '=', :values => []}}
+
+ WorkflowTransition.delete_all
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+ assert_equal ['1','2','3','4'], query.available_filters['status_id'][:values].map(&:second)
+ end
+
+ def test_issue_statuses_without_project_should_return_all_statuses
+ query = IssueQuery.new(:name => '_')
+ query.filters = {'status_id' => {:operator => '=', :values => []}}
+
+ WorkflowTransition.delete_all
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
+ WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 3)
+
+ assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
+ end
end