From a0479c768ef80cbdaaf858b7550793fd327fc04c Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 29 Oct 2018 04:05:18 +0000 Subject: [PATCH] Filter time entries after project status (#20081). 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 | 10 ++++++++++ test/functional/timelog_controller_test.rb | 19 +++++++++++++++++++ test/unit/time_entry_query_test.rb | 15 +++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index 260800078..a612ba7c5 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -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 diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 47da3e3b7..1139d0756 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -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) diff --git a/test/unit/time_entry_query_test.rb b/test/unit/time_entry_query_test.rb index e2f7caac2..2f6891893 100644 --- a/test/unit/time_entry_query_test.rb +++ b/test/unit/time_entry_query_test.rb @@ -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 -- 2.39.5