diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-02-23 11:07:43 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-02-23 11:07:43 +0000 |
commit | 797a9f1ea945c891b5974881d0b3d6b5c4f56125 (patch) | |
tree | f0ed773e17d6b1d5a0619ab7f5ac06078e30f9a7 /app | |
parent | 9b1ebd6808d260a95eff38c2a93ec2c1b7ed8183 (diff) | |
download | redmine-797a9f1ea945c891b5974881d0b3d6b5c4f56125.tar.gz redmine-797a9f1ea945c891b5974881d0b3d6b5c4f56125.zip |
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11448 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issues_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/timelog_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 20 | ||||
-rw-r--r-- | app/helpers/queries_helper.rb | 20 | ||||
-rw-r--r-- | app/helpers/timelog_helper.rb | 15 |
5 files changed, 22 insertions, 37 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 11469a20b..314460c6f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -85,7 +85,7 @@ class IssuesController < ApplicationController Issue.load_visible_relations(@issues) if include_in_api_response?('relations') } format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } - format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } + format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } end else diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index e90442c68..92210fff5 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -87,7 +87,7 @@ class TimelogController < ApplicationController :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause ) - send_data(entries_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') + send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') } end end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index a0c48e20d..59cff5ec1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -370,24 +370,4 @@ module IssuesHelper end end end - - def issues_to_csv(issues, project, query, options={}) - encoding = l(:general_csv_encoding) - columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) - if options[:description] - if description = query.available_columns.detect {|q| q.name == :description} - columns << description - end - end - - export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| - # csv header fields - csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } - # csv lines - issues.each do |issue| - csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) } - end - end - export - end end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 80bceaf10..2001a59e6 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -123,6 +123,26 @@ module QueriesHelper end end + def query_to_csv(items, query, options={}) + encoding = l(:general_csv_encoding) + columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) + query.available_block_columns.each do |column| + if options[column.name].present? + columns << column + end + end + + export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| + # csv header fields + csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } + # csv lines + items.each do |item| + csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) } + end + end + export + end + # Retrieve query from session or build a new query def retrieve_query if !params[:query_id].blank? diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb index 380c4721c..f6bdba2ec 100644 --- a/app/helpers/timelog_helper.rb +++ b/app/helpers/timelog_helper.rb @@ -86,21 +86,6 @@ module TimelogHelper value) end - def entries_to_csv(entries, query, options={}) - encoding = l(:general_csv_encoding) - columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) - - export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| - # csv header fields - csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } - # csv lines - entries.each do |entry| - csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, entry), encoding) } - end - end - export - end - def format_criteria_value(criteria_options, value) if value.blank? "[#{l(:label_none)}]" |