Feature #20081 » 0001-Filter-issues-after-project-status.patch
| app/models/issue_query.rb | ||
|---|---|---|
|
:values => lambda { subproject_values }
|
||
|
end
|
||
|
add_available_filter("project.status",
|
||
|
:type => :list,
|
||
|
:name => l(:label_attribute_of_project, :name => l(:field_status)),
|
||
|
:values => lambda { project_statuses_values }
|
||
|
) if project.nil? || !project.leaf?
|
||
|
add_custom_fields_filters(issue_custom_fields)
|
||
|
add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
|
||
| ... | ... | |
|
"(#{sql})"
|
||
|
end
|
||
|
def sql_for_project_status_field(field, operator, value, options={})
|
||
|
sql_for_field(field, operator, value, Project.table_name, "status")
|
||
|
end
|
||
|
def find_assigned_to_id_filter_values(values)
|
||
|
Principal.visible.where(:id => values).map {|p| [p.name, p.id.to_s]}
|
||
|
end
|
||
| app/models/project.rb | ||
|---|---|---|
|
STATUS_CLOSED = 5
|
||
|
STATUS_ARCHIVED = 9
|
||
|
LABEL_BY_STATUS = {
|
||
|
1 => l(:project_status_active),
|
||
|
5 => l(:project_status_closed),
|
||
|
9 => l(:project_status_archived),
|
||
|
}
|
||
|
# Maximum length for project identifiers
|
||
|
IDENTIFIER_MAX_LENGTH = 100
|
||
| app/models/query.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
# Returns a scope of project statuses that are available as columns or filters
|
||
|
def project_statuses_values
|
||
|
project_statuses = Project::LABEL_BY_STATUS
|
||
|
# Remove archived status from filters
|
||
|
project_statuses.delete(9)
|
||
|
project_statuses.stringify_keys.invert.to_a
|
||
|
end
|
||
|
# Adds available filters
|
||
|
def initialize_available_filters
|
||
|
# implemented by sub-classes
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
assert_equal [3, 5], issues_in_list.map(&:project_id).uniq.sort
|
||
|
end
|
||
|
def test_index_with_project_status_filter
|
||
|
project = Project.find(2)
|
||
|
project.close
|
||
|
project.save
|
||
|
get :index, :params => {
|
||
|
:set_filter => 1,
|
||
|
:f => ['project.status'],
|
||
|
:op => {'project.status' => '='},
|
||
|
:v => {'project.status' => ['1']}
|
||
|
}
|
||
|
assert_response :success
|
||
|
issues = issues_in_list.map(&:id).uniq.sort
|
||
|
assert_include 1, issues
|
||
|
assert_not_include 4, issues
|
||
|
end
|
||
|
def test_index_with_query
|
||
|
get :index, :params => {
|
||
|
:project_id => 1,
|
||
| test/helpers/queries_helper_test.rb | ||
|---|---|---|
|
with_locale 'en' do
|
||
|
options = filters_options_for_select(IssueQuery.new)
|
||
|
assert_select_in options, 'optgroup[label=?]', 'Project', 1
|
||
|
assert_select_in options, 'optgroup[label=?] > option', 'Project', 2
|
||
|
assert_select_in options, 'optgroup[label=?] > option', 'Project', 3
|
||
|
assert_select_in options, 'optgroup > option[value=?]', "project.cf_#{cf1.id}", :text => "Project's Foo"
|
||
|
end
|
||
|
end
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
|
||
|
end
|
||
|
def test_project_status_filter_should_be_available_in_global_queries
|
||
|
query = IssueQuery.new(:project => nil, :name => '_')
|
||
|
assert query.available_filters.has_key?('project.status')
|
||
|
end
|
||
|
def test_project_status_filter_should_be_available_when_project_has_subprojects
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
assert query.available_filters.has_key?('project.status')
|
||
|
end
|
||
|
def test_project_status_filter_should_not_be_available_when_project_is_leaf
|
||
|
query = IssueQuery.new(:project => Project.find(2), :name => '_')
|
||
|
assert !query.available_filters.has_key?('project.status')
|
||
|
end
|
||
|
def test_project_statuses_values_should_return_only_active_and_closed_statuses
|
||
|
query = IssueQuery.new(:project => nil, :name => '_')
|
||
|
project_status_filter = query.available_filters['project.status']
|
||
|
assert_not_nil project_status_filter
|
||
|
assert_equal [["active", "1"], ["closed", "5"]], project_status_filter[:values]
|
||
|
end
|
||
|
end
|
||