diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 888062ef6..394bde659 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1107,10 +1107,68 @@ class ProtocolsController < ApplicationController 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 protocolsio_string_to_table_element(description_string) + string_without_tables = string_html_table_remove(description_string) + table_regex = %r{]*>(.*?)<\/table>}m + tr_regex = %r{]*>(.*?)<\/tr>}m + td_regex = %r{]*>(.*?)<\/td>}m + tables = {} + table_counter = 0 + table_strings = description_string.scan(table_regex) + table_strings.each do |table| + tables[table_counter.to_s] = {} + tr_counter = 0 + tr_strings = table[0].scan(tr_regex) + contents = {} + contents['data'] = [] + tr_strings.each do |tr| + td_counter = 0 + td_strings = tr[0].scan(td_regex) + contents['data'][tr_counter] = [] + td_strings.each do |td| + contents['data'][tr_counter].push(td[0]) + td_counter += 1 + break if td_counter >= 5 + end + tr_counter += 1 + end + tables[table_counter.to_s]['contents'] = Base64.encode64( + contents.to_s.sub('=>', ':') + ) + tables[table_counter.to_s]['name'] = nil + table_counter += 1 + end + # return string_without_tables, tables + return tables, string_without_tables + end + helper_method :protocolsio_string_to_table_element + + def string_html_table_remove(description_string) + description_string.delete! "\n" + description_string.delete! "\t" + description_string.delete! "\r" + description_string.delete! "\f" + table_whole_regex = %r{(]*>.*?<\/table>)}m + 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 + helper_method :string_html_table_remove + def move_protocol(action) rollbacked = false results = [] 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 365fc8dd2..266a9ed07 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 @@ -15,50 +15,89 @@
-
- <% if json_object['before_start'].present? %> - <%= t('protocols.protocols_io_import.preview.b_s_p') %> - <%= sanitize_input(json_object['before_start'].html_safe) %>
- <% end %> - <% if json_object['warning'].present? %> - <%= t('protocols.protocols_io_import.preview.warn') %> - <%= sanitize_input(json_object['warning'].html_safe) %>
- <% end %> - <% if json_object['guidelines'].present? %> - <%= t('protocols.protocols_io_import.preview.guideln') %> - <%= sanitize_input(json_object['guidelines'].html_safe) %>
- <% end %> - <% if json_object['manuscript_citation'].present? %> - <%= t('protocols.protocols_io_import.preview.manu_cit') %> - <%= sanitize_input(json_object['manuscript_citation'].html_safe) %>
- <% end %> - <% if json_object['publish_date'].present? %> - <%= t('protocols.protocols_io_import.preview.pbl_date') %> - <%= sanitize_input(json_object['publish_date']) %>
- <% end %> - <% if json_object['vendor_name'].present? %> - <%= t('protocols.protocols_io_import.preview.vnd_name') %> - <%= sanitize_input(json_object['vendor_name']) %>
- <% end %> - <% if json_object['vendor_link'].present? %> - <%= t('protocols.protocols_io_import.preview.vnd_link') %> - <%= sanitize_input(json_object['vendor_link'].html_safe) %>
- <% end %> - <% if json_object['keywords'].present? %> - <%= t('protocols.protocols_io_import.preview.key_wrd') %> - <%= sanitize_input(json_object['keywords']) %>
- <% end %> - <% if json_object['tags'].present? %> - <%= t('protocols.protocols_io_import.preview.tags') %> - <% json_object['tags'].each do |tag| %> - <%= sanitize_input(tag['tag_name'])+' , ' %>
+
+ <% prot_info_string = '' %> + <% protocol_table_elements_array = [] %> + <% if json_object['before_start'].present? %> + <% prot_info_string += (json_object['before_start']) %> + <%= t('protocols.protocols_io_import.preview.b_s_p') %> + <%= sanitize_input(string_html_table_remove(json_object['before_start']).html_safe) %>
+ <% end %> + <% if json_object['warning'].present? %> + <% prot_info_string += (json_object['warning']) %> + <%= t('protocols.protocols_io_import.preview.warn') %> + <%= sanitize_input(string_html_table_remove(json_object['warning']).html_safe) %>
+ <% end %> + <% if json_object['guidelines'].present? %> + <% prot_info_string += (json_object['guidelines']) %> + <%= t('protocols.protocols_io_import.preview.guideln') %> + <%= sanitize_input(string_html_table_remove(json_object['guidelines']).html_safe) %>
+ <% end %> + <% if json_object['manuscript_citation'].present? %> + <% prot_info_string += (json_object['manuscript_citation']) %> + <%= t('protocols.protocols_io_import.preview.manu_cit') %> + <%= sanitize_input(string_html_table_remove(json_object['manuscript_citation']).html_safe) %>
+ <% end %> + <% if json_object['publish_date'].present? %> + <%= t('protocols.protocols_io_import.preview.pbl_date') %> + <%= sanitize_input(json_object['publish_date']) %>
+ <% end %> + <% if json_object['vendor_name'].present? %> + <%= t('protocols.protocols_io_import.preview.vnd_name') %> + <%= sanitize_input(json_object['vendor_name']) %>
+ <% end %> + <% if json_object['vendor_link'].present? %> + <%= t('protocols.protocols_io_import.preview.vnd_link') %> + <%= sanitize_input(json_object['vendor_link'].html_safe) %>
+ <% end %> + <% if json_object['keywords'].present? %> + <%= t('protocols.protocols_io_import.preview.key_wrd') %> + <%= sanitize_input(json_object['keywords']) %>
+ <% end %> + <% if json_object['tags'].present? %> + <%= t('protocols.protocols_io_import.preview.tags') %> + <% json_object['tags'].each do |tag| %> + <%= sanitize_input(tag['tag_name'])+' , ' %>
+ <% end %> + <% end %> + <% if json_object['link'].present? %> + <%= t('protocols.protocols_io_import.preview.p_link') %> + <%= sanitize_input(json_object['link'].html_safe) %>
+ <% end %> + <% tables, garbage = protocolsio_string_to_table_element(prot_info_string) %> + <% if tables.present? %> +


+ <% end %> + <% table_count = 0 %> + <% tables.each do |index, table| %> + <% table_hash = JSON.parse((Base64.decode64(table['contents']))) %> + <% pio_table_id = "pio_table_prot_info_"+table_count.to_s %> + <% protocol_table_elements_array.push([pio_table_id,table_hash['data']]) %> +
+ <% table_count += 1 %> <% end %> - <% end %> - <% if json_object['link'].present? %> - <%= t('protocols.protocols_io_import.preview.p_link') %> - <%= sanitize_input(json_object['link'].html_safe) %>
- <% 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 6d161af63..0d2b4358f 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 @@ -1,13 +1,14 @@ <% whitelist_simple=['1','6','17'] %> <% whitelist_complex=['8','9','15','18','19','20']%> +<% step_table_elements_array = [] %> <% json_object['steps'].each_with_index do |step,counter_orig| %> -<% counter = counter_orig + 1 %> +<% counter = counter_orig + 2 %>

- <%= (counter+1) %> + <%= (counter) %>     @@ -28,6 +29,7 @@
+ <% step_info_string = '' %> <% step['components'].each do |key,value| %> <%#here i made an if to distinguish the first step from the others, because the first step #sometimes has index values as keys instead of @@ -38,19 +40,22 @@
<% case key['component_type_id'] when '1' %> + <% step_info_string += (key['data']) %>
<%= t('protocols.protocols_io_import.preview.strng_s_desc') %> - <%=sanitize_input(key['data'].html_safe)%>
+ <%=sanitize_input(string_html_table_remove(key['data']).html_safe)%>
<% when '17' %> + <% step_info_string += (key['data']) %>
<%= t('protocols.protocols_io_import.preview.s_exp_res') %> - <%=sanitize_input(key['data'].html_safe)%> + <%=sanitize_input(string_html_table_remove(key['data']).html_safe)%>
<% end %> <% elsif key && whitelist_complex.include?(key['component_type_id']) %> <% case key['component_type_id'] when '8'%> + <% step_info_string += key['source_data']['name'] %>
<%= key['name']+': ' %> - <%= sanitize_input(key['source_data']['name'].html_safe) %> + <%= sanitize_input(string_html_table_remove(key['source_data']['name']).html_safe) %>
<%= t('protocols.protocols_io_import.preview.dev') %> <%= sanitize_input(key['source_data']['developer'].html_safe) %>
<%= t('protocols.protocols_io_import.preview.vers') %> @@ -63,17 +68,19 @@ <%= sanitize_input(key['source_data']['os_name'].html_safe)+ ' , '+sanitize_input(key['source_data']['os_version'].html_safe) %> <% when '9'%> + <% step_info_string += key['source_data']['name'] %>
<%= key['name']+': ' %> - <%= sanitize_input(key['source_data']['name'].html_safe) %> + <%= sanitize_input(string_html_table_remove(key['source_data']['name']).html_safe) %>
<%= t('protocols.protocols_io_import.preview.s_link') %> <%= sanitize_input(key['source_data']['link'].html_safe) %> <% when '15'%> + <% step_info_string += key['source_data']['description'] %>
<%= key['name']+': ' %> <%= sanitize_input(key['source_data']['name'].html_safe) %>
<%= t('protocols.protocols_io_import.preview.s_desc') %> - <%= sanitize_input(key['source_data']['description'].html_safe) %> + <%= sanitize_input(string_html_table_remove(key['source_data']['description']).html_safe) %>
<%= t('protocols.protocols_io_import.preview.os') %> <%= sanitize_input(key['source_data']['os_name'].html_safe)+ ' , '+sanitize_input(key['source_data']['os_version'].html_safe) %> @@ -88,9 +95,10 @@ <%= sanitize_input(key['source_data']['link'].html_safe) %> <% end %> <% when '19'%> + <% step_info_string += key['source_data']['body'] %>
<%= key['name']+': ' %> - <%= sanitize_input(key['source_data']['body'].html_safe) %> + <%= sanitize_input(string_html_table_remove(key['source_data']['body']).html_safe) %>
<%= t('protocols.protocols_io_import.preview.s_link') %> <%= sanitize_input(key['source_data']['link'].html_safe) %> <% when '20'%> @@ -98,9 +106,43 @@ <% end #case if%> <% end #inner if%> <% end #step component loop %> + <% tables, garbage = protocolsio_string_to_table_element(step_info_string) %> + <% if tables.present? %> +


+ <% end %> + <% table_count = 0 %> + <% tables.each do |index, table| %> + <% table_hash = JSON.parse((Base64.decode64(table['contents']))) %> + <% pio_table_id = "pio_table_step_"+counter.to_s+"_info_"+table_count.to_s %> + <% step_table_elements_array.push([pio_table_id,table_hash['data']]) %> +
+ <% table_count += 1 %> + <% end %>
<% end #step loop%>
+ diff --git a/app/views/protocols/protocolsio_import_create.js.erb b/app/views/protocols/protocolsio_import_create.js.erb index b9dbd0cd5..d7284b504 100644 --- a/app/views/protocols/protocolsio_import_create.js.erb +++ b/app/views/protocols/protocolsio_import_create.js.erb @@ -15,4 +15,5 @@ HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_err ); <% end %> $('#modal-import-json-protocol-preview').modal('show'); + <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3331e45cd..83710d5af 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1404,6 +1404,7 @@ en: key_wrd: "Keywords:" tags: "Tags:" comp_append: + table_moved: "
There was a table here, it was moved to the end of this step. " missing_step: "Step" missing_desc: "Description missing" general_link: "
Link: " @@ -1421,7 +1422,7 @@ en: desc: "
Description: " os: "
OS name , OS version: " sub_protocol: - title: "
This protocol also contains an attached sub-protocol: " + title: "
This step also contains an attached sub-protocol: " author: "
Author: " safety_infor: title: "
Safety information: "