]> source.dussan.org Git - redmine.git/commitdiff
Adds issue category filter to spent time queries (#28391).
authorGo MAEDA <maeda@farend.jp>
Sun, 1 Apr 2018 00:29:22 +0000 (00:29 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 1 Apr 2018 00:29:22 +0000 (00:29 +0000)
Patch by Marius BALTEANU.

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

app/models/time_entry_query.rb
test/functional/timelog_controller_test.rb
test/unit/time_entry_query_test.rb

index 706c6b234760cb2edcd7021554e21ce8ea5a33ba..ea32cb9396652ba373b6fb8edfc08b36eb23195d 100644 (file)
@@ -65,6 +65,10 @@ class TimeEntryQuery < Query
       :type => :list,
       :name => l("label_attribute_of_issue", :name => l(:field_fixed_version)),
       :values => lambda { fixed_version_values })
+    add_available_filter "issue.category_id",
+      :type => :list_optional,
+      :name => l("label_attribute_of_issue", :name => l(:field_category)),
+      :values => lambda { project.issue_categories.collect{|s| [s.name, s.id.to_s] } } if project
 
     add_available_filter("user_id",
       :type => :list_optional, :values => lambda { author_values }
@@ -197,6 +201,10 @@ class TimeEntryQuery < Query
     sql_for_field("status_id", operator, value, Issue.table_name, "status_id")
   end
 
+  def sql_for_issue_category_id_field(field, operator, value)
+    sql_for_field("category_id", operator, value, Issue.table_name, "category_id")
+  end
+
   # Accepts :from/:to params as shortcut filters
   def build_from_params(params, defaults={})
     super
index 1dfe229879c87d05c70b4ce871cdb9be4e74673b..02338e20d04e86c85b74198124888b8d69bee3ff 100644 (file)
@@ -1025,6 +1025,17 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_equal Tracker.where(:id => [1, 2, 3]).sorted.pluck(:name), values
   end
 
+  def test_index_with_issue_category_filter
+    get :index, :params => {
+      :project_id => 'ecookbook',
+      :f => ['issue.category_id'],
+      :op => {'issue.category_id' => '='},
+      :v => {'issue.category_id' => ['1']}
+    }
+    assert_response :success
+    assert_equal ['1', '2'], css_select('input[name="ids[]"]').map {|e| e.attr('value')}
+  end
+
   def test_index_with_filter_on_issue_custom_field
     issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
     entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
index e00e3384505ed6833427f8ae1e37be253c6993f6..637f884f4b4fb5835793e8b10e0eb70ce9135ded 100644 (file)
@@ -102,4 +102,9 @@ class TimeEntryQueryTest < ActiveSupport::TestCase
     assert_include "issue.cf_#{field_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
     assert_not_include "issue.cf_#{field_not_on_project.id}", query.available_columns.map(&:name).map(&:to_s)
   end
+
+  def test_issue_category_filter_should_not_be_available_in_global_queries
+    query = TimeEntryQuery.new(:project => nil, :name => '_')
+    assert !query.available_filters.has_key?('issue.category_id')
+  end
 end