Merge branch 'images_not_imported_SCI1807' of https://github.com/Zanz2/scinote-web into images_not_imported_SCI1807

This commit is contained in:
Zanz2 2018-01-26 11:08:47 +01:00
commit 020e9ddc16
3 changed files with 36 additions and 12 deletions

View file

@ -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
) +
'<br>'
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?
'<strong>' + t('protocols.protocols_io_import.preview.description') +
'</strong>' +
prepare_for_view(
json_hash['description'],
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,
'no_table',
true
).html_safe
else
'<strong>' + t('protocols.protocols_io_import.preview.description') +
@ -274,12 +288,16 @@ module ProtocolsIoHelper
description_string += '<br>'
elsif json_hash[e].present?
new_e = '<strong>' + e.humanize + '</strong>'
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 + '<br>'
# 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

View file

@ -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 %>
<strong><%= t(translation_string) %></strong>
<%= 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 %>
<br>
<% end %>

View file

@ -43,13 +43,13 @@
<% step_info_string += (key['data']) %>
<br>
<strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong>
<%= 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 %>
<br>
<% when '17' %>
<% step_info_string += (key['data']) %>
<br>
<strong><%= t('protocols.protocols_io_import.preview.s_exp_res') %></strong>
<%= 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 %>
<br>
<% end %>
<% elsif key && whitelist_complex.include?(key['component_type_id']) %>