diff --git a/app/controllers/settings/plans_controller.rb b/app/controllers/settings/plans_controller.rb index 9708521..c9be594 100644 --- a/app/controllers/settings/plans_controller.rb +++ b/app/controllers/settings/plans_controller.rb @@ -23,6 +23,7 @@ if params[:commit] == 'Reset' s.formatting = nil s.fields = nil + s.title = nil else s.formatting = export_params[:formatting] s.fields = export_params[:fields] @@ -31,13 +32,13 @@ end if settings.save - respond_to do |format| - format.html { redirect_to(export_project_path(@plan.project)) } - end + flash[:notice] = _('Export settings updated successfully.') else - settings.formatting = nil - @export_settings = settings - render(action: :show) + flash[:alert] = _('An error has occurred while saving/resetting your export settings.') + end + respond_to do |format| + format.html { redirect_to(show_export_plan_path(@plan.id)) } + # format.json { render json: settings_json } end end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index ae52513..44b0e3a 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -100,6 +100,11 @@ @admin_details ||= self.settings(:export).fields[:admin] end + # Retrieves the title field + def title + self.settings(:export).title + end + # Export formats def as_csv diff --git a/app/views/plans/_export.html.erb b/app/views/plans/_export.html.erb index b33c2ea..cd7ed05 100644 --- a/app/views/plans/_export.html.erb +++ b/app/views/plans/_export.html.erb @@ -4,6 +4,6 @@

<%= _('Export') %> <%= plan.title %>: <%= plan.template.title %>

diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index 0b15d34..3099163 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -214,10 +214,8 @@ <% phases = plan.template.phases %> - <% if phases.any? %> - <% if phases.count == 1 then %> + <% if phases.count == 1 %> <% phases.each do |phase| %> -
<%= link_to _('Answer questions'), edit_plan_phase_path(plan,phase), :class => 'btn btn-primary' %> <%= _('Export') %> @@ -239,7 +237,7 @@

<%= section.title %>

- + <% if section.questions.any? %>
- <%end%> - <%end%> - <%end%> + <%end%> diff --git a/app/views/plans/_toolbar.html.erb b/app/views/plans/_toolbar.html.erb index 128c9bd..9208396 100644 --- a/app/views/plans/_toolbar.html.erb +++ b/app/views/plans/_toolbar.html.erb @@ -6,7 +6,7 @@ - + diff --git a/app/views/plans/show_export.html.erb b/app/views/plans/show_export.html.erb index 7e5224a..72a3781 100644 --- a/app/views/plans/show_export.html.erb +++ b/app/views/plans/show_export.html.erb @@ -12,7 +12,7 @@ <%= raw _("

From here you can download your plan in various formats. This may be useful if you need to submit your plan as part of a grant application.
Select what format you wish to use and click to 'Export'.

")%> <% if @plan.phases.count == 1 %> - <%= render :partial => "/shared/export_links", locals: {plan: @plan} %> + <%= render :partial => "/shared/export_links", locals: {plan: @plan, phase: @phan.phases[0]} %> <%else%> <% @plan.phases.each do |phase| %>
@@ -24,7 +24,7 @@
- <%= render :partial => "/shared/export_links", locals: {plan: @plan} %> + <%= render :partial => "/shared/export_links", locals: {plan: @plan, phase: phase} %>
diff --git a/app/views/settings/phases/_export_formatting_form.html.erb b/app/views/settings/phases/_export_formatting_form.html.erb index 37998ba..492b416 100644 --- a/app/views/settings/phases/_export_formatting_form.html.erb +++ b/app/views/settings/phases/_export_formatting_form.html.erb @@ -1,14 +1,14 @@ <% - plan ||= @plan @export_settings ||= plan.settings(:export) admin_settings = @export_settings.fields[:admin] question_settings = @export_settings.fields[:questions] || :all + filename = @export_settings.title.present? ? @export_settings.title : plan.title %> <% @export_settings.errors.full_messages.each do |error| %>
<%= error %>
<% end %> -<%= form_for(@export_settings, url: settings_phase_path(plan), method: :put, as: :export, remote: true) do |f| %> +<%= form_for(@export_settings, url: settings_plan_path(plan), method: :put, as: :export) do |f| %>
<%= submit_tag(_('Reset'), class: "btn btn-primary") %> <%= submit_tag(_('Save'), class: "btn btn-primary", "data-toggle" => "collapse", "data-target" => "#settings-accordion-plan-#{plan.id}") %> @@ -21,7 +21,7 @@
  • <%= label_tag("export[title]", _('File Name')) %>
    - <%= text_field_tag("export[title]", plan.title) %> + <%= text_field_tag("export[title]", filename) %>
  • @@ -37,8 +37,8 @@ name = "export[fields][admin][#{field}]" %>
  • - <%= label_tag(name, t("helpers.plan.export.#{field}")) %> - <%= check_box_tag(name, true, false) %> + <%= label_tag(name, t("helpers.plan.export.#{field}")) %> + <%= check_box_tag(name, true, admin_settings.include?(field.to_sym)) %>
  • <% end %> @@ -46,7 +46,6 @@
      - <% plan.template.phases.each do |phase| %> <% phase.sections.each do |section| %>
    1. @@ -67,7 +66,6 @@
    2. <% end %> - <% end %>
    diff --git a/app/views/shared/_export_links.html.erb b/app/views/shared/_export_links.html.erb index 4e34e8d..6898a04 100644 --- a/app/views/shared/_export_links.html.erb +++ b/app/views/shared/_export_links.html.erb @@ -7,5 +7,5 @@

    Export Settings <%= plan_settings_indicator(plan) -%>

    - <%= render(partial: "settings/phases/export_formatting_form", locals: { plan: plan }) %> + <%= render(partial: "settings/phases/export_formatting_form", locals: { plan: plan, phase: phase }) %>
    diff --git a/config/routes.rb b/config/routes.rb index 592e683..5242472 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,8 +240,7 @@ resources :roles, only: [:create, :update, :destroy] namespace :settings do - resource :plans, only: [:show, :update] - resources :phase, only: [:show, :update] + resources :plans, only: [:update] end resources :token_permission_types, only: [:index]