From e2cde541f865e516b05a622c357af205389c4a9d Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Thu, 22 Mar 2018 22:09:23 +0000 Subject: [PATCH 2/2] adds issue category column to spent time queries --- app/models/time_entry_query.rb | 4 ++++ test/functional/timelog_controller_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index ea32cb9..1a938c5 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -30,6 +30,7 @@ class TimeEntryQuery < Query QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"), QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.position"), QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.position"), + QueryAssociationColumn.new(:issue, :category, :caption => :field_category, :sortable => "#{IssueCategory.table_name}.name"), QueryColumn.new(:comments), QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true), ] @@ -228,6 +229,9 @@ class TimeEntryQuery < Query if order_options.include?('trackers') joins << "LEFT OUTER JOIN #{Tracker.table_name} ON #{Tracker.table_name}.id = #{Issue.table_name}.tracker_id" end + if order_options.include?('issue_categories') + joins << "LEFT OUTER JOIN #{IssueCategory.table_name} ON #{IssueCategory.table_name}.id = #{Issue.table_name}.category_id" + end end joins.compact! diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 02338e2..652ee12 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -1036,6 +1036,32 @@ class TimelogControllerTest < Redmine::ControllerTest assert_equal ['1', '2'], css_select('input[name="ids[]"]').map {|e| e.attr('value')} end + def test_index_with_issue_category_column + get :index, :params => { + :project_id => 'ecookbook', + :c => %w(project spent_on issue comments hours issue.category) + } + + assert_response :success + assert_select 'td.issue-category', :text => 'Printing' + end + + def test_index_with_issue_category_sort + issue = Issue.find(3) + issue.category_id = 2 + issue.save! + + get :index, :params => { + :c => ["hours", 'issue.category'], + :sort => 'issue.category' + } + assert_response :success + + # Make sure that values are properly sorted + values = css_select("td.issue-category").map(&:text).reject(&:blank?) + assert_equal ['Printing', 'Printing', 'Recipes'], values + 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) -- 2.1.4