From 9b5ddc67897cef3ff0abb705003171c14c169969 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Tue, 6 Feb 2018 11:03:17 +0100 Subject: [PATCH] moved code from older branch to new master --- app/helpers/protocols_io_helper.rb | 53 +++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index d1107561f..ef8e85241 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -175,6 +175,7 @@ module ProtocolsIoHelper else ' , ' end + # intercept tables here, before they are shortened if attribute_name == 'protocol_name' output_string += pio_eval_title_len(attribute_text) else @@ -189,7 +190,7 @@ module ProtocolsIoHelper def pio_stp_1(iterating_key) # protocols io description parser br = '
' append = - if iterating_key.present? + if iterating_key.present? # intercept tables here before cutting br + prepare_for_view( iterating_key, @@ -213,7 +214,7 @@ module ProtocolsIoHelper if iterating_key.present? append = t('protocols.protocols_io_import.comp_append.expected_result') + - prepare_for_view( + prepare_for_view( # intercept tables here, before cutting iterating_key, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL ) + '
' @@ -228,7 +229,7 @@ module ProtocolsIoHelper parse_elements_array.each do |element| return '' unless iterating_key[element] append += fill_attributes( - element, + element, # intercept tables here, before cutting iterating_key[element], en_local_text ) @@ -237,22 +238,28 @@ module ProtocolsIoHelper end def protocols_io_fill_desc(json_hash) + unshortened_string_for_tables = '' description_array = %w[ ( before_start warning guidelines manuscript_citation publish_date vendor_name vendor_link keywords tags link created_on ) ] - 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 - ).html_safe - else - '' + t('protocols.protocols_io_import.preview.description') + - '' + t('protocols.protocols_io_import.comp_append.missing_desc') - end + if json_hash['description'].present? + unshortened_string_for_tables += json_hash['description'] + description_string = + '' + + t('protocols.protocols_io_import.preview.description') + + '' + + prepare_for_view( + json_hash['description'], # intercept tables here, before they are cut + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM + ).html_safe + else + description_string = + '' + + t('protocols.protocols_io_import.preview.description') + + '' + + t('protocols.protocols_io_import.comp_append.missing_desc') + end description_string += '
' description_array.each do |e| if e == 'created_on' && json_hash[e].present? @@ -279,16 +286,17 @@ module ProtocolsIoHelper ) description_string += '
' elsif json_hash[e].present? + unshortened_string_for_tables += json_hash[e] new_e = '' + e.humanize + '' description_string += - new_e.to_s + ': ' + + new_e.to_s + ': ' + # intercept tables here, before cut pio_eval_prot_desc( sanitize_input(json_hash[e]), e ).html_safe + '
' end end - description_string + return description_string, unshortened_string_for_tables end def protocols_io_guid_reorder_step_json(unordered_step_json) @@ -325,9 +333,15 @@ module ProtocolsIoHelper newj['0']['position'] = 0 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) + shortened_string, unshortened_tables_string = protocols_io_fill_desc( + original_json ) + newj['0']['tables'] = protocolsio_string_to_table_element( + sanitize_input(unshortened_tables_string).html_safe + )[0] + table_str = protocolsio_string_to_table_element( + sanitize_input(shortened_string).html_safe + )[1] newj['0']['description'] = table_str original_json['steps'].each_with_index do |step, pos_orig| # loop over steps i = pos_orig + 1 @@ -344,6 +358,7 @@ module ProtocolsIoHelper # append is the string that we append values into for description # pio_stp_x means protocols io step (id of component) parser case key['component_type_id'] + # intercept tables in all of below before cutting when '1' newj[i.to_s]['description'] += pio_stp_1(key['data']) when '6'