summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/timelog_controller.rb9
-rw-r--r--app/helpers/timelog_helper.rb8
-rw-r--r--app/views/timelog/_report_criteria.rhtml4
3 files changed, 17 insertions, 4 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 3081c50dd..2c90093bd 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -26,6 +26,8 @@ class TimelogController < ApplicationController
include SortHelper
helper :issues
include TimelogHelper
+ helper :custom_fields
+ include CustomFieldsHelper
def report
@available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
@@ -51,6 +53,13 @@ class TimelogController < ApplicationController
:label => :label_issue}
}
+ # Add list and boolean custom fields as available criterias
+ @project.all_custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
+ @available_criterias["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM custom_values c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = issues.id)",
+ :format => cf.field_format,
+ :label => cf.name}
+ end
+
@criterias = params[:criterias] || []
@criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
@criterias.uniq!
diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb
index e0459581d..db13556a1 100644
--- a/app/helpers/timelog_helper.rb
+++ b/app/helpers/timelog_helper.rb
@@ -77,6 +77,10 @@ module TimelogHelper
export
end
+ def format_criteria_value(criteria, value)
+ value.blank? ? l(:label_none) : ((k = @available_criterias[criteria][:klass]) ? k.find_by_id(value.to_i) : format_value(value, @available_criterias[criteria][:format]))
+ end
+
def report_to_csv(criterias, periods, hours)
export = StringIO.new
CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
@@ -103,11 +107,11 @@ module TimelogHelper
end
def report_criteria_to_csv(csv, criterias, periods, hours, level=0)
- hours.collect {|h| h[criterias[level]]}.uniq.each do |value|
+ hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value|
hours_for_value = select_hours(hours, criterias[level], value)
next if hours_for_value.empty?
row = [''] * level
- row << to_utf8(value.nil? ? l(:label_none) : @available_criterias[criterias[level]][:klass].find_by_id(value))
+ row << to_utf8(format_criteria_value(criterias[level], value))
row += [''] * (criterias.length - level - 1)
total = 0
periods.each do |period|
diff --git a/app/views/timelog/_report_criteria.rhtml b/app/views/timelog/_report_criteria.rhtml
index 661e1fdb8..94f3d20f9 100644
--- a/app/views/timelog/_report_criteria.rhtml
+++ b/app/views/timelog/_report_criteria.rhtml
@@ -1,9 +1,9 @@
-<% @hours.collect {|h| h[criterias[level]]}.uniq.each do |value| %>
+<% @hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
<% hours_for_value = select_hours(hours, criterias[level], value) -%>
<% next if hours_for_value.empty? -%>
<tr class="<%= cycle('odd', 'even') %> <%= 'last-level' unless criterias.length > level+1 %>">
<%= '<td></td>' * level %>
-<td><%= value.nil? ? l(:label_none) : @available_criterias[criterias[level]][:klass].find_by_id(value) %></td>
+<td><%= format_criteria_value(criterias[level], value) %></td>
<%= '<td></td>' * (criterias.length - level - 1) -%>
<% total = 0 -%>
<% @periods.each do |period| -%>