diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index c9d234d..8bedcbc 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -292,49 +292,46 @@ # ------------------------------------------------------------- def public_export @plan = Plan.find(params[:id]) - # If the plan has multiple phases we should export each - @plan.phases.each do |phase| - @exported_plan = ExportedPlan.new.tap do |ep| - ep.plan = @plan - ep.phase_id = phase.id - ep.format = :pdf - plan_settings = @plan.settings(:export) + @exported_plan = ExportedPlan.new.tap do |ep| + ep.plan = @plan + ep.phase_id = @plan.phases.first.id + ep.format = :pdf + plan_settings = @plan.settings(:export) - Settings::Template::DEFAULT_SETTINGS.each do |key, value| - ep.settings(:export).send("#{key}=", plan_settings.send(key)) - end - end - - begin - @exported_plan.save! - # If the template has multiple phases then append the phase title to the filename - if @plan.phases.count > 1 - file_name = "#{@plan.title.gsub(/ /, "_")}-#{phase.title}" - else - file_name = @plan.title.gsub(/ /, "_") - end - - respond_to do |format| - format.pdf do - @formatting = @plan.settings(:export).formatting - render pdf: file_name, - margin: @formatting[:margin], - footer: { - center: _('This document was generated by %{application_name}') % {application_name: Rails.configuration.branding[:application][:name]}, - font_size: 8, - spacing: (@formatting[:margin][:bottom] / 2) - 4, - right: '[page] of [topage]' - } - end - end - rescue ActiveRecord::RecordInvalid => e - @phase_options = @plan.phases.order(:number).pluck(:title,:id) - redirect_to show_export_plan_path(@plan), alert: _('Unable to download the DMP at this time.') + Settings::Template::DEFAULT_SETTINGS.each do |key, value| + ep.settings(:export).send("#{key}=", plan_settings.send(key)) end end + # need to determine which phases to export + @a_q_ids = Answer.where(plan_id: @plan.id).pluck(:question_id).uniq + @a_s_ids = Question.where(id: @a_q_ids).pluck(:section_id).uniq + a_p_ids = Section.where(id: @a_s_ids).pluck(:phase_id).uniq + @phases = Phase.includes(sections: :questions).where(id: a_p_ids).order(:number) + + begin + @exported_plan.save! + file_name = @plan.title.gsub(/ /, "_") + + respond_to do |format| + format.pdf do + @formatting = @plan.settings(:export).formatting + render pdf: file_name, + margin: @formatting[:margin], + footer: { + center: _('This document was generated by %{application_name}') % {application_name: Rails.configuration.branding[:application][:name]}, + font_size: 8, + spacing: (@formatting[:margin][:bottom] / 2) - 4, + right: '[page] of [topage]' + } + end + end + rescue ActiveRecord::RecordInvalid => e + @phase_options = @plan.phases.order(:number).pluck(:title,:id) + redirect_to show_export_plan_path(@plan), alert: _('Unable to download the DMP at this time.') + end end - + def duplicate plan = Plan.find(params[:id]) authorize plan diff --git a/app/views/plans/public_export.pdf.erb b/app/views/plans/public_export.pdf.erb index f33d1d9..ca7fb83 100644 --- a/app/views/plans/public_export.pdf.erb +++ b/app/views/plans/public_export.pdf.erb @@ -1,70 +1,61 @@ -
- -<%= admin_field_t(field.to_s) -%> <%= value -%>
- <% else %> -<%= admin_field_t(field.to_s) -%> <%= _('-') %>
- <% end %> - <% end %> - -<%= _("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") %>
+ + +<%= _('Question not answered.') -%>
- <% else %> - <% q_format = question.question_format %> - <% if q_format.option_based? %> -<%= _("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") %>
+ <% @phases.each do |phase| %> + +<%= _('Question not answered.') -%>
+ <% else %> + <% q_format = question.question_format %> + <% if q_format.option_based? %> +