diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index ff989cf00..1798dca63 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -468,6 +468,7 @@ class ProtocolsController < ApplicationController end def load_from_repository + respond_to do |format| if @protocol.can_destroy? transaction_error = false @@ -518,6 +519,7 @@ class ProtocolsController < ApplicationController def load_from_file # This is actually very similar to import + respond_to do |format| if @protocol.can_destroy? transaction_error = false @@ -566,7 +568,8 @@ class ProtocolsController < ApplicationController end end - def import + def import #tega uporabi .eln import + protocol = nil respond_to do |format| transaction_error = false @@ -605,7 +608,10 @@ def protocolsio_import_create json_file_contents=File.read(params[:json_file].path) - @json_object=JSON.parse(json_file_contents) + json_file_contents.gsub! '\"', "'" + #byebug + + @json_object=JSON.parse((json_file_contents)) @protocol=Protocol.new respond_to do |format| @@ -615,12 +621,44 @@ def protocolsio_import_create end + def protocolsio_import_save #@temp_json=JsonTemp.new + byebug + protocol = nil respond_to do |format| - format.html {render protocols} - format.js {render nothing} + transaction_error = false + @steps_object=JSON.parse(params["steps"]["steps_object"]) + byebug + Protocol.transaction do + begin + + protocol = import_new_protocol(@protocol_json, @team, @type, current_user) + rescue Exception + transaction_error = true + raise ActiveRecord:: Rollback + end + end + + p_name = + if @protocol_json['name'].present? && !@protocol_json['name'].empty? + escape_input(@protocol_json['name']) + else + t('protocols.index.no_protocol_name') + end + if transaction_error + format.json { + render json: { name: p_name, status: :bad_request }, status: :bad_request + } + else + format.json { + render json: { + name: p_name, new_name: protocol.name, status: :ok + }, + status: :ok + } + end end end diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index 0e0edddf1..9a9d259db 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -1,7 +1,7 @@ module ProtocolsImporter include RenamingUtil - def import_new_protocol(protocol_json, team, type, user) + def import_new_protocol(protocol_json, team, type, user) # .eln import remove_empty_inputs(protocol_json) protocol = Protocol.new( name: protocol_json["name"], diff --git a/app/views/protocols/import_export/_import_json_protocol_modal.html.erb b/app/views/protocols/import_export/_import_json_protocol_modal.html.erb index 5d35ba8c7..b4aa30e74 100644 --- a/app/views/protocols/import_export/_import_json_protocol_modal.html.erb +++ b/app/views/protocols/import_export/_import_json_protocol_modal.html.erb @@ -1,4 +1,4 @@ -