mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-24 08:07:14 +00:00
Show statuses of project trackers only (#5385).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@16575 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
335a16e4fd
commit
ba37a2c476
@ -82,7 +82,7 @@ class IssueQuery < Query
|
||||
|
||||
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 }
|
||||
|
||||
@ -324,6 +324,7 @@ class Project < ActiveRecord::Base
|
||||
@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
|
||||
@ -452,6 +453,17 @@ class Project < ActiveRecord::Base
|
||||
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
|
||||
|
||||
@ -551,6 +551,16 @@ class Query < ActiveRecord::Base
|
||||
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
|
||||
|
||||
@ -483,6 +483,21 @@ class ProjectTest < ActiveSupport::TestCase
|
||||
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])
|
||||
|
||||
@ -2093,4 +2093,30 @@ class QueryTest < ActiveSupport::TestCase
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user