From bba9570228a2dfed4e3a3cb11f61e76ac096157c Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 28 Feb 2023 11:36:27 +0100 Subject: [PATCH 1/3] Fix protocol duplication in table [SCI-7990] --- app/datatables/protocols_datatable.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 72f1b874b..3efc0e9b6 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -89,7 +89,8 @@ class ProtocolsDatatable < CustomDatatable { DT_RowId: record.id, DT_RowAttr: { - 'data-permissions-url': permissions_protocol_path(record) + 'data-permissions-url': permissions_protocol_path(record), + 'data-clone-url': clone_protocol_path(record) }, '1': name_html(record), '2': record.code, From 219814ec06758d769abe8175d1d1f0269500d4ed Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 28 Feb 2023 13:11:49 +0100 Subject: [PATCH 2/3] Change protocol clone to support bulk in future [SCI-7990] --- app/controllers/protocols_controller.rb | 2 +- app/datatables/protocols_datatable.rb | 2 +- config/routes.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index fe8fa992b..cff4b10f7 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1162,7 +1162,7 @@ class ProtocolsController < ApplicationController def check_clone_permissions load_team_and_type - protocol = Protocol.find_by(id: params[:id]) + protocol = Protocol.find_by(id: params[:ids][0]) @original = protocol.latest_published_version || protocol if @original.blank? || diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 3efc0e9b6..1c057a211 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -90,7 +90,7 @@ class ProtocolsDatatable < CustomDatatable DT_RowId: record.id, DT_RowAttr: { 'data-permissions-url': permissions_protocol_path(record), - 'data-clone-url': clone_protocol_path(record) + 'data-clone-url': clone_protocols_path(ids: [record.id]) }, '1': name_html(record), '2': record.code, diff --git a/config/routes.rb b/config/routes.rb index afa3ee4dc..55af0f173 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -585,7 +585,6 @@ Rails.application.routes.draw do put 'name', to: 'protocols#update_name' patch 'authors', to: 'protocols#update_authors' patch 'keywords', to: 'protocols#update_keywords' - post 'clone', to: 'protocols#clone' get 'unlink_modal', to: 'protocols#unlink_modal' post 'unlink', to: 'protocols#unlink' get 'revert_modal', to: 'protocols#revert_modal' @@ -618,6 +617,7 @@ Rails.application.routes.draw do post 'make_private', to: 'protocols#make_private' post 'archive', to: 'protocols#archive' post 'restore', to: 'protocols#restore' + post 'clone', to: 'protocols#clone' post 'import', to: 'protocols#import' post 'protocolsio_import_create', to: 'protocols#protocolsio_import_create' From a3ffb38d2b95511f67900d9b5a3eca98b18f49bb Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 28 Feb 2023 14:22:02 +0100 Subject: [PATCH 3/3] Refactor cloning feature to better prepare for bulk clone [SCI-7990] --- app/assets/javascripts/protocols/index.js | 26 +++++++++++-------- app/datatables/protocols_datatable.rb | 3 +-- .../protocols/index/_action_toolbar.html.erb | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index f7d42bb4e..c6a72198f 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -495,25 +495,29 @@ var ProtocolsIndex = (function() { function initDuplicateProtocols() { $('.protocols-index').on('click', '#duplicateProtocol', function() { - duplicateProtocols(rowsSelected[0]); + duplicateProtocols($(this)); }); } - function duplicateProtocols(id) { - var row = $("tr[data-row-id='" + id + "']"); - animateSpinner(); - - $.post(row.attr('data-clone-url'), (data) => { - animateSpinner(null, false); - HelperModule.flashAlertMsg(data.message, 'success'); - reloadTable(); - }).error((data) => { + function duplicateProtocols($el) { + $.ajax( + { + type: 'POST', + url: $el.data('url'), + data: JSON.stringify({ ids: rowsSelected }), + contentType: 'application/json' + }, + (data) => { + animateSpinner(null, false); + HelperModule.flashAlertMsg(data.message, 'success'); + reloadTable(); + } + ).error((data) => { animateSpinner(null, false); HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); }); } - function initLinkedChildrenModal() { // Only do this if the repository is public/private if (repositoryType !== 'archive') { diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 1c057a211..72f1b874b 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -89,8 +89,7 @@ class ProtocolsDatatable < CustomDatatable { DT_RowId: record.id, DT_RowAttr: { - 'data-permissions-url': permissions_protocol_path(record), - 'data-clone-url': clone_protocols_path(ids: [record.id]) + 'data-permissions-url': permissions_protocol_path(record) }, '1': name_html(record), '2': record.code, diff --git a/app/views/protocols/index/_action_toolbar.html.erb b/app/views/protocols/index/_action_toolbar.html.erb index 3d7260ea0..3ac83ba6a 100644 --- a/app/views/protocols/index/_action_toolbar.html.erb +++ b/app/views/protocols/index/_action_toolbar.html.erb @@ -7,7 +7,7 @@ <%= t("protocols.index.action_toolbar.access") %> -