mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 07:26:15 +08:00
added validations to controllers (file too big, names too big), some javascript error messagges, and fixed some nil exceptions in controllers appending nil strings to descriptions
This commit is contained in:
parent
1dbb03e22d
commit
deef790951
|
@ -606,9 +606,20 @@ class ProtocolsController < ApplicationController
|
|||
#
|
||||
#tule
|
||||
def protocolsio_import_create
|
||||
|
||||
@protocolsio_too_big=false
|
||||
file_size=(File.size(params[:json_file].path))
|
||||
|
||||
if(file_size/1000>Constants::FILE_MAX_SIZE_MB)
|
||||
@protocolsio_too_big=true
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
end
|
||||
else
|
||||
@protocolsio_too_big=false
|
||||
end
|
||||
|
||||
json_file_contents=File.read(params[:json_file].path)
|
||||
|
||||
json_file_contents.gsub! '\"', "'"
|
||||
|
||||
|
||||
|
@ -632,7 +643,7 @@ def protocolsio_import_save
|
|||
# will have to fit various things in here (guidelines, manuscript citations etc etc)
|
||||
#"before_start","warning","guidelines","manuscript_citation","publish_date","created_on"
|
||||
#"vendor_name","vendor_link","keywords","tags"
|
||||
description_array = [ "before_start","warning","guidelines","manuscript_citation","publish_date","created_on","vendor_name","vendor_link","keywords","tags" ]
|
||||
description_array = [ "before_start","warning","guidelines","manuscript_citation","publish_date","created_on","vendor_name","vendor_link","keywords","tags","link" ]
|
||||
description_string=params["protocol"]["description"]
|
||||
#@import_object["description"]=params["protocol"]["description"]
|
||||
description_array.each do |element|
|
||||
|
@ -640,16 +651,16 @@ def protocolsio_import_save
|
|||
if(@json_object[element]&&@json_object[element]!="")
|
||||
new_element = element.slice(0,1).capitalize + element.slice(1..-1)
|
||||
new_element= new_element.gsub("_"," ")
|
||||
description_string=description_string+new_element.to_s+": "+params["protocol"]["created_at"].to_s+"\n"
|
||||
description_string=description_string+new_element.to_s+": "+Sanitize.clean(params["protocol"]["created_at"].to_s)+"\n"
|
||||
end
|
||||
else
|
||||
if(element=="tags")
|
||||
if(@json_object[element]&&@json_object[element]!="")
|
||||
if(@json_object[element].any?&&@json_object[element]!="")
|
||||
new_element = element.slice(0,1).capitalize + element.slice(1..-1)
|
||||
new_element= new_element.gsub("_"," ")
|
||||
description_string=description_string+new_element.to_s+": "
|
||||
@json_object[element].each do |tag|
|
||||
description_string=description_string+tag["tag_name"]+" , "
|
||||
description_string=description_string+Sanitize.clean(tag["tag_name"])+" , "
|
||||
end
|
||||
description_string=description_string+"\n"
|
||||
end
|
||||
|
@ -658,7 +669,7 @@ def protocolsio_import_save
|
|||
if(@json_object[element]&&@json_object[element]!="")
|
||||
new_element = element.slice(0,1).capitalize + element.slice(1..-1)
|
||||
new_element= new_element.gsub("_"," ")
|
||||
description_string=description_string+new_element.to_s+": "+@json_object[element].to_s+"\n"
|
||||
description_string=description_string+new_element.to_s+": "+Sanitize.clean(@json_object[element].to_s)+"\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -696,7 +707,7 @@ def protocolsio_import_save
|
|||
when "1"
|
||||
if !key["data"].nil? && key["data"]!=""
|
||||
|
||||
element_string="<br>"+key["data"]+"<br>"
|
||||
element_string="<br>"+(key["data"])+"<br>"
|
||||
if(@import_object["steps"][step_pos.to_s]["description"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
else
|
||||
|
@ -714,7 +725,7 @@ def protocolsio_import_save
|
|||
when "17"
|
||||
if !key["data"].nil? && key["data"]!=""
|
||||
|
||||
element_string="<br><strong>Expected result: </strong>"+key["data"]+"<br>"
|
||||
element_string="<br><strong>Expected result: </strong>"+(key["data"])+"<br>"
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
else
|
||||
|
@ -726,22 +737,33 @@ def protocolsio_import_save
|
|||
elsif key && whitelist_complex.include?(key["component_type_id"])
|
||||
case key["component_type_id"]
|
||||
when "8"
|
||||
element_string="<br><strong>Software package: </strong>"+key["source_data"]["name"]+"<br>Developer: "+key["source_data"]["developer"]+"<br>Version: "+key["source_data"]["version"]+"<br>Link: "+key["source_data"]["link"]+"<br>Repository: "+key["source_data"]["repository"]+"<br> OS name , OS version: "+key["source_data"]["os_name"]+" , "+key["source_data"]["os_version"]
|
||||
if(key["source_data"]["name"]&&key["source_data"]["developer"]&&key["source_data"]["version"]&&key["source_data"]["link"]&&key["source_data"]["repository"]&&key["source_data"]["os_name"]&&key["source_data"]["os_version"])
|
||||
element_string="<br><strong>Software package: </strong>"+(key["source_data"]["name"])+"<br>Developer: "+(key["source_data"]["developer"])+"<br>Version: "+(key["source_data"]["version"])+"<br>Link: "+(key["source_data"]["link"])+"<br>Repository: "+(key["source_data"]["repository"])+"<br> OS name , OS version: "+(key["source_data"]["os_name"])+" , "+(key["source_data"]["os_version"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "9"
|
||||
element_string="<br><strong>Dataset: </strong>"+key["source_data"]["name"]+"<br>Link: "+key["source_data"]["link"]
|
||||
if(key["source_data"]["name"]&&key["source_data"]["link"])
|
||||
element_string="<br><strong>Dataset: </strong>"+(key["source_data"]["name"])+"<br>Link: "+(key["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "15"
|
||||
element_string="<br><strong>Command: </strong>"+key["source_data"]["name"]+"<br>Description: "+key["source_data"]["description"]+"<br>OS name , OS version: "+key["source_data"]["os_name"]+" , "+key["source_data"]["os_version"]
|
||||
if(key["source_data"]["name"]&&key["source_data"]["description"]&&key["source_data"]["os_name"]&&key["source_data"]["os_version"])
|
||||
element_string="<br><strong>Command: </strong>"+(key["source_data"]["name"])+"<br>Description: "+(key["source_data"]["description"])+"<br>OS name , OS version: "+(key["source_data"]["os_name"])+" , "+(key["source_data"]["os_version"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "18"
|
||||
element_string="<br><strong>This protocol also contains an attached sub-protocol: </strong>"+key["source_data"]["protocol_name"]+"<br>Author: "+key["source_data"]["full_name"]+"<br>Link: "+key["source_data"]["link"]
|
||||
if(key["source_data"]["protocol_name"]&&key["source_data"]["full_name"]&&key["source_data"]["link"])
|
||||
element_string="<br><strong>This protocol also contains an attached sub-protocol: </strong>"+(key["source_data"]["protocol_name"])+"<br>Author: "+(key["source_data"]["full_name"])+"<br>Link: "+(key["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
|
||||
end
|
||||
#if key["source_data"]["link"]&&key["source_data"]["link"]!=""
|
||||
#end
|
||||
when "19"
|
||||
element_string="<br><strong>Safety information</strong>"+key["source_data"]["body"]+"<br>Link: "+key["source_data"]["link"]
|
||||
if(key["source_data"]["body"]&&key["source_data"]["link"])
|
||||
element_string="<br><strong>Safety information: </strong>"+(key["source_data"]["body"])+"<br>Link: "+(key["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "20"
|
||||
else
|
||||
|
||||
|
@ -759,7 +781,7 @@ def protocolsio_import_save
|
|||
when "1"
|
||||
if !value["data"].nil? && value["data"]!=""
|
||||
|
||||
element_string="<br>"+value["data"]+"<br>"
|
||||
element_string="<br>"+(value["data"].to_s)+"<br>"
|
||||
if(@import_object["steps"][step_pos.to_s]["description"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
else
|
||||
|
@ -777,7 +799,7 @@ def protocolsio_import_save
|
|||
when "17"
|
||||
if !value["data"].nil? && value["data"]!=""
|
||||
|
||||
element_string="<br><strong>Expected result: </strong>"+value["data"]+"<br>"
|
||||
element_string="<br><strong>Expected result: </strong>"+(value["data"])+"<br>"
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
else
|
||||
|
@ -789,22 +811,37 @@ def protocolsio_import_save
|
|||
elsif value && whitelist_complex.include?(value["component_type_id"])
|
||||
case value["component_type_id"]
|
||||
when "8"
|
||||
element_string="<br><strong>Software package: </strong>"+value["source_data"]["name"]+"<br>Developer: "+value["source_data"]["developer"]+"<br>Version: "+value["source_data"]["version"]+"<br>Link: "+value["source_data"]["link"]+"<br>Repository: "+value["source_data"]["repository"]+"<br> OS name , OS version: "+value["source_data"]["os_name"]+" , "+value["source_data"]["os_version"]
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
when "9"
|
||||
element_string="<br><strong>Dataset: </strong>"+value["source_data"]["name"]+"<br>Link: "+value["source_data"]["link"]
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
when "15"
|
||||
element_string="<br><strong>Command: </strong>"+value["source_data"]["name"]+"<br>Description: "+value["source_data"]["description"]+"<br>OS name , OS version: "+value["source_data"]["os_name"]+" , "+value["source_data"]["os_version"]
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
when "18"
|
||||
element_string="<br><strong>This protocol also contains an attached sub-protocol: </strong>"+value["source_data"]["protocol_name"]+"<br>Author: "+value["source_data"]["full_name"]+"<br>Link: "+value["source_data"]["link"]
|
||||
if(value["source_data"]["name"]&&value["source_data"]["developer"]&&value["source_data"]["version"]&&value["source_data"]["link"]&&value["source_data"]["repository"]&&value["source_data"]["os_name"]&&value["source_data"]["os_version"])
|
||||
|
||||
element_string="<br><strong>Software package: </strong>"+(value["source_data"]["name"])+"<br>Developer: "+(value["source_data"]["developer"])+"<br>Version: "+(value["source_data"]["version"])+"<br>Link: "+(value["source_data"]["link"])+"<br>Repository: "+(value["source_data"]["repository"])+"<br> OS name , OS version: "+(value["source_data"]["os_name"])+" , "+(value["source_data"]["os_version"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "9"
|
||||
if(value["source_data"]["name"]&&value["source_data"]["link"])
|
||||
|
||||
element_string="<br><strong>Dataset: </strong>"+(value["source_data"]["name"])+"<br>Link: "+(value["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "15"
|
||||
if(value["source_data"]["name"]&&value["source_data"]["description"]&&value["source_data"]["os_name"]&&value["source_data"]["os_version"])
|
||||
|
||||
element_string="<br><strong>Command: </strong>"+(value["source_data"]["name"])+"<br>Description: "+(value["source_data"]["description"])+"<br>OS name , OS version: "+(value["source_data"]["os_name"])+" , "+(value["source_data"]["os_version"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "18"
|
||||
if(value["source_data"]["protocol_name"]&&value["source_data"]["full_name"]&&value["source_data"]["link"])
|
||||
|
||||
element_string="<br><strong>This protocol also contains an attached sub-protocol: </strong>"+(value["source_data"]["protocol_name"])+"<br>Author: "+(value["source_data"]["full_name"])+"<br>Link: "+(value["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
#if key["source_data"]["link"]&&key["source_data"]["link"]!=""
|
||||
#end
|
||||
when "19"
|
||||
element_string="<br><strong>Safety information</strong>"+value["source_data"]["body"]+"<br>Link: "+value["source_data"]["link"]
|
||||
if(value["source_data"]["body"]&&value["source_data"]["link"])
|
||||
|
||||
element_string="<br><strong>Safety information: </strong>"+(value["source_data"]["body"])+"<br>Link: "+(value["source_data"]["link"])
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
end
|
||||
when "20"
|
||||
else
|
||||
|
||||
|
@ -819,10 +856,10 @@ def protocolsio_import_save
|
|||
respond_to do |format|
|
||||
transaction_error = false
|
||||
#@steps_object=JSON.parse(params["steps"]["steps_object"])
|
||||
|
||||
@protocolsio_general_error=false
|
||||
Protocol.transaction do
|
||||
begin
|
||||
#byebug
|
||||
|
||||
protocol = import_new_protocol(@import_object, current_team, params[:type].to_sym, current_user)
|
||||
|
||||
rescue Exception
|
||||
|
@ -841,15 +878,17 @@ def protocolsio_import_save
|
|||
|
||||
if transaction_error
|
||||
|
||||
format.json {
|
||||
render json: { name: p_name, status: :bad_request }, status: :bad_request
|
||||
}
|
||||
@protocolsio_general_error=true
|
||||
# format.json {
|
||||
# render json: { name: p_name, status: :bad_request }, status: :bad_request
|
||||
# }
|
||||
format.js{}
|
||||
|
||||
#:location => root_url
|
||||
# protocolsDatatable.ajax.reload();
|
||||
# $('#modal-import-json-protocol-preview').modal('hide');
|
||||
else
|
||||
@protocolsio_general_error=false
|
||||
format.json {
|
||||
render json: {
|
||||
name: p_name, new_name: protocol.name, status: :ok
|
||||
|
|
|
@ -86,6 +86,13 @@
|
|||
<strong>Guidelines:</strong><br>
|
||||
<%= (@json_object["guidelines"]) %><br>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% if @json_object["link"]&&@json_object["link"]!="" %>
|
||||
|
||||
<br><strong>Supplied link:</strong><br>
|
||||
<%= (@json_object["link"]) %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% counter=0 %>
|
||||
|
@ -317,37 +324,37 @@
|
|||
|
||||
<% if @json_object["manuscript_citation"]&&@json_object["manuscript_citation"]!="" %>
|
||||
|
||||
<br><strong>Manuscript citation</strong><br>
|
||||
<br><strong>Manuscript citation:</strong><br>
|
||||
<%= (@json_object["manuscript_citation"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["publish_date"]&&@json_object["publish_date"]!="" %>
|
||||
|
||||
<br><strong>Publish date</strong><br>
|
||||
<br><strong>Publish date:</strong><br>
|
||||
<%= (@json_object["publish_date"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["vendor_name"]&&@json_object["vendor_name"]!="" %>
|
||||
|
||||
<br><strong>Vendor name</strong><br>
|
||||
<br><strong>Vendor name:</strong><br>
|
||||
<%= (@json_object["vendor_name"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["vendor_link"]&&@json_object["vendor_link"]!="" %>
|
||||
|
||||
<br><strong>Vendor link</strong><br>
|
||||
<br><strong>Vendor link:</strong><br>
|
||||
<%= (@json_object["vendor_link"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["keywords"]&&@json_object["keywords"]!="" %>
|
||||
|
||||
<br><strong>Keywords</strong><br>
|
||||
<br><strong>Keywords:</strong><br>
|
||||
<%= (@json_object["keywords"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["tags"]&&@json_object["tags"]!="" %>
|
||||
|
||||
<br><strong>Tags</strong><br>
|
||||
<br><strong>Tags:</strong><br>
|
||||
<% @json_object["tags"].each do |tag| %>
|
||||
<%= (tag["tag_name"])+" , " %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
|
||||
$('#modal-import-json-protocol').modal('hide');
|
||||
<% if remotipart_submitted? %>
|
||||
$('#protocolsio-preview-modal-target').html("<%= j "#{render(:partial => 'protocols/import_export/import_json_protocol_preview_modal')}" %>");
|
||||
<% if @protocolsio_too_big %>
|
||||
alert('<%= I18n.t('my_modules.protocols.load_from_file_size_error',
|
||||
size: Constants::FILE_MAX_SIZE_MB ) %>');
|
||||
|
||||
|
||||
<% else %>
|
||||
$('#protocolsio-preview-modal-target').html("<%= j render(:partial => 'protocols/import_export/import_json_protocol_preview_modal') %>");
|
||||
<% end %>
|
||||
|
||||
$('#modal-import-json-protocol-preview').modal('show');
|
||||
$('#modal-import-json-protocol').modal('hide');
|
||||
<% if remotipart_submitted? %>
|
||||
$('#protocolsio-preview-modal-target').html("<%= j "#{render(:partial => 'protocols/import_export/import_json_protocol_preview_modal')}" %>");
|
||||
<% else %>
|
||||
$('#protocolsio-preview-modal-target').html("<%= j render(:partial => 'protocols/import_export/import_json_protocol_preview_modal') %>");
|
||||
<% end %>
|
||||
$('#modal-import-json-protocol-preview').modal('show');
|
||||
<% end %>
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
<% if @protocolsio_general_error %>
|
||||
alert('<%= I18n.t('my_modules.protocols.load_from_file_protocol_general_error', max: Constants::NAME_MAX_LENGTH, min: Constants::NAME_MIN_LENGTH) %>');
|
||||
<% else %>
|
||||
|
||||
$('#modal-import-json-protocol-preview').modal('hide');
|
||||
protocolsDatatable.ajax.reload();
|
||||
<% end %>
|
||||
|
|
|
@ -603,6 +603,7 @@ en:
|
|||
load_from_file_error: "Failed to load the protocol from file."
|
||||
load_from_file_error_locked: "Failed to load the protocol from file. One or more files are currently being edited."
|
||||
load_from_file_size_error: "Failed to load the protocol from file. Limit is %{size}Mb."
|
||||
load_from_file_protocol_general_error: "Failed to load the protocol from file. It is likely that certain fields (protocol and individual step titles and names) contain too many or too few characters.(max is %{max} and min is %{min})"
|
||||
results:
|
||||
head_title: "%{project} | %{module} | Results"
|
||||
add_label: "Add new result:"
|
||||
|
|
Loading…
Reference in a new issue