diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 0f110a58b..aabc9f6b5 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -640,10 +640,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'] - ) + unless step_hash_null?(@json_object['steps']) + @json_object['steps'] = protocols_io_guid_reorder_step_json( + @json_object['steps'] + ) + end @protocol = Protocol.new respond_to do |format| @@ -658,23 +659,26 @@ class ProtocolsController < ApplicationController @db_json = {} @toolong = false @db_json['name'] = pio_eval_title_len( - sanitize_input(params['protocol']['name']) + sanitize_input(not_null(params['protocol']['name'])) ) # since scinote only has description field, and protocols.io has many others # ,here i am putting everything important from protocols.io into description @db_json['authors'] = pio_eval_title_len( - sanitize_input(params['protocol']['authors']) + sanitize_input(not_null(params['protocol']['authors'])) ) @db_json['created_at'] = pio_eval_title_len( - sanitize_input(params['protocol']['created_at']) + sanitize_input(not_null(params['protocol']['created_at'])) ) @db_json['updated_at'] = pio_eval_title_len( - sanitize_input(params['protocol']['last_modified']) + sanitize_input(not_null(params['protocol']['last_modified'])) ) @db_json['steps'] = {} - @db_json['steps'] = protocols_io_fill_step( - @json_object, @db_json['steps'] - ) + + unless step_hash_null?(@json_object['steps']) + @db_json['steps'] = protocols_io_fill_step( + @json_object, @db_json['steps'] + ) + end protocol = nil respond_to do |format| transaction_error = false diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 18998dc2e..6f80a3d71 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -102,6 +102,8 @@ module ProtocolsIoHelper @toolong = true end text + else + '' end end @@ -128,6 +130,8 @@ module ProtocolsIoHelper @remaining -= text.length - reserved end text + else + '' end end @@ -145,10 +149,15 @@ module ProtocolsIoHelper Nokogiri::HTML::DocumentFragment.parse(text).to_html end + def step_hash_null?(step_json) + step_json.dig(0, 'components', 0, 'component_type_id').nil? + end + # Images are allowed in: # Step: description, expected result # Protocol description : description before_start warning # guidelines manuscript_citation + def prepare_for_view( attribute_text1, size, table = 'no_table', image_allowed = false ) @@ -321,9 +330,12 @@ module ProtocolsIoHelper end def protocols_io_guid_reorder_step_json(unordered_step_json) + return '' if unordered_step_json.blank? base_step = unordered_step_json.find { |step| step['previous_guid'].nil? } return unordered_step_json if base_step.nil? number_of_steps = unordered_step_json.size + return unordered_step_json if number_of_steps == 1 + base_step = unordered_step_json.find { |step| step['previous_guid'].nil? } step_order = [] step_counter = 0 step_order[step_counter] = base_step diff --git a/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb b/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb index 4af0850ff..6f67da96a 100644 --- a/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb +++ b/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb @@ -30,7 +30,7 @@ - <%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(@json_object['protocol_name'])), class: + <%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(not_null(@json_object['protocol_name']))), class: "form-control" %>