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