moved code from older branch to new master

This commit is contained in:
Zanz2 2018-02-06 11:03:17 +01:00
parent f67f633562
commit 9b5ddc6789

View file

@ -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 = '<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
) +
'<br>'
@ -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?
'<strong>' + t('protocols.protocols_io_import.preview.description') +
'</strong>' +
prepare_for_view(
json_hash['description'],
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
).html_safe
else
'<strong>' + t('protocols.protocols_io_import.preview.description') +
'</strong>' + t('protocols.protocols_io_import.comp_append.missing_desc')
end
if json_hash['description'].present?
unshortened_string_for_tables += json_hash['description']
description_string =
'<strong>' +
t('protocols.protocols_io_import.preview.description') +
'</strong>' +
prepare_for_view(
json_hash['description'], # intercept tables here, before they are cut
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
).html_safe
else
description_string =
'<strong>' +
t('protocols.protocols_io_import.preview.description') +
'</strong>' +
t('protocols.protocols_io_import.comp_append.missing_desc')
end
description_string += '<br>'
description_array.each do |e|
if e == 'created_on' && json_hash[e].present?
@ -279,16 +286,17 @@ module ProtocolsIoHelper
)
description_string += '<br>'
elsif json_hash[e].present?
unshortened_string_for_tables += json_hash[e]
new_e = '<strong>' + e.humanize + '</strong>'
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 + '<br>'
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'