diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 2ee90c9..94aecaf 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -268,7 +268,7 @@ respond_to do |format| format.html { render layout: false } - format.csv { send_data @plan.as_csv(@show_sections_questions, @show_unanswered, @selected_phase, @show_custom_sections), filename: "#{file_name}.csv" } + format.csv { send_data @plan.as_csv(@show_sections_questions, @show_unanswered, @selected_phase, @show_custom_sections, @show_coversheet), filename: "#{file_name}.csv" } format.text { send_data render_to_string(partial: 'shared/export/plan_txt'), filename: "#{file_name}.txt" } format.docx { render docx: "#{file_name}.docx", content: render_to_string(partial: 'shared/export/plan') } format.pdf do diff --git a/app/models/concerns/exportable_plan.rb b/app/models/concerns/exportable_plan.rb index 6a6fdde..1701b83 100644 --- a/app/models/concerns/exportable_plan.rb +++ b/app/models/concerns/exportable_plan.rb @@ -4,10 +4,30 @@ prepare(coversheet) end - def as_csv(headings = true, unanswered = true, selected_phase = nil, show_custom_sections = true) - hash = prepare(false) + def as_csv(headings = true, unanswered = true, selected_phase = nil, show_custom_sections = true, show_coversheet = false) + hash = prepare(show_coversheet) CSV.generate do |csv| + if show_coversheet + csv << [ hash[:attribution].many? ? _("Creators: ") : _('Creator:'), _(hash[:attribution].join(', ')) ] + csv << [ "Affiliation: ", _(hash[:affiliation]) ] + if hash[:funder].present? + csv << [ _("Template: "), _(hash[:funder]) ] + else + csv << [ _("Template: "), _(hash[:template] + hash[:customizer]) ] + end + if self.grant_number.present? + csv << [ _("Grant number: "), _(self.grant_number) ] + end + if self.description.present? + csv << [ _("Project abstract: "), _(Nokogiri::HTML(self.description).text) ] + end + csv << [ _("Last modified: "), _(self.updated_at.to_date.strftime("%d-%m-%Y")) ] + csv << [ _("Copyright information:"), _("The above plan creator(s) have agreed that others may use as much of the text of this plan as they would like in their own plans, and customise it as necessary. You do not need to credit the creator(s) as the source of the language used, but using any of the plan's text does not imply that the creator(s) endorse, or have any relationship to, your project or proposal") ] + csv << [] + csv << [] + end + hdrs = (hash[:phases].many? ? [_('Phase')] : []) if headings hdrs << [_('Section'),_('Question'),_('Answer')] diff --git a/app/views/shared/export/_plan_txt.erb b/app/views/shared/export/_plan_txt.erb index d2be1c2..ed05921 100644 --- a/app/views/shared/export/_plan_txt.erb +++ b/app/views/shared/export/_plan_txt.erb @@ -1,7 +1,7 @@ <%= "#{@plan.title}" %> <%= "----------------------------------------------------------\n" %> <% if @show_coversheet %> -<%= @hash[:attribution].length > 1 ? _("Creators: ") : _('Creator:') %> <%= @hash[:attribution].join(', ') %> +<%= @hash[:attribution].many? ? _("Creators: ") : _('Creator:') %> <%= @hash[:attribution].join(', ') %> <%= _("Affiliation: ") + @hash[:affiliation] %> <% if @hash[:funder].present? %> <%= _("Template: ") + @hash[:funder] %> @@ -24,7 +24,7 @@ <% @hash[:phases].each do |phase| %> <%# Only render selected phase %> <% if phase[:title] == @selected_phase.title %> - <%= (@hash[:phases].length > 1 ? "#{phase[:title]}" : "") %> +<%= (@hash[:phases].many? ? "#{phase[:title]}" : "") %> <% phase[:sections].each do |section| %> <% if display_questions_and_section_headings(section, @show_sections_questions, @show_custom_sections) %> <%= "#{section[:title]}\n" %> @@ -36,7 +36,7 @@ <%= "#{strip_tags(txt.gsub(//, '\n'))}\n" %> <% end %> <% else %> -<%= "#{strip_tags(question[:text][0].gsub(/(\s||<\/td>| )*(<\/tr>|)/,""))}\n" if question[:text].present? && question[:text][0].present? %> +<%= "#{strip_tags(question[:text].gsub(/(\s||<\/td>| )*(<\/tr>|)/,""))}\n" if question[:text].present? && question[:text][0].present? %> <% end %> <% answer = @plan.answer(question[:id], false) %> <% blank = (answer.present? && answer.is_valid?) ? answer.text.gsub(/<\/?p>/, '').gsub(//, '\n').chomp.blank? : true %>