]> source.dussan.org Git - redmine.git/commitdiff
Filter issues after project status (#20081).
authorGo MAEDA <maeda@farend.jp>
Mon, 29 Oct 2018 04:03:52 +0000 (04:03 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 29 Oct 2018 04:03:52 +0000 (04:03 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@17607 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb
app/models/project.rb
app/models/query.rb
app/views/repositories/diff.html.erb
test/functional/issues_controller_test.rb
test/helpers/queries_helper_test.rb
test/unit/query_test.rb

index 38946f75a81ab420c1dfc70c2ba6d6916cecc8db..9b9b87cc9f7479d6305164bc23a0f6673da05614 100644 (file)
@@ -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
index 038398e04bdc7f8bfe3d8a81d79381a295d0f416..a8dd058163928482843d04c4054ffaf7f7718b8d 100644 (file)
@@ -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
 
index 8bb391e66c80e61d1724d403775bd2191cbdf639..1e8080b86337cbf95af41fdb34898d4bd05d1e22 100644 (file)
@@ -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
index 889a65f7e95c9705773da2ae7b233e6c0a1d939f..12875f21ee96caaf1eaf126a44488138bc862f23 100644 (file)
@@ -1,3 +1,30 @@
+<div class="contextual">
+  &#171;
+  <% 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 -%>
+  &#187;&nbsp;
+
+  <%= 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 %>
index 17af8981c86a4511831b827c294c581837aa4b8c..62d96bd10b1df2e114a9696c155ac650f1d7a714 100644 (file)
@@ -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,
index 402d67ab82ccf67d6a371e5f4ce3fe0739c58ac3..8cce2625b7ded07ae7e143c6b4cda81b9fd9b419 100644 (file)
@@ -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
index 8c530caeb6c89393735cbce8c89454ff399bea10..1a66bc4db454dc338970a23e65191b31d9ac8f45 100644 (file)
@@ -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