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

git-svn-id: http://svn.redmine.org/redmine/trunk@17608 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 260800078df61ac1735d9f1887c81987509e4e84..a612ba7c5c5b36ca803fe9fdc94bea5bd6ec329d 100644 (file)
@@ -80,6 +80,12 @@ class TimeEntryQuery < Query
       :type => :list, :values => activities.map {|a| [a.name, a.id.to_s]}
     )
 
+    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_available_filter "comments", :type => :text
     add_available_filter "hours", :type => :float
 
@@ -205,6 +211,10 @@ class TimeEntryQuery < Query
     sql_for_field("category_id", operator, value, Issue.table_name, "category_id")
   end
 
+  def sql_for_project_status_field(field, operator, value, options={})
+    sql_for_field(field, operator, value, Project.table_name, "status")
+  end
+
   # Accepts :from/:to params as shortcut filters
   def build_from_params(params, defaults={})
     super
index 47da3e3b754732fdec570e2abf996439f38b067c..1139d07563358f179319f484ff3fc2d2a868e837 100644 (file)
@@ -986,6 +986,25 @@ class TimelogControllerTest < Redmine::ControllerTest
     assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
   end
 
+  def test_index_with_project_status_filter
+    project = Project.find(3)
+    project.close
+    project.save
+
+    get :index, :params => {
+        :set_filter => 1,
+        :f => ['project.status'],
+        :op => {'project.status' => '='},
+        :v => {'project.status' => ['1']}
+    }
+
+    assert_response :success
+
+    time_entries = css_select('input[name="ids[]"]').map {|e| e.attr('value')}
+    assert_include '1', time_entries
+    assert_not_include '4', time_entries
+  end
+
   def test_index_with_issue_status_column
     issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
     entry = TimeEntry.generate!(:issue => issue)
index e2f7caac24d34100c3ef03f558920f9b43ebffe5..2f689189335d46874b1d46ffdd9aff96f9ea2dbf 100644 (file)
@@ -108,4 +108,19 @@ class TimeEntryQueryTest < ActiveSupport::TestCase
     query = TimeEntryQuery.new(:project => nil, :name => '_')
     assert !query.available_filters.has_key?('issue.category_id')
   end
+
+  def test_project_status_filter_should_be_available_in_global_queries
+    query = TimeEntryQuery.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 = TimeEntryQuery.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 = TimeEntryQuery.new(:project => Project.find(2), :name => '_')
+    assert !query.available_filters.has_key?('project.status')
+  end
 end