mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Update protocol templates update action on task [SCI-7903] (#5009)
* Update protocol templates update action on task [SCI-7903] * Simplify logic for update from parent [SCI-7903]
This commit is contained in:
parent
6bfc88434e
commit
96cf2f1d38
|
@ -2,6 +2,7 @@
|
|||
// scss-lint:disable NestingDepth
|
||||
// scss-lint:disable SelectorFormat
|
||||
// scss-lint:disable ImportantRule
|
||||
// scss-lint:disable IdSelector
|
||||
|
||||
@import "constants";
|
||||
@import "mixins";
|
||||
|
@ -667,3 +668,9 @@
|
|||
display: inline-block;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
#confirm-link-update-modal {
|
||||
.warning {
|
||||
margin: 0 15px 15px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -429,7 +429,7 @@ class ProtocolsController < ApplicationController
|
|||
transaction_error = false
|
||||
Protocol.transaction do
|
||||
# Revert is basically update from parent
|
||||
@protocol.update_from_parent(current_user)
|
||||
@protocol.update_from_parent(current_user, @protocol.parent)
|
||||
rescue StandardError
|
||||
transaction_error = true
|
||||
raise ActiveRecord::Rollback
|
||||
|
@ -507,41 +507,38 @@ class ProtocolsController < ApplicationController
|
|||
end
|
||||
|
||||
def update_from_parent
|
||||
protocol_can_destroy = @protocol.can_destroy?
|
||||
respond_to do |format|
|
||||
if @protocol.can_destroy?
|
||||
if protocol_can_destroy
|
||||
transaction_error = false
|
||||
Protocol.transaction do
|
||||
@protocol.update_from_parent(current_user)
|
||||
# Find original published protocol template
|
||||
source_parent = if @protocol.parent.in_repository_published_original?
|
||||
@protocol.parent
|
||||
else
|
||||
@protocol.parent.parent
|
||||
end
|
||||
@protocol.update_from_parent(current_user, source_parent.latest_published_version)
|
||||
rescue StandardError
|
||||
transaction_error = true
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
if transaction_error
|
||||
# Bad request error
|
||||
format.json do
|
||||
render json: {
|
||||
message: t('my_modules.protocols.update_from_parent_error')
|
||||
},
|
||||
status: :bad_request
|
||||
end
|
||||
format.json do
|
||||
if !protocol_can_destroy
|
||||
render json: { message: t('my_modules.protocols.update_from_parent_error_locked') }, status: :bad_request
|
||||
elsif transaction_error
|
||||
render json: { message: t('my_modules.protocols.update_from_parent_error') }, status: :bad_request
|
||||
else
|
||||
# Everything good, display flash & render 200
|
||||
log_activity(:update_protocol_in_task_from_repository,
|
||||
@protocol.my_module.experiment.project,
|
||||
my_module: @protocol.my_module.id,
|
||||
protocol_repository: @protocol.parent.id)
|
||||
flash[:success] = t(
|
||||
'my_modules.protocols.update_from_parent_flash'
|
||||
)
|
||||
|
||||
flash[:success] = t('my_modules.protocols.update_from_parent_flash')
|
||||
flash.keep(:success)
|
||||
format.json { render json: {}, status: :ok }
|
||||
end
|
||||
else
|
||||
format.json do
|
||||
render json: {
|
||||
message: t('my_modules.protocols.update_from_parent_error_locked')
|
||||
}, status: :bad_request
|
||||
render json: {}, status: :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -922,7 +919,7 @@ class ProtocolsController < ApplicationController
|
|||
render json: {
|
||||
title: t('my_modules.protocols.confirm_link_update_modal.update_self_title'),
|
||||
message: t('my_modules.protocols.confirm_link_update_modal.update_self_message'),
|
||||
btn_text: t('general.update'),
|
||||
btn_text: t('my_modules.protocols.confirm_link_update_modal.update_self_btn_text'),
|
||||
url: update_from_parent_protocol_path(@protocol)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -522,21 +522,22 @@ class Protocol < ApplicationRecord
|
|||
save!
|
||||
end
|
||||
|
||||
def update_from_parent(current_user)
|
||||
def update_from_parent(current_user, source)
|
||||
ActiveRecord::Base.no_touching do
|
||||
# First, destroy step contents
|
||||
destroy_contents
|
||||
|
||||
# Now, clone parent's step contents
|
||||
Protocol.clone_contents(parent, self, current_user, false)
|
||||
Protocol.clone_contents(source, self, current_user, false)
|
||||
end
|
||||
|
||||
# Lastly, update the metadata
|
||||
reload
|
||||
self.record_timestamps = false
|
||||
self.updated_at = parent.updated_at
|
||||
self.parent_updated_at = parent.updated_at
|
||||
self.updated_at = source.published_on
|
||||
self.parent_updated_at = source.published_on
|
||||
self.added_by = current_user
|
||||
self.parent = source
|
||||
save!
|
||||
end
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<h4 class="modal-title" id="confirm-link-update-modal-label"></h4>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<h3 class="warning"><%= t('my_modules.protocols.confirm_link_update_modal.warning') %></h3>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel") %></button>
|
||||
<button type="button" class="btn btn-success" data-action="submit"></button>
|
||||
|
|
|
@ -1087,8 +1087,10 @@ en:
|
|||
revert_btn_text: "Revert"
|
||||
update_parent_title: "Update templates version"
|
||||
update_parent_message: "Are you sure you want to update the templates protocol with this version? This will override any other changes made in the templates version."
|
||||
update_self_title: "Update from templates"
|
||||
update_self_message: "Are you sure you want to update this protocol with the version from the templates? This will override any local changes you made."
|
||||
update_self_title: "Update from protocol templates"
|
||||
update_self_message: "This will override any changes you made. We can’t recover them once you update this protocol with the new version. "
|
||||
update_self_btn_text: "Yes, update it"
|
||||
warning: "Are you sure?"
|
||||
unlink_flash: "Protocol was successfully unlinked."
|
||||
unlink_error: "Failed to unlink protocol."
|
||||
revert_flash: "Protocol was successfully reverted to protocol version."
|
||||
|
|
Loading…
Reference in a new issue