Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV export fails when (sub-)project name contains whitespaces #64

Open
catabu1 opened this issue May 11, 2016 · 1 comment
Open

CSV export fails when (sub-)project name contains whitespaces #64

catabu1 opened this issue May 11, 2016 · 1 comment

Comments

@catabu1
Copy link

catabu1 commented May 11, 2016

Only confirmed for subprojects. There is a problem when the timesheet should be exported to csv and the time_entries are sorted by project.

The following is a related entry from the production log:

Completed 500 Internal Server Error in 227ms (ActiveRecord: 47.0ms)

NoMethodError (undefined method `name' for "Project / Subproject with Whitespaces":String):
  app/models/project.rb:551:in `<=>'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `<=>'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `sort'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `block in to_csv'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:153:in `to_csv'
  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:87:in `block (2 levels) in report'
  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:85:in `report'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'
  plugins/redmine_dmsf/lib/redmine_dmsf/webdav/no_parse.rb:33:in `call'

I changed the line that's sorting the entries in the method to_csv to the following, which fixed my issues:

diff --git a/app/models/timesheet.rb b/app/models/timesheet.rb
index 84196d9..0e7b43e 100644
--- a/app/models/timesheet.rb
+++ b/app/models/timesheet.rb
@@ -162,7 +162,7 @@ class Timesheet
           end
         end
       when :issue
-        time_entries.sort.each do |project, entries|
+        time_entries.sort {|a,b| a[0].to_s <=> b[0].to_s}.each do |project, entries|
           entries[:issues].sort {|a,b| a[0].id <=> b[0].id}.each do |issue, time_entries|
             time_entries.each do |e|
               csv << time_entry_to_csv(e)

I'm no expert on ruby and I don't know if that's the cleanest solution possible (hence no pull request), but that's what fixed it for me for now.

@ghost
Copy link

ghost commented May 11, 2016

Well, you are passing the options to string and , since we are putting them in .csv, its ok.
Ill test this , cause im making a modification of this plugin to filter the columns for both , the form and the .csv, and showing the custom fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant