mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 09:46:02 +01:00
Filter issues after project status (#20081).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@17607 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -165,6 +165,12 @@ class IssueQuery < Query
|
||||
: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
|
||||
|
||||
@@ -577,6 +583,10 @@ class IssueQuery < Query
|
||||
"(#{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
|
||||
|
||||
@@ -24,6 +24,12 @@ class Project < ActiveRecord::Base
|
||||
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
|
||||
|
||||
|
||||
@@ -579,6 +579,14 @@ class Query < ActiveRecord::Base
|
||||
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
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
<div class="contextual">
|
||||
«
|
||||
<% unless @changeset.previous.nil? -%>
|
||||
<%= link_to_revision(@changeset.previous, @repository,
|
||||
:text => l(:label_previous), :accesskey => accesskey(:previous)) %>
|
||||
<% else -%>
|
||||
<%= l(:label_previous) %>
|
||||
<% end -%>
|
||||
|
|
||||
<% unless @changeset.next.nil? -%>
|
||||
<%= link_to_revision(@changeset.next, @repository,
|
||||
:text => l(:label_next), :accesskey => accesskey(:next)) %>
|
||||
<% else -%>
|
||||
<%= l(:label_next) %>
|
||||
<% end -%>
|
||||
»
|
||||
|
||||
<%= form_tag({:controller => 'repositories',
|
||||
:action => 'revision',
|
||||
:id => @project,
|
||||
:repository_id => @repository.identifier_param,
|
||||
:rev => nil},
|
||||
:method => :get) do %>
|
||||
<%= text_field_tag 'rev', @rev, :size => 8 %>
|
||||
<%= submit_tag 'OK', :name => nil %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% if @changeset && @changeset_to.nil? %>
|
||||
<%= render :partial => 'changeset' %>
|
||||
<% else %>
|
||||
|
||||
@@ -264,6 +264,25 @@ class IssuesControllerTest < Redmine::ControllerTest
|
||||
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,
|
||||
|
||||
@@ -75,7 +75,7 @@ class QueriesHelperTest < Redmine::HelperTest
|
||||
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
|
||||
|
||||
@@ -2199,4 +2199,27 @@ class QueryTest < ActiveSupport::TestCase
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user