mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-01 04:32:16 +08:00
saving work for later
This commit is contained in:
parent
ad8f93b57f
commit
95501eb046
4 changed files with 65 additions and 7 deletions
|
@ -640,7 +640,8 @@ class ProtocolsController < ApplicationController
|
|||
return 0 # return 0 stops the rest of the controller code from executing
|
||||
end
|
||||
@json_object = JSON.parse(json_file_contents)
|
||||
|
||||
@json_object['steps'] = step_hash_not_null(@json_object['steps'])
|
||||
byebug
|
||||
@json_object['steps'] = protocols_io_guid_reorder_step_json(
|
||||
@json_object['steps']
|
||||
)
|
||||
|
@ -672,6 +673,8 @@ class ProtocolsController < ApplicationController
|
|||
sanitize_input(params['protocol']['last_modified'])
|
||||
)
|
||||
@db_json['steps'] = {}
|
||||
@json_object['steps'] = step_hash_not_null(@json_object['steps'])
|
||||
byebug
|
||||
@db_json['steps'] = protocols_io_fill_step(
|
||||
@json_object, @db_json['steps']
|
||||
)
|
||||
|
|
|
@ -103,6 +103,8 @@ module ProtocolsIoHelper
|
|||
@toolong = true
|
||||
end
|
||||
text
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,6 +131,8 @@ module ProtocolsIoHelper
|
|||
@remaining -= text.length - reserved
|
||||
end
|
||||
text
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,10 +150,59 @@ module ProtocolsIoHelper
|
|||
Nokogiri::HTML::DocumentFragment.parse(text).to_html
|
||||
end
|
||||
|
||||
def step_hash_not_null(step_json)
|
||||
is_null_check = false
|
||||
if step_json.blank?
|
||||
is_null_check = true
|
||||
elsif step_json[0].blank?
|
||||
is_null_check = true
|
||||
elsif step_json[0]['components'].blank?
|
||||
is_null_check = true
|
||||
elsif step_json[0]['components'][0].blank?
|
||||
is_null_check = true
|
||||
elsif step_json[0]['components'][0]['component_type_id'].blank?
|
||||
is_null_check = true
|
||||
else
|
||||
is_null_check = false
|
||||
end
|
||||
if is_null_check
|
||||
return generate_null_step_skeleton
|
||||
else
|
||||
step_json
|
||||
end
|
||||
end
|
||||
|
||||
# Creates dummy info for when empty steps json is sent, or
|
||||
# hash structure is modified
|
||||
def generate_null_step_skeleton
|
||||
json_string = [
|
||||
{
|
||||
"guid": 0,
|
||||
"previous_guid": nil,
|
||||
"components":
|
||||
[
|
||||
{
|
||||
"component_type_id": '1',
|
||||
"name": 'Description',
|
||||
"data": '',
|
||||
"data_id": nil
|
||||
},
|
||||
{
|
||||
"component_type_id": '6',
|
||||
"name": 'Section',
|
||||
"data": 'Step',
|
||||
"data_id": '0'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
json_string
|
||||
end
|
||||
# Images are allowed in:
|
||||
# Step: description, expected result
|
||||
# Protocol description : description before_start warning
|
||||
# guidelines manuscript_citation
|
||||
|
||||
def prepare_for_view(
|
||||
attribute_text1, size, table = 'no_table', image_allowed = false
|
||||
)
|
||||
|
@ -314,8 +367,10 @@ module ProtocolsIoHelper
|
|||
end
|
||||
|
||||
def protocols_io_guid_reorder_step_json(unordered_step_json)
|
||||
base_step = unordered_step_json.find { |step| step['previous_guid'].nil? }
|
||||
return '' if unordered_step_json.nil?
|
||||
number_of_steps = unordered_step_json.size
|
||||
return unordered_step_json if number_of_steps == 1
|
||||
base_step = unordered_step_json.find { |step| step['previous_guid'].nil? }
|
||||
step_order = []
|
||||
step_counter = 0
|
||||
step_order[step_counter] = base_step
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
<label><%= t('protocols.import_export.import_modal.name_label') %></label>
|
||||
|
||||
<%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(@json_object['protocol_name'])), class:
|
||||
<%= f.text_field :name, :value => pio_eval_title_len(sanitize_input(not_null(@json_object['protocol_name']))), class:
|
||||
"form-control" %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -52,14 +52,14 @@
|
|||
<div class="col-xs-4">
|
||||
<label><%= t('protocols.import_export.import_modal.created_at_label') %></label>
|
||||
|
||||
<% display_created_at=Time.at(@json_object['created_on'].to_i) %>
|
||||
<% display_created_at=Time.at(not_null(@json_object['created_on']).to_i) %>
|
||||
<%= f.text_field :created_at, :value => display_created_at.to_s,
|
||||
readonly: true, class: "form-control" %>
|
||||
</div>
|
||||
<div class="col-xs-4">
|
||||
<label><%= t('protocols.import_export.import_modal.updated_at_label') %></label>
|
||||
|
||||
<% display_last_modified=Time.at(@json_object['last_modified'].to_i) %>
|
||||
<% display_last_modified=Time.at(not_null(@json_object['last_modified']).to_i) %>
|
||||
<%= f.text_field :last_modified, :value =>
|
||||
display_last_modified.to_s,readonly: true, class:
|
||||
"form-control" %>
|
||||
|
|
|
@ -40,13 +40,13 @@
|
|||
<br>
|
||||
<% case key['component_type_id']
|
||||
when '1' %>
|
||||
<% step_info_string += (key['data']) %>
|
||||
<% step_info_string += not_null(key['data']) %>
|
||||
<br>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.strng_s_desc') %></strong>
|
||||
<%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
|
||||
<br>
|
||||
<% when '17' %>
|
||||
<% step_info_string += (key['data']) %>
|
||||
<% step_info_string += not_null(key['data']) %>
|
||||
<br>
|
||||
<strong><%= t('protocols.protocols_io_import.preview.s_exp_res') %></strong>
|
||||
<%= prepare_for_view(key['data'],ProtocolsIoHelper::PIO_ELEMENT_RESERVED_LENGTH_SMALL,'table',true).html_safe %>
|
||||
|
|
Loading…
Reference in a new issue