Merge pull request #5038 from artoscinote/ma_SCI_7990

Fix protocol duplication in table [SCI-7990]
This commit is contained in:
artoscinote 2023-02-28 14:28:08 +01:00 committed by GitHub
commit fab7d9c3d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 14 deletions

View file

@ -498,25 +498,29 @@ var ProtocolsIndex = (function() {
function initDuplicateProtocols() { function initDuplicateProtocols() {
$('.protocols-index').on('click', '#duplicateProtocol', function() { $('.protocols-index').on('click', '#duplicateProtocol', function() {
duplicateProtocols(rowsSelected[0]); duplicateProtocols($(this));
}); });
} }
function duplicateProtocols(id) { function duplicateProtocols($el) {
var row = $("tr[data-row-id='" + id + "']"); $.ajax(
animateSpinner(); {
type: 'POST',
$.post(row.attr('data-clone-url'), (data) => { url: $el.data('url'),
data: JSON.stringify({ ids: rowsSelected }),
contentType: 'application/json'
},
(data) => {
animateSpinner(null, false); animateSpinner(null, false);
HelperModule.flashAlertMsg(data.message, 'success'); HelperModule.flashAlertMsg(data.message, 'success');
reloadTable(); reloadTable();
}).error((data) => { }
).error((data) => {
animateSpinner(null, false); animateSpinner(null, false);
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
}); });
} }
function initLinkedChildrenModal() { function initLinkedChildrenModal() {
// Only do this if the repository is public/private // Only do this if the repository is public/private
if (repositoryType !== 'archive') { if (repositoryType !== 'archive') {

View file

@ -1159,7 +1159,7 @@ class ProtocolsController < ApplicationController
def check_clone_permissions def check_clone_permissions
load_team_and_type 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 @original = protocol.latest_published_version || protocol
if @original.blank? || if @original.blank? ||

View file

@ -7,7 +7,7 @@
<i class="fas fa-door-open"></i> <i class="fas fa-door-open"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span> <span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span>
</button> </button>
<button id="duplicateProtocol" class="btn btn-light single-object-action hidden only-active" data-for="copyable"> <button id="duplicateProtocol" class="btn btn-light single-object-action hidden only-active" data-url="<%= clone_protocols_path %>" data-for="copyable">
<i class="fas fa-copy"></i> <i class="fas fa-copy"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.duplicate") %></span> <span class="button-text"><%= t("protocols.index.action_toolbar.duplicate") %></span>
</button> </button>

View file

@ -585,7 +585,6 @@ Rails.application.routes.draw do
put 'name', to: 'protocols#update_name' put 'name', to: 'protocols#update_name'
patch 'authors', to: 'protocols#update_authors' patch 'authors', to: 'protocols#update_authors'
patch 'keywords', to: 'protocols#update_keywords' patch 'keywords', to: 'protocols#update_keywords'
post 'clone', to: 'protocols#clone'
get 'unlink_modal', to: 'protocols#unlink_modal' get 'unlink_modal', to: 'protocols#unlink_modal'
post 'unlink', to: 'protocols#unlink' post 'unlink', to: 'protocols#unlink'
get 'revert_modal', to: 'protocols#revert_modal' get 'revert_modal', to: 'protocols#revert_modal'
@ -618,6 +617,7 @@ Rails.application.routes.draw do
post 'make_private', to: 'protocols#make_private' post 'make_private', to: 'protocols#make_private'
post 'archive', to: 'protocols#archive' post 'archive', to: 'protocols#archive'
post 'restore', to: 'protocols#restore' post 'restore', to: 'protocols#restore'
post 'clone', to: 'protocols#clone'
post 'import', to: 'protocols#import' post 'import', to: 'protocols#import'
post 'protocolsio_import_create', post 'protocolsio_import_create',
to: 'protocols#protocolsio_import_create' to: 'protocols#protocolsio_import_create'