diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb
index 9e7a7d5..4519ea4 100644
--- a/app/controllers/plans_controller.rb
+++ b/app/controllers/plans_controller.rb
@@ -2,14 +2,18 @@
require 'pp'
helper SettingsTemplateHelper
- after_action :verify_authorized
+ after_action :verify_authorized, except: ['public_index', 'public_export']
def index
authorize Plan
@plans = current_user.plans
end
-
+ # GET /plans/public_index
+ # ------------------------------------------------------------------------------------
+ def public_index
+ @plans = Plan.publicly_visible
+ end
# GET /plans/new
# ------------------------------------------------------------------------------------
@@ -235,96 +239,6 @@
end
end
-
-# TODO: Remove these endpoints now that we're no longer using them
-=begin
- def section_answers
- @plan = Plan.find(params[:id])
- authorize @plan
- respond_to do |format|
- format.json { render json: @plan.section_answers(params[:section_id]) }
- end
- end
-
- def locked
- @plan = Plan.find(params[:id])
- authorize @plan
- if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then
- respond_to do |format|
- format.json { render json: @plan.locked(params[:section_id],current_user.id) }
- end
- else
- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
- end
- end
-
- def delete_recent_locks
- @plan = Plan.find(params[:id])
- authorize @plan
- if user_signed_in? && @plan.editable_by(current_user.id) then
- respond_to do |format|
- if @plan.delete_recent_locks(current_user.id)
- format.html { render action: "edit" }
- else
- format.html { render action: "edit" }
- end
- end
- else
- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
- end
- end
-
- def unlock_all_sections
- @plan = Plan.find(params[:id])
- authorize @plan
- if user_signed_in? && @plan.editable_by(current_user.id) then
- respond_to do |format|
- if @plan.unlock_all_sections(current_user.id)
- format.html { render action: "edit" }
- else
- format.html { render action: "edit" }
- end
- end
- else
- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
- end
- end
-
- def lock_section
- @plan = Plan.find(params[:id])
- authorize @plan
- if user_signed_in? && @plan.editable_by(current_user.id) then
- respond_to do |format|
- if @plan.lock_section(params[:section_id], current_user.id)
- format.html { render action: "edit" }
- else
- format.html { render action: "edit" }
- format.json { render json: @plan.errors, status: :unprocessable_entity }
- end
- end
- else
- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
- end
- end
-
- def unlock_section
- @plan = Plan.find(params[:id])
- authorize @plan
- if user_signed_in? && @plan.editable_by(current_user.id) then
- respond_to do |format|
- if @plan.unlock_section(params[:section_id], current_user.id)
- format.html { render action: "edit" }
-
- else
- format.html { render action: "edit" }
- end
- end
- else
- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
- end
- end
-=end
-
def answer
@plan = Plan.find(params[:id])
authorize @plan
@@ -393,6 +307,52 @@
end
end
+ # GET /plans/[:plan_slug]/public_export
+ # -------------------------------------------------------------
+ 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)
+
+ 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
+ redirect_to show_export_plan_path(@plan), notice: _('Unable to download the DMP at this time.')
+ end
+ end
+ end
+
def duplicate
plan = Plan.find(params[:id])
authorize plan
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 78ecb7c..540d199 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -2,6 +2,7 @@
class RegistrationsController < Devise::RegistrationsController
def edit
+ @user.create_default_preferences
@languages = Language.all.order("name")
@orgs = Org.where(parent_id: nil).order("name")
@other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id)
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
index 6f38009..d111b3f 100644
--- a/app/controllers/static_pages_controller.rb
+++ b/app/controllers/static_pages_controller.rb
@@ -15,59 +15,4 @@
def roadmap
end
-
- def public_plans
- @plans = Plan.publicly_visible
- end
-
- # GET /plans/[:plan_slug]/public_export
- # -------------------------------------------------------------
- def public_export
- redirect_to public_plans_path, notice: _('Exporting public plan is under development. Apologies for any inconvience.')
- #@plan = Plan.find(params[:id])
-
- # Force PDF response
- #request.format = :pdf
-
- # if the project is designated as public
- #if @plan.visibility == :publicly_visible
- # if !@plan.nil?
- # @exported_plan = ExportedPlan.new.tap do |ep|
- # ep.plan = @plan
- # ep.user = current_user ||= nil
- # #ep.format = request.format.try(:symbol)
- # ep.format = request.format.to_sym
- # plan_settings = @plan.settings(:export)
-
- # Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value|
- # ep.settings(:export).send("#{key}=", plan_settings.send(key))
- # end
- # end
-
- # @exported_plan.save! # FIXME: handle invalid request types without erroring?
- # file_name = @exported_plan.project_name
-
- # respond_to do |format|
- # format.pdf do
- # @formatting = @plan.settings(:export).formatting
- # render pdf: file_name,
- # margin: @formatting[:margin],
- # footer: {
- # center: t('helpers.plan.export.pdf.generated_by'),
- # font_size: 8,
- # spacing: (@formatting[:margin][:bottom] / 2) - 4,
- # right: '[page] of [topage]'
- # }
- # end
- # end
-
- # else
- # the project has no plans for some reason
- # redirect_to public_plans_path, notice: _('The plan is incomplete.')
- # end
- #else
- # Otherwise redirect to the home page with an unauthorized message
- # redirect_to public_plans_path, notice: _('This account does not have access to that plan.')
- #end
- end
end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 9103a5e..08ed05b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -283,8 +283,10 @@
##
# User Notification Preferences
def create_default_preferences
- # Set the default preferences if this is a new user
- self.prefs = self.class.create_default_preferences if self.id.nil?
+ # Set the default preferences for a new user or if existing user if null
+ if self.id.nil? || self.prefs == {}
+ self.prefs = self.class.create_default_preferences
+ end
end
def self.create_default_preferences
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index 8762484..8cb10ea 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -34,7 +34,6 @@
-
- <%= raw _('
The table below lists the plans that you have created, and any that have been shared with you by others.These can be edited, shared, exported or deleted at anytime.
')%> - ++ <%= raw _('
The table below lists the plans that you have created, and any that have been shared with you by others.These can be edited, shared, exported or deleted at anytime.
')%> + - <%= render(partial: "toolbar") %> -| <%= _('Plan') %> | -<%= _('Template') %> | -<%= _('Edited') %> | -<%= _('Role') %> | -<%= _('Visibility') %> | -<%= _('Test') %> | -<%= _('Select an Action') %> | - - + <%= render(partial: "toolbar") %> +
|---|
| <%= _('Plan') %> | +<%= _('Template') %> | +<%= _('Edited') %> | +<%= _('Role') %> | +<%= _('Visibility') %> | +<%= _('Test') %> | +<%= _('Select an Action') %> | +
|---|---|---|---|---|---|---|
| <%= plan.title %> | -<%= plan.template.title %> | -<%= l(plan.latest_update.to_date, formats: :short) %> | -<%= display_role(plan.roles.find_by(user: current_user)) %> | -<%= display_visibility(plan.visibility) %> | -- <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> - | -- <% if plan.editable_by?(current_user.id) then %> - <%= link_to _('Edit'), plan_path(plan), :class => "dmp_table_link"%> + |
| <%= plan.title %> | +<%= plan.template.title %> | +<%= l(plan.latest_update.to_date, formats: :short) %> | +<%= display_role(plan.roles.find_by(user: current_user)) %> | +<%= display_visibility(plan.visibility) %> | ++ <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> + | ++ <% if plan.editable_by?(current_user.id) then %> + <%= link_to _('Edit'), + plan_path(plan), + class: "dmp_table_link" %> - <% if plan.administerable_by?(current_user.id) then %> - <%= link_to _('Share'), share_plan_path(plan), :class => "dmp_table_link"%> - <% end %> + <% if plan.administerable_by?(current_user.id) then %> + <%= link_to _('Share'), + share_plan_path(plan), + class: "dmp_table_link" %> + <% end %> - <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%> + <%= link_to _('Export'), + show_export_plan_path(plan), + class: "dmp_table_link" %> - <%= link_to _('Duplicate'), duplicate_plan_path(plan), method: :post, remote: true, :class => "dmp_table_link"%> + <%= link_to _('Duplicate'), + duplicate_plan_path(plan), + class: "dmp_table_link" %> - <% if plan.owned_by?(current_user.id) then %> - <%= link_to _('Delete'), plan_path(plan), :class => "dmp_table_link", - :method => :delete, :data => { - :confirm => _('Are you sure you wish to delete this plan? If the plan is being shared with other users, by deleting it from your list, the plan will be deleted from their plan list as well') - }%> - <% end %> - <% else %> - <%= link_to _('View'), plan_path(plan), :class => "dmp_table_link"%> - <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%> - <% end %> - | -
- <%= raw _("
Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
")%> - ++ <%= raw _("
Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
")%> + <% end %>- <%= link_to _('Create plan'), + <%= link_to _('Create plan'), new_plan_path, class: "btn btn-primary" %> diff --git a/app/views/plans/public_export.pdf.erb b/app/views/plans/public_export.pdf.erb new file mode 100644 index 0000000..b9ab084 --- /dev/null +++ b/app/views/plans/public_export.pdf.erb @@ -0,0 +1,68 @@ + + +
+ +<%= admin_field_t(field.to_s) -%> <%= value -%>
+ <% else %> +<%= admin_field_t(field.to_s) -%> <%= _('-') %>
+ <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> + <% questions = @exported_plan.questions_for_section(section.id) + if questions.present? + %> +<%= _('Question not answered.') -%>
+ <% else %> + <% q_format = question.question_format %> + <% if q_format.option_based? %> ++ <%= _('Public DMPs are plans created using the %{application_name} and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines.') % {application_name: Rails.application.config.branding[:application][:name]} %> +
+ + <%= render(partial: "toolbar") %> +| <%= _('Plan') %> | +<%= _('Template') %> | +<%= _('Organisation') %> | +<%= _('Owner') %> | +<%= _('Download') %> | +
|---|---|---|---|---|
| <%= plan.title %> | +<%= plan.template.title %> | +<%= plan.owner.org.nil? ? _('Not Applicable') : plan.owner.org.name %> | +<%= plan.owner.name %> | ++ <%= link_to _('PDF'), + public_export_path(plan, format: :pdf), + class: "dmp_table_link" %> + | +
+ <%= _("There are currently no public DMPs.")%> +
+<% end %> diff --git a/app/views/static_pages/public_export.html.erb b/app/views/static_pages/public_export.html.erb deleted file mode 100644 index 37f1a18..0000000 --- a/app/views/static_pages/public_export.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -<%- model_class = Project -%> - - -<%= render :partial => "/projects/project_title", locals: {project: @project} %> - - -<%= render :partial => "project_nav_tabs", locals: {project: @project, active: "export_page"} %> - - -<%= t("helpers.plan.export.#{field}") -%> <%= value -%>
- <% end %> - <% end %> - - <% @exported_plan.sections.each do |section| %> -<%= t('helpers.plan.export.pdf.question_not_answered') -%>
- <% else %> - <% q_format = question.question_format%> - - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || - q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> -- <%= _('Public DMPs are plans created using the DMPTool and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines.') %> -
- -| <%= _('Name') %> | -<%= _('Template') %> | -<%= _('Organization') %> | -<%= _('Owner') %> | - -
|---|---|---|---|
- <%= _("There are no public DMPs.")%> -
-<% end %> diff --git a/config/routes.rb b/config/routes.rb index c2e9f61..1cd4960 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,8 +78,8 @@ get "help" => 'static_pages#help' get "roadmap" => 'static_pages#roadmap' get "terms" => 'static_pages#termsuse' - get "public_plans" => 'static_pages#public_plans' - get "public_export/:id" => 'static_pages#public_export', as: 'public_export' + get "public_plans" => 'plans#public_index' + get "public_export/:id" => 'plans#public_export', as: 'public_export' get "existing_users" => 'existing_users#index' #post 'contact_form' => 'contacts', as: 'localized_contact_creation' diff --git a/lib/assets/javascripts/toolbar.js b/lib/assets/javascripts/toolbar.js index 219084d..6ffa33f 100644 --- a/lib/assets/javascripts/toolbar.js +++ b/lib/assets/javascripts/toolbar.js @@ -1,76 +1,6 @@ $(document).ready(function() { - - var toolbar = $('.dmp_toolbar').first(), - form = null; - - $('#toolbar_configure').click(function(e) { - e.preventDefault(); - - if (form) { - form.toggle(); - } else { - $.get('/settings/projects.json') - .done(buildSettingsForm) - .fail(function(data) { - // Handle failure? - }); - } - }); - - // FIXME: it would be simpler just to return the partial from - // Settings::ProjectsController#show, but that would perhaps - // mean responding to a JSON request with HTML. - function buildSettingsForm(data) { - if (!form) - form = $(''); - - var table = $('' + __('The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box.') + '
'); - - // Default name column - table.before(''); - thead.append('