From 292c1e3c312ff3d008e3fb7b075eb337fd6dbed1 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 25 Sep 2017 14:14:27 +0200 Subject: [PATCH] Fixed bug, seems like unconssistent indexes instead of hash values can also happen in steps that arent first --- app/controllers/protocols_controller.rb | 16 +++++++++------- .../_import_json_protocol_preview_modal.html.erb | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 05c55fad1..70c22b2b9 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -700,16 +700,17 @@ class ProtocolsController < ApplicationController step['components'].each do |key,value| element_string = nil - if counter <= 1 - # here i made an if to distinguish the first step from the others, - # because the first step - # sometimes has index values as keys instead of hashes, for no good reason - key = value if value.class == Hash - end + + + # sometimes there are random index values as keys + # instead of hashes, this is a workaround to that buggy json format + key = value if value.class == Hash + if whitelist_simple.include?(key['component_type_id']) case key['component_type_id'] when '1' + if !key['data'].nil? && key['data'] != '' element_string = '
' + (key['data']) + '
' if @import_object['steps'][step_pos.to_s]['description'] @@ -718,7 +719,8 @@ class ProtocolsController < ApplicationController @import_object['steps'][step_pos.to_s]['description'] = element_string end else - @import_object['steps'][step_pos.to_s]['description'] ||= 'Description missing!' + + @import_object['steps'][step_pos.to_s]['description'] = 'Description missing!' end when '6' if !key['data'].nil? && key['data'] != '' 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 8a479cc19..c717d2b6e 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 @@ -121,11 +121,11 @@ CGI.parse(URI.parse(request.referrer).query).fetch("type") %> <% title=nil %> <% step["components"].each do |key1,value1| #finding section (title of step) %> - <% if counter <=1 %> + <% if value1.class==Hash %> <% key1=value1 %> <% end %> - <% end %> + <% if(key1["component_type_id"]=="6") %> <% if(!key1["data"].nil? && key1["data"]!="") %> <% title ||=key1["data"] %> @@ -146,14 +146,14 @@ CGI.parse(URI.parse(request.referrer).query).fetch("type") %>
<% step["components"].each do |key,value| %> - <% if counter<=1 %> + <%#here i made an if to distinguish the first step from the others, because the first step #sometimes has index values as keys instead of hashes, you might see this elsewhere %> <% if value.class==Hash %> <% key=value %> <% end %> - <% end %> + <% # the below blocks of code output the various attributes if they exist and arent null or "" from the json object %> <% if whitelist_simple.include?(key["component_type_id"]) && key["data"]!="" && key["data"] %>