Small fixes [SCI-9340]

This commit is contained in:
Anton 2023-09-22 10:07:29 +02:00
parent 77948572f1
commit 566705cb67
2 changed files with 8 additions and 23 deletions

View file

@ -45,23 +45,12 @@ module StepElements
ActiveRecord::Base.transaction do
new_items = @checklist_item.save_multiline!
new_items.each_with_index do |item, i|
if i.zero?
log_activity(
"#{@step.protocol.in_module? ? :task : :protocol}_step_checklist_item_edited",
checklist_item: item.text,
checklist_name: @checklist.name
)
checklist_item_annotation(@step, item, old_text)
else
log_activity(
"#{@step.protocol.in_module? ? :task : :protocol}_step_checklist_item_added",
{
checklist_item: item.text,
checklist_name: @checklist.name
}
)
checklist_item_annotation(@step, item)
end
log_activity(
"#{@step.protocol.in_module? ? :task : :protocol}_step_checklist_item_#{i.zero? ? 'edited' : 'added'}",
checklist_item: item.text,
checklist_name: @checklist.name
)
checklist_item_annotation(@step, item, old_text)
end
end

View file

@ -40,7 +40,7 @@ class ChecklistItem < ApplicationRecord
items = []
if new_record?
start_position = position
split_multiline.each do |line|
text.split("\n").compact.each do |line|
new_item = checklist.checklist_items.create!(text: line)
new_item.insert_at(start_position + 1)
start_position = new_item.position
@ -48,7 +48,7 @@ class ChecklistItem < ApplicationRecord
end
else
item = self
split_multiline.each_with_index do |line, index|
text.split("\n").compact.each_with_index do |line, index|
if index.zero?
update!(text: line)
items.push(self)
@ -73,8 +73,4 @@ class ChecklistItem < ApplicationRecord
checklist.touch
# rubocop:enable Rails/SkipsModelValidations
end
def split_multiline
text.split("\n").compact
end
end