diff --git a/app/controllers/api/v0/madmp/plans_controller.rb b/app/controllers/api/v0/madmp/plans_controller.rb index efe3863..a8e639e 100644 --- a/app/controllers/api/v0/madmp/plans_controller.rb +++ b/app/controllers/api/v0/madmp/plans_controller.rb @@ -33,7 +33,7 @@ end respond_to do |format| - format.json + format.json render "shared/export/madmp_export_templates/rda/plan", locals: { dmp: plan_fragment } diff --git a/app/models/settings/template.rb b/app/models/settings/template.rb index 6bef9a9..c1299f4 100644 --- a/app/models/settings/template.rb +++ b/app/models/settings/template.rb @@ -1,20 +1,20 @@ -# == Schema Information -# -# Table name: settings -# -# id :integer not null, primary key -# target_type :string not null -# value :text -# var :string not null -# created_at :datetime not null -# updated_at :datetime not null -# target_id :integer not null -# -# Indexes -# -# settings_target_type_target_id_var_key (target_type,target_id,var) UNIQUE -# - +# == Schema Information +# +# Table name: settings +# +# id :integer not null, primary key +# target_type :string not null +# value :text +# var :string not null +# created_at :datetime not null +# updated_at :datetime not null +# target_id :integer not null +# +# Indexes +# +# settings_target_type_target_id_var_key (target_type,target_id,var) UNIQUE +# + module Settings class Template < RailsSettings::SettingObject @@ -29,7 +29,7 @@ VALID_ADMIN_FIELDS = ['project_name', 'project_identifier', 'grant_title', 'principal_investigator', 'project_data_contact', 'project_description', 'funder', 'institution', 'orcid'] - VALID_FORMATS = ['html', 'pdf', 'docx'] + VALID_FORMATS = ['html', 'pdf', 'docx', ["RDA Commons Standards", "json"]] DEFAULT_SETTINGS = { formatting: { diff --git a/lib/dmpopidor/controllers/plan_exports.rb b/lib/dmpopidor/controllers/plan_exports.rb index fde897b..689a751 100644 --- a/lib/dmpopidor/controllers/plan_exports.rb +++ b/lib/dmpopidor/controllers/plan_exports.rb @@ -1,72 +1,86 @@ +# frozen_string_literal: true + module Dmpopidor - module Controllers - module PlanExports - # CHANGES: Can now send multiple phases when exporting - def show - @plan = Plan.includes(:answers, :research_outputs).find(params[:plan_id]) - - if privately_authorized? && export_params[:form].present? - skip_authorization - @show_coversheet = export_params[:project_details].present? - @show_sections_questions = export_params[:question_headings].present? - @show_unanswered = export_params[:unanswered_questions].present? - @show_custom_sections = export_params[:custom_sections].present? - @public_plan = false - - elsif publicly_authorized? - skip_authorization - @show_coversheet = true - @show_sections_questions = true - @show_unanswered = true - @show_custom_sections = true - @public_plan = true - - else - raise Pundit::NotAuthorizedError - end - - @hash = @plan.as_pdf(@show_coversheet) - @formatting = export_params[:formatting] || @plan.settings(:export).formattingz - @research_output_export_mode = export_params[:research_output_mode] ? export_params[:research_output_mode] : 'by_section' - @research_outputs_number = @plan.research_outputs.length + module Controllers - if @formatting.nil? - @formatting = Settings::Template::DEFAULT_SETTINGS[:formatting] - end + module PlanExports - if params.key?(:selected_phases) - @hash[:phases] = @hash[:phases].select { |p| params[:selected_phases].include?(p[:id].to_s)} - end + # CHANGES: Can now send multiple phases when exporting + def show + @plan = Plan.includes(:answers, :research_outputs).find(params[:plan_id]) - if params.key?(:selected_research_outputs) - @hash[:research_outputs] = @hash[:research_outputs].select { |d| params[:selected_research_outputs].include?(d[:id].to_s)} - end - - respond_to do |format| - format.html { show_html } - format.csv { show_csv } - format.text { show_text } - format.docx { show_docx } - format.pdf { show_pdf } - end - end - - # CHANGES: Changed footer - def show_pdf - render pdf: file_name, - margin: @formatting[:margin], - footer: { - center: d_("dmpopidor", "%{plan_title} - Last modified %{date}") % { - plan_title: @plan.title, - date: l(@plan.updated_at.to_date, format: :readable) - }, - font_size: 8, - spacing: (Integer(@formatting[:margin][:bottom]) / 2) - 4, - right: "[page] of [topage]", - encoding: "utf8" - } - end + if privately_authorized? && export_params[:form].present? + skip_authorization + @show_coversheet = export_params[:project_details].present? + @show_sections_questions = export_params[:question_headings].present? + @show_unanswered = export_params[:unanswered_questions].present? + @show_custom_sections = export_params[:custom_sections].present? + @public_plan = false + + elsif publicly_authorized? + skip_authorization + @show_coversheet = true + @show_sections_questions = true + @show_unanswered = true + @show_custom_sections = true + @public_plan = true + + else + raise Pundit::NotAuthorizedError + end + + @hash = @plan.as_pdf(@show_coversheet) + @formatting = export_params[:formatting] || @plan.settings(:export).formattingz + @research_output_export_mode = export_params[:research_output_mode] ? export_params[:research_output_mode] : 'by_section' + @research_outputs_number = @plan.research_outputs.length + + if @formatting.nil? + @formatting = Settings::Template::DEFAULT_SETTINGS[:formatting] + end + + if params.key?(:selected_phases) + @hash[:phases] = @hash[:phases].select { |p| params[:selected_phases].include?(p[:id].to_s)} + end + + if params.key?(:selected_research_outputs) + @hash[:research_outputs] = @hash[:research_outputs].select { |d| params[:selected_research_outputs].include?(d[:id].to_s)} + end + + respond_to do |format| + format.html { show_html } + format.csv { show_csv } + format.text { show_text } + format.docx { show_docx } + format.pdf { show_pdf } + format.json { show_json } + end end + + # CHANGES: Changed footer + def show_pdf + render pdf: file_name, + margin: @formatting[:margin], + footer: { + center: d_("dmpopidor", "%{plan_title} - Last modified %{date}") % { + plan_title: @plan.title, + date: l(@plan.updated_at.to_date, format: :readable) + }, + font_size: 8, + spacing: (Integer(@formatting[:margin][:bottom]) / 2) - 4, + right: "[page] of [topage]", + encoding: "utf8" + } + end + + def show_json + render "shared/export/madmp_export_templates/rda/plan", locals: { + dmp: @plan.json_fragment + } + end + end - end \ No newline at end of file + + end + +end \ No newline at end of file