diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 09bde5ddf..6875c71e3 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -632,6 +632,11 @@ class ProtocolsController < ApplicationController return 0 # return 0 stops the rest of the controller code from executing end @json_object = JSON.parse(json_file_contents) + + @json_object['steps'] = protocols_io_guid_reorder_step_json( + @json_object['steps'] + ) + @protocol = Protocol.new respond_to do |format| format.js {} # go to the js.erb file named the same as this controller, diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index e4eb5f70a..6490c4e54 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -199,7 +199,9 @@ module ProtocolsIoHelper end def pio_stp_6(iterating_key) # protocols io section(title) parser - return pio_eval_title_len(sanitize_input(iterating_key)) if iterating_key.present? + if iterating_key.present? + return pio_eval_title_len(CGI.unescapeHTML(sanitize_input(iterating_key))) + end t('protocols.protocols_io_import.comp_append.missing_step') end @@ -285,6 +287,24 @@ module ProtocolsIoHelper description_string end + def protocols_io_guid_reorder_step_json(unordered_step_json) + base_step = unordered_step_json.find { |step| step['previous_guid'].nil? } + number_of_steps = unordered_step_json.size + step_order = [] + step_counter = 0 + step_order[step_counter] = base_step + step_counter += 1 + while step_order.length != number_of_steps + step_order[step_counter] = + unordered_step_json.find do |step| + step['previous_guid'] == base_step['guid'] + end + base_step = step_order[step_counter] + step_counter += 1 + end + step_order + end + def protocols_io_fill_step(original_json, newj) # newj = new json # (simple to map) id 1= step description, id 6= section (title), @@ -293,6 +313,10 @@ module ProtocolsIoHelper # id 9 = dataset, id 15 = command, id 18 = attached sub protocol # id 19= safety information , # id 20= regents (materials, like scinote samples kind of) + + original_json['steps'] = protocols_io_guid_reorder_step_json( + original_json['steps'] + ) newj['0'] = {} newj['0']['position'] = 0 newj['0']['name'] = 'Protocol info'