Project

General

Profile

Actions

Patch #21841

closed

Correctly export collections associated with issues.

Added by Anonymous about 8 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Issues
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

When you have a plugins that add a 1:m association to issues (say tags) and you want to export the associated entities the CSV and PDF exports give you a ActiveRecord_Associations_CollectionProxy object serialization as the column value.

This patch Fixes the behaviour for all mappable (or collectable if you prefer) objects (see attached before and after exports).


Files

0001-Fixed-exporting-collections-associated-with-issues.patch (1.58 KB) 0001-Fixed-exporting-collections-associated-with-issues.patch Anonymous, 2016-01-25 17:25
pdf_export_after.pdf (95 KB) pdf_export_after.pdf Anonymous, 2016-01-25 17:29
pdf_export_before.pdf (95.1 KB) pdf_export_before.pdf Anonymous, 2016-01-25 17:29
csv_export_after.csv (111 Bytes) csv_export_after.csv Anonymous, 2016-01-25 17:31
csv_export_before.csv (186 Bytes) csv_export_before.csv Anonymous, 2016-01-25 17:31
Actions #2

Updated by Anonymous about 8 years ago

Toshi MARUYAMA wrote:

How about you use #to_a?
http://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-to_a

Where exactly do you suggest I use the to_a method?
Both exports (CSV and PDF) loop trough the available columns of the issue query and format the values for display. There is no place to specify that a certain value is a collection or to inject a transformation.
Rails uses to_a when calling a method from Enumerable (ex: collect) on an AR collection. This patch ensures that it gets called when the appropriate type is given (it could be a plain array or a proxy that resolves to an array).

Actions #3

Updated by Toshi MARUYAMA about 8 years ago

Codruț Gușoi wrote:

Where exactly do you suggest I use the to_a method?

For example: r13248.

Actions #4

Updated by Toshi MARUYAMA about 8 years ago

In your patch:

diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb
index a7a4956..a3293a3 100644
--- a/lib/redmine/export/pdf/issues_pdf_helper.rb
+++ b/lib/redmine/export/pdf/issues_pdf_helper.rb
@@ -360,6 +360,8 @@ module Redmine
                 format_date(value)
               elsif value.is_a?(Time)
                 format_time(value)
+              elsif value.respond_to?(:collect)
+                value.collect(&:to_s).compact.join(', ')
               else
                 value
               end

How about joining value in your plugin?

Actions #5

Updated by Anonymous about 5 years ago

  • Status changed from New to Resolved

Closing this as I am no longer interested in the issue.

Actions #6

Updated by Marius BĂLTEANU about 5 years ago

  • Status changed from Resolved to Closed

Codruț Gușoi wrote:

Closing this as I am no longer interested in the issue.

Thanks.

Actions

Also available in: Atom PDF