Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add exporting csv feature

  • Loading branch information...
commit 144486a34a5ab9f5c84b9aac4ae7b9f1fa312bec 1 parent 742e753
@marutosi marutosi authored
View
9 app/controllers/ratios_controller.rb
@@ -2,6 +2,9 @@ class RatiosController < ApplicationController
unloadable
include IndicatorsLogic
+ helper :ratios
+ include RatiosHelper
+
def index
project = Project.find(params[:id])
data = IndicatorsLogic::retrive_data(project)
@@ -17,5 +20,11 @@ def index
:indicators => IndicatorsLogic::calc_indicators(my_version, data[0], data[1])
}
end
+ respond_to do |format|
+ format.html { render :action => 'index' }
+ format.csv {
+ send_data(evm_csv(@evms), :type => 'text/csv; header=present', :filename => 'evm.csv')
+ }
+ end
end
end
View
24 app/helpers/ratios_helper.rb
@@ -1,2 +1,26 @@
module RatiosHelper
+ def evm_csv(evms)
+ decimal_separator = l(:general_csv_decimal_separator)
+ export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
+ evms.each do |evm|
+ fields = ["", "cpi", "spi"]
+ csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c,
+ l(:general_csv_encoding) ) }
+ fields = []
+ fields << evm[:name]
+ fields << evm[:indicators][1].to_s.gsub('.', decimal_separator)
+ fields << evm[:indicators][2].to_s.gsub('.', decimal_separator)
+ csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c,
+ l(:general_csv_encoding) ) }
+ evm[:indicators][0].each do |ent|
+ csv << ent.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c.to_s.gsub('.', decimal_separator),
+ l(:general_csv_encoding) ) }
+ end
+ end
+ end
+ export
+ end
end
View
4 app/views/ratios/index.html.erb
@@ -10,3 +10,7 @@
<%= render "ratios/head_js" %>
<%= render :partial=>"ratios/bottom_js", :locals => {:evm => evm} %>
<% end %>
+
+<% other_formats_links do |f| %>
+ <%= f.link_to 'CSV', :url => params %>
+<% end %>
Please sign in to comment.
Something went wrong with that request. Please try again.