From 21034c5628d980bd18c6ef3f3ef898969745c390 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 29 Oct 2018 04:03:52 +0000 Subject: [PATCH] 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 --- app/models/issue_query.rb | 10 +++++++++ app/models/project.rb | 6 +++++ app/models/query.rb | 8 +++++++ app/views/repositories/diff.html.erb | 27 +++++++++++++++++++++++ test/functional/issues_controller_test.rb | 19 ++++++++++++++++ test/helpers/queries_helper_test.rb | 2 +- test/unit/query_test.rb | 23 +++++++++++++++++++ 7 files changed, 94 insertions(+), 1 deletion(-) diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 38946f75a..9b9b87cc9 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 038398e04..a8dd05816 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/query.rb b/app/models/query.rb index 8bb391e66..1e8080b86 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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 diff --git a/app/views/repositories/diff.html.erb b/app/views/repositories/diff.html.erb index 889a65f7e..12875f21e 100644 --- a/app/views/repositories/diff.html.erb +++ b/app/views/repositories/diff.html.erb @@ -1,3 +1,30 @@ +
+ « + <% 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 %> +
<% if @changeset && @changeset_to.nil? %> <%= render :partial => 'changeset' %> <% else %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 17af8981c..62d96bd10 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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, diff --git a/test/helpers/queries_helper_test.rb b/test/helpers/queries_helper_test.rb index 402d67ab8..8cce2625b 100644 --- a/test/helpers/queries_helper_test.rb +++ b/test/helpers/queries_helper_test.rb @@ -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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 8c530caeb..1a66bc4db 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -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 -- 2.39.5