This commit is contained in:
Zanz2 2017-11-09 18:55:17 +01:00
commit fa2c0fe556
5 changed files with 192 additions and 51 deletions

View file

@ -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\b[^>]*>(.*?)<\/table>}m
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
td_regex = %r{<td\b[^>]*>(.*?)<\/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\b[^>]*>.*?<\/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 = []

View file

@ -15,50 +15,89 @@
<div class="tab-content">
<div class="tab-pane active" role="tabpanel">
<div data-val="description" class="ql-editor">
<br>
<% if json_object['before_start'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.b_s_p') %></strong>
<%= sanitize_input(json_object['before_start'].html_safe) %><br>
<% end %>
<% if json_object['warning'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.warn') %></strong>
<%= sanitize_input(json_object['warning'].html_safe) %><br>
<% end %>
<% if json_object['guidelines'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.guideln') %></strong>
<%= sanitize_input(json_object['guidelines'].html_safe) %><br>
<% end %>
<% if json_object['manuscript_citation'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.manu_cit') %></strong>
<%= sanitize_input(json_object['manuscript_citation'].html_safe) %><br>
<% end %>
<% if json_object['publish_date'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.pbl_date') %></strong>
<%= sanitize_input(json_object['publish_date']) %><br>
<% end %>
<% if json_object['vendor_name'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.vnd_name') %></strong>
<%= sanitize_input(json_object['vendor_name']) %><br>
<% end %>
<% if json_object['vendor_link'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.vnd_link') %></strong>
<%= sanitize_input(json_object['vendor_link'].html_safe) %><br>
<% end %>
<% if json_object['keywords'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.key_wrd') %></strong>
<%= sanitize_input(json_object['keywords']) %><br>
<% end %>
<% if json_object['tags'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.tags') %></strong>
<% json_object['tags'].each do |tag| %>
<%= sanitize_input(tag['tag_name'])+' , ' %><br>
<br>
<% prot_info_string = '' %>
<% protocol_table_elements_array = [] %>
<% if json_object['before_start'].present? %>
<% prot_info_string += (json_object['before_start']) %>
<strong><%= t('protocols.protocols_io_import.preview.b_s_p') %></strong>
<%= sanitize_input(string_html_table_remove(json_object['before_start']).html_safe) %><br>
<% end %>
<% if json_object['warning'].present? %>
<% prot_info_string += (json_object['warning']) %>
<strong><%= t('protocols.protocols_io_import.preview.warn') %></strong>
<%= sanitize_input(string_html_table_remove(json_object['warning']).html_safe) %><br>
<% end %>
<% if json_object['guidelines'].present? %>
<% prot_info_string += (json_object['guidelines']) %>
<strong><%= t('protocols.protocols_io_import.preview.guideln') %></strong>
<%= sanitize_input(string_html_table_remove(json_object['guidelines']).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>
<%= sanitize_input(string_html_table_remove(json_object['manuscript_citation']).html_safe) %><br>
<% end %>
<% if json_object['publish_date'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.pbl_date') %></strong>
<%= sanitize_input(json_object['publish_date']) %><br>
<% end %>
<% if json_object['vendor_name'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.vnd_name') %></strong>
<%= sanitize_input(json_object['vendor_name']) %><br>
<% end %>
<% if json_object['vendor_link'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.vnd_link') %></strong>
<%= sanitize_input(json_object['vendor_link'].html_safe) %><br>
<% end %>
<% if json_object['keywords'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.key_wrd') %></strong>
<%= sanitize_input(json_object['keywords']) %><br>
<% end %>
<% if json_object['tags'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.tags') %></strong>
<% json_object['tags'].each do |tag| %>
<%= sanitize_input(tag['tag_name'])+' , ' %><br>
<% end %>
<% end %>
<% if json_object['link'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.p_link') %></strong>
<%= sanitize_input(json_object['link'].html_safe) %><br>
<% end %>
<% tables, garbage = protocolsio_string_to_table_element(prot_info_string) %>
<% if tables.present? %>
<br><hr><br>
<% 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']]) %>
<div id="<%=pio_table_id%>" ></div>
<% table_count += 1 %>
<% end %>
<% end %>
<% if json_object['link'].present? %>
<strong><%= t('protocols.protocols_io_import.preview.p_link') %></strong>
<%= sanitize_input(json_object['link'].html_safe) %><br>
<% end %>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#modal-import-json-protocol-preview').on('shown.bs.modal', function (e) {
var javascript_table_elements_p = <%=raw sanitize_input(protocol_table_elements_array.to_json) %>
for(var j=0;j<javascript_table_elements_p.length;j++)
{
var target = document.getElementById(javascript_table_elements_p[j][0]);
var hot = new Handsontable(target, {
data: javascript_table_elements_p[j][1],
startRows: <%= Constants::HANDSONTABLE_INIT_ROWS_CNT %>,
startCols: <%= Constants::HANDSONTABLE_INIT_COLS_CNT %>,
rowHeaders: true,
colHeaders: true,
fillHandle: false,
formulas: true,
readOnly: true
});
}
})
</script>

View file

@ -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 %>
<div style="display: block;">
<hr>
<td>
<div class="badge-num">
<span class="badge-preview bg-primary size-digit-1">
<b data-val="position"><%= (counter+1) %></b>
<b data-val="position"><%= (counter) %></b>
</span>
&nbsp; &nbsp;
<span class="step-panel-collapse-link" data-toggle="collapse">
@ -28,6 +29,7 @@
<div class="tab-content">
<div class="tab-pane active" role="tabpanel">
<div data-val="description" class="ql-editor">
<% 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 @@
<br>
<% case key['component_type_id']
when '1' %>
<% step_info_string += (key['data']) %>
<br><strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong>
<%=sanitize_input(key['data'].html_safe)%><br>
<%=sanitize_input(string_html_table_remove(key['data']).html_safe)%><br>
<% when '17' %>
<% step_info_string += (key['data']) %>
<br><strong><%= t('protocols.protocols_io_import.preview.s_exp_res') %></strong>
<%=sanitize_input(key['data'].html_safe)%>
<%=sanitize_input(string_html_table_remove(key['data']).html_safe)%>
<br>
<% end %>
<% elsif key && whitelist_complex.include?(key['component_type_id']) %>
<% case key['component_type_id']
when '8'%>
<% step_info_string += key['source_data']['name'] %>
<br>
<strong><%= key['name']+': ' %></strong>
<%= sanitize_input(key['source_data']['name'].html_safe) %>
<%= sanitize_input(string_html_table_remove(key['source_data']['name']).html_safe) %>
<br><%= t('protocols.protocols_io_import.preview.dev') %>
<%= sanitize_input(key['source_data']['developer'].html_safe) %>
<br><%= 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'] %>
<br>
<strong><%= key['name']+': ' %></strong>
<%= sanitize_input(key['source_data']['name'].html_safe) %>
<%= sanitize_input(string_html_table_remove(key['source_data']['name']).html_safe) %>
<br><%= 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'] %>
<br>
<strong><%= key['name']+': ' %></strong>
<%= sanitize_input(key['source_data']['name'].html_safe) %>
<br><%= 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) %>
<br><%= 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'] %>
<br>
<strong><%= key['name']+': ' %></strong>
<%= sanitize_input(key['source_data']['body'].html_safe) %>
<%= sanitize_input(string_html_table_remove(key['source_data']['body']).html_safe) %>
<br><%= 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? %>
<br><hr><br>
<% 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']]) %>
<div id="<%=pio_table_id%>" ></div>
<% table_count += 1 %>
<% end %>
</div>
</div>
</div>
</div>
<% end #step loop%>
<br>
<script type="text/javascript">
$('#modal-import-json-protocol-preview').on('shown.bs.modal', function (e) {
var javascript_table_elements_s = <%=raw sanitize_input(step_table_elements_array.to_json) %>
for(var j=0;j<javascript_table_elements_s.length;j++)
{
var target = document.getElementById(javascript_table_elements_s[j][0]);
var hot = new Handsontable(target, {
data: javascript_table_elements_s[j][1],
startRows: <%= Constants::HANDSONTABLE_INIT_ROWS_CNT %>,
startCols: <%= Constants::HANDSONTABLE_INIT_COLS_CNT %>,
rowHeaders: true,
colHeaders: true,
fillHandle: false,
formulas: true,
readOnly: true
});
}
})
</script>

View file

@ -15,4 +15,5 @@ HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_err
);
<% end %>
$('#modal-import-json-protocol-preview').modal('show');
<% end %>

View file

@ -1404,6 +1404,7 @@ en:
key_wrd: "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>"
missing_step: "Step"
missing_desc: "Description missing"
general_link: "<br>Link: "
@ -1421,7 +1422,7 @@ en:
desc: "<br>Description: "
os: "<br>OS name , OS version: "
sub_protocol:
title: "<br><strong>This protocol also contains an attached sub-protocol: </strong>"
title: "<br><strong>This step also contains an attached sub-protocol: </strong>"
author: "<br>Author: "
safety_infor:
title: "<br><strong>Safety information: </strong>"