From 566705cb6770af2a546e74f23fee362c9ebbf1f5 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 22 Sep 2023 10:07:29 +0200 Subject: [PATCH] Small fixes [SCI-9340] --- .../checklist_items_controller.rb | 23 +++++-------------- app/models/checklist_item.rb | 8 ++----- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/app/controllers/step_elements/checklist_items_controller.rb b/app/controllers/step_elements/checklist_items_controller.rb index e9872e1dd..9889d6f51 100644 --- a/app/controllers/step_elements/checklist_items_controller.rb +++ b/app/controllers/step_elements/checklist_items_controller.rb @@ -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 diff --git a/app/models/checklist_item.rb b/app/models/checklist_item.rb index 35d087495..0f3adeab5 100644 --- a/app/models/checklist_item.rb +++ b/app/models/checklist_item.rb @@ -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