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/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/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index c980f4f..75d285a 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -36,6 +36,10 @@ <%= link_to _('Home'), root_path %> <% end %> + +
  • > + <%= link_to _('Public DMPs'), public_plans_path %> +
  • > <%= link_to _('About'), about_us_path %> @@ -48,22 +52,25 @@
  • > <%= link_to _('Help'), help_path %>
  • - <% if MANY_LANGUAGES %> - - - <% end %> + + <% if !user_signed_in? %> + <% if MANY_LANGUAGES %> + + + <% end %> + <% end %> <% end %> diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index 9d77329..b1b4e8a 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -3,76 +3,100 @@ <% javascript "plans/index.js" %>

    - <%= _('My plans') %> + <%= _('My plans') %>

    <% if @plans.count > 0 %> -

    - <%= 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") %> - - - - - - - - - - - + <%= render(partial: "toolbar") %> +
    <%= _('Plan') %><%= _('Template') %><%= _('Edited') %><%= _('Role') %><%= _('Visibility') %><%= _('Test') %><%= _('Select an Action') %>
    + + + + + + + + + + + + <% @plans.each do |plan| %> - - - - - - - - + + + + + + + - + <% if plan.owned_by?(current_user.id) then %> + <%= link_to raw(''), + plan_path(plan), + class: "dmp_table_link", + title: _('Delete'), + 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 raw(''), + plan_path(plan), + class: "dmp_table_link", + title: _('View') %> + + <%= link_to raw(''), + show_export_plan_path(plan), + class: "dmp_table_link", + title: _('Export') %> + <% end %> + + <% end %> - -
    <%= _('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 raw(''), + plan_path(plan), + class: "dmp_table_link", + title: _('Edit') %> - <% 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 raw(''), + share_plan_path(plan), + class: "dmp_table_link", + title: _('Share') %> + <% end %> - <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%> + <%= link_to raw(''), + show_export_plan_path(plan), + class: "dmp_table_link", + title: _('Export') %> - <%= link_to _('Duplicate'), duplicate_plan_path(plan), method: :post, remote: true, :class => "dmp_table_link"%> + <%= link_to raw(''), + duplicate_plan_path(plan), + class: "dmp_table_link", + title: _('Copy/Duplicate') %> - <% 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 %> -
    - + + + <% else %> -

    - <%= 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_index.html.erb b/app/views/plans/public_index.html.erb new file mode 100644 index 0000000..0542cfe --- /dev/null +++ b/app/views/plans/public_index.html.erb @@ -0,0 +1,46 @@ +<%- model_class = Plan -%> +<% javascript "toolbar.js" %> + +

    + <%= raw _('Public DMPs') %> +

    + + +<% if @plans.count > 0 %> +

    + <%= _('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") %> + + + + + + + + + + + + <% @plans.each do |plan| %> + + + + + + + + <% end %> + +
    <%= _('Plan') %><%= _('Template') %><%= _('Organisation') %><%= _('Owner') %><%= _('Download') %>
    <%= plan.title %><%= plan.template.title %><%= plan.owner.org.name %><%= plan.owner.name %> + <%= link_to raw(''), + public_export_path(plan), + class: "dmp_table_link", + title: _('Download PDF') %> +
    +<% else %> +

    + <%= _("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"} %> - - -
    - - <%= raw t('helpers.project.export_text_html')%> - - - <% if @project.plans.any? %> - <% if @project.plans.count == 1 then %> - <% @project.plans.each do |plan| %> - <%= render :partial => "/shared/export_links", locals: {plan: plan} %> - <% end %> - <%else%> - <% @project.plans.each do |plan| %> -
    -
    - -
    -
    - <%= render :partial => "/shared/export_links", locals: {plan: plan} %> -
    -
    -
    -
    - <%end%> - <%end%> - <%end%> - -
    \ No newline at end of file diff --git a/app/views/static_pages/public_export.pdf.erb b/app/views/static_pages/public_export.pdf.erb deleted file mode 100644 index 77d68cb..0000000 --- a/app/views/static_pages/public_export.pdf.erb +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - <% if @plan.project.dmptemplate.phases.count > 1 then %> - <%= "#{@plan.project.title} - #{@plan.title}" %> - <% else %> - <%= @plan.project.title %> - <% end %> - - - - -

    <%= @plan.title %>

    - <% @exported_plan.admin_details.each do |field| - value = @exported_plan.send(field) - if value.present? - %> -

    <%= t("helpers.plan.export.#{field}") -%> <%= value -%>

    - <% end %> - <% end %> - - <% @exported_plan.sections.each do |section| %> -

    <%= section.title %>

    - <% questions = @exported_plan.questions_for_section(section.id) %> - <% questions.each_with_index do |question, idx| %> -
    - <% unless idx == 0 && question.text == section.title %> -

    <%= raw question.text %>

    - <% end %> - <% answer = @plan.answer(question.id, false) %> - <% if answer.nil? then %> -

    <%= 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%> - - - <% if question.option_comment_display == true then%> - <% if !answer.text.nil? then %> - <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> - <%end%> - <%end%> - <%else%> - - <% if !answer.text.nil? then %> - <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> - <%end%> - <% end %> - <% end %> -
    - <% end %> - <% end %> - - \ No newline at end of file diff --git a/app/views/static_pages/public_plans.html.erb b/app/views/static_pages/public_plans.html.erb deleted file mode 100644 index 6a14750..0000000 --- a/app/views/static_pages/public_plans.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -<%- model_class = Plan -%> -

    - <%= raw _('Public DMPs') %> -

    - - -<% if @plans.count > 0 %> -

    - <%= _('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.') %> -

    - - - - - - - - - - - - - <% @plans.each do |plan| %> - - <% ['non_link_name', 'template', 'organisation', 'owner'].each do |column| %> - <%= plan_list_column_body(column, plan) %> - <% end %> - - - - - <% end %> - -
    <%= _('Name') %><%= _('Template') %><%= _('Organization') %><%= _('Owner') %>
    -<% else %> -

    - <%= _("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 = $('
    ').appendTo(form), - thead = $('').appendTo(table), - tbody = $('').appendTo(table), - tfoot = $('').appendTo(table), - cols = data.all_columns, - selected = []; - - // grab the keys from the data.selected_columns hash - $.each(data.selected_columns, function(k,v){ - selected.push(k); - }); - - table.before(''); // PUT not POST - table.before(''); // Auth token - table.after('

    ' + __('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(''); - tbody.append('') - - for (var i = 0, len = cols.length; i < len; i++) { - var title = cols[i].replace(/^\w|_/g, function(c) { return c === '_' ? ' ' : c.toUpperCase(); }), - label = $('').appendTo(thead), - container = $('').appendTo(tbody), - input = $('').appendTo(container); - - if (selected.indexOf(cols[i]) > -1) - input.attr('checked', 'checked'); - } - - thead.append(''); - tbody.append('') - - var submit = $('').appendTo(tfoot); - cancel = $('' + __('Cancel') + '').appendTo(tfoot); - - cancel.click(function(e) { - e.preventDefault(); - form.toggle(); - }); - - toolbar.before(form); - } - /* - 'My plans' filtering + 'Plans' filtering */ var no_matches_message = $('' + __('No matches') + '').appendTo($('#dmp_table tbody')), rows = $('#dmp_table tbody tr'), diff --git a/lib/assets/stylesheets/roadmap.scss b/lib/assets/stylesheets/roadmap.scss index daad890..22b9763 100644 --- a/lib/assets/stylesheets/roadmap.scss +++ b/lib/assets/stylesheets/roadmap.scss @@ -103,25 +103,25 @@ div.roadmap-info-box { position: absolute; - float: right; + float: right; top: 180px; right: 12%; background-color: $white; padding: 8px 20px; border-radius: 5px; - vertical-align: middle; - - span { - padding-left: 30px; - } - .fa { - position: absolute; - top: 10px; - background: transparent; - color: $black; - font-size: 16pt; - margin-right: 15px; - } + vertical-align: middle; + + span { + padding-left: 30px; + } + .fa { + position: absolute; + top: 10px; + background: transparent; + color: $black; + font-size: 16pt; + margin-right: 15px; + } } table.dmp_table{ @@ -132,23 +132,28 @@ margin-bottom: 20px; table-layout: fixed; - thead th, tbody td { - padding: 6px 15px 6px 6px; - overflow: hidden; - } + thead th, tbody td { + padding: 6px 15px 6px 6px; + overflow: hidden; + } - .col-tiny { - width: 5%; - } - .col-small { - width: 10%; - } - .col-medium { - width: 20%; - } - th.col-large { - width: 35%; - } + .col-tiny { + width: 5%; + } + .col-small { + width: 10%; + } + .col-medium { + width: 20%; + } + th.col-large { + width: 35%; + } + + a.dmp_table_link i { + font-size: 14pt; + margin-right: 5px; + } }