From 87d5e5029a838bd1c95cddbbbc4adb4fbc13a765 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Fri, 23 Nov 2018 17:37:26 +0100 Subject: [PATCH] Fix publish_date in PIO import --- app/helpers/protocols_io_helper.rb | 25 ++++++++----------- .../_import_json_protocol_p_desc.html.erb | 8 ++++-- .../_import_json_protocol_s_desc.html.erb | 4 +-- config/locales/en.yml | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 7ff1e9f7c..e30f13a97 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -82,26 +82,23 @@ module ProtocolsIoHelper return tables, string_without_tables end - def uniq_tables(description_string) - # Extract uniq tables from the HTML + def string_html_table_remove(description_string) description_string.remove!("\n", "\t", "\r", "\f") table_whole_regex = %r{(]*>.*?<\/table>)}m - description_string.scan(table_whole_regex).uniq - end - - def string_html_table_remove(description_string) - table_pattern_array = uniq_tables(description_string) - if table_pattern_array.length.zero? - description_string - else - table_text = table_pattern_array.length.times.collect { t('protocols.protocols_io_import.comp_append.table_moved').html_safe }.join - "

#{table_text}
" + table_pattern_array = description_string.scan(table_whole_regex) + string_without_tables = description_string + table_pattern_array.each do |table_pattern| + string_without_tables = string_without_tables.gsub( + table_pattern[0], + t('protocols.protocols_io_import.comp_append.table_moved').html_safe + ) end + string_without_tables end def pio_eval_prot_desc(text, attribute_name) case attribute_name - when 'publish_date' + when 'published_on' pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL) when 'vendor_link', 'link' pio_eval_len(text, ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG) @@ -291,7 +288,7 @@ module ProtocolsIoHelper def protocols_io_fill_desc(json_hash) unshortened_string_for_tables = '' 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 ) ] allowed_image_attributes = %w[ 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 a8b9d10ba..280bbe101 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 @@ -29,7 +29,7 @@ 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, + published_on: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL, link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG, vendor_link: ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_BIG } %> <% allowed_image_attributes = %w( @@ -39,7 +39,11 @@ <% element = element.to_s %> <% if(json_object[element].present?) %> - <% if element == 'tags' %> + <% if element == 'published_on' %> + <% translation_string = 'protocols.protocols_io_import.preview.' + element %> + <%= t(translation_string) %> + <%= 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 %> <%= t(translation_string) %> <% string_of_tags='' %> 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 07fb3e779..db2a3d64c 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 @@ -31,15 +31,13 @@
<% step_info_string = '' %> <% step['components'].each do |key| %> - <% puts('component') %> - <% puts(key) %> <% if whitelist_simple.include?(key['type_id']) && key['source'].present? %>
<% case key['type_id'] when 1 %> <% data = key['source']['description'] %> <% if data.present? %> - <% step_info_string += uniq_tables(sanitize_input(not_null(data))).join %> + <% step_info_string += not_null(data) %>
<%= t('protocols.protocols_io_import.preview.strng_s_desc') %> <%= prepare_for_view( diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d44d9ccd..3764bc221 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1554,7 +1554,7 @@ en: sub_prot: "This protocol also contains an attached sub-protocol:" auth: "Author:" manuscript_citation: "Manuscript citation:" - publish_date: "Publish date:" + published_on: "Publish date:" vendor_name: "Vendor name:" vendor_link: "Vendor link:" keywords: "Keywords:"