mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Fix saving protocol to repository [SCI-6935] (#4190)
This commit is contained in:
parent
7af1684db0
commit
9aeb107635
|
@ -465,7 +465,6 @@ function init() {
|
|||
initEditMyModuleDescription();
|
||||
initEditProtocolDescription();
|
||||
initEditDescription();
|
||||
initCopyToRepository();
|
||||
initLinkUpdate();
|
||||
initLoadFromRepository();
|
||||
refreshProtocolStatusBar();
|
||||
|
|
|
@ -331,9 +331,11 @@ class ProtocolsController < ApplicationController
|
|||
link_protocols,
|
||||
current_user
|
||||
)
|
||||
rescue StandardError
|
||||
rescue StandardError => e
|
||||
transaction_error = true
|
||||
raise ActiveRecord:: Rollback
|
||||
Rails.logger.error(e.message)
|
||||
Rails.logger.error(e.backtrace.join("\n"))
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
if transaction_error
|
||||
|
|
|
@ -295,28 +295,24 @@ class Protocol < ApplicationRecord
|
|||
|
||||
# Copy checklists
|
||||
step.checklists.asc.each do |checklist|
|
||||
checklist2 = Checklist.new(
|
||||
checklist2 = Checklist.create!(
|
||||
name: checklist.name,
|
||||
step: step2
|
||||
step: step2,
|
||||
created_by: current_user,
|
||||
last_modified_by: current_user
|
||||
)
|
||||
checklist2.created_by = current_user
|
||||
checklist2.last_modified_by = current_user
|
||||
checklist2.save!
|
||||
|
||||
checklist.checklist_items.each do |item|
|
||||
item2 = ChecklistItem.new(
|
||||
ChecklistItem.create!(
|
||||
text: item.text,
|
||||
checked: false,
|
||||
checklist: checklist2,
|
||||
position: item.position
|
||||
position: item.position,
|
||||
created_by: current_user,
|
||||
last_modified_by: current_user
|
||||
)
|
||||
item2.created_by = current_user
|
||||
item2.last_modified_by = current_user
|
||||
item2.save!
|
||||
end
|
||||
|
||||
step2.checklists << checklist2
|
||||
|
||||
step2.step_orderable_elements.create!(
|
||||
position: position,
|
||||
orderable: checklist2
|
||||
|
@ -335,18 +331,18 @@ class Protocol < ApplicationRecord
|
|||
|
||||
# Copy tables
|
||||
step.tables.each do |table|
|
||||
table2 = Table.new(
|
||||
table2 = Table.create!(
|
||||
name: table.name,
|
||||
contents: table.contents.encode('UTF-8', 'UTF-8')
|
||||
step: step2,
|
||||
contents: table.contents.encode('UTF-8', 'UTF-8'),
|
||||
team: dest.team,
|
||||
created_by: current_user,
|
||||
last_modified_by: current_user
|
||||
)
|
||||
table2.created_by = current_user
|
||||
table2.last_modified_by = current_user
|
||||
table2.team = dest.team
|
||||
step2.tables << table2
|
||||
|
||||
step2.step_orderable_elements.create!(
|
||||
position: position,
|
||||
orderable: table2.step_tables.first
|
||||
orderable: table2
|
||||
)
|
||||
|
||||
position += 1
|
||||
|
|
|
@ -15,7 +15,7 @@ class StepOrderableElement < ApplicationRecord
|
|||
if step != orderable.step
|
||||
errors.add(
|
||||
:step_orderable_element,
|
||||
I18n.t('activerecord.errors.models.step_orderable_elements.attributes.step.wrong_step')
|
||||
I18n.t('activerecord.errors.models.step_orderable_element.attributes.step.wrong_step')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,7 @@ class Table < ApplicationRecord
|
|||
has_one :result_table, inverse_of: :table
|
||||
has_one :result, through: :result_table
|
||||
has_many :report_elements, inverse_of: :table, dependent: :destroy
|
||||
has_many :step_orderable_elements, as: :orderable, dependent: :destroy
|
||||
|
||||
after_save :update_ts_index
|
||||
after_save { result&.touch; step&.touch }
|
||||
|
|
Loading…
Reference in a new issue