]> source.dussan.org Git - redmine.git/commitdiff
Adds a version filter on time entries (#13558).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 13 Jul 2016 18:26:44 +0000 (18:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 13 Jul 2016 18:26:44 +0000 (18:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15646 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
app/models/time_entry_query.rb
test/functional/timelog_controller_test.rb

index 1038637f2ceb4af73e21b8e8fbdf7a392eb5c6ba..5e8e0cd90ac0fbbc11867848b2ba1fcc8c3defbf 100644 (file)
@@ -691,9 +691,9 @@ class Query < ActiveRecord::Base
       if field =~ /cf_(\d+)$/
         # custom field
         filters_clauses << sql_for_custom_field(field, operator, v, $1)
-      elsif respond_to?("sql_for_#{field}_field")
+      elsif respond_to?(method = "sql_for_#{field.gsub('.','_')}_field")
         # specific statement
-        filters_clauses << send("sql_for_#{field}_field", field, operator, v)
+        filters_clauses << send(method, field, operator, v)
       else
         # regular field
         filters_clauses << '(' + sql_for_field(field, operator, v, queried_table_name, field) + ')'
index bb042ff167672958b87b3393e7fe0660df203d2c..dde34264ac5fbb04934ffdade8d2e66b3c5d9482 100644 (file)
@@ -41,6 +41,7 @@ class TimeEntryQuery < Query
     add_available_filter "spent_on", :type => :date_past
 
     principals = []
+    versions = []
     if project
       principals += project.principals.visible.sort
       unless project.leaf?
@@ -52,6 +53,7 @@ class TimeEntryQuery < Query
           principals += Principal.member_of(subprojects).visible
         end
       end
+      versions = project.shared_versions.to_a
     else
       if all_projects.any?
         # members of visible projects
@@ -69,6 +71,10 @@ class TimeEntryQuery < Query
     end
 
     add_available_filter("issue_id", :type => :tree, :label => :label_issue)
+    add_available_filter("issue.fixed_version_id",
+      :type => :list,
+      :name => l("label_attribute_of_issue", :name => l(:field_fixed_version)),
+      :values => Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] })
 
     principals.uniq!
     principals.sort!
@@ -136,6 +142,24 @@ class TimeEntryQuery < Query
     end
   end
 
+  def sql_for_issue_fixed_version_id_field(field, operator, value)
+    issue_ids = Issue.where(:fixed_version_id => value.first.to_i).pluck(:id)
+    case operator
+    when "="
+      if issue_ids.any?
+        "#{TimeEntry.table_name}.issue_id IN (#{issue_ids.join(',')})"
+      else
+        "1=0"
+      end
+    when "!"
+      if issue_ids.any?
+        "#{TimeEntry.table_name}.issue_id NOT IN (#{issue_ids.join(',')})"
+      else
+        "1=1"
+      end
+    end
+  end
+
   def sql_for_activity_id_field(field, operator, value)
     condition_on_id = sql_for_field(field, operator, value, Enumeration.table_name, 'id')
     condition_on_parent_id = sql_for_field(field, operator, value, Enumeration.table_name, 'parent_id')
index 25bfea2fa8096827d212dd832ca5fd2051cfd20c..b85ee67be34576c54c045226a6e39cdf7ca5551d 100644 (file)
@@ -639,6 +639,27 @@ class TimelogControllerTest < ActionController::TestCase
     end
   end
 
+  def test_index_at_project_level_with_issue_id_short_filter
+    issue = Issue.generate!(:project_id => 1)
+    TimeEntry.generate!(:issue => issue, :hours => 4)
+    TimeEntry.generate!(:issue => issue, :hours => 3)
+    @request.session[:user_id] = 2
+
+    get :index, :project_id => 'ecookbook', :issue_id => issue.id.to_s, :set_filter => 1
+    assert_select '.total-hours', :text => 'Total time: 7.00 hours'
+  end
+
+  def test_index_at_project_level_with_issue_fixed_version_id_short_filter
+    version = Version.generate!(:project_id => 1)
+    issue = Issue.generate!(:project_id => 1, :fixed_version => version)
+    TimeEntry.generate!(:issue => issue, :hours => 2)
+    TimeEntry.generate!(:issue => issue, :hours => 3)
+    @request.session[:user_id] = 2
+
+    get :index, :project_id => 'ecookbook', :"issue.fixed_version_id" => version.id.to_s, :set_filter => 1
+    assert_select '.total-hours', :text => 'Total time: 5.00 hours'
+  end
+
   def test_index_at_project_level_with_date_range
     get :index, :project_id => 'ecookbook',
       :f => ['spent_on'],