From 00ac774fde85dfdd23ef79eaf2ae69b3abc0bf84 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Wed, 24 Jan 2018 13:40:13 +0100 Subject: [PATCH] Made images now display in protocol description, before_start, warning,guidelines, manuscript_citation, and also in Step description and step expected result --- app/helpers/protocols_io_helper.rb | 36 ++++++++++++++----- .../_import_json_protocol_p_desc.html.erb | 8 ++++- .../_import_json_protocol_s_desc.html.erb | 4 +-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index e4eb5f70a..411e48e0b 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -146,12 +146,17 @@ module ProtocolsIoHelper Nokogiri::HTML::DocumentFragment.parse(text).to_html end - def prepare_for_view(attribute_text1, size, table = 'no_table') + # 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) + image_tag = Array(nil) + image_tag = Array('img') if image_allowed if table == 'no_table' - attribute_text = sanitize_input(not_null(attribute_text1)) + attribute_text = sanitize_input(not_null(attribute_text1),image_tag) elsif table == 'table' attribute_text = sanitize_input( - string_html_table_remove(not_null(attribute_text1)) + string_html_table_remove(not_null(attribute_text1)),image_tag ) end pio_eval_len( @@ -189,7 +194,9 @@ module ProtocolsIoHelper br + prepare_for_view( iterating_key, - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, + 'no_table', + true ) + br else @@ -208,7 +215,9 @@ module ProtocolsIoHelper append = t('protocols.protocols_io_import.comp_append.expected_result') + prepare_for_view( - iterating_key, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + iterating_key, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, + 'no_table', + true ) + '
' return append @@ -235,13 +244,18 @@ module ProtocolsIoHelper ( before_start warning guidelines manuscript_citation publish_date vendor_name vendor_link keywords tags link created_on ) ] + allowed_image_attributes = %w[ + ( before_start warning guidelines manuscript_citation ) + ] description_string = if json_hash['description'].present? '' + t('protocols.protocols_io_import.preview.description') + '' + prepare_for_view( json_hash['description'], - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + 'no_table', + true ).html_safe else '' + t('protocols.protocols_io_import.preview.description') + @@ -274,12 +288,16 @@ module ProtocolsIoHelper description_string += '
' elsif json_hash[e].present? new_e = '' + e.humanize + '' + + image_tag = Array(nil) + image_tag = Array('img') if allowed_image_attributes.include? e description_string += new_e.to_s + ': ' + pio_eval_prot_desc( - sanitize_input(json_hash[e]), + sanitize_input(json_hash[e],image_tag), e ).html_safe + '
' + # Problematicno, image_tag_testing end end description_string @@ -298,8 +316,8 @@ module ProtocolsIoHelper newj['0']['name'] = 'Protocol info' @remaining = ProtocolsIoHelper::PIO_P_AVAILABLE_LENGTH newj['0']['tables'], table_str = protocolsio_string_to_table_element( - sanitize_input(protocols_io_fill_desc(original_json).html_safe) - ) + sanitize_input(protocols_io_fill_desc(original_json).html_safe,Array('img')) + ) # Problematicno image_tag_testing newj['0']['description'] = table_str original_json['steps'].each_with_index do |step, pos_orig| # loop over steps i = pos_orig + 1 diff --git a/app/views/protocols/import_export/_import_json_protocol_p_desc.html.erb b/app/views/protocols/import_export/_import_json_protocol_p_desc.html.erb index dae8b49f6..1c35f1c2f 100644 --- a/app/views/protocols/import_export/_import_json_protocol_p_desc.html.erb +++ b/app/views/protocols/import_export/_import_json_protocol_p_desc.html.erb @@ -32,8 +32,12 @@ publish_date: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG, vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %> + <% allowed_image_attributes = %w[ + ( description before_start warning guidelines manuscript_citation ) + ] %> <% protocol_attr_len_hash.each do |element, value|%> <% element = element.to_s %> + <% if(json_object[element].present?) %> <% if element == 'tags' %> <% translation_string = 'protocols.protocols_io_import.preview.' + element %> @@ -47,7 +51,9 @@ <% prot_info_string += not_null(json_object[element]) if add_to_info_string_elements.include? element %> <% translation_string = 'protocols.protocols_io_import.preview.' + element %> <%= t(translation_string) %> - <%= prepare_for_view(json_object[element],protocol_attr_len_hash[element.to_sym],'table').html_safe %> + <% image_tag = false %> + <% image_tag = true if allowed_image_attributes.include? element %> + <%= prepare_for_view(json_object[element],protocol_attr_len_hash[element.to_sym],'table',true).html_safe %> <% end %>
<% end %> diff --git a/app/views/protocols/import_export/_import_json_protocol_s_desc.html.erb b/app/views/protocols/import_export/_import_json_protocol_s_desc.html.erb index 7c3c82092..f1fef70d7 100644 --- a/app/views/protocols/import_export/_import_json_protocol_s_desc.html.erb +++ b/app/views/protocols/import_export/_import_json_protocol_s_desc.html.erb @@ -43,13 +43,13 @@ <% step_info_string += (key['data']) %>
<%= t('protocols.protocols_io_import.preview.strng_s_desc') %> - <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %> + <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
<% when '17' %> <% step_info_string += (key['data']) %>
<%= t('protocols.protocols_io_import.preview.s_exp_res') %> - <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %> + <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
<% end %> <% elsif key && whitelist_complex.include?(key['component_type_id']) %>