From 835ac6910f58a68490da4f1a8a024a128ee01cb0 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Sat, 2 Dec 2017 00:29:47 +0100 Subject: [PATCH 1/7] Code refactor part 1 --- app/controllers/protocols_controller.rb | 290 ---------------- app/helpers/protocols_io_helper.rb | 312 ++++++++++++++++++ .../_import_json_protocol_p_desc.html.erb | 76 ++--- .../_import_json_protocol_s_desc.html.erb | 150 +++------ 4 files changed, 382 insertions(+), 446 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 9d017982f..ba024c3ec 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -968,296 +968,6 @@ class ProtocolsController < ApplicationController return false end - # pio_stp_x means protocols io step (id of component) parser - def pio_stp_1(iterating_key) # protocols io description parser - br = '
' - append = - if iterating_key.present? - br + - pio_eval_len( - sanitize_input(iterating_key), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - br - else - t('protocols.protocols_io_import.comp_append.missing_desc') - end - append - end - - def pio_stp_6(iterating_key) # protocols io section(title) parser - return pio_eval_title_len(sanitize_input(iterating_key)) if iterating_key.present? - t('protocols.protocols_io_import.comp_append.missing_step') - end - - 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') + - pio_eval_len( - sanitize_input(iterating_key), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - '
' - return append - end - '' - 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 = t('protocols.protocols_io_import.comp_append.soft_packg.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.dev') + - pio_eval_len( - sanitize_input(iterating_key['developer']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.vers') + - pio_eval_len( - sanitize_input(iterating_key['version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.repo') + - pio_eval_len( - sanitize_input(iterating_key['repository']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.os') + - pio_eval_len( - sanitize_input(iterating_key['os_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + ' , ' + - pio_eval_len( - sanitize_input(iterating_key['os_version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) - return append - end - '' - end - - def pio_stp_9(iterating_key) # protocols io dataset parser - if iterating_key['name'].present? && - iterating_key['link'] - append = t('protocols.protocols_io_import.comp_append.dataset.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) - return append - end - '' - 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 = t('protocols.protocols_io_import.comp_append.command.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.command.desc') + - pio_eval_len( - sanitize_input(iterating_key['description']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.command.os') + - pio_eval_len( - sanitize_input(iterating_key['os_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - ' , ' + - pio_eval_len( - sanitize_input(iterating_key['os_version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) - return append - end - '' - 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 = - t( - 'protocols.protocols_io_import.comp_append.sub_protocol.title' - ) + - pio_eval_len( - sanitize_input(iterating_key['protocol_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t( - 'protocols.protocols_io_import.comp_append.sub_protocol.author' - ) + - pio_eval_len( - sanitize_input(iterating_key['full_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) - return append - end - '' - end - - def pio_stp_19(iterating_key) # protocols io safety information parser - if iterating_key['body'].present? && - iterating_key['link'] - append = - t( - 'protocols.protocols_io_import.comp_append.safety_infor.title' - ) + - pio_eval_len( - sanitize_input(iterating_key['body']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) - return append - end - '' - end - - def protocols_io_fill_desc(json_hash) - 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.prot_desc') + - '' + pio_eval_len( - sanitize_input(json_hash['description']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ).html_safe - else - '' + t('protocols.protocols_io_import.preview.prot_desc') + - '' + 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? - new_e = '' + e.humanize + '' - description_string += - new_e.to_s + ': ' + pio_eval_len( - sanitize_input(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 + '' - description_string += - new_e.to_s + ': ' - tags_length_checker = '' - json_hash[e].each do |tag| - tags_length_checker += - sanitize_input(tag['tag_name']) + ' , ' - end - description_string += pio_eval_len( - tags_length_checker, - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) - description_string += '
' - elsif json_hash[e].present? - new_e = '' + e.humanize + '' - description_string += - new_e.to_s + ': ' + - pio_eval_prot_desc( - sanitize_input(json_hash[e]), - e - ).html_safe + '
' - end - end - description_string - end - - def protocols_io_fill_step(original_json, newj) - # newj = new json - # (simple to map) id 1= step description, id 6= section (title), - # id 17= expected result - # (complex mapping with nested hashes) id 8 = software package, - # id 9 = dataset, id 15 = command, id 18 = attached sub protocol - # id 19= safety information , - # id 20= regents (materials, like scinote samples kind of) - newj['0'] = {} - 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) - ) - newj['0']['description'] = table_str - original_json['steps'].each_with_index do |step, pos_orig| # loop over steps - i = pos_orig + 1 - @remaining = ProtocolsIoHelper::PIO_S_AVAILABLE_LENGTH - # position of step (first, second.... etc), - newj[i.to_s] = {} # the json we will insert into db - newj[i.to_s]['position'] = i - newj[i.to_s]['description'] = '' unless newj[i.to_s].key?('description') - newj[i.to_s]['name'] = '' unless newj[i.to_s].key?('name') - step['components'].each do |key, value| - # sometimes there are random index values as keys - # instead of hashes, this is a workaround to that buggy json format - key = value if value.class == Hash - # 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'] - when '1' - newj[i.to_s]['description'] += pio_stp_1(key['data']) - when '6' - newj[i.to_s]['name'] = pio_stp_6(key['data']) - when '17' - newj[i.to_s]['description'] += pio_stp_17(key['data']) - when '8' - newj[i.to_s]['description'] += pio_stp_8(key['source_data']) - when '9' - newj[i.to_s]['description'] += pio_stp_9(key['source_data']) - when '15' - newj[i.to_s]['description'] += pio_stp_15(key['source_data']) - when '18' - newj[i.to_s]['description'] += pio_stp_18(key['source_data']) - when '19' - newj[i.to_s]['description'] += pio_stp_19(key['source_data']) - end # case end - end # finished looping over step components - newj[i.to_s]['tables'], table_str = protocolsio_string_to_table_element( - newj[i.to_s]['description'] - ) - newj[i.to_s]['description'] = table_str - end # steps - newj - end - def move_protocol(action) rollbacked = false results = [] diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index be72de36d..66c1305d3 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -145,4 +145,316 @@ module ProtocolsIoHelper def close_open_html_tags(text) 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 + ) + else + end + end + + # pio_stp_x means protocols io step (id of component) parser + def pio_stp_1(iterating_key) # protocols io description parser + br = '
' + append = + if iterating_key.present? + br + + pio_eval_len( + sanitize_input(iterating_key), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + br + else + t('protocols.protocols_io_import.comp_append.missing_desc') + end + append + end + + def pio_stp_6(iterating_key) # protocols io section(title) parser + return pio_eval_title_len(sanitize_input(iterating_key)) if iterating_key.present? + t('protocols.protocols_io_import.comp_append.missing_step') + end + + 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') + + pio_eval_len( + sanitize_input(iterating_key), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + '
' + return append + end + '' + 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 = t('protocols.protocols_io_import.comp_append.soft_packg.title') + + pio_eval_len( + sanitize_input(iterating_key['name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.soft_packg.dev') + + pio_eval_len( + sanitize_input(iterating_key['developer']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.soft_packg.vers') + + pio_eval_len( + sanitize_input(iterating_key['version']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.general_link') + + pio_eval_len( + sanitize_input(iterating_key['link']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.soft_packg.repo') + + pio_eval_len( + sanitize_input(iterating_key['repository']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.soft_packg.os') + + pio_eval_len( + sanitize_input(iterating_key['os_name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + ' , ' + + pio_eval_len( + sanitize_input(iterating_key['os_version']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + return append + end + '' + end + + def pio_stp_9(iterating_key) # protocols io dataset parser + if iterating_key['name'].present? && + iterating_key['link'] + append = t('protocols.protocols_io_import.comp_append.dataset.title') + + pio_eval_len( + sanitize_input(iterating_key['name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.general_link') + + pio_eval_len( + sanitize_input(iterating_key['link']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + return append + end + '' + 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 = t('protocols.protocols_io_import.comp_append.command.title') + + pio_eval_len( + sanitize_input(iterating_key['name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.command.desc') + + pio_eval_len( + sanitize_input(iterating_key['description']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.command.os') + + pio_eval_len( + sanitize_input(iterating_key['os_name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + ' , ' + + pio_eval_len( + sanitize_input(iterating_key['os_version']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + return append + end + '' + 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 = + t( + 'protocols.protocols_io_import.comp_append.sub_protocol.title' + ) + + pio_eval_len( + sanitize_input(iterating_key['protocol_name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t( + 'protocols.protocols_io_import.comp_append.sub_protocol.author' + ) + + pio_eval_len( + sanitize_input(iterating_key['full_name']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.general_link') + + pio_eval_len( + sanitize_input(iterating_key['link']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + return append + end + '' + end + + def pio_stp_19(iterating_key) # protocols io safety information parser + if iterating_key['body'].present? && + iterating_key['link'] + append = + t( + 'protocols.protocols_io_import.comp_append.safety_infor.title' + ) + + pio_eval_len( + sanitize_input(iterating_key['body']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + + t('protocols.protocols_io_import.comp_append.general_link') + + pio_eval_len( + sanitize_input(iterating_key['link']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL + ) + return append + end + '' + end + + def protocols_io_fill_desc(json_hash) + 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.prot_desc') + + '' + pio_eval_len( + sanitize_input(json_hash['description']), + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM + ).html_safe + else + '' + t('protocols.protocols_io_import.preview.prot_desc') + + '' + 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? + new_e = '' + e.humanize + '' + description_string += + new_e.to_s + ': ' + pio_eval_len( + sanitize_input(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 + '' + description_string += + new_e.to_s + ': ' + tags_length_checker = '' + json_hash[e].each do |tag| + tags_length_checker += + sanitize_input(tag['tag_name']) + ' , ' + end + description_string += pio_eval_len( + tags_length_checker, + ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM + ) + description_string += '
' + elsif json_hash[e].present? + new_e = '' + e.humanize + '' + description_string += + new_e.to_s + ': ' + + pio_eval_prot_desc( + sanitize_input(json_hash[e]), + e + ).html_safe + '
' + end + end + description_string + end + + def protocols_io_fill_step(original_json, newj) + # newj = new json + # (simple to map) id 1= step description, id 6= section (title), + # id 17= expected result + # (complex mapping with nested hashes) id 8 = software package, + # id 9 = dataset, id 15 = command, id 18 = attached sub protocol + # id 19= safety information , + # id 20= regents (materials, like scinote samples kind of) + newj['0'] = {} + 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) + ) + newj['0']['description'] = table_str + original_json['steps'].each_with_index do |step, pos_orig| # loop over steps + i = pos_orig + 1 + @remaining = ProtocolsIoHelper::PIO_S_AVAILABLE_LENGTH + # position of step (first, second.... etc), + newj[i.to_s] = {} # the json we will insert into db + newj[i.to_s]['position'] = i + newj[i.to_s]['description'] = '' unless newj[i.to_s].key?('description') + newj[i.to_s]['name'] = '' unless newj[i.to_s].key?('name') + step['components'].each do |key, value| + # sometimes there are random index values as keys + # instead of hashes, this is a workaround to that buggy json format + key = value if value.class == Hash + # 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'] + when '1' + newj[i.to_s]['description'] += pio_stp_1(key['data']) + when '6' + newj[i.to_s]['name'] = pio_stp_6(key['data']) + when '17' + newj[i.to_s]['description'] += pio_stp_17(key['data']) + when '8' + newj[i.to_s]['description'] += pio_stp_8(key['source_data']) + when '9' + newj[i.to_s]['description'] += pio_stp_9(key['source_data']) + when '15' + newj[i.to_s]['description'] += pio_stp_15(key['source_data']) + when '18' + newj[i.to_s]['description'] += pio_stp_18(key['source_data']) + when '19' + newj[i.to_s]['description'] += pio_stp_19(key['source_data']) + end # case end + end # finished looping over step components + newj[i.to_s]['tables'], table_str = protocolsio_string_to_table_element( + newj[i.to_s]['description'] + ) + newj[i.to_s]['description'] = table_str + end # steps + newj + end + end 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 5693e4029..d448dfa60 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 @@ -22,78 +22,52 @@ <% if json_object['description'].present? %> <% prot_info_string += (json_object['description']) %> <%= t('protocols.protocols_io_import.preview.prot_desc') %> - <% description = pio_eval_len( - sanitize_input(string_html_table_remove(json_object['description'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM) %> - <%= description.html_safe %>
+ <%= prepare_for_view(json_object['description'],'medium').html_safe %> +
<% end %> <% if json_object['before_start'].present? %> <% prot_info_string += (json_object['before_start']) %> <%= t('protocols.protocols_io_import.preview.b_s_p') %> - <% before_start = pio_eval_len( - sanitize_input(string_html_table_remove(json_object['before_start'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= before_start.html_safe %>
+ <%= prepare_for_view(json_object['before_start'],'medium').html_safe %> +
<% end %> <% if json_object['warning'].present? %> <% prot_info_string += (json_object['warning']) %> <%= t('protocols.protocols_io_import.preview.warn') %> - <% sft_warning = pio_eval_len( - sanitize_input(string_html_table_remove(json_object['warning'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= sft_warning.html_safe%>
+ <%= prepare_for_view(json_object['warning'],'medium').html_safe %> +
<% end %> <% if json_object['guidelines'].present? %> <% prot_info_string += (json_object['guidelines']) %> <%= t('protocols.protocols_io_import.preview.guideln') %> - <% guidelines = pio_eval_len( - sanitize_input(string_html_table_remove(json_object['guidelines'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= guidelines.html_safe %>
+ <%= prepare_for_view(json_object['guidelines'],'medium').html_safe %> +
<% end %> <% if json_object['manuscript_citation'].present? %> <% prot_info_string += (json_object['manuscript_citation']) %> <%= t('protocols.protocols_io_import.preview.manu_cit') %> - <% manu_cit = pio_eval_len( - sanitize_input(string_html_table_remove(json_object['manuscript_citation'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= manu_cit.html_safe %>
+ <%= prepare_for_view(json_object['manuscript_citation'],'medium').html_safe %> +
<% end %> <% if json_object['publish_date'].present? %> <%= t('protocols.protocols_io_import.preview.pbl_date') %> - <% pbl_date = pio_eval_len( - sanitize_input(json_object['publish_date']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) %> - <%= pbl_date.html_safe %>
+ <%= prepare_for_view(json_object['publish_date'],'small').html_safe %> +
<% end %> <% if json_object['vendor_name'].present? %> <%= t('protocols.protocols_io_import.preview.vnd_name') %> - <% vnd_name = pio_eval_len( - sanitize_input(json_object['vendor_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= vnd_name.html_safe %>
+ <%= prepare_for_view(json_object['vendor_name'],'medium').html_safe %> +
<% end %> <% if json_object['vendor_link'].present? %> <%= t('protocols.protocols_io_import.preview.vnd_link') %> - <% vnd_link = pio_eval_len( - sanitize_input(json_object['vendor_link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG - ) %> - <%= vnd_link.html_safe %>
+ <%= prepare_for_view(json_object['vendor_link'],'big').html_safe %> +
<% end %> <% if json_object['keywords'].present? %> <%= t('protocols.protocols_io_import.preview.key_wrd') %> - <% keywords = pio_eval_len( - sanitize_input(json_object['keywords']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ) %> - <%= keywords.html_safe %>
+ <%= prepare_for_view(json_object['keywords'],'medium').html_safe %> +
<% end %> <% if json_object['tags'].present? %> <%= t('protocols.protocols_io_import.preview.tags') %> @@ -101,19 +75,13 @@ <% json_object['tags'].each do |tag| %> <% string_of_tags += tag['tag_name']+' , ' %> <% end %> - <% tags = pio_eval_len( - sanitize_input(string_of_tags), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - )%> - <%= tags.html_safe %>
+ <%= prepare_for_view(string_of_tags,'medium').html_safe %> +
<% end %> <% if json_object['link'].present? %> <%= t('protocols.protocols_io_import.preview.p_link') %> - <% link = pio_eval_len( - sanitize_input(json_object['link']).html_safe, - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG - ) %> - <%= link.html_safe %>
+ <%= prepare_for_view(json_object['link'],'big').html_safe %> +
<% end %> <% tables, garbage = protocolsio_string_to_table_element(prot_info_string) %> <% if tables.present? %> 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 12f43a41f..14527f809 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 @@ -41,20 +41,15 @@ <% case key['component_type_id'] when '1' %> <% step_info_string += (key['data']) %> -
<%= t('protocols.protocols_io_import.preview.strng_s_desc') %> - <% s_desc = pio_eval_len( - sanitize_input(string_html_table_remove(key['data'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - )%> - <%= s_desc.html_safe %>
+
+ <%= t('protocols.protocols_io_import.preview.strng_s_desc') %> + <%= prepare_for_view(key['data'],'small').html_safe %> +
<% when '17' %> <% step_info_string += (key['data']) %> -
<%= t('protocols.protocols_io_import.preview.s_exp_res') %> - <% s_exp_res = pio_eval_len( - sanitize_input(string_html_table_remove(key['data'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - )%> - <%= s_exp_res.html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.s_exp_res') %> + <%= prepare_for_view(key['data'],'small').html_safe %>
<% end %> <% elsif key && whitelist_complex.include?(key['component_type_id']) %> @@ -63,112 +58,63 @@ <% step_info_string += not_null(key['source_data']['name']) %>
<%= not_null(key['name'])+': ' %> - <%= pio_eval_len( - sanitize_input(string_html_table_remove(not_null(key['source_data']['name'])).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.dev') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['developer']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.vers') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['version']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.s_link') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['link']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.repo') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['repository']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.os') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['os_name']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe+ - ' , '+ - pio_eval_len( - sanitize_input(not_null(key['source_data']['os_version']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> + <%= prepare_for_view(key['source_data']['name'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.dev') %> + <%= prepare_for_view(key['source_data']['developer'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.vers') %> + <%= prepare_for_view(key['source_data']['version'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.s_link') %> + <%= prepare_for_view(key['source_data']['link'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.repo') %> + <%= prepare_for_view(key['source_data']['repository'],'small').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 %> <% when '9'%> <% step_info_string += not_null(key['source_data']['name']) %>
<%= not_null(key['name'])+': ' %> - <%= pio_eval_len( - sanitize_input(string_html_table_remove(not_null(key['source_data']['name'])).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.s_link') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['link']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> + <%= prepare_for_view(key['source_data']['name'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.s_link') %> + <%= prepare_for_view(key['source_data']['link'],'small').html_safe %> <% when '15'%> <% step_info_string += not_null(key['source_data']['description']) %>
<%= key['name']+': ' %> - <% s_cmd = pio_eval_len( - sanitize_input(not_null(key['source_data']['name'])), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) %> - <%= s_cmd.html_safe %> -
<%= t('protocols.protocols_io_import.preview.s_desc') %> - <% s_cmd_desc = pio_eval_len( - sanitize_input(string_html_table_remove(not_null(key['source_data']['description']))), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) %> - <% s_cmd_desc.html_safe %> -
<%= t('protocols.protocols_io_import.preview.os') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['os_name']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe + - ' , '+ - pio_eval_len( - sanitize_input(not_null(key['source_data']['os_version']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> + <%= prepare_for_view(key['source_data']['name'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.s_desc') %> + <%= prepare_for_view(key['source_data']['description'],'small').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 %> <% when '18'%> -
<%= t('protocols.protocols_io_import.preview.sub_prot') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['protocol_name']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> -
<%= t('protocols.protocols_io_import.preview.auth') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['full_name']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.sub_prot') %> + <%= prepare_for_view(key['source_data']['protocol_name'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.auth') %> + <%= prepare_for_view(key['source_data']['full_name'],'small').html_safe %>
<% if key['source_data']['link'].present? %> <%= t('protocols.protocols_io_import.preview.s_nobr_link') %> - <%= pio_eval_len( - sanitize_input(key['source_data']['link'].html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> + <%= prepare_for_view(key['source_data']['link'],'small').html_safe %> <% end %> <% when '19'%> <% step_info_string += not_null(key['source_data']['body']) %>
- <%= key['name']+': ' %> - <% s_safety = pio_eval_len( - sanitize_input(string_html_table_remove(not_null(key['source_data']['body']))), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) %> - <%= s_safety.html_safe %> -
<%= t('protocols.protocols_io_import.preview.s_link') %> - <%= pio_eval_len( - sanitize_input(not_null(key['source_data']['link']).html_safe), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ).html_safe %> - <% when '20'%> + <%= not_null(key['name'])+': ' %> + <%= prepare_for_view(key['source_data']['body'],'small').html_safe %> +
+ <%= t('protocols.protocols_io_import.preview.s_link') %> + <%= prepare_for_view(key['source_data']['link'],'small').html_safe %> <% else %> <% end #case if%> <% end #inner if%> From fcbd956d6e2e19c06eebff1d66e2b28545dd52a7 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Sun, 3 Dec 2017 01:17:49 +0100 Subject: [PATCH 2/7] Finished code beautification --- app/helpers/protocols_io_helper.rb | 198 +++++++----------- .../_import_json_protocol_p_desc.html.erb | 95 +++------ config/locales/en.yml | 44 ++-- 3 files changed, 135 insertions(+), 202 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 66c1305d3..f30fa28eb 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -147,7 +147,7 @@ module ProtocolsIoHelper end def prepare_for_view(attribute_text, size) - case(size) + case size when 'small' pio_eval_len( sanitize_input(string_html_table_remove(not_null(attribute_text))), @@ -163,20 +163,62 @@ module ProtocolsIoHelper sanitize_input(string_html_table_remove(not_null(attribute_text))), ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG ) - else + 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 + ) end end + def fill_attributes(attribute_name, attribute_text, step_component_key) + 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 += + if attribute_name != 'os_name' && attribute_name != 'os_version' + attribute_name + else + 'os' + end + output_string += + if attribute_name != 'os_version' + t(trans_string) + else + ' , ' + end + output_string += prepare_for_view(attribute_text, 'small-no-table') + output_string + end + # pio_stp_x means protocols io step (id of component) parser def pio_stp_1(iterating_key) # protocols io description parser br = '
' append = if iterating_key.present? br + - pio_eval_len( - sanitize_input(iterating_key), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + + prepare_for_view(iterating_key, 'small-no-table') + br else t('protocols.protocols_io_import.comp_append.missing_desc') @@ -193,10 +235,7 @@ module ProtocolsIoHelper if iterating_key.present? append = t('protocols.protocols_io_import.comp_append.expected_result') + - pio_eval_len( - sanitize_input(iterating_key), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + + prepare_for_view(iterating_key, 'small-no-table') + '
' return append end @@ -211,40 +250,13 @@ module ProtocolsIoHelper iterating_key['repository'] && iterating_key['os_name'] && iterating_key['os_version'] - append = t('protocols.protocols_io_import.comp_append.soft_packg.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.dev') + - pio_eval_len( - sanitize_input(iterating_key['developer']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.vers') + - pio_eval_len( - sanitize_input(iterating_key['version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.repo') + - pio_eval_len( - sanitize_input(iterating_key['repository']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.soft_packg.os') + - pio_eval_len( - sanitize_input(iterating_key['os_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + ' , ' + - pio_eval_len( - sanitize_input(iterating_key['os_version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + append = fill_attributes('name', iterating_key['name'], '8') + + fill_attributes('developer', iterating_key['developer'], '8') + + fill_attributes('version', iterating_key['version'], '8') + + fill_attributes('link', iterating_key['link'], '8') + + fill_attributes('repository', iterating_key['repository'], '8') + + fill_attributes('os_name', iterating_key['os_name'], '8') + + fill_attributes('os_version', iterating_key['os_version'], '8') return append end '' @@ -253,16 +265,8 @@ module ProtocolsIoHelper def pio_stp_9(iterating_key) # protocols io dataset parser if iterating_key['name'].present? && iterating_key['link'] - append = t('protocols.protocols_io_import.comp_append.dataset.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + append = fill_attributes('name', iterating_key['name'], '9') + + fill_attributes('link', iterating_key['link'], '9') return append end '' @@ -273,26 +277,10 @@ module ProtocolsIoHelper iterating_key['description'] && iterating_key['os_name'] && iterating_key['os_version'] - append = t('protocols.protocols_io_import.comp_append.command.title') + - pio_eval_len( - sanitize_input(iterating_key['name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.command.desc') + - pio_eval_len( - sanitize_input(iterating_key['description']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.command.os') + - pio_eval_len( - sanitize_input(iterating_key['os_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - ' , ' + - pio_eval_len( - sanitize_input(iterating_key['os_version']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + append = fill_attributes('name', iterating_key['name'], '15') + + fill_attributes('description', iterating_key['description'], '15') + + fill_attributes('os_name', iterating_key['os_name'], '15') + + fill_attributes('os_version', iterating_key['os_version'], '15') return append end '' @@ -302,26 +290,9 @@ module ProtocolsIoHelper if iterating_key['protocol_name'].present? && iterating_key['full_name'] && iterating_key['link'] - append = - t( - 'protocols.protocols_io_import.comp_append.sub_protocol.title' - ) + - pio_eval_len( - sanitize_input(iterating_key['protocol_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t( - 'protocols.protocols_io_import.comp_append.sub_protocol.author' - ) + - pio_eval_len( - sanitize_input(iterating_key['full_name']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + append = fill_attributes('protocol_name', iterating_key['protocol_name'], '18') + + fill_attributes('full_name', iterating_key['full_name'], '18') + + fill_attributes('link', iterating_key['link'], '18') return append end '' @@ -330,19 +301,8 @@ module ProtocolsIoHelper def pio_stp_19(iterating_key) # protocols io safety information parser if iterating_key['body'].present? && iterating_key['link'] - append = - t( - 'protocols.protocols_io_import.comp_append.safety_infor.title' - ) + - pio_eval_len( - sanitize_input(iterating_key['body']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + - t('protocols.protocols_io_import.comp_append.general_link') + - pio_eval_len( - sanitize_input(iterating_key['link']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + append = fill_attributes('body', iterating_key['body'], '19') + + fill_attributes('link', iterating_key['link'], '19') return append end '' @@ -355,13 +315,11 @@ module ProtocolsIoHelper ] description_string = if json_hash['description'].present? - '' + t('protocols.protocols_io_import.preview.prot_desc') + - '' + pio_eval_len( - sanitize_input(json_hash['description']), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM - ).html_safe + '' + t('protocols.protocols_io_import.preview.description') + + '' + + prepare_for_view(json_hash['description'], 'medium-no-table').html_safe else - '' + t('protocols.protocols_io_import.preview.prot_desc') + + '' + t('protocols.protocols_io_import.preview.description') + '' + t('protocols.protocols_io_import.comp_append.missing_desc') end description_string += '
' @@ -369,10 +327,11 @@ module ProtocolsIoHelper if e == 'created_on' && json_hash[e].present? new_e = '' + e.humanize + '' description_string += - new_e.to_s + ': ' + pio_eval_len( - sanitize_input(params['protocol']['created_at'].to_s), - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL - ) + '
' + new_e.to_s + ': ' + + prepare_for_view( + params['protocol']['created_at'].to_s, 'small-no-table' + ) + + + '
' elsif e == 'tags' && json_hash[e].any? && json_hash[e] != '' new_e = '' + e.humanize + '' description_string += @@ -382,9 +341,8 @@ module ProtocolsIoHelper tags_length_checker += sanitize_input(tag['tag_name']) + ' , ' end - description_string += pio_eval_len( - tags_length_checker, - ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM + description_string += prepare_for_view( + tags_length_checker, 'medium-no-table' ) 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 d448dfa60..e82ce934d 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 @@ -19,69 +19,40 @@ <% prot_info_string = '' %> <% @remaining = ProtocolsIoHelper::PIO_P_AVAILABLE_LENGTH %> <% protocol_table_elements_array = [] %> - <% if json_object['description'].present? %> - <% prot_info_string += (json_object['description']) %> - <%= t('protocols.protocols_io_import.preview.prot_desc') %> - <%= prepare_for_view(json_object['description'],'medium').html_safe %> -
- <% end %> - <% if json_object['before_start'].present? %> - <% prot_info_string += (json_object['before_start']) %> - <%= t('protocols.protocols_io_import.preview.b_s_p') %> - <%= prepare_for_view(json_object['before_start'],'medium').html_safe %> -
- <% end %> - <% if json_object['warning'].present? %> - <% prot_info_string += (json_object['warning']) %> - <%= t('protocols.protocols_io_import.preview.warn') %> - <%= prepare_for_view(json_object['warning'],'medium').html_safe %> -
- <% end %> - <% if json_object['guidelines'].present? %> - <% prot_info_string += (json_object['guidelines']) %> - <%= t('protocols.protocols_io_import.preview.guideln') %> - <%= prepare_for_view(json_object['guidelines'],'medium').html_safe %> -
- <% end %> - <% if json_object['manuscript_citation'].present? %> - <% prot_info_string += (json_object['manuscript_citation']) %> - <%= t('protocols.protocols_io_import.preview.manu_cit') %> - <%= prepare_for_view(json_object['manuscript_citation'],'medium').html_safe %> -
- <% end %> - <% if json_object['publish_date'].present? %> - <%= t('protocols.protocols_io_import.preview.pbl_date') %> - <%= prepare_for_view(json_object['publish_date'],'small').html_safe %> -
- <% end %> - <% if json_object['vendor_name'].present? %> - <%= t('protocols.protocols_io_import.preview.vnd_name') %> - <%= prepare_for_view(json_object['vendor_name'],'medium').html_safe %> -
- <% end %> - <% if json_object['vendor_link'].present? %> - <%= t('protocols.protocols_io_import.preview.vnd_link') %> - <%= prepare_for_view(json_object['vendor_link'],'big').html_safe %> -
- <% end %> - <% if json_object['keywords'].present? %> - <%= t('protocols.protocols_io_import.preview.key_wrd') %> - <%= prepare_for_view(json_object['keywords'],'medium').html_safe %> -
- <% end %> - <% if json_object['tags'].present? %> - <%= t('protocols.protocols_io_import.preview.tags') %> - <% string_of_tags='' %> - <% json_object['tags'].each do |tag| %> - <% string_of_tags += tag['tag_name']+' , ' %> + <% protocol_iterate_elements = ['description','before_start','warning','guidelines','manuscript_citation', + 'publish_date','vendor_name','vendor_link','keywords','tags','link'] %> + <% add_to_info_string_elements = ['description','before_start','warning','guidelines','manuscript_citation']%> + <% big_elements = ['vendor_link','link'] %> + <% medium_elements = ['description','before_start','warning','guidelines','manuscript_citation', + 'vendor_name','keywords','tags'] %> + <% small_elements = ['publish_date'] %> + + <% protocol_iterate_elements.each do |element|%> + <% if(json_object[element].present?) %> + <% if element == 'tags' %> + <% translation_string = 'protocols.protocols_io_import.preview.' + element %> + <%= t(translation_string) %> + <% string_of_tags='' %> + <% json_object['tags'].each do |tag| %> + <% string_of_tags += tag['tag_name']+' , ' %> + <% end %> + <%= prepare_for_view(string_of_tags,'medium').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 %> + <% end %> + <% if medium_elements.include? element %> + <%= prepare_for_view(json_object[element],'medium').html_safe %> + <% end %> + <% if small_elements.include? element %> + <%= prepare_for_view(json_object[element],'small').html_safe %> + <% end %> + <% end %> +
<% end %> - <%= prepare_for_view(string_of_tags,'medium').html_safe %> -
- <% end %> - <% if json_object['link'].present? %> - <%= t('protocols.protocols_io_import.preview.p_link') %> - <%= prepare_for_view(json_object['link'],'big').html_safe %> -
<% end %> <% tables, garbage = protocolsio_string_to_table_element(prot_info_string) %> <% if tables.present? %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 85ddffff1..24eff00e1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1389,11 +1389,11 @@ en: too_long: "... Text is too long so we had to cut it off." import_description_notice: "The protocols description is listed below under \"Protocol info\"." preview: - prot_desc: "Protocol Description: " - b_s_p: "Before starting protocol information:" - warn: "Protocol warning:" - guideln: "Guidelines:" - p_link: "Link:" + description: "Protocol Description: " + before_start: "Before starting protocol information:" + warning: "Protocol warning:" + guidelines: "Guidelines:" + link: "Link:" s_nobr_link: "Link:" s_link: "Link:" s_desc: "Description:" @@ -1405,11 +1405,11 @@ en: os: "OS name , OS version:" sub_prot: "This protocol also contains an attached sub-protocol:" auth: "Author:" - manu_cit: "Manuscript citation:" - pbl_date: "Publish date:" - vnd_name: "Vendor name:" - vnd_link: "Vendor link:" - key_wrd: "Keywords:" + manuscript_citation: "Manuscript citation:" + publish_date: "Publish date:" + vendor_name: "Vendor name:" + vendor_link: "Vendor link:" + keywords: "Keywords:" tags: "Tags:" comp_append: table_moved: "
There was a table here, it was moved to the end of this step. " @@ -1418,22 +1418,26 @@ en: general_link: "
Link: " expected_result: "
Expected result: " soft_packg: - title: "
Software package: " - dev: "
Developer: " - vers: "
Version: " - repo: "
Repository: " + name: "
Software package: " + developer: "
Developer: " + version: "
Version: " + link: "
Link: " + repository: "
Repository: " os: "
OS name , OS version: " dataset: - title: "
Dataset: " + name: "
Dataset: " + link: "
Link: " command: - title: "
Command: " - desc: "
Description: " + name: "
Command: " + description: "
Description: " os: "
OS name , OS version: " sub_protocol: - title: "
This step also contains an attached sub-protocol: " - author: "
Author: " + protocol_name: "
This step also contains an attached sub-protocol: " + full_name: "
Author: " + link: "
Link: " safety_infor: - title: "
Safety information: " + body: "
Safety information: " + link: "
Link: " import_export: load_file_error: "Failed to load the protocol file." import_modal: From b0012ab9361845de27af13f863183ebedd79ef44 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Sun, 3 Dec 2017 16:50:06 +0100 Subject: [PATCH 3/7] Simplified repeating method calls --- app/helpers/protocols_io_helper.rb | 45 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index f30fa28eb..464bbe41e 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -250,13 +250,13 @@ module ProtocolsIoHelper iterating_key['repository'] && iterating_key['os_name'] && iterating_key['os_version'] - append = fill_attributes('name', iterating_key['name'], '8') + - fill_attributes('developer', iterating_key['developer'], '8') + - fill_attributes('version', iterating_key['version'], '8') + - fill_attributes('link', iterating_key['link'], '8') + - fill_attributes('repository', iterating_key['repository'], '8') + - fill_attributes('os_name', iterating_key['os_name'], '8') + - fill_attributes('os_version', iterating_key['os_version'], '8') + append = '' + parse_elements_array = %w( + name developer version link repository os_name os_version + ) + parse_elements_array.each do |element| + append += fill_attributes(element, iterating_key[element], '8') + end return append end '' @@ -265,8 +265,11 @@ module ProtocolsIoHelper def pio_stp_9(iterating_key) # protocols io dataset parser if iterating_key['name'].present? && iterating_key['link'] - append = fill_attributes('name', iterating_key['name'], '9') + - fill_attributes('link', iterating_key['link'], '9') + append = '' + parse_elements_array = %w(name link) + parse_elements_array.each do |element| + append += fill_attributes(element, iterating_key[element], '9') + end return append end '' @@ -277,10 +280,11 @@ module ProtocolsIoHelper iterating_key['description'] && iterating_key['os_name'] && iterating_key['os_version'] - append = fill_attributes('name', iterating_key['name'], '15') + - fill_attributes('description', iterating_key['description'], '15') + - fill_attributes('os_name', iterating_key['os_name'], '15') + - fill_attributes('os_version', iterating_key['os_version'], '15') + 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 end '' @@ -290,9 +294,11 @@ module ProtocolsIoHelper if iterating_key['protocol_name'].present? && iterating_key['full_name'] && iterating_key['link'] - append = fill_attributes('protocol_name', iterating_key['protocol_name'], '18') + - fill_attributes('full_name', iterating_key['full_name'], '18') + - fill_attributes('link', iterating_key['link'], '18') + 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 end '' @@ -301,8 +307,11 @@ module ProtocolsIoHelper def pio_stp_19(iterating_key) # protocols io safety information parser if iterating_key['body'].present? && iterating_key['link'] - append = fill_attributes('body', iterating_key['body'], '19') + - fill_attributes('link', iterating_key['link'], '19') + append = '' + parse_elements_array = %w(body link) + parse_elements_array.each do |element| + append += fill_attributes(element, iterating_key[element], '19') + end return append end '' From 53561ffd84937004cb5871d4cbd9dbbd10ce13e6 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Fri, 15 Dec 2017 20:39:15 +0100 Subject: [PATCH 4/7] Refactored according to PR --- app/helpers/protocols_io_helper.rb | 188 ++++++++---------- .../_import_json_protocol_p_desc.html.erb | 8 +- .../_import_json_protocol_s_desc.html.erb | 40 ++-- 3 files changed, 106 insertions(+), 130 deletions(-) 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%> From 83e1b04c7a917c97b1866827940576b0a33096d3 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Sun, 24 Dec 2017 01:49:04 +0100 Subject: [PATCH 5/7] Fixed pull request --- app/helpers/protocols_io_helper.rb | 67 +++++++++++++------ .../_import_json_protocol_p_desc.html.erb | 27 ++++---- 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 9a1ca383b..8fa648d7d 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -216,73 +216,66 @@ module ProtocolsIoHelper '' end - def pio_stp_8(iterating_key) # protocols io software package parser + def pio_stp_8(iterating_key, parse_elements_array, en_local_text) # protocols io software package parser 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.' + en_local_text ) end append end - def pio_stp_9(iterating_key) # protocols io dataset parser + def pio_stp_9(iterating_key, parse_elements_array, en_local_text) # protocols io dataset parser 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.' + en_local_text ) end append end - def pio_stp_15(iterating_key) # protocols io commands parser + def pio_stp_15(iterating_key, parse_elements_array, en_local_text) # protocols io commands parser 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.' + en_local_text ) end append end - def pio_stp_18(iterating_key) # protocols io sub protocol parser + def pio_stp_18(iterating_key, parse_elements_array, en_local_text) # protocols io sub protocol parser 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.' + en_local_text ) end append end - def pio_stp_19(iterating_key) # protocols io safety information parser + def pio_stp_19(iterating_key, parse_elements_array, en_local_text) # protocols io safety information parser 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.' + en_local_text ) end append @@ -381,15 +374,45 @@ module ProtocolsIoHelper when '17' newj[i.to_s]['description'] += pio_stp_17(key['data']) when '8' - newj[i.to_s]['description'] += pio_stp_8(key['source_data']) + pe_array = %w( + name developer version link repository os_name os_version + ) + trans_text = 'protocols.protocols_io_import.comp_append.soft_packg.' + newj[i.to_s]['description'] += pio_stp_8( + key['source_data'], pe_array, trans_text + ) when '9' - newj[i.to_s]['description'] += pio_stp_9(key['source_data']) + pe_array = %w( + name link + ) + trans_text = 'protocols.protocols_io_import.comp_append.dataset.' + newj[i.to_s]['description'] += pio_stp_9( + key['source_data'], pe_array, trans_text + ) when '15' - newj[i.to_s]['description'] += pio_stp_15(key['source_data']) + pe_array = %w( + name description os_name os_version + ) + trans_text = 'protocols.protocols_io_import.comp_append.command.' + newj[i.to_s]['description'] += pio_stp_15( + key['source_data'], pe_array, trans_text + ) when '18' - newj[i.to_s]['description'] += pio_stp_18(key['source_data']) + pe_array = %w( + protocol_name full_name link + ) + trans_text = 'protocols.protocols_io_import.comp_append.sub_protocol.' + newj[i.to_s]['description'] += pio_stp_18( + key['source_data'], pe_array, trans_text + ) when '19' - newj[i.to_s]['description'] += pio_stp_19(key['source_data']) + pe_array = %w( + body link + ) + trans_text = 'protocols.protocols_io_import.comp_append.safety_infor.' + newj[i.to_s]['description'] += pio_stp_19( + key['source_data'], pe_array, trans_text + ) end # case end end # finished looping over step components newj[i.to_s]['tables'], table_str = protocolsio_string_to_table_element( 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 ff037d2c8..35d384d9c 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 @@ -22,11 +22,18 @@ <% protocol_iterate_elements = ['description','before_start','warning','guidelines','manuscript_citation', 'publish_date','vendor_name','vendor_link','keywords','tags','link'] %> <% add_to_info_string_elements = ['description','before_start','warning','guidelines','manuscript_citation']%> - <% big_elements = ['vendor_link','link'] %> - <% medium_elements = ['description','before_start','warning','guidelines','manuscript_citation', - 'vendor_name','keywords','tags'] %> - <% small_elements = ['publish_date'] %> - + <% protocol_attr_len_hash = { + description: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + before_start: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + warning: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + guidelines: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + manuscript_citation: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + vendor_name: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + keywords: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + tags: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, + publish_date: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, + link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG, + vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %> <% protocol_iterate_elements.each do |element|%> <% if(json_object[element].present?) %> <% if element == 'tags' %> @@ -41,15 +48,7 @@ <% 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],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG,'table').html_safe %> - <% end %> - <% if medium_elements.include? element %> - <%= 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],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table').html_safe %> - <% end %> + <%= prepare_for_view(json_object[element],protocol_attr_len_hash[element.to_sym],'table').html_safe %> <% end %>
<% end %> From 7bad7225535d25f8eaf8c7b82dbc26f495cb4e24 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Sun, 24 Dec 2017 02:06:14 +0100 Subject: [PATCH 6/7] Made small oversight and fixed it --- app/helpers/protocols_io_helper.rb | 65 ++++-------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 8fa648d7d..e4eb5f70a 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -215,60 +215,9 @@ module ProtocolsIoHelper end '' end + # protocols io software package,dataset,commands,sub_protocol and safety_information parser - def pio_stp_8(iterating_key, parse_elements_array, en_local_text) # protocols io software package parser - append = '' - parse_elements_array.each do |element| - return '' unless iterating_key[element] - append += fill_attributes( - element, - iterating_key[element], - en_local_text - ) - end - append - end - - def pio_stp_9(iterating_key, parse_elements_array, en_local_text) # protocols io dataset parser - append = '' - parse_elements_array.each do |element| - return '' unless iterating_key[element] - append += fill_attributes( - element, - iterating_key[element], - en_local_text - ) - end - append - end - - def pio_stp_15(iterating_key, parse_elements_array, en_local_text) # protocols io commands parser - append = '' - parse_elements_array.each do |element| - return '' unless iterating_key[element] - append += fill_attributes( - element, - iterating_key[element], - en_local_text - ) - end - append - end - - def pio_stp_18(iterating_key, parse_elements_array, en_local_text) # protocols io sub protocol parser - append = '' - parse_elements_array.each do |element| - return '' unless iterating_key[element] - append += fill_attributes( - element, - iterating_key[element], - en_local_text - ) - end - append - end - - def pio_stp_19(iterating_key, parse_elements_array, en_local_text) # protocols io safety information parser + def pio_stp(iterating_key, parse_elements_array, en_local_text) append = '' parse_elements_array.each do |element| return '' unless iterating_key[element] @@ -378,7 +327,7 @@ module ProtocolsIoHelper name developer version link repository os_name os_version ) trans_text = 'protocols.protocols_io_import.comp_append.soft_packg.' - newj[i.to_s]['description'] += pio_stp_8( + newj[i.to_s]['description'] += pio_stp( key['source_data'], pe_array, trans_text ) when '9' @@ -386,7 +335,7 @@ module ProtocolsIoHelper name link ) trans_text = 'protocols.protocols_io_import.comp_append.dataset.' - newj[i.to_s]['description'] += pio_stp_9( + newj[i.to_s]['description'] += pio_stp( key['source_data'], pe_array, trans_text ) when '15' @@ -394,7 +343,7 @@ module ProtocolsIoHelper name description os_name os_version ) trans_text = 'protocols.protocols_io_import.comp_append.command.' - newj[i.to_s]['description'] += pio_stp_15( + newj[i.to_s]['description'] += pio_stp( key['source_data'], pe_array, trans_text ) when '18' @@ -402,7 +351,7 @@ module ProtocolsIoHelper protocol_name full_name link ) trans_text = 'protocols.protocols_io_import.comp_append.sub_protocol.' - newj[i.to_s]['description'] += pio_stp_18( + newj[i.to_s]['description'] += pio_stp( key['source_data'], pe_array, trans_text ) when '19' @@ -410,7 +359,7 @@ module ProtocolsIoHelper body link ) trans_text = 'protocols.protocols_io_import.comp_append.safety_infor.' - newj[i.to_s]['description'] += pio_stp_19( + newj[i.to_s]['description'] += pio_stp( key['source_data'], pe_array, trans_text ) end # case end From 3c6d37ce6484a94c8d0ba3fe73dd84e212f83de2 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Thu, 11 Jan 2018 18:37:36 +0100 Subject: [PATCH 7/7] Fixed according to PR review --- .../import_export/_import_json_protocol_p_desc.html.erb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 35d384d9c..dae8b49f6 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 @@ -19,8 +19,6 @@ <% prot_info_string = '' %> <% @remaining = ProtocolsIoHelper::PIO_P_AVAILABLE_LENGTH %> <% protocol_table_elements_array = [] %> - <% protocol_iterate_elements = ['description','before_start','warning','guidelines','manuscript_citation', - 'publish_date','vendor_name','vendor_link','keywords','tags','link'] %> <% add_to_info_string_elements = ['description','before_start','warning','guidelines','manuscript_citation']%> <% protocol_attr_len_hash = { description: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, @@ -34,7 +32,8 @@ publish_date: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG, vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %> - <% protocol_iterate_elements.each do |element|%> + <% 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 %>