From 2cd55a42c8f06055edd10580175b882275e0d98f Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Wed, 4 Jul 2018 11:35:58 +0200 Subject: [PATCH 1/9] Added direct link for plan creation from templates list --- .../paginable/templates/_publicly_visible.html.erb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index 824234e6ba..cc0fea5e45 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -12,6 +12,7 @@ <%= _('Sample Plans') %>
<%= _('(if available)') %> <%= sample_plans_tooltip %> + <%= _('Actions') %> @@ -42,8 +43,17 @@ <%= sanitize links_to_a_elements(template.links['sample_plan'], '
') %> + + <%= link_to(plans_url(plan: { + org_id: template.org.id, + funder_id: '-1', + template_id: template.id, + }), method: :post, title: _('Create plan')) do %> + + <% end %> + <% end %> - \ No newline at end of file + From ce082eb4dc68474e33c0c1d90812cd7c4f85ae72 Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Fri, 6 Jul 2018 11:30:50 +0200 Subject: [PATCH 2/9] Moved link generation to helper --- app/helpers/template_helper.rb | 11 +++++++++++ .../paginable/templates/_publicly_visible.html.erb | 10 ++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 3905e98735..28bc119dd1 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,4 +33,15 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end + def direct_link(template) + params = { + org_id: template.org.id, + funder_id: '-1', + template_id: template.id, + } + + link_to(plans_url(plan: params), method: :post, title: _('Create plan')) do + ''.html_safe + end + end end diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index cc0fea5e45..c474a35438 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -44,14 +44,8 @@ <%= sanitize links_to_a_elements(template.links['sample_plan'], '
') %> - <%= link_to(plans_url(plan: { - org_id: template.org.id, - funder_id: '-1', - template_id: template.id, - }), method: :post, title: _('Create plan')) do %> - - <% end %> - + <%= direct_link(template) %> + <% end %> From 41b46345197a44c2a732f1a7350867bb49075ca5 Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Fri, 6 Jul 2018 12:01:07 +0200 Subject: [PATCH 3/9] Added modal for link copy --- app/helpers/template_helper.rb | 2 +- .../templates/_publicly_visible.html.erb | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 28bc119dd1..51783f4784 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -40,7 +40,7 @@ def direct_link(template) template_id: template.id, } - link_to(plans_url(plan: params), method: :post, title: _('Create plan')) do + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: 'direct-link') do ''.html_safe end end diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index c474a35438..556f8fd222 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -45,9 +45,30 @@ <%= direct_link(template) %> + <% end %> + + From 2bf6fe37b3c2458b8fd272efa40ebb0425758eb0 Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Fri, 6 Jul 2018 15:41:55 +0200 Subject: [PATCH 4/9] Added JS for link copy --- app/javascript/packs/application.js | 1 + app/javascript/views/public_templates/show.js | 15 +++++++++++++++ .../templates/_publicly_visible.html.erb | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 app/javascript/views/public_templates/show.js diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index adbe7ed762..d612b09ed2 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -47,3 +47,4 @@ import '../views/usage/index'; 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/app/javascript/views/public_templates/show.js b/app/javascript/views/public_templates/show.js new file mode 100644 index 0000000000..16bf07f7dc --- /dev/null +++ b/app/javascript/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'); + }); +}); diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index 556f8fd222..124002b7ce 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -45,7 +45,7 @@ <%= direct_link(template) %> - + <% end %> From 0a6ee390e1ca98f03917589ffbaa84e9dac54148 Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Mon, 9 Jul 2018 11:01:33 +0200 Subject: [PATCH 5/9] Improved modal style and moved it to a partial --- .../templates/_publicly_visible.html.erb | 20 +------------------ app/views/shared/_copy_link_modal.html.erb | 16 +++++++++++++++ 2 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 app/views/shared/_copy_link_modal.html.erb diff --git a/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index 124002b7ce..f74d4041b4 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -53,22 +53,4 @@ - +<%= render 'shared/copy_link_modal' %> 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 0000000000..5f62bfc20a --- /dev/null +++ b/app/views/shared/_copy_link_modal.html.erb @@ -0,0 +1,16 @@ + From 6026800f38d04642ae5e9b816bcd1066ee700acf Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Mon, 9 Jul 2018 11:02:19 +0200 Subject: [PATCH 6/9] Added template link copy to admin area (organisation templates) --- app/helpers/template_helper.rb | 4 ++-- .../templates/_organisational.html.erb | 22 ++++++++++++------- .../templates/_publicly_visible.html.erb | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 51783f4784..adff9270ef 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,14 +33,14 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end - def direct_link(template) + def direct_link(template, hidden = false) params = { org_id: template.org.id, funder_id: '-1', template_id: template.id, } - link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: 'direct-link') do + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: 'direct-link', style: hidden ? 'display: none' : '') do ''.html_safe end end diff --git a/app/views/paginable/templates/_organisational.html.erb b/app/views/paginable/templates/_organisational.html.erb index e19df20425..0fdba4df2a 100644 --- a/app/views/paginable/templates/_organisational.html.erb +++ b/app/views/paginable/templates/_organisational.html.erb @@ -76,14 +76,18 @@ 'data-confirm': _('Are you sure you want to remove "%{template_title}"? Any published versions will become unavailable to users.') % { template_title: template.title} %> <% end %> -
  • <%= link_to template_export_org_admin_template_url(template, format: :pdf), - title: export_as_pdf, - target: '_blank', - class: 'has-new-window-popup-info' do %> - <%= export_as_pdf %> - <%= _('(new window)') %> - <%= _('Opens in new window') %> - <% end %> +
  • <%= link_to template_export_org_admin_template_url(template, format: :pdf), + title: export_as_pdf, + target: '_blank', + class: 'has-new-window-popup-info' do %> + <%= export_as_pdf %> + <%= _('(new window)') %> + <%= _('Opens in new window') %> + <% end %> +
  • +
  • + <%= direct_link(template, true) %> + <%= _('Copy link') %>
  • @@ -94,3 +98,5 @@ + +<%= 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 f74d4041b4..60c5b41937 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -45,7 +45,7 @@ <%= direct_link(template) %> - + <% end %> From 954256529674b5b3393db4bb785a896594b8045b Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Mon, 9 Jul 2018 14:59:35 +0200 Subject: [PATCH 7/9] Added confirmation modal for creation link --- app/controllers/plans_controller.rb | 4 ++++ app/helpers/template_helper.rb | 18 ++++++++++-------- app/javascript/views/plans/index.js | 2 ++ .../templates/_publicly_visible.html.erb | 8 ++++---- app/views/plans/index.html.erb | 2 ++ app/views/shared/_copy_link_modal.html.erb | 2 +- app/views/shared/_create_plan_modal.html.erb | 15 +++++++++++++++ 7 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 app/views/shared/_create_plan_modal.html.erb diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 361660b3b5..2a3fccff17 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -17,6 +17,10 @@ def index @organisationally_or_publicly_visible = Plan.organisationally_or_publicly_visible(current_user).page(1) end + + if params[:plan].present? + @template = Template.find(params[:plan][:template_id]) + end end # GET /plans/new diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index adff9270ef..bddc015ed6 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,15 +33,17 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end - def direct_link(template, hidden = false) - params = { - org_id: template.org.id, - funder_id: '-1', - template_id: template.id, - } + def direct_link(template, hidden = false, text = 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: 'direct-link', style: hidden ? 'display: none' : '') do - ''.html_safe + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, style: style) do + if text.nil? + ''.html_safe + else + text.html_safe + end end end end diff --git a/app/javascript/views/plans/index.js b/app/javascript/views/plans/index.js index b030b67f4e..b3cd74c1eb 100644 --- a/app/javascript/views/plans/index.js +++ b/app/javascript/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/app/views/paginable/templates/_publicly_visible.html.erb b/app/views/paginable/templates/_publicly_visible.html.erb index 60c5b41937..df28a59265 100644 --- a/app/views/paginable/templates/_publicly_visible.html.erb +++ b/app/views/paginable/templates/_publicly_visible.html.erb @@ -8,11 +8,11 @@ <%= _('Organisation Name') %> <%= paginable_sort_link('orgs.name') %> <%= _('Last Updated') %> <%= paginable_sort_link('templates.updated_at') %> <%= _('Funder Links') %> + <%= _('Actions') %> <%= _('Sample Plans') %>
    <%= _('(if available)') %> <%= sample_plans_tooltip %> - <%= _('Actions') %> @@ -40,13 +40,13 @@ <%= sanitize links_to_a_elements(template.links['funder'], '
    ') %> - - <%= sanitize links_to_a_elements(template.links['sample_plan'], '
    ') %> - <%= direct_link(template) %> + + <%= sanitize links_to_a_elements(template.links['sample_plan'], '
    ') %> + <% end %> diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index e3d33cd997..2687edb611 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -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 index 5f62bfc20a..c9c8d07441 100644 --- a/app/views/shared/_copy_link_modal.html.erb +++ b/app/views/shared/_copy_link_modal.html.erb @@ -10,7 +10,7 @@ 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 0000000000..6523ae48c0 --- /dev/null +++ b/app/views/shared/_create_plan_modal.html.erb @@ -0,0 +1,15 @@ + From 42f8183702f159ad2181d14fd839e546d837afb5 Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Fri, 13 Jul 2018 16:31:42 +0200 Subject: [PATCH 8/9] Minor changes for direct_link helper --- app/helpers/template_helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index bddc015ed6..10bfa22184 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,12 +33,17 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end - def direct_link(template, hidden = false, text = nil) + # Generate a direct plan creation link with 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] HTML 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, style: style) do + link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, id: id, style: style) do if text.nil? ''.html_safe else From adc78a901b4f876421956e88ee520d78e74892ac Mon Sep 17 00:00:00 2001 From: Quentin Sonrel Date: Fri, 13 Jul 2018 16:35:00 +0200 Subject: [PATCH 9/9] Fixed typo in YARD doc --- app/helpers/template_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/template_helper.rb b/app/helpers/template_helper.rb index 10bfa22184..2a8392eddc 100644 --- a/app/helpers/template_helper.rb +++ b/app/helpers/template_helper.rb @@ -33,11 +33,11 @@ def links_to_a_elements(links, separator = ", ") a.join(separator) end - # Generate a direct plan creation link with based on provided template + # 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 hidden [Boolean] should the link be hidden? # @param text [String] text for the link - # @param id [String] HTML id for the link element + # @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'