]> source.dussan.org Git - redmine.git/commitdiff
Makes issue custom fields available as timelog columns (#1766).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Jan 2013 13:09:06 +0000 (13:09 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Jan 2013 13:09:06 +0000 (13:09 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11174 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 97a635c105aeee5dfa1e9a2454635dc238869ee5..5094cc3a9bc1c0628f115048b1d6fecc76b8154c 100644 (file)
@@ -85,6 +85,28 @@ class QueryCustomFieldColumn < QueryColumn
   end
 end
 
+class QueryAssociationCustomFieldColumn < QueryCustomFieldColumn
+
+  def initialize(association, custom_field)
+    super(custom_field)
+    self.name = "#{association}.cf_#{custom_field.id}".to_sym
+    # TODO: support sorting/grouping by association custom field
+    self.sortable = false
+    self.groupable = false
+    @association = association
+  end
+
+  def value(object)
+    if assoc = object.send(@association)
+      super(assoc)
+    end
+  end
+
+  def css_classes
+    @css_classes ||= "#{@association}_cf_#{@cf.id} #{@cf.field_format}"
+  end
+end
+
 class Query < ActiveRecord::Base
   class StatementInvalid < ::ActiveRecord::StatementInvalid
   end
index 9ffa5f15de02f8afecda0744ee459bf07c999ae0..7283fbd2fb058125259d48abb2740bf25ecd88e7 100644 (file)
@@ -100,6 +100,7 @@ class TimeEntryQuery < Query
     return @available_columns if @available_columns
     @available_columns = self.class.available_columns.dup
     @available_columns += TimeEntryCustomField.all.map {|cf| QueryCustomFieldColumn.new(cf) }
+    @available_columns += IssueCustomField.all.map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf) }
     @available_columns
   end
 
index cb81a41ad4e4af18d94f9f923824f90ae43f2f8c..ae0561bfa63f5999d0a4dc2e5a229ecc6eaad87c 100644 (file)
@@ -528,6 +528,16 @@ class TimelogControllerTest < ActionController::TestCase
     assert_equal [entry], assigns(:entries)
   end
 
+  def test_index_with_issue_custom_field_column
+    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)
+
+    get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
+    assert_response :success
+    assert_include :'issue.cf_2', assigns(:query).column_names
+    assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
+  end
+
   def test_index_atom_feed
     get :index, :project_id => 1, :format => 'atom'
     assert_response :success