@@ -85,7 +85,7 class IssuesController < ApplicationController | |||||
85 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') |
|
85 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') | |
86 | } |
|
86 | } | |
87 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
87 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
88 |
format.csv { send_data( |
|
88 | format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
89 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
89 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
90 | end |
|
90 | end | |
91 | else |
|
91 | else |
@@ -87,7 +87,7 class TimelogController < ApplicationController | |||||
87 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], |
|
87 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], | |
88 | :order => sort_clause |
|
88 | :order => sort_clause | |
89 | ) |
|
89 | ) | |
90 |
send_data( |
|
90 | send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') | |
91 | } |
|
91 | } | |
92 | end |
|
92 | end | |
93 | end |
|
93 | end |
@@ -370,24 +370,4 module IssuesHelper | |||||
370 | end |
|
370 | end | |
371 | end |
|
371 | end | |
372 | end |
|
372 | end | |
373 |
|
||||
374 | def issues_to_csv(issues, project, query, options={}) |
|
|||
375 | encoding = l(:general_csv_encoding) |
|
|||
376 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) |
|
|||
377 | if options[:description] |
|
|||
378 | if description = query.available_columns.detect {|q| q.name == :description} |
|
|||
379 | columns << description |
|
|||
380 | end |
|
|||
381 | end |
|
|||
382 |
|
||||
383 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
|||
384 | # csv header fields |
|
|||
385 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } |
|
|||
386 | # csv lines |
|
|||
387 | issues.each do |issue| |
|
|||
388 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) } |
|
|||
389 | end |
|
|||
390 | end |
|
|||
391 | export |
|
|||
392 | end |
|
|||
393 | end |
|
373 | end |
@@ -123,6 +123,26 module QueriesHelper | |||||
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
|
126 | def query_to_csv(items, query, options={}) | |||
|
127 | encoding = l(:general_csv_encoding) | |||
|
128 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) | |||
|
129 | query.available_block_columns.each do |column| | |||
|
130 | if options[column.name].present? | |||
|
131 | columns << column | |||
|
132 | end | |||
|
133 | end | |||
|
134 | ||||
|
135 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |||
|
136 | # csv header fields | |||
|
137 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } | |||
|
138 | # csv lines | |||
|
139 | items.each do |item| | |||
|
140 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) } | |||
|
141 | end | |||
|
142 | end | |||
|
143 | export | |||
|
144 | end | |||
|
145 | ||||
126 | # Retrieve query from session or build a new query |
|
146 | # Retrieve query from session or build a new query | |
127 | def retrieve_query |
|
147 | def retrieve_query | |
128 | if !params[:query_id].blank? |
|
148 | if !params[:query_id].blank? |
@@ -86,21 +86,6 module TimelogHelper | |||||
86 | value) |
|
86 | value) | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def entries_to_csv(entries, query, options={}) |
|
|||
90 | encoding = l(:general_csv_encoding) |
|
|||
91 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) |
|
|||
92 |
|
||||
93 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
|||
94 | # csv header fields |
|
|||
95 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } |
|
|||
96 | # csv lines |
|
|||
97 | entries.each do |entry| |
|
|||
98 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, entry), encoding) } |
|
|||
99 | end |
|
|||
100 | end |
|
|||
101 | export |
|
|||
102 | end |
|
|||
103 |
|
||||
104 | def format_criteria_value(criteria_options, value) |
|
89 | def format_criteria_value(criteria_options, value) | |
105 | if value.blank? |
|
90 | if value.blank? | |
106 | "[#{l(:label_none)}]" |
|
91 | "[#{l(:label_none)}]" |
@@ -391,13 +391,18 class IssuesControllerTest < ActionController::TestCase | |||||
391 | end |
|
391 | end | |
392 |
|
392 | |||
393 | def test_index_csv_with_description |
|
393 | def test_index_csv_with_description | |
394 | get :index, :format => 'csv', :description => '1' |
|
394 | Issue.generate!(:description => 'test_index_csv_with_description') | |
395 | assert_response :success |
|
395 | ||
396 | assert_not_nil assigns(:issues) |
|
396 | with_settings :default_language => 'en' do | |
397 | assert_equal 'text/csv; header=present', @response.content_type |
|
397 | get :index, :format => 'csv', :description => '1' | |
398 | assert @response.body.starts_with?("#,") |
|
398 | assert_response :success | |
399 | lines = @response.body.chomp.split("\n") |
|
399 | assert_not_nil assigns(:issues) | |
400 | assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size |
|
400 | end | |
|
401 | ||||
|
402 | assert_equal 'text/csv; header=present', response.content_type | |||
|
403 | headers = response.body.chomp.split("\n").first.split(',') | |||
|
404 | assert_include 'Description', headers | |||
|
405 | assert_include 'test_index_csv_with_description', response.body | |||
401 | end |
|
406 | end | |
402 |
|
407 | |||
403 | def test_index_csv_with_spent_time_column |
|
408 | def test_index_csv_with_spent_time_column |
General Comments 0
You need to be logged in to leave comments.
Login now