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

This commit is contained in:
Zanz2 2018-01-27 13:50:35 +01:00
commit 2a287193b7
3 changed files with 47 additions and 16 deletions

View file

@ -146,12 +146,20 @@ 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(
@ -186,14 +194,17 @@ module ProtocolsIoHelper
end
# pio_stp_x means protocols io step (id of component) parser
def pio_stp_1(iterating_key) # protocols io description parser
# protocols io description parser
def pio_stp_1(iterating_key)
br = '<br>'
append =
if iterating_key.present?
br +
prepare_for_view(
iterating_key,
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,
'no_table',
true
) +
br
else
@ -202,26 +213,31 @@ module ProtocolsIoHelper
append
end
def pio_stp_6(iterating_key) # protocols io section(title) parser
def pio_stp_6(iterating_key)
if iterating_key.present?
# protocols io section(title) parser
return pio_eval_title_len(CGI.unescapeHTML(sanitize_input(iterating_key)))
end
t('protocols.protocols_io_import.comp_append.missing_step')
end
def pio_stp_17(iterating_key) # protocols io expected result parser
def pio_stp_17(iterating_key)
# protocols io expected result parser
if iterating_key.present?
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
end
''
end
# protocols io software package,dataset,commands,sub_protocol and safety_information parser
# protocols io software package,dataset,commands,
# sub_protocol and safety_information parser
def pio_stp(iterating_key, parse_elements_array, en_local_text)
append = ''
@ -241,13 +257,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') +
@ -280,10 +301,13 @@ 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>'
end
@ -326,7 +350,9 @@ 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')
)
)
newj['0']['description'] = table_str
original_json['steps'].each_with_index do |step, pos_orig| # loop over steps
@ -399,5 +425,4 @@ module ProtocolsIoHelper
end # steps
newj
end
end

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']) %>