mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-28 23:18:10 +08:00
Fix building of circular protocols for protocols.io [SCI-7388] (#4665)
This commit is contained in:
parent
6f60a7cd4f
commit
369fffc467
1 changed files with 14 additions and 2 deletions
|
|
@ -43,16 +43,28 @@ module ProtocolImporters
|
|||
|
||||
# set positions
|
||||
if protocol_hash[:steps].any?
|
||||
first_step_id = normalized_data[:steps].find { |s| s[:position].zero? }[:source_id]
|
||||
first_step = normalized_data[:steps].find { |s| s[:position].present? && s[:position].zero? }
|
||||
first_step_id = if first_step.present?
|
||||
first_step[:source_id]
|
||||
else
|
||||
protocol_hash[:steps].min_by do |el|
|
||||
el[:id]
|
||||
end[:id]
|
||||
end
|
||||
next_step_id = protocol_hash[:steps].find { |s| s[:previous_id] == first_step_id }.try(:[], :id)
|
||||
steps = normalized_data[:steps].map { |s| [s[:source_id], s] }.to_h
|
||||
original_order = protocol_hash[:steps].map { |m| [m[:previous_id], m[:id]] }.to_h
|
||||
|
||||
current_position = 0
|
||||
steps[first_step_id][:position] = current_position
|
||||
while next_step_id
|
||||
current_position += 1
|
||||
steps[next_step_id][:position] = current_position
|
||||
next_step_id = original_order[next_step_id]
|
||||
next_step_id = if original_order[next_step_id] == first_step_id
|
||||
nil
|
||||
else
|
||||
original_order[next_step_id]
|
||||
end
|
||||
end
|
||||
|
||||
# Check if step name are valid
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue