From 19f974f3b80c1434e8665897d1112a4783b4f118 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Wed, 10 Jan 2018 14:43:01 +0100 Subject: [PATCH] Fix 'uninitialized constant Timesheet::FCSV'; fixes #58 --- app/helpers/timesheet_helper.rb | 15 +++++++++++++++ app/models/timesheet.rb | 14 ++++++++++++++ app/views/timesheet/report.html.erb | 2 +- init.rb | 14 +++++++------- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/helpers/timesheet_helper.rb b/app/helpers/timesheet_helper.rb index 9861cff..af1ad48 100644 --- a/app/helpers/timesheet_helper.rb +++ b/app/helpers/timesheet_helper.rb @@ -39,6 +39,21 @@ def link_to_csv_export(timesheet) :class => 'icon icon-timesheet') end + def form_for_to_timesheet(timesheet) + params_like_decode_url = CGI.unescape({:timesheet => timesheet.to_param}.to_query) + inputs = "" + form = form_tag :controller => 'timesheet', :action => 'report' do + params_like_decode_url.split("&").each do |param| + param_arr = param.split("=") + inputs << hidden_field_tag(param_arr.first, param_arr.last, :id => "") + end + inputs << submit_tag(l(:timesheet_permalink)) + inputs.html_safe + end + form.html_safe + end + + def toggle_arrows(element, js_function) js = "#{js_function}('#{element}');" diff --git a/app/models/timesheet.rb b/app/models/timesheet.rb index 34ee427..4e86e9c 100644 --- a/app/models/timesheet.rb +++ b/app/models/timesheet.rb @@ -162,6 +162,20 @@ def to_param def to_csv out = ""; + + + handle_time_entries = {} + time_entries.each do |k,v| + if k.is_a? String + handle_time_entries[k] = v + next; + end + handle_time_entries[k.name] = v + end + + time_entries = handle_time_entries + + FCSV.generate(out, :encoding => 'utf-8', :force_quotes => true) do |csv| csv << csv_header diff --git a/app/views/timesheet/report.html.erb b/app/views/timesheet/report.html.erb index 73a0c7d..1adea84 100644 --- a/app/views/timesheet/report.html.erb +++ b/app/views/timesheet/report.html.erb @@ -1,6 +1,6 @@
<%= link_to_csv_export(@timesheet) %> - <%= permalink_to_timesheet(@timesheet) %> + <%= form_for_to_timesheet(@timesheet) %>

<%= l(:timesheet_title)%>

diff --git a/init.rb b/init.rb index 94276f9..beb0979 100644 --- a/init.rb +++ b/init.rb @@ -1,12 +1,12 @@ require 'redmine' -## Taken from lib/redmine.rb -#if RUBY_VERSION < '1.9' -# require 'faster_csv' -#else -# require 'csv' -# FCSV = CSV -#end +# Taken from lib/redmine.rb +if RUBY_VERSION < '1.9' + require 'faster_csv' +else + require 'csv' + FCSV = CSV +end if Rails::VERSION::MAJOR < 3 require 'dispatcher'