Fix publish_date in PIO import

This commit is contained in:
Jure Grabnar 2018-11-23 17:37:26 +01:00
parent 76c2da4bae
commit 87d5e5029a
4 changed files with 19 additions and 20 deletions

View file

@ -82,26 +82,23 @@ module ProtocolsIoHelper
return tables, string_without_tables return tables, string_without_tables
end end
def uniq_tables(description_string) def string_html_table_remove(description_string)
# Extract uniq tables from the HTML
description_string.remove!("\n", "\t", "\r", "\f") description_string.remove!("\n", "\t", "\r", "\f")
table_whole_regex = %r{(<table\b[^>]*>.*?<\/table>)}m table_whole_regex = %r{(<table\b[^>]*>.*?<\/table>)}m
description_string.scan(table_whole_regex).uniq table_pattern_array = description_string.scan(table_whole_regex)
end string_without_tables = description_string
table_pattern_array.each do |table_pattern|
def string_html_table_remove(description_string) string_without_tables = string_without_tables.gsub(
table_pattern_array = uniq_tables(description_string) table_pattern[0],
if table_pattern_array.length.zero? t('protocols.protocols_io_import.comp_append.table_moved').html_safe
description_string )
else
table_text = table_pattern_array.length.times.collect { t('protocols.protocols_io_import.comp_append.table_moved').html_safe }.join
"<div class='text-blocks'><br>#{table_text}<br></div>"
end end
string_without_tables
end end
def pio_eval_prot_desc(text, attribute_name) def pio_eval_prot_desc(text, attribute_name)
case attribute_name case attribute_name
when 'publish_date' when 'published_on'
pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL) pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL)
when 'vendor_link', 'link' when 'vendor_link', 'link'
pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG) pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG)
@ -291,7 +288,7 @@ module ProtocolsIoHelper
def protocols_io_fill_desc(json_hash) def protocols_io_fill_desc(json_hash)
unshortened_string_for_tables = '' unshortened_string_for_tables = ''
description_array = %w[ description_array = %w[
( before_start warning guidelines manuscript_citation publish_date ( before_start warning guidelines manuscript_citation published_on
vendor_name vendor_link keywords tags link created_on ) vendor_name vendor_link keywords tags link created_on )
] ]
allowed_image_attributes = %w[ allowed_image_attributes = %w[

View file

@ -29,7 +29,7 @@
vendor_name: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, vendor_name: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,
keywords: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, keywords: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,
tags: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM, tags: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_MEDIUM,
publish_date: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, published_on: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,
link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG, link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG,
vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %> vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %>
<% allowed_image_attributes = %w( <% allowed_image_attributes = %w(
@ -39,7 +39,11 @@
<% element = element.to_s %> <% element = element.to_s %>
<% if(json_object[element].present?) %> <% if(json_object[element].present?) %>
<% if element == 'tags' %> <% if element == 'published_on' %>
<% translation_string = 'protocols.protocols_io_import.preview.' + element %>
<strong><%= t(translation_string) %></strong>
<%= prepare_for_view(Time.at(json_object[element]).utc.to_datetime,protocol_attr_len_hash[element.to_sym]).html_safe %>
<% elsif element == 'tags' %>
<% translation_string = 'protocols.protocols_io_import.preview.' + element %> <% translation_string = 'protocols.protocols_io_import.preview.' + element %>
<strong><%= t(translation_string) %></strong> <strong><%= t(translation_string) %></strong>
<% string_of_tags='' %> <% string_of_tags='' %>

View file

@ -31,15 +31,13 @@
<div data-val="description" class="ql-editor"> <div data-val="description" class="ql-editor">
<% step_info_string = '' %> <% step_info_string = '' %>
<% step['components'].each do |key| %> <% step['components'].each do |key| %>
<% puts('component') %>
<% puts(key) %>
<% if whitelist_simple.include?(key['type_id']) && key['source'].present? %> <% if whitelist_simple.include?(key['type_id']) && key['source'].present? %>
<br> <br>
<% case key['type_id'] <% case key['type_id']
when 1 %> when 1 %>
<% data = key['source']['description'] %> <% data = key['source']['description'] %>
<% if data.present? %> <% if data.present? %>
<% step_info_string += uniq_tables(sanitize_input(not_null(data))).join %> <% step_info_string += not_null(data) %>
<br> <br>
<strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong> <strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong>
<%= prepare_for_view( <%= prepare_for_view(

View file

@ -1554,7 +1554,7 @@ en:
sub_prot: "This protocol also contains an attached sub-protocol:" sub_prot: "This protocol also contains an attached sub-protocol:"
auth: "Author:" auth: "Author:"
manuscript_citation: "Manuscript citation:" manuscript_citation: "Manuscript citation:"
publish_date: "Publish date:" published_on: "Publish date:"
vendor_name: "Vendor name:" vendor_name: "Vendor name:"
vendor_link: "Vendor link:" vendor_link: "Vendor link:"
keywords: "Keywords:" keywords: "Keywords:"