diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb
index 464bbe41e..9a1ca383b 100644
--- a/app/helpers/protocols_io_helper.rb
+++ b/app/helpers/protocols_io_helper.rb
@@ -146,56 +146,23 @@ module ProtocolsIoHelper
Nokogiri::HTML::DocumentFragment.parse(text).to_html
end
- def prepare_for_view(attribute_text, size)
- case size
- when 'small'
- pio_eval_len(
- sanitize_input(string_html_table_remove(not_null(attribute_text))),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
- )
- when 'medium'
- pio_eval_len(
- sanitize_input(string_html_table_remove(not_null(attribute_text))),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
- )
- when 'big'
- pio_eval_len(
- sanitize_input(string_html_table_remove(not_null(attribute_text))),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG
- )
- when 'small-no-table'
- pio_eval_len(
- sanitize_input(not_null(attribute_text)),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
- )
- when 'medium-no-table'
- pio_eval_len(
- sanitize_input(not_null(attribute_text)),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
- )
- when 'big-no-table'
- pio_eval_len(
- sanitize_input(not_null(attribute_text)),
- ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG
+ def prepare_for_view(attribute_text1, size, table = 'no_table')
+ if table == 'no_table'
+ attribute_text = sanitize_input(not_null(attribute_text1))
+ elsif table == 'table'
+ attribute_text = sanitize_input(
+ string_html_table_remove(not_null(attribute_text1))
)
end
+ pio_eval_len(
+ attribute_text,
+ size
+ )
end
- def fill_attributes(attribute_name, attribute_text, step_component_key)
+ def fill_attributes(attribute_name, attribute_text, step_component)
output_string = ''
- trans_string = ''
- case step_component_key
- when '8'
- trans_string = 'protocols.protocols_io_import.comp_append.soft_packg.'
- when '9'
- trans_string = 'protocols.protocols_io_import.comp_append.dataset.'
- when '15'
- trans_string = 'protocols.protocols_io_import.comp_append.command.'
- when '18'
- trans_string = 'protocols.protocols_io_import.comp_append.sub_protocol.'
- when '19'
- trans_string = 'protocols.protocols_io_import.comp_append.safety_infor.'
- end
+ trans_string = step_component
trans_string +=
if attribute_name != 'os_name' && attribute_name != 'os_version'
attribute_name
@@ -208,7 +175,9 @@ module ProtocolsIoHelper
else
' , '
end
- output_string += prepare_for_view(attribute_text, 'small-no-table')
+ output_string += prepare_for_view(
+ attribute_text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
+ )
output_string
end
@@ -218,7 +187,10 @@ module ProtocolsIoHelper
append =
if iterating_key.present?
br +
- prepare_for_view(iterating_key, 'small-no-table') +
+ prepare_for_view(
+ iterating_key,
+ ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
+ ) +
br
else
t('protocols.protocols_io_import.comp_append.missing_desc')
@@ -235,7 +207,9 @@ module ProtocolsIoHelper
if iterating_key.present?
append =
t('protocols.protocols_io_import.comp_append.expected_result') +
- prepare_for_view(iterating_key, 'small-no-table') +
+ prepare_for_view(
+ iterating_key, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
+ ) +
'
'
return append
end
@@ -243,78 +217,75 @@ module ProtocolsIoHelper
end
def pio_stp_8(iterating_key) # protocols io software package parser
- if iterating_key['name'] &&
- iterating_key['developer'] &&
- iterating_key['version'] &&
- iterating_key['link'] &&
- iterating_key['repository'] &&
- iterating_key['os_name'] &&
- iterating_key['os_version']
- append = ''
- parse_elements_array = %w(
- name developer version link repository os_name os_version
+ append = ''
+ parse_elements_array = %w(
+ name developer version link repository os_name os_version
+ )
+ parse_elements_array.each do |element|
+ return '' unless iterating_key[element]
+ append += fill_attributes(
+ element,
+ iterating_key[element],
+ 'protocols.protocols_io_import.comp_append.soft_packg.'
)
- parse_elements_array.each do |element|
- append += fill_attributes(element, iterating_key[element], '8')
- end
- return append
end
- ''
+ append
end
def pio_stp_9(iterating_key) # protocols io dataset parser
- if iterating_key['name'].present? &&
- iterating_key['link']
- append = ''
- parse_elements_array = %w(name link)
- parse_elements_array.each do |element|
- append += fill_attributes(element, iterating_key[element], '9')
- end
- return append
+ append = ''
+ parse_elements_array = %w(name link)
+ parse_elements_array.each do |element|
+ return '' unless iterating_key[element]
+ append += fill_attributes(
+ element,
+ iterating_key[element],
+ 'protocols.protocols_io_import.comp_append.dataset.'
+ )
end
- ''
+ append
end
def pio_stp_15(iterating_key) # protocols io commands parser
- if iterating_key['name'].present? &&
- iterating_key['description'] &&
- iterating_key['os_name'] &&
- iterating_key['os_version']
- append = ''
- parse_elements_array = %w(name description os_name os_version)
- parse_elements_array.each do |element|
- append += fill_attributes(element, iterating_key[element], '15')
- end
- return append
+ append = ''
+ parse_elements_array = %w(name description os_name os_version)
+ parse_elements_array.each do |element|
+ return '' unless iterating_key[element]
+ append += fill_attributes(
+ element,
+ iterating_key[element],
+ 'protocols.protocols_io_import.comp_append.command.'
+ )
end
- ''
+ append
end
def pio_stp_18(iterating_key) # protocols io sub protocol parser
- if iterating_key['protocol_name'].present? &&
- iterating_key['full_name'] &&
- iterating_key['link']
- append = ''
- parse_elements_array = %w(protocol_name full_name link)
- parse_elements_array.each do |element|
- append += fill_attributes(element, iterating_key[element], '18')
- end
- return append
+ append = ''
+ parse_elements_array = %w(protocol_name full_name link)
+ parse_elements_array.each do |element|
+ return '' unless iterating_key[element]
+ append += fill_attributes(
+ element,
+ iterating_key[element],
+ 'protocols.protocols_io_import.comp_append.sub_protocol.'
+ )
end
- ''
+ append
end
def pio_stp_19(iterating_key) # protocols io safety information parser
- if iterating_key['body'].present? &&
- iterating_key['link']
- append = ''
- parse_elements_array = %w(body link)
- parse_elements_array.each do |element|
- append += fill_attributes(element, iterating_key[element], '19')
- end
- return append
+ append = ''
+ parse_elements_array = %w(body link)
+ parse_elements_array.each do |element|
+ return '' unless iterating_key[element]
+ append += fill_attributes(
+ element,
+ iterating_key[element],
+ 'protocols.protocols_io_import.comp_append.safety_infor.'
+ )
end
- ''
+ append
end
def protocols_io_fill_desc(json_hash)
@@ -326,7 +297,10 @@ module ProtocolsIoHelper
if json_hash['description'].present?
'' + t('protocols.protocols_io_import.preview.description') +
'' +
- prepare_for_view(json_hash['description'], 'medium-no-table').html_safe
+ 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')
@@ -338,8 +312,9 @@ module ProtocolsIoHelper
description_string +=
new_e.to_s + ': ' +
prepare_for_view(
- params['protocol']['created_at'].to_s, 'small-no-table'
- ) +
+ params['protocol']['created_at'].to_s,
+ ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
+ ) +
+ '
'
elsif e == 'tags' && json_hash[e].any? && json_hash[e] != ''
new_e = '' + e.humanize + ''
@@ -351,7 +326,8 @@ module ProtocolsIoHelper
sanitize_input(tag['tag_name']) + ' , '
end
description_string += prepare_for_view(
- tags_length_checker, 'medium-no-table'
+ tags_length_checker,
+ ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
)
description_string += '
'
elsif json_hash[e].present?
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 e82ce934d..ff037d2c8 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
@@ -36,19 +36,19 @@
<% json_object['tags'].each do |tag| %>
<% string_of_tags += tag['tag_name']+' , ' %>
<% end %>
- <%= prepare_for_view(string_of_tags,'medium').html_safe %>
+ <%= prepare_for_view(string_of_tags, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,'table').html_safe %>
<% else %>
<% 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) %>
<% if big_elements.include? element %>
- <%= prepare_for_view(json_object[element],'big').html_safe %>
+ <%= prepare_for_view(json_object[element],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG,'table').html_safe %>
<% end %>
<% if medium_elements.include? element %>
- <%= prepare_for_view(json_object[element],'medium').html_safe %>
+ <%= prepare_for_view(json_object[element],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,'table').html_safe %>
<% end %>
<% if small_elements.include? element %>
- <%= prepare_for_view(json_object[element],'small').html_safe %>
+ <%= prepare_for_view(json_object[element],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').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 14527f809..7c3c82092 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'],'small').html_safe %>
+ <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% when '17' %>
<% step_info_string += (key['data']) %>
<%= t('protocols.protocols_io_import.preview.s_exp_res') %>
- <%= prepare_for_view(key['data'],'small').html_safe %>
+ <%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% end %>
<% elsif key && whitelist_complex.include?(key['component_type_id']) %>
@@ -58,63 +58,63 @@
<% step_info_string += not_null(key['source_data']['name']) %>
<%= not_null(key['name'])+': ' %>
- <%= prepare_for_view(key['source_data']['name'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.dev') %>
- <%= prepare_for_view(key['source_data']['developer'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['developer'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.vers') %>
- <%= prepare_for_view(key['source_data']['version'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['version'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.s_link') %>
- <%= prepare_for_view(key['source_data']['link'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['link'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.repo') %>
- <%= prepare_for_view(key['source_data']['repository'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['repository'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.os') %>
- <%= prepare_for_view(key['source_data']['os_name'],'small').html_safe + ' , ' +
- prepare_for_view(key['source_data']['os_version'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['os_name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe + ' , ' +
+ prepare_for_view(key['source_data']['os_version'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% when '9'%>
<% step_info_string += not_null(key['source_data']['name']) %>
<%= not_null(key['name'])+': ' %>
- <%= prepare_for_view(key['source_data']['name'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.s_link') %>
- <%= prepare_for_view(key['source_data']['link'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['link'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% when '15'%>
<% step_info_string += not_null(key['source_data']['description']) %>
<%= key['name']+': ' %>
- <%= prepare_for_view(key['source_data']['name'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.s_desc') %>
- <%= prepare_for_view(key['source_data']['description'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['description'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.os') %>
- <%= prepare_for_view(key['source_data']['os_name'],'small').html_safe + ' , ' +
- prepare_for_view(key['source_data']['os_version'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['os_name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe + ' , ' +
+ prepare_for_view(key['source_data']['os_version'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% when '18'%>
<%= t('protocols.protocols_io_import.preview.sub_prot') %>
- <%= prepare_for_view(key['source_data']['protocol_name'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['protocol_name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.auth') %>
- <%= prepare_for_view(key['source_data']['full_name'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['full_name'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% if key['source_data']['link'].present? %>
<%= t('protocols.protocols_io_import.preview.s_nobr_link') %>
- <%= prepare_for_view(key['source_data']['link'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['link'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% end %>
<% when '19'%>
<% step_info_string += not_null(key['source_data']['body']) %>
<%= not_null(key['name'])+': ' %>
- <%= prepare_for_view(key['source_data']['body'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['body'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<%= t('protocols.protocols_io_import.preview.s_link') %>
- <%= prepare_for_view(key['source_data']['link'],'small').html_safe %>
+ <%= prepare_for_view(key['source_data']['link'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %>
<% else %>
<% end #case if%>
<% end #inner if%>