mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 12:09:17 +08:00
Made code nicer, hopefully not unintentionally breaking something
This commit is contained in:
parent
549346bb0a
commit
11b2ef3112
5 changed files with 389 additions and 355 deletions
|
@ -600,176 +600,189 @@ class ProtocolsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def protocolsio_import_create
|
||||
@protocolsio_too_big=false
|
||||
file_size=(File.size(params[:json_file].path))
|
||||
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
|
||||
if file_size / 1000 > Constants::FILE_MAX_SIZE_MB
|
||||
@protocolsio_too_big = true
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
# if file is too big, default to the js.erb file,
|
||||
# named the same as this controller
|
||||
# where a javascript alert is called
|
||||
end
|
||||
end
|
||||
json_file_contents = File.read(params[:json_file].path)
|
||||
json_file_contents.gsub! '\"', "'"
|
||||
# escaped double quotes too stressfull, html works with single quotes too
|
||||
# json double quotes dont get escaped since they dont match \"
|
||||
@json_object = JSON.parse(json_file_contents)
|
||||
@protocol = Protocol.new
|
||||
respond_to do |format|
|
||||
format.js {} #if file is too big, default to the js.erb file named the same as this controller
|
||||
# where a javascript alert is called
|
||||
format.js {} # go to the js.erb file named the same as this controller,
|
||||
# where a preview modal is rendered,
|
||||
# and some modals get closed and opened
|
||||
end
|
||||
end
|
||||
json_file_contents=File.read(params[:json_file].path)
|
||||
json_file_contents.gsub! '\"', "'" #escaped double quotes too stressfull, html works with single quotes too
|
||||
#json double quotes dont get escaped since they dont match \", they are just "
|
||||
@json_object=JSON.parse(json_file_contents)
|
||||
@protocol=Protocol.new
|
||||
respond_to do |format|
|
||||
format.js {} # go to the js.erb file named the same as this controller, where a preview modal is rendered, and
|
||||
# some modals get closed and opened
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def protocolsio_import_save
|
||||
@json_object=JSON.parse(params["json_object"])
|
||||
@import_object=Hash.new
|
||||
@import_object["name"]=params["protocol"]["name"]
|
||||
# since scinote only has description field, while protocols.io has many many others, here i am basically
|
||||
#putting everything important from protocols.io into description
|
||||
description_array = [ "before_start","warning","guidelines","manuscript_citation","publish_date","created_on","vendor_name","vendor_link","keywords","tags","link" ]
|
||||
description_string=params["protocol"]["description"]
|
||||
description_array.each do |element|
|
||||
if(element=="created_on")
|
||||
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+": "+Sanitize.clean(params["protocol"]["created_at"].to_s)+"\n"
|
||||
def protocolsio_import_save
|
||||
@json_object = JSON.parse(params['json_object'])
|
||||
@import_object = {}
|
||||
@import_object['name'] = params['protocol']['name']
|
||||
# since scinote only has description field, and protocols.io has many others
|
||||
# ,here i am putting everything important from protocols.io into description
|
||||
description_array = %w[
|
||||
(before_start warning guidelines manuscript_citation publish_date
|
||||
created_on vendor_name vendor_link keywords tags link)
|
||||
]
|
||||
description_string = Sanitize.clean(params['protocol']['description'])
|
||||
description_array.each do |element|
|
||||
if element == 'created_on'
|
||||
if @json_object[element] && @json_object[element] != ''
|
||||
new_element = element.slice(0, 1).capitalize + element.slice(1..-1)
|
||||
new_element = new_element.tr('_', ' ')
|
||||
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].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+": "
|
||||
if element == 'tags'
|
||||
if @json_object[element].any? && @json_object[element] != ''
|
||||
new_element = element.slice(0, 1).capitalize + element.slice(1..-1)
|
||||
new_element = new_element.tr('_', ' ')
|
||||
description_string = description_string + new_element.to_s + ': '
|
||||
@json_object[element].each do |tag|
|
||||
description_string=description_string+Sanitize.clean(tag["tag_name"])+" , "
|
||||
description_string =
|
||||
description_string +
|
||||
Sanitize.clean(tag['tag_name']) + ' , '
|
||||
end
|
||||
description_string=description_string+"\n"
|
||||
description_string += "\n"
|
||||
end
|
||||
#Since protocols description field doesnt show html, i just remove it here because its even messier Otherwise
|
||||
#what this does is basically appends "FIELD NAME: "+" FIELD VALUE" to description for various fields
|
||||
# Since protocols description field doesnt show html,i just remove it here
|
||||
# because its even messier Otherwise
|
||||
# what this does is basically appends "FIELD NAME: "+" FIELD VALUE"
|
||||
# to description for various fields
|
||||
else
|
||||
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+": "+Sanitize.clean(@json_object[element].to_s)+"\n"
|
||||
if @json_object[element] && @json_object[element] != ''
|
||||
new_element = element.slice(0, 1).capitalize + element.slice(1..-1)
|
||||
new_element = new_element.tr('_', ' ')
|
||||
description_string +=
|
||||
new_element.to_s + ': ' +
|
||||
Sanitize.clean(@json_object[element].to_s) + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@import_object["authors"]=params["protocol"]["authors"]
|
||||
@import_object["created_at"]=params["protocol"]["created_at"]
|
||||
@import_object["updated_at"]=params["protocol"]["last_modified"]
|
||||
@import_object["description"]=description_string
|
||||
@import_object["steps"]=Hash.new
|
||||
counter=0
|
||||
step_pos=-1
|
||||
#these whitelists are there to not let some useless step components trough, that always have data set to null (data doesnt get imported over to json)
|
||||
whitelist_simple=["1","6","17"] #(simple to map) id 1= step description, id 6= section (title), id 17= expected result
|
||||
whitelist_complex=["8","9","15","18","19","20"] #(complex mapping with nested hashes) id 8 = software package, id 9 = dataset, id 15 = command, id 18 = attached sub protocol
|
||||
# id 19= safety information ,id 20= regents (materials, like scinote samples kind of)
|
||||
@json_object["steps"].each do |step|
|
||||
step_pos+=1
|
||||
counter+=1
|
||||
@import_object["steps"][step_pos.to_s]=Hash.new
|
||||
@import_object["steps"][step_pos.to_s]["position"]=step_pos
|
||||
end
|
||||
@import_object['authors'] = params['protocol']['authors']
|
||||
@import_object['created_at'] = params['protocol']['created_at']
|
||||
@import_object['updated_at'] = params['protocol']['last_modified']
|
||||
@import_object['description'] = description_string
|
||||
@import_object['steps'] = {}
|
||||
counter = 0
|
||||
step_pos = -1
|
||||
# these whitelists are there to not let some useless step components trough,
|
||||
# that always have data set to null (data doesnt get imported over to json)
|
||||
whitelist_simple = %w(1 6 17)
|
||||
# (simple to map) id 1= step description, id 6= section (title),
|
||||
# id 17= expected result
|
||||
whitelist_complex = %w(8 9 15 18 19 20)
|
||||
# (complex mapping with nested hashes) id 8 = software package,
|
||||
# id 9 = dataset, id 15 = command, id 18 = attached sub protocol
|
||||
# id 19= safety information ,
|
||||
# id 20= regents (materials, like scinote samples kind of)
|
||||
@json_object['steps'].each do |step|
|
||||
step_pos += 1
|
||||
counter += 1
|
||||
@import_object['steps'][step_pos.to_s] = {}
|
||||
@import_object['steps'][step_pos.to_s]['position'] = step_pos
|
||||
|
||||
step["components"].each do |key,value|
|
||||
element_string=nil
|
||||
if counter<=1 #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 hashes, for no good reason
|
||||
if value.class==Hash
|
||||
key=value
|
||||
end
|
||||
end
|
||||
if whitelist_simple.include?(key["component_type_id"])
|
||||
step['components'].each do |key,value|
|
||||
element_string = nil
|
||||
if counter <= 1
|
||||
# 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 hashes, for no good reason
|
||||
key = value if value.class == Hash
|
||||
end
|
||||
if whitelist_simple.include?(key['component_type_id'])
|
||||
|
||||
case key["component_type_id"]
|
||||
when "1"
|
||||
if !key["data"].nil? && key["data"]!=""
|
||||
|
||||
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
|
||||
@import_object["steps"][step_pos.to_s]["description"]=element_string
|
||||
end
|
||||
else
|
||||
@import_object["steps"][step_pos.to_s]["description"]||="Description missing!"
|
||||
end
|
||||
when "6"
|
||||
if !key["data"].nil? && key["data"]!=""
|
||||
@import_object["steps"][step_pos.to_s]["name"]=key["data"]
|
||||
case key['component_type_id']
|
||||
when '1'
|
||||
if !key['data'].nil? && key['data'] != ''
|
||||
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
|
||||
@import_object["steps"][step_pos.to_s]["name"]="Step"
|
||||
end
|
||||
when "17"
|
||||
if !key["data"].nil? && key["data"]!=""
|
||||
|
||||
element_string="<br><strong>Expected result: </strong>"+(key["data"])+"<br>"
|
||||
@import_object["steps"][step_pos.to_s]["description"]<<element_string
|
||||
@import_object['steps'][step_pos.to_s]['description'] = element_string
|
||||
end
|
||||
else
|
||||
@import_object['steps'][step_pos.to_s]['description'] ||= 'Description missing!'
|
||||
end
|
||||
when '6'
|
||||
if !key['data'].nil? && key['data'] != ''
|
||||
@import_object['steps'][step_pos.to_s]['name'] = key['data']
|
||||
else
|
||||
@import_object['steps'][step_pos.to_s]['name'] = 'Step'
|
||||
end
|
||||
when '17'
|
||||
if !key['data'].nil? && key['data'] != ''
|
||||
element_string = '<br><strong>Expected result: </strong>' + (key['data']) + '<br>'
|
||||
@import_object['steps'][step_pos.to_s]['description'] << element_string
|
||||
|
||||
end#(complex mapping with nested hashes) id 8 = software package, id 9 = dataset,
|
||||
#id 15 = command, id 18 = attached sub protocol
|
||||
# id 19= safety information ,id 20= regents (materials, like scinote samples kind of)
|
||||
end
|
||||
end
|
||||
# (complex mapping with nested hashes)
|
||||
# id 8 = software package, id 9 = dataset,
|
||||
# id 15 = command, id 18 = attached sub protocol
|
||||
# id 19= safety information ,
|
||||
# id 20= regents (materials, like scinote samples kind of)
|
||||
|
||||
elsif key && whitelist_complex.include?(key["component_type_id"])
|
||||
case key["component_type_id"]
|
||||
when "8"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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
|
||||
elsif key && whitelist_complex.include?(key['component_type_id'])
|
||||
case key['component_type_id']
|
||||
when '8'
|
||||
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'
|
||||
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'
|
||||
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'
|
||||
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"
|
||||
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
|
||||
end
|
||||
when '19'
|
||||
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' placeholder za materiale
|
||||
end
|
||||
end # finished step component iteration
|
||||
end # finished looping over step components
|
||||
end # steps
|
||||
|
||||
end
|
||||
end #finished step component iteration
|
||||
|
||||
|
||||
end #finished looping over step components
|
||||
end #steps
|
||||
|
||||
protocol = nil
|
||||
respond_to do |format|
|
||||
protocol = nil
|
||||
respond_to do |format|
|
||||
transaction_error = false
|
||||
#@steps_object=JSON.parse(params["steps"]["steps_object"])
|
||||
@protocolsio_general_error=false
|
||||
@protocolsio_general_error = false
|
||||
Protocol.transaction do
|
||||
begin
|
||||
|
||||
# pass the import_object we made, current team,user
|
||||
# and the type (private,public)
|
||||
protocol = import_new_protocol(@import_object, current_team, params[:type].to_sym, current_user)
|
||||
|
||||
rescue Exception
|
||||
|
||||
transaction_error = true
|
||||
raise ActiveRecord:: Rollback
|
||||
end
|
||||
|
@ -783,31 +796,25 @@ def protocolsio_import_save
|
|||
end
|
||||
|
||||
if transaction_error
|
||||
@protocolsio_general_error = true
|
||||
# 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
|
||||
# General something went wrong, upload to db failed error
|
||||
@protocolsio_general_error = false
|
||||
format.json {
|
||||
render json: {
|
||||
name: p_name, new_name: protocol.name, status: :ok
|
||||
},
|
||||
render json:
|
||||
{ name: p_name, new_name: protocol.name, status: :ok },
|
||||
status: :ok
|
||||
}
|
||||
format.js{}
|
||||
end
|
||||
format.js {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
def export
|
||||
# Make a zip output stream and send it to the client
|
||||
respond_to do |format|
|
||||
|
|
|
@ -1,21 +1,29 @@
|
|||
<div class="modal fade" id="modal-import-json-protocol" tabindex="-1" role="dialog" >
|
||||
<div
|
||||
class="modal fade"
|
||||
id="modal-import-json-protocol"
|
||||
tabindex="-1"
|
||||
role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title"><%= t('protocols.index.modal_import_json_title') %></h4>
|
||||
<%= t("protocols.index.modal_import_json_notice") %>
|
||||
</div>
|
||||
<%= form_tag({ action: "protocolsio_import_create"}, id:"protocols_io_form", format: :json, multipart: true,remote: true,:method => "post") do %>
|
||||
<%= form_tag({ action: "protocolsio_import_create"}, id:"protocols_io_form",
|
||||
format: :json, multipart: true,remote: true,:method => "post") do %>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<%= file_field_tag 'json_file', accept: '.txt' %>
|
||||
<%= file_field_tag 'json_file', accept: '.txt' %>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('general.cancel')%></button>
|
||||
<%= submit_tag t("protocols.index.modal_import_json_submit"), class: "btn btn-default" %>
|
||||
<%= submit_tag t("protocols.index.modal_import_json_submit"), class: "btn
|
||||
btn-default" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1,52 +1,59 @@
|
|||
<%= form_for(@protocol, :url => url_for(:controller => 'protocols', :action => 'protocolsio_import_save'),method: :post,format: :javascript,remote: true,:html => { :id => "protocolsio-import-form" }) do |f| %>
|
||||
<%= form_for(@protocol, :url => url_for(:controller => 'protocols', :action =>'protocolsio_import_save'),method: :post,format: :javascript,remote: true,:html=> { :id => "protocolsio-import-form" }) do |f| %>
|
||||
|
||||
<%= hidden_field_tag :json_object, JSON.generate(@json_object) %>
|
||||
<%= hidden_field_tag :type, CGI.parse(URI.parse(request.referrer).query).fetch("type") %>
|
||||
|
||||
<div id="modal-import-json-protocol-preview" class="modal fade" role="dialog" tabindex="-1">
|
||||
<%= hidden_field_tag :json_object, JSON.generate(@json_object) %>
|
||||
<%= hidden_field_tag :type,
|
||||
CGI.parse(URI.parse(request.referrer).query).fetch("type") %>
|
||||
<!--Get the type of protocol to import (private, public) from the url -->
|
||||
<div
|
||||
id="modal-import-json-protocol-preview"
|
||||
class="modal fade"
|
||||
role="dialog"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title" data-role="header-import-into-protocol_protocols_io"><%= t("protocols.import_export.import_modal.title_import_into_protocol_protocols_io") %></h4>
|
||||
<h4 class="modal-title" data-role="header-import-into-protocol_protocols_io"><%=
|
||||
t("protocols.import_export.import_modal.title_import_into_protocol_protocols_io")
|
||||
%></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
|
||||
|
||||
<!-- General protocol info -->
|
||||
<div class="form-group">
|
||||
|
||||
<label><%= t("protocols.import_export.import_modal.name_label") %></label>
|
||||
|
||||
<%= f.text_field :name, :value => @json_object['protocol_name'], class: "form-control" %>
|
||||
<%= f.text_field :name, :value => @json_object['protocol_name'], class:
|
||||
"form-control" %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<span class="glyphicon glyphicon-user"></span> <%= t("protocols.import_export.import_modal.authors_label") %>
|
||||
</label>
|
||||
<%= f.text_field :authors, :value => @json_object['full_name'], class: "form-control" %>
|
||||
|
||||
<%= f.text_field :authors, :value => @json_object['full_name'], class:
|
||||
"form-control" %>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label><%= t("protocols.import_export.import_modal.description_label") %></label>
|
||||
|
||||
<%= f.text_area :description, :value => @json_object['description'], class: "form-control" %>
|
||||
<%= f.text_area :description, :value => @json_object['description'], class:
|
||||
"form-control" %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<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) %>
|
||||
<%= f.text_field :created_at, :value => display_created_at.to_s+" (Protocols.io value)",readonly: true, class: "form-control" %>
|
||||
<% display_created_at=Time.at(@json_object['created_on'].to_i) %>
|
||||
<%= f.text_field :created_at, :value => display_created_at.to_s+"(Protocols.io value)",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) %>
|
||||
<%= f.text_field :last_modified, :value => display_last_modified.to_s+" (Protocols.io value)",readonly: true, class: "form-control" %>
|
||||
<%= f.text_field :last_modified, :value => display_last_modified.to_s+"(Protocols.io value)",readonly: true, class: "form-control" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -59,170 +66,189 @@
|
|||
|
||||
<!-- Preview scroller -->
|
||||
|
||||
<div
|
||||
class="import-protocols-modal-preview-container-json"
|
||||
data-role="preview-container">
|
||||
<hr>
|
||||
|
||||
<div class="import-protocols-modal-preview-container-json" data-role="preview-container">
|
||||
<% if @json_object["before_start"]&&@json_object["before_start"]!="" %>
|
||||
|
||||
<strong>Before starting protocol information:</strong><br>
|
||||
<%= (@json_object["before_start"]) %><br>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["warning"]&&@json_object["warning"]!="" %>
|
||||
|
||||
<strong>Protocol warning:</strong><br>
|
||||
<%= (@json_object["warning"]) %><br>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["guidelines"]&&@json_object["guidelines"]!="" %>
|
||||
|
||||
<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 %>
|
||||
<% whitelist_simple=["1","6","17"] %>
|
||||
<% whitelist_complex=["8","9","15","18","19","20"]%>
|
||||
<% @json_object["steps"].each do |step| %>
|
||||
<div style="display: block;">
|
||||
<hr>
|
||||
|
||||
<% if @json_object["before_start"]&&@json_object["before_start"]!="" %>
|
||||
|
||||
<strong>Before starting protocol information:</strong><br>
|
||||
<%= (@json_object["before_start"]) %><br>
|
||||
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["warning"]&&@json_object["warning"]!="" %>
|
||||
|
||||
<strong>Protocol warning:</strong><br>
|
||||
<%= (@json_object["warning"]) %><br>
|
||||
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["guidelines"]&&@json_object["guidelines"]!="" %>
|
||||
|
||||
<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 %>
|
||||
<% whitelist_simple=["1","6","17"] %>
|
||||
<% whitelist_complex=["8","9","15","18","19","20"]%>
|
||||
<% @json_object["steps"].each do |step| %>
|
||||
<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>
|
||||
</span>
|
||||
|
||||
|
||||
<span class="step-panel-collapse-link" data-toggle="collapse">
|
||||
<span class="glyphicon collapse-step-icon glyphicon-collapse-up"></span>
|
||||
|
||||
|
||||
<%#= Step guid (Protocols.io) :%><%#= step["guid"] %>
|
||||
<%# if counter>1 #only steps after the first one have previous step guid field valid%>
|
||||
<%#=Guid of previous step (Protocols.io) :%><%#= step["previous_guid"] %>
|
||||
<%# end %>
|
||||
<% title=nil %>
|
||||
<% step["components"].each do |key1,value1| #finding section (title of step) %>
|
||||
<td>
|
||||
<div class="badge-num">
|
||||
<span class="badge-preview bg-primary size-digit-1">
|
||||
<b data-val="position"><%= (counter+=1) %></b>
|
||||
</span>
|
||||
|
||||
<span class="step-panel-collapse-link" data-toggle="collapse">
|
||||
<span class="glyphicon collapse-step-icon glyphicon-collapse-up"></span>
|
||||
<%# this guid attributes were ommited because they didnt seem relevenat %>
|
||||
<%#= Step guid (Protocols.io) :%><%#= step["guid"] %>
|
||||
<%# if counter>1 #only steps after the first one have previous step guid field
|
||||
valid%>
|
||||
<%#=Guid of previous step (Protocols.io) :%><%#= step["previous_guid"] %>
|
||||
<%# end %>
|
||||
<% title=nil %>
|
||||
<% step["components"].each do |key1,value1| #finding section (title of step) %>
|
||||
|
||||
<% if counter <=1 %>
|
||||
<% if value1.class==Hash %>
|
||||
<% key1=value1 %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if(key1["component_type_id"]=="6") %>
|
||||
<% if(!key1["data"].nil? && key1["data"]!="") %>
|
||||
<%# byebug %>
|
||||
<% title ||=key1["data"] %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if value1.class==Hash %>
|
||||
<% key1=value1 %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if(key1["component_type_id"]=="6") %>
|
||||
<% if(!key1["data"].nil? && key1["data"]!="") %>
|
||||
<% title ||=key1["data"] %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<% if title.nil? %>
|
||||
<%# byebug %>
|
||||
<% title ="Step" %>
|
||||
<% end %>
|
||||
<strong data-val="name"><%= title %></strong>
|
||||
<% end %>
|
||||
<% if title.nil? %>
|
||||
<% title ="Step" %>
|
||||
<% end %>
|
||||
<strong data-val="name"><%= title %></strong>
|
||||
</span>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" role="tabpanel">
|
||||
<div data-val="description" class="ql-editor">
|
||||
<div class="tab-pane active" role="tabpanel">
|
||||
<div data-val="description" class="ql-editor">
|
||||
|
||||
|
||||
<% step["components"].each do |key,value| %>
|
||||
<% if counter<=1 #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 hashes
|
||||
%>
|
||||
<% step["components"].each do |key,value| %>
|
||||
<% if counter<=1 %>
|
||||
<%#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
|
||||
hashes, you might see this elsewhere %>
|
||||
<% if value.class==Hash %>
|
||||
<% key=value %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
<% end %>
|
||||
<% # the below blocks of code output the various attributes if they exist and arent null or "" from the json object %>
|
||||
<% if whitelist_simple.include?(key["component_type_id"]) && key["data"]!="" && key["data"] %>
|
||||
<br>
|
||||
<% case key["component_type_id"]%>
|
||||
<% when "1" %>
|
||||
<br><strong>Description: </strong> <%=key["data"]%><br>
|
||||
<br>
|
||||
<strong>Description:
|
||||
</strong>
|
||||
<%=key["data"]%><br>
|
||||
<% when "17" %>
|
||||
<br><strong>Expected result: </strong> <%=key["data"]%><br>
|
||||
<% else %>
|
||||
<br>
|
||||
<strong>Expected result:
|
||||
</strong>
|
||||
<%=key["data"]%><br>
|
||||
<% else %>
|
||||
<% end %>
|
||||
<% elsif key && whitelist_complex.include?(key["component_type_id"]) %>
|
||||
|
||||
<% case key["component_type_id"]%>
|
||||
<% when "8"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></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"]) %>
|
||||
<% case key["component_type_id"]%>
|
||||
<% when "8"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></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"]) %>
|
||||
|
||||
<% when "9"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></strong> <%= key["source_data"]["name"] %>
|
||||
<br>
|
||||
Link : <%= (key["source_data"]["link"]) %>
|
||||
<% when "9"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></strong>
|
||||
<%= key["source_data"]["name"] %>
|
||||
<br>
|
||||
Link :
|
||||
<%= (key["source_data"]["link"]) %>
|
||||
|
||||
<% when "15"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></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"]) %>
|
||||
|
||||
<% when "15"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></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"]) %>
|
||||
<% when "18"%>
|
||||
<br>
|
||||
<strong>This protocol also contains an attached sub-protocol:
|
||||
</strong>
|
||||
<%= (key["source_data"]["protocol_name"]) %>
|
||||
<br>
|
||||
Author:
|
||||
<%= (key["source_data"]["full_name"]) %>
|
||||
<br>
|
||||
<% if key["source_data"]["link"]&&key["source_data"]["link"]!="" %>
|
||||
Link:
|
||||
<%= (key["source_data"]["link"]) %>
|
||||
<% end %>
|
||||
<% when "19"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></strong>
|
||||
<%= key["source_data"]["body"] %>
|
||||
<br>
|
||||
Link:
|
||||
<%= (key["source_data"]["link"]) %>
|
||||
|
||||
<% when "18"%>
|
||||
<br>
|
||||
<strong>This protocol also contains an attached sub-protocol: </strong> <%= (key["source_data"]["protocol_name"]) %>
|
||||
<br>
|
||||
Author: <%= (key["source_data"]["full_name"]) %>
|
||||
<br>
|
||||
<% if key["source_data"]["link"]&&key["source_data"]["link"]!="" %>
|
||||
Link: <%= (key["source_data"]["link"]) %>
|
||||
<% end %>
|
||||
<% when "19"%>
|
||||
<br>
|
||||
<strong><%= key["name"]+": " %></strong> <%= key["source_data"]["body"] %>
|
||||
<br>
|
||||
Link: <%= (key["source_data"]["link"]) %>
|
||||
<% when "20"%>
|
||||
|
||||
<% else %>
|
||||
|
||||
<% when "20"%>
|
||||
|
||||
<% else %>
|
||||
|
||||
<% end #case if%>
|
||||
<% end #case if%>
|
||||
|
||||
<% end #inner if%>
|
||||
|
||||
<% end #step component loop %>
|
||||
|
||||
<% end #step component loop %>
|
||||
</div>
|
||||
<hr>
|
||||
<!-- This could be implemented later maybe,i believe this is different styling
|
||||
for scinotes own rich text format tables
|
||||
|
||||
</div>
|
||||
<hr>
|
||||
<!-- <div class="row">
|
||||
<div class="row">
|
||||
<div data-toggle="tables" class="col-xs-12" style="display: none;">
|
||||
<div data-hold="tables"> </div>
|
||||
</div>
|
||||
|
@ -235,71 +261,76 @@
|
|||
<div data-hold="checklists"></div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div> <%# block div%>
|
||||
<% end #step loop%>
|
||||
|
||||
<% if
|
||||
@json_object["manuscript_citation"]&&@json_object["manuscript_citation"]!="" %>
|
||||
|
||||
|
||||
<% if @json_object["manuscript_citation"]&&@json_object["manuscript_citation"]!="" %>
|
||||
|
||||
<br><strong>Manuscript citation:</strong><br>
|
||||
<%= (@json_object["manuscript_citation"]) %>
|
||||
<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>
|
||||
<%= (@json_object["publish_date"]) %>
|
||||
<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>
|
||||
<%= (@json_object["vendor_name"]) %>
|
||||
<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>
|
||||
<%= (@json_object["vendor_link"]) %>
|
||||
<br>
|
||||
<strong>Vendor link:</strong><br>
|
||||
<%= (@json_object["vendor_link"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["keywords"]&&@json_object["keywords"]!="" %>
|
||||
|
||||
<br><strong>Keywords:</strong><br>
|
||||
<%= (@json_object["keywords"]) %>
|
||||
<br>
|
||||
<strong>Keywords:</strong><br>
|
||||
<%= (@json_object["keywords"]) %>
|
||||
|
||||
<% end %>
|
||||
<% if @json_object["tags"]&&@json_object["tags"]!="" %>
|
||||
|
||||
<br><strong>Tags:</strong><br>
|
||||
<% @json_object["tags"].each do |tag| %>
|
||||
<%= (tag["tag_name"])+" , " %>
|
||||
<% end %>
|
||||
<br>
|
||||
<strong>Tags:</strong><br>
|
||||
<% @json_object["tags"].each do |tag| %>
|
||||
<%= (tag["tag_name"])+" , " %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t("general.cancel") %></button>
|
||||
|
||||
<%= f.submit t("protocols.import_export.import_modal.import"),class: "btn btn-primary" %>
|
||||
<% end %>
|
||||
<%= f.submit t("protocols.import_export.import_modal.import"),class: "btn
|
||||
btn-primary" %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$('#modal-import-json-protocol-preview').on('hide.bs.modal',function(){
|
||||
$('#protocols_io_form').trigger("reset");
|
||||
})
|
||||
</script>
|
||||
<% # the below script resets all the fields after you decide not to import the file (cancel (modal hide)) %>
|
||||
<script>
|
||||
$('#modal-import-json-protocol-preview').on('hide.bs.modal', function () {
|
||||
$('#protocols_io_form').trigger("reset");
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
|
||||
<a class="btn-link-alt btn-default-link btn-open-file" <%= can_import_protocols(@current_team) ? 'data-action="import"' : 'disabled="disabled"' %>>
|
||||
<span class="glyphicon glyphicon-file"></span>
|
||||
<span class="hidden-xs"><%= t("protocols.index.import_alt") %></span>
|
||||
|
@ -61,20 +60,13 @@
|
|||
data-team-id="<%= @current_team.id %>"
|
||||
data-type="<%= @type %>" data-import-url="<%= import_protocols_path %>"
|
||||
<%= 'disabled="disabled"' unless can_import_protocols(@current_team) %>>
|
||||
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
||||
|
||||
<%= link_to "#modal-import-json-protocol", "data-toggle" => "modal" do %>
|
||||
<span class="glyphicon glyphicon-file"></span>
|
||||
<span class="hidden-xs"><%= t("protocols.index.import_json") %></span>
|
||||
<% end %>
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
@ -417,12 +417,8 @@ Rails.application.routes.draw do
|
|||
post 'archive', to: 'protocols#archive'
|
||||
post 'restore', to: 'protocols#restore'
|
||||
post 'import', to: 'protocols#import'
|
||||
##
|
||||
##-tule gre tvoje json_import match
|
||||
post 'protocolsio_import_create', to: 'protocols#protocolsio_import_create'
|
||||
post 'protocolsio_import_save', to: 'protocols#protocolsio_import_save'
|
||||
#get 'testcontroller', to: 'protocols#testcontroller'
|
||||
##
|
||||
get 'export', to: 'protocols#export'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue