diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 83c119f..6cba2fb 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -9,6 +9,10 @@ authorize Plan @plans = Plan.active(current_user).page(1) @organisationally_or_publicly_visible = Plan.organisationally_or_publicly_visible(current_user).page(1) + + if params[:plan].present? + @template = Template.find(params[:plan][:template_id]) + end end # GET /plans/new @@ -153,18 +157,18 @@ def edit plan = Plan.find(params[:id]) authorize plan - + plan, phase = Plan.load_for_phase(params[:id], params[:phase_id]) - + readonly = !plan.editable_by?(current_user.id) - + guidance_groups_ids = plan.guidance_groups.collect(&:id) - + guidance_groups = GuidanceGroup.where(published: true, id: guidance_groups_ids) # Since the answers have been pre-fetched through plan (see Plan.load_for_phase) # we create a hash whose keys are question id and value is the answer associated answers = plan.answers.reduce({}){ |m, a| m[a.question_id] = a; m } - + render('/phases/edit', locals: { base_template_org: phase.template.base_org, plan: plan, phase: phase, readonly: readonly, @@ -172,7 +176,7 @@ guidance_groups: guidance_groups, answers: answers }) end - + # PUT /plans/1 # PUT /plans/1.json def update @@ -186,7 +190,7 @@ guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i).uniq @plan.guidance_groups = GuidanceGroup.where(id: guidance_group_ids) @plan.save - + if @plan.update_attributes(attrs) format.html { redirect_to overview_plan_path(@plan), notice: success_message(_('plan'), _('saved')) } format.json {render json: {code: 1, msg: success_message(_('plan'), _('saved'))}} @@ -195,7 +199,7 @@ format.html { render action: "edit" } format.json {render json: {code: 0, msg: flash[:alert]}} end - + rescue Exception flash[:alert] = failed_update_error(@plan, _('plan')) format.html { render action: "edit" } diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 42ab240..5c0550a 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -5,4 +5,23 @@ end a.join(separator) end -end \ No newline at end of file + + # Generate a direct plan creation link based on provided template + # @param template [Template] template used for plan creation + # @param hidden [Boolean] should the link be hidden? + # @param text [String] text for the link + # @param id [String] id for the link element + def direct_link(template, hidden = false, text = nil, id = nil) + params = { org_id: template.org.id, funder_id: '-1', template_id: template.id } + cls = text.nil? ? 'direct-link' : 'direct-link btn btn-default' + style = hidden ? 'display: none' : '' + + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, id: id, style: style) do + if text.nil? + ''.html_safe + else + text.html_safe + end + end + end +end diff --git a/app/views/paginable/templates/_organisational.html.erb b/app/views/paginable/templates/_organisational.html.erb index 98c7904..997a620 100644 --- a/app/views/paginable/templates/_organisational.html.erb +++ b/app/views/paginable/templates/_organisational.html.erb @@ -64,11 +64,15 @@
  • <%= link_to _('Copy'), copy_org_admin_template_path(template.id), 'data-method': 'post' %>
  • <% if template.removable? %>
  • - <%= link_to _('Remove'), org_admin_template_path(id: template.id), + <%= link_to _('Remove'), org_admin_template_path(id: template.id), 'data-method': 'delete', rel: 'nofollow', 'data-confirm': _('Are you sure you want to remove "%{template_title}"? Any published versions will become unavailable to users.') % { template_title: template.title} %>
  • <% end %> +
  • + <%= direct_link(template, true) %> + <%= _('Copy link') %> +
  • @@ -77,4 +81,6 @@ <% end %> - \ No newline at end of file + + +<%= render 'shared/copy_link_modal' %> diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index cf57d57..f75a497 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -8,6 +8,7 @@ <%= d_('dmpopidor', 'Description') %> <%= _('Last Updated') %> <%= paginable_sort_link('templates.updated_at') %> <%= _('Download') %> + <%= _('Actions') %> @@ -22,8 +23,14 @@ <%= link_to _('DOCX'), template_export_path(template.family_id, format: :docx), target: '_blank' %>
    <%= link_to _('PDF'), template_export_path(template.family_id, format: :pdf), target: '_blank' %> + + <%= direct_link(template) %> + + <% end %> - \ No newline at end of file + + +<%= render 'shared/copy_link_modal' %> diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index 862d276..e8e9397 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -1,6 +1,6 @@ <% title _('My Dashboard') %>
    -
    +

    <%= _('My Dashboard') %>

    @@ -19,7 +19,7 @@ <%= paginable_renderise( partial: '/paginable/plans/privately_visible', controller: 'paginable/plans', - action: 'privately_visible', + action: 'privately_visible', scope: @plans, query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>

    @@ -43,3 +43,5 @@ <% end %>
    + +<%= render 'shared/create_plan_modal' unless @template.nil? %> diff --git a/app/views/shared/_copy_link_modal.html.erb b/app/views/shared/_copy_link_modal.html.erb new file mode 100644 index 0000000..c9c8d07 --- /dev/null +++ b/app/views/shared/_copy_link_modal.html.erb @@ -0,0 +1,16 @@ + diff --git a/app/views/shared/_create_plan_modal.html.erb b/app/views/shared/_create_plan_modal.html.erb new file mode 100644 index 0000000..6523ae4 --- /dev/null +++ b/app/views/shared/_create_plan_modal.html.erb @@ -0,0 +1,15 @@ + diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index bae67df..1640fe2 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -45,3 +45,4 @@ import './views/users/notification_preferences'; import './views/users/admin_grant_permissions'; import './views/super_admin/notifications/edit'; +import './views/public_templates/show'; diff --git a/lib/assets/javascripts/views/plans/index.js b/lib/assets/javascripts/views/plans/index.js index b030b67..b3cd74c 100644 --- a/lib/assets/javascripts/views/plans/index.js +++ b/lib/assets/javascripts/views/plans/index.js @@ -26,4 +26,6 @@ $(paginableSelector).on('ajax:error', '.set_test_plan', () => { // TODO adequate error handling for network error }); + + $('#create-modal').modal('show'); }); diff --git a/lib/assets/javascripts/views/public_templates/show.js b/lib/assets/javascripts/views/public_templates/show.js new file mode 100644 index 0000000..16bf07f --- /dev/null +++ b/lib/assets/javascripts/views/public_templates/show.js @@ -0,0 +1,15 @@ +$(() => { + $('.copy-link').click((e) => { + const link = $(e.currentTarget).siblings('.direct-link'); + + $('#link-modal').on('show.bs.modal', () => { + $('#link').val(link.attr('href')); + }); + }); + + $('#copy-link-btn').click(() => { + $('#link').select(); + // eslint-disable-next-line + document.execCommand('copy'); + }); +});