mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-01 20:48:23 +08:00
Finished code beautification
This commit is contained in:
parent
835ac6910f
commit
fcbd956d6e
3 changed files with 135 additions and 202 deletions
|
@ -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 = '<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') +
|
||||
'<br>'
|
||||
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?
|
||||
'<strong>' + t('protocols.protocols_io_import.preview.prot_desc') +
|
||||
'</strong>' + pio_eval_len(
|
||||
sanitize_input(json_hash['description']),
|
||||
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM
|
||||
).html_safe
|
||||
'<strong>' + t('protocols.protocols_io_import.preview.description') +
|
||||
'</strong>' +
|
||||
prepare_for_view(json_hash['description'], 'medium-no-table').html_safe
|
||||
else
|
||||
'<strong>' + t('protocols.protocols_io_import.preview.prot_desc') +
|
||||
'<strong>' + t('protocols.protocols_io_import.preview.description') +
|
||||
'</strong>' + t('protocols.protocols_io_import.comp_append.missing_desc')
|
||||
end
|
||||
description_string += '<br>'
|
||||
|
@ -369,10 +327,11 @@ module ProtocolsIoHelper
|
|||
if e == 'created_on' && json_hash[e].present?
|
||||
new_e = '<strong>' + e.humanize + '</strong>'
|
||||
description_string +=
|
||||
new_e.to_s + ': ' + pio_eval_len(
|
||||
sanitize_input(params['protocol']['created_at'].to_s),
|
||||
ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL
|
||||
) + '<br>'
|
||||
new_e.to_s + ': ' +
|
||||
prepare_for_view(
|
||||
params['protocol']['created_at'].to_s, 'small-no-table'
|
||||
) +
|
||||
+ '<br>'
|
||||
elsif e == 'tags' && json_hash[e].any? && json_hash[e] != ''
|
||||
new_e = '<strong>' + e.humanize + '</strong>'
|
||||
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 += '<br>'
|
||||
elsif json_hash[e].present?
|
||||
|
|
|
@ -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']) %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.prot_desc') %></strong>
|
||||
<%= prepare_for_view(json_object['description'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['before_start'].present? %>
|
||||
<% prot_info_string += (json_object['before_start']) %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.b_s_p') %></strong>
|
||||
<%= prepare_for_view(json_object['before_start'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['warning'].present? %>
|
||||
<% prot_info_string += (json_object['warning']) %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.warn') %></strong>
|
||||
<%= prepare_for_view(json_object['warning'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['guidelines'].present? %>
|
||||
<% prot_info_string += (json_object['guidelines']) %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.guideln') %></strong>
|
||||
<%= prepare_for_view(json_object['guidelines'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['manuscript_citation'].present? %>
|
||||
<% prot_info_string += (json_object['manuscript_citation']) %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.manu_cit') %></strong>
|
||||
<%= prepare_for_view(json_object['manuscript_citation'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['publish_date'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.pbl_date') %></strong>
|
||||
<%= prepare_for_view(json_object['publish_date'],'small').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['vendor_name'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.vnd_name') %></strong>
|
||||
<%= prepare_for_view(json_object['vendor_name'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['vendor_link'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.vnd_link') %></strong>
|
||||
<%= prepare_for_view(json_object['vendor_link'],'big').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['keywords'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.key_wrd') %></strong>
|
||||
<%= prepare_for_view(json_object['keywords'],'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['tags'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.tags') %></strong>
|
||||
<% 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 %>
|
||||
<strong><%= t(translation_string) %></strong>
|
||||
<% 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 %>
|
||||
<strong><%= t(translation_string) %></strong>
|
||||
<% 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 %>
|
||||
<br>
|
||||
<% end %>
|
||||
<%= prepare_for_view(string_of_tags,'medium').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% if json_object['link'].present? %>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.p_link') %></strong>
|
||||
<%= prepare_for_view(json_object['link'],'big').html_safe %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% tables, garbage = protocolsio_string_to_table_element(prot_info_string) %>
|
||||
<% if tables.present? %>
|
||||
|
|
|
@ -1389,11 +1389,11 @@ en:
|
|||
too_long: "... <span class='label label-warning'>Text is too long so we had to cut it off.</span>"
|
||||
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: "<br><strong><i>There was a table here, it was moved to the end of this step. </i></strong>"
|
||||
|
@ -1418,22 +1418,26 @@ en:
|
|||
general_link: "<br>Link: "
|
||||
expected_result: "<br><strong>Expected result: </strong>"
|
||||
soft_packg:
|
||||
title: "<br><strong>Software package: </strong>"
|
||||
dev: "<br>Developer: "
|
||||
vers: "<br>Version: "
|
||||
repo: "<br>Repository: "
|
||||
name: "<br><strong>Software package: </strong>"
|
||||
developer: "<br>Developer: "
|
||||
version: "<br>Version: "
|
||||
link: "<br>Link: "
|
||||
repository: "<br>Repository: "
|
||||
os: "<br>OS name , OS version: "
|
||||
dataset:
|
||||
title: "<br><strong>Dataset: </strong>"
|
||||
name: "<br><strong>Dataset: </strong>"
|
||||
link: "<br>Link: "
|
||||
command:
|
||||
title: "<br><strong>Command: </strong>"
|
||||
desc: "<br>Description: "
|
||||
name: "<br><strong>Command: </strong>"
|
||||
description: "<br>Description: "
|
||||
os: "<br>OS name , OS version: "
|
||||
sub_protocol:
|
||||
title: "<br><strong>This step also contains an attached sub-protocol: </strong>"
|
||||
author: "<br>Author: "
|
||||
protocol_name: "<br><strong>This step also contains an attached sub-protocol: </strong>"
|
||||
full_name: "<br>Author: "
|
||||
link: "<br>Link: "
|
||||
safety_infor:
|
||||
title: "<br><strong>Safety information: </strong>"
|
||||
body: "<br><strong>Safety information: </strong>"
|
||||
link: "<br>Link: "
|
||||
import_export:
|
||||
load_file_error: "Failed to load the protocol file."
|
||||
import_modal:
|
||||
|
|
Loading…
Reference in a new issue