diff --git a/app/assets/javascripts/my_modules/protocols.js.erb b/app/assets/javascripts/my_modules/protocols.js.erb
index e11845f4a..cc1384b44 100644
--- a/app/assets/javascripts/my_modules/protocols.js.erb
+++ b/app/assets/javascripts/my_modules/protocols.js.erb
@@ -1,5 +1,4 @@
//= require protocols/import_export/import
-//= require protocols/import_export/export
//= require comments
//= require datatables
@@ -17,7 +16,6 @@ function init() {
initLoadFromRepository();
initRefreshStatusBar();
initImport();
- initExport();
Comments.bindNewElement();
Comments.initialize();
initTutorial();
@@ -510,11 +508,4 @@ function initImport() {
});
}
-function initExport() {
- var exportBtn = $("[data-action='export']");
- exportBtn.on("click", function() {
- exportProtocols([ $(this).attr("data-id") ]);
- });
-}
-
init();
diff --git a/app/assets/javascripts/protocols/import_export/export.js b/app/assets/javascripts/protocols/import_export/export.js
deleted file mode 100644
index a3c082911..000000000
--- a/app/assets/javascripts/protocols/import_export/export.js
+++ /dev/null
@@ -1,372 +0,0 @@
-//= require jszip.min.js
-
-function exportProtocols(protocol_ids) {
- /*********************************************/
- /* INNER FUNCTIONS */
- /*********************************************/
-
- // Custom StringBuilder 'object'
- function StringBuilder() {
- this.tokens = [];
-
- this.add = function(token) {
- this.tokens.push(token);
- return this;
- };
-
- this.nl = function() {
- this.tokens.push('\n');
- return this;
- };
-
- this.build = function() {
- var str = this.tokens.join("");
- this.tokens = null;
- return str;
- };
- }
-
- function getGuid(id) {
- var str1 = "00000000-0000-";
- var str2 = id.toString();
- for (var i = str2.length; i < 19; i++) {
- str2 = "0" + str2;
- }
- str2 = "4" + str2;
- var str2n = str2.slice(0, 4) + "-" + str2.slice(4, 8) + "-" + str2.slice(8);
- return str1 + str2n;
- }
-
- // Escape null in String
- function esn(val) {
- if (val === null) {
- return "";
- } else {
- return String(val);
- }
- }
-
- function extractFileExtension(fileName) {
- var tokens = fileName.split(".");
- if (tokens.length <= 1) {
- return "";
- } else {
- return "." + tokens[tokens.length - 1];
- }
- }
-
- function generateEnvelopeXsd() {
- var sb = new StringBuilder();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('');
- return sb.build();
- }
-
- function generateElnXsd() {
- var sb = new StringBuilder();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('').nl();
- sb.add('');
- return sb.build();
- }
-
- /*********************************************/
- /* ACTUAL FUNCTION CODE */
- /*********************************************/
-
- if (protocol_ids.length > 0) {
- animateSpinner();
-
- $.ajax({
- type: "GET",
- url: "/protocols/export",
- dataType: "json",
- data: { protocol_ids: protocol_ids},
- success: function (data) {
- var zip = new JSZip();
-
- // Envelope code
- var esb = new StringBuilder();
- esb.add('').nl();
-
- _.each(data.protocols, function(protocol) {
- var protocolGuid = getGuid(protocol.id);
-
- // Create folder for this protocol
- var protocolFolder = zip.folder(protocolGuid);
-
- var protocolXml = [];
- var psb = new StringBuilder();
-
- // Header
- psb.add('').nl();
-
- // Protocol
- psb.add('').nl();
- psb.add('' + esn(protocol.name) + '').nl();
- psb.add('' + esn(protocol.authors) + '').nl();
- psb.add('' + esn(protocol.description) + '').nl();
- psb.add('' + esn(protocol.created_at) + '').nl();
- psb.add('' + esn(protocol.updated_at) + '').nl();
-
- // Steps
- if (protocol.steps.length > 0) {
- psb.add('').nl();
- _.each(protocol.steps, function(step) {
- var stepGuid = getGuid(step.id);
-
- var ssb = new StringBuilder();
-
- ssb.add('').nl();
- ssb.add('' + esn(step.name) + '').nl();
- ssb.add('' + esn(step.description) + '').nl();
-
- // Assets
- if (step.assets.length > 0) {
- ssb.add('').nl();
- _.each(step.assets, function(asset) {
- var assetGuid = getGuid(asset.id);
-
- // Generate the asset file inside ZIP
- var assetFileName = assetGuid + extractFileExtension(asset.fileName);
- var decodedData = window.atob(asset.bytes);
- zip.folder(protocolGuid).folder(stepGuid).file(assetFileName, decodedData, { binary: true });
-
- var asb = new StringBuilder();
-
- asb.add('').nl();
- asb.add('' + esn(asset.fileName) + '').nl();
- asb.add('' + esn(asset.fileType) + '').nl();
- asb.add('').nl();
-
- ssb.add(asb.build());
- });
- ssb.add('').nl();
- }
-
- // Tables
- if (step.tables.length > 0) {
- ssb.add('').nl();
- _.each(step.tables, function(table) {
- var tsb = new StringBuilder();
-
- tsb.add('').nl();
- tsb.add('' + esn(table.name) + '').nl();
- tsb.add('' + esn(table.contents) + '').nl();
- tsb.add('');
-
- ssb.add(tsb.build()).nl();
- });
- ssb.add('').nl();
- }
-
- // Checklists
- if (step.checklists.length > 0) {
- ssb.add('').nl();
- _.each(step.checklists, function(checklist) {
- var csb = new StringBuilder();
-
- csb.add('').nl();
- csb.add('' + esn(checklist.name) + '').nl();
-
- if (checklist.items.length > 0) {
- csb.add('').nl();
- _.each(checklist.items, function(item) {
- var isb = new StringBuilder();
-
- isb.add('- ').nl();
- isb.add('' + esn(item.text) + '').nl();
- isb.add('
');
-
- csb.add(isb.build()).nl();
- });
- csb.add('').nl();
- }
- csb.add('');
-
- ssb.add(csb.build()).nl();
- });
- ssb.add('').nl();
- }
-
- psb.add(ssb.build());
- psb.add('').nl();
- });
- psb.add('').nl();
- }
-
- psb.add('').nl();
- psb.add('');
-
- // Okay, we have a generated XML for
- // individual protocol, save it to protocol folder
- protocolFolder.file("eln.xml", psb.build());
-
- // Add protocol to the envelope
- esb.add('' + esn(protocol.name) + '').nl();
- });
- esb.add('').nl();
-
- // Save envelope to root directory in ZIP
- zip.file("scinote.xml", esb.build());
-
- // Add the XSD schemes into the ZIP
- zip.file("scinote.xsd", generateEnvelopeXsd());
- zip.file("eln.xsd", generateElnXsd());
-
- // NOW, DOWNLOAD THE ZIP
- var blob = zip.generate({ type: "blob" });
-
- var fileName = "protocol.eln";
- if (data.protocols.length === 1) {
- // Try to construct an OS-safe file name
- if (data.protocols[0].name.length && data.protocols[0].name.length > 0) {
- var escapedName = data.protocols[0].name.replace(/[^0-9a-zA-Z-.,_]/gi, '_').toLowerCase().substring(0, 250);
- if (escapedName.length > 0) {
- fileName = escapedName + ".eln";
- }
- }
- } else if (data.protocols.length > 1) {
- fileName = "protocols.eln";
- }
-
- var link = document.createElement("a");
- if (link.download !== undefined) {
- // Browsers that support HTML5 download attribute
- link.setAttribute("href", window.URL.createObjectURL(blob));
- link.setAttribute("download", fileName);
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else {
- alert("Please use latest version of Chrome, Firefox, or Opera browser for the export!");
- }
-
- animateSpinner(null, false);
- },
- error: function() {
- alert("Ajax error!");
- }
- });
- }
-}
\ No newline at end of file
diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb
index 4d70fd057..cd9c449c6 100644
--- a/app/controllers/protocols_controller.rb
+++ b/app/controllers/protocols_controller.rb
@@ -560,38 +560,61 @@ class ProtocolsController < ApplicationController
end
def export
- #respond_to do |format|
- # format.json {
- # render json: {
- # protocols: export_protocols(@protocols)
- # }, status: :ok
- # }
- #end
-
# Make a zip output stream and send it to the client
respond_to do |format|
- format.html
- format.zip do
- Dir.mktmpdir do |tmp_dir|
-
-
- end
-
+ format.html do
z_output_stream = Zip::OutputStream.write_buffer do |ostream|
- ostream.put_next_entry('eln.xml')
- ostream.print(protocol_xml)
- ostream.put_next_entry("#{arch_dir}/scinote.xml")
- ostream.print(envelope_xml)
- ostream.put_next_entry("#{arch_dir}/scinote.xsd")
+ ostream.put_next_entry('scinote.xml')
+ ostream.print(generate_envelope_xml(@protocols))
+ ostream.put_next_entry('scinote.xsd')
ostream.print(generate_envelope_xsd)
- ostream.put_next_entry("#{arch_dir}/eln.xsd")
+ ostream.put_next_entry('eln.xsd')
ostream.print(generate_eln_xsd)
+
+ # Create folder and xml file for each protocol and populate it
+ @protocols.each do |protocol|
+ protocol_dir = get_guid(protocol.id).to_s
+ ostream.put_next_entry("#{protocol_dir}/eln.xml")
+ ostream.print(generate_protocol_xml(protocol))
+ # Add assets to protocol folder
+ if protocol.steps.count > 0
+ protocol.steps.order(:id).each do |step|
+ step_guid = get_guid(step.id)
+ step_dir = "#{protocol_dir}/#{step_guid}"
+ if step.assets.count > 0
+ step.assets.order(:id).each do |asset|
+ asset_guid = get_guid(asset.id)
+ asset_file_name = asset_guid.to_s +
+ File.extname(asset.file_file_name).to_s
+ ostream.put_next_entry("#{step_dir}/#{asset_file_name}")
+ input_file = asset.open
+ ostream.print(input_file.read)
+ input_file.close
+ end
+ end
+ end
+ end
+ end
end
z_output_stream.rewind
- send_data compressed_filestream.read, filename: "protocol.eln"
+
+ protocol_name = get_protocol_name(@protocols[0])
+
+ # Now generate filename of the archive and send file to user
+ if @protocols.count == 1
+ # Try to construct an OS-safe file name
+ file_name = 'protocol.eln'
+ unless protocol_name.nil?
+ escaped_name = protocol_name.gsub(/[^0-9a-zA-Z-.,_]/i, '_')
+ .downcase[0..250]
+ file_name = escaped_name + '.eln' unless escaped_name.empty?
+ end
+ elsif @protocols.length > 1
+ file_name = 'protocols.eln'
+ end
+ send_data(z_output_stream.read, filename: file_name)
end
end
-
end
def unlink_modal
diff --git a/app/utilities/protocols_exporter.rb b/app/utilities/protocols_exporter.rb
index d3ef68e65..41505368e 100644
--- a/app/utilities/protocols_exporter.rb
+++ b/app/utilities/protocols_exporter.rb
@@ -1,152 +1,6 @@
-require 'tmpdir'
require 'zip'
module ProtocolsExporter
- def export_protocols(protocols)
- #protocols_json = []
- #protocols.each do |protocol|
- # protocols_json << export_protocol(protocol)
- #end
-
- #return protocols_json
-
- # create temporary working dir, will be deleted in the end
- Dir.mktmpdir do |tmp_dir|
- # create dir for archive
- arch_dir = "#{tmp_dir}/protocols"
- Dir.mkdir(arch_dir)
- # create xml envelope document
- envelope_xml = "\n"
- protocols.each do |protocol|
- protocol_guid = get_guid(protocol.id)
- # Create a folder for this protocol
- protocol_dir = "#{arch_dir}/#{protocol_guid}"
- Dir.mkdir(protocol_dir)
- # Protocol
- protocol_xml = "\n"
- protocol_xml << "\n"
- protocol_xml << "#{protocol.name}\n"
- protocol_xml << "#{protocol.authors}\n"
- protocol_xml << "#{protocol.description}\n"
- protocol_xml << "#{protocol.created_at}\n"
- protocol_xml << "#{protocol.updated_at}\n"
-
- # Steps
- if protocol.steps
- protocol_xml << "\n"
- protocol.steps.each do |step|
- step_guid = get_guid(step.id)
- step_xml = "\n"
- step_xml << "#{step.name}\n"
- step_xml << "#{step.description}\n"
-
- # Assets
- if step.assets
- p step.id
- p "assets"
- step_xml << ''
- step.assets.each do |asset|
- asset_guid = get_guid(asset.id)
- # create dir in protocol dir for assets
- step_dir = "#{protocol_dir}/#{step_guid}"
- p step_dir
- Dir.mkdir(step_dir)
- # create file for asset inside step dir
- asset_file_name = "#{step_dir}/#{asset_guid}#{File.extname(asset.file_file_name)}"
- output_file = File.open(asset_file_name, 'wb')
- input_file = asset.open
- p 'opened'
- # p input_file
- # puts `ls -la /tmp`
- #output_file.write(input_file.read)
- while buffer = input_file.read(4096)
- output_file.write(buffer)
- end
- input_file.close
- p output_file.size
- asset_xml = "\n"
- asset_xml << "#{asset.file_file_name}\n"
- asset_xml << "#{asset.file_content_type}\n"
- asset_xml << "\n"
- step_xml << asset_xml
- end
- step_xml << "\n"
- end
-
- # Tables
- if step.tables
- step_xml << "\n"
- step.tables.each do |table|
- table_xml = "\n"
- table_xml << "#{table.contents.unpack('H*')[0]}\n"
- table_xml << "\n"
- step_xml << table_xml
- end
- step_xml << "\n"
- end
-
- # Checklists
- if step.checklists
- step_xml << "\n"
- step.checklists.each do |checklist|
- checklist_xml = "\n"
- checklist_xml << "#{checklist.name}\n"
- if checklist.items
- checklist_xml << "\n"
- checklist.items.each do |item|
- item_xml = "- \n"
- item_xml << "#{item.text}\n"
- item_xml << "
\n"
- checklist_xml << item_xml
- end
- checklist_xml << "\n"
- end
- checklist_xml << "\n"
- step_xml << checklist_xml
- end
- step_xml << "\n"
- end
- protocol_xml << step_xml
- protocol_xml << "\n"
- end
- protocol_xml << "\n"
- end
- protocol_xml << "\n"
- protocol_xml << ''
- p protocol_xml
- # Okay, we have a generated XML for
- # individual protocol, save it to protocol folder
- output_file = File.open("#{protocol_dir}/eln.xml", 'w')
- output_file.write(protocol_xml)
- output_file.close
- # Add protocol to the envelope
- envelope_xml << "#{protocol.name}\n"
- end
- envelope_xml << "\n"
-
- # Save envelope to root directory in archive
- output_file = File.open("#{arch_dir}/scinote.xml", 'w')
- output_file.write(envelope_xml)
- output_file.close
- output_file = File.open("#{arch_dir}/scinote.xsd", 'w')
- output_file.write(generate_envelope_xsd)
- output_file.close
- output_file = File.open("#{arch_dir}/eln.xsd", 'w')
- output_file.write(generate_eln_xsd)
- output_file.close
- puts `ls -la #{arch_dir}`
-
- # Now make zip output stream and send it to the client
- zip_name = "#{tmp_dir}/protocol.eln"
- Zip::File.open(zip_name, Zip::File::CREATE) do |zipfile|
- zipfile.add("eln.xsd", "#{arch_dir}/eln.xsd")
- zipfile.add("eln.xsd", "#{arch_dir}/scinote.xml")
- zipfile.add("eln.xsd", "#{arch_dir}/scinote.xsd")
- end
-
- end
- end
-
private
def get_guid(id)
@@ -160,9 +14,120 @@ module ProtocolsExporter
str1 + str2n
end
+ def get_protocol_name(protocol)
+ ## "Inject" module's name
+ if protocol.in_module? && protocol.name.blank?
+ protocol_name = protocol.my_module.name
+ else
+ protocol_name = protocol.name
+ end
+ protocol_name
+ end
+
+ def generate_envelope_xml(protocols)
+ envelope_xml = "\n"
+ protocols.each do |protocol|
+ protocol_name = get_protocol_name(protocol)
+ envelope_xml << "#{protocol_name}" \
+ "\n"
+ end
+ envelope_xml << "\n"
+ envelope_xml
+ end
+
+ def generate_protocol_xml(protocol)
+ protocol_name = get_protocol_name(protocol)
+ protocol_xml = "\n"
+ protocol_xml << "\n"
+ protocol_xml << "#{protocol_name}\n"
+ protocol_xml << "#{protocol.authors}\n"
+ protocol_xml << "#{protocol.description}\n"
+ protocol_xml << "#{protocol.created_at.as_json}\n"
+ protocol_xml << "#{protocol.updated_at.as_json}\n"
+
+ # Steps
+ if protocol.steps.count > 0
+ protocol_xml << "\n"
+ protocol.steps.order(:id).each do |step|
+ step_guid = get_guid(step.id)
+ step_xml = "\n"
+ step_xml << "#{step.name}\n"
+ step_xml << "#{step.description}\n"
+
+ # Assets
+ if step.assets.count > 0
+ step_xml << "\n"
+ step.assets.order(:id).each do |asset|
+ asset_guid = get_guid(asset.id)
+ asset_file_name = "#{asset_guid}" \
+ "#{File.extname(asset.file_file_name)}"
+ asset_xml = "\n"
+ asset_xml << "#{asset.file_file_name}\n"
+ asset_xml << "#{asset.file_content_type}\n"
+ asset_xml << "\n"
+ step_xml << asset_xml
+ end
+ step_xml << "\n"
+ end
+
+ # Tables
+ if step.tables.count > 0
+ step_xml << "\n"
+ step.tables.order(:id).each do |table|
+ table_xml = "\n"
+ table_xml << "#{table.contents.unpack('H*')[0]}" \
+ "\n"
+ table_xml << "\n"
+ step_xml << table_xml
+ end
+ step_xml << "\n"
+ end
+
+ # Checklists
+ if step.checklists.count > 0
+ step_xml << "\n"
+ step.checklists.order(:id).each do |checklist|
+ checklist_xml = "\n"
+ checklist_xml << "#{checklist.name}\n"
+ if checklist.items
+ checklist_xml << "\n"
+ checklist.items.each do |item|
+ item_xml = "- \n"
+ item_xml << "#{item.text}\n"
+ item_xml << "
\n"
+ checklist_xml << item_xml
+ end
+ checklist_xml << "\n"
+ end
+ checklist_xml << "\n"
+ step_xml << checklist_xml
+ end
+ step_xml << "\n"
+ end
+ protocol_xml << step_xml
+ protocol_xml << "\n"
+ end
+ protocol_xml << "\n"
+ end
+ protocol_xml << "\n"
+ protocol_xml << ''
+ protocol_xml
+ end
+
def generate_envelope_xsd
envelope_xsd = "\n"
- envelope_xsd << "\n"
+ envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
@@ -170,15 +135,19 @@ module ProtocolsExporter
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
- envelope_xsd << "\n"
- envelope_xsd << "\n"
+ envelope_xsd << "\n"
+ envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
- envelope_xsd << "\n"
- envelope_xsd << "\n"
+ envelope_xsd << "\n"
+ envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
envelope_xsd << "\n"
@@ -187,7 +156,9 @@ module ProtocolsExporter
def generate_eln_xsd
eln_xsd = "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
@@ -195,10 +166,14 @@ module ProtocolsExporter
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
@@ -206,7 +181,8 @@ module ProtocolsExporter
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
@@ -222,17 +198,22 @@ module ProtocolsExporter
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "" \
+ "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
@@ -244,12 +225,17 @@ module ProtocolsExporter
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
@@ -261,111 +247,44 @@ module ProtocolsExporter
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << "\n"
- eln_xsd << "\n"
+ eln_xsd << "\n"
+ eln_xsd << "\n"
eln_xsd << "\n"
eln_xsd << "\n"
- eln_xsd << ''
- end
-
- def export_protocol(protocol)
- protocol_json = protocol.as_json(only: [
- :id,
- :name,
- :description,
- :authors,
- :created_at,
- :updated_at
- ])
-
- # "Inject" module's name
- if protocol.in_module? && protocol.name.blank?
- protocol_json["name"] = protocol.my_module.name
- end
-
- protocol_json["steps"] = []
- protocol.steps.find_each do |step|
- step_json = step.as_json(only: [
- :id,
- :name,
- :description,
- :position
- ])
-
- step_json["tables"] = []
- step.tables.find_each do |table|
- table_json = table.as_json(only: [:id, :name])
- table_json["contents"] = table.contents.unpack("H*")[0]
-
- step_json["tables"] << table_json
- end
-
- step_json["assets"] = []
- step.assets.find_each do |asset|
- asset_json = asset.as_json(only: [
- :id,
- :file_file_name,
- :file_content_type
- ])
- asset_json["fileName"] = asset_json.delete("file_file_name")
- asset_json["fileType"] = asset_json.delete("file_content_type")
-
- # Retrieve file contents
- file = asset.open
- asset_json["bytes"] = Base64.encode64(file.read)
- file.close
-
- step_json["assets"] << asset_json
- end
-
- step_json["checklists"] = []
- step.checklists.find_each do |checklist|
- checklist_json = checklist.as_json(only: [
- :id,
- :name
- ])
-
- checklist_json["items"] = []
- checklist.checklist_items.find_each do |item|
- item_json = item.as_json(only: [
- :id,
- :text,
- :position
- ])
-
- checklist_json["items"] << item_json
- end
-
- step_json["checklists"] << checklist_json
- end
-
- protocol_json["steps"] << step_json
- end
-
- return protocol_json
+ eln_xsd << "\n"
end
end
diff --git a/app/views/my_modules/protocols/_protocol_buttons.html.erb b/app/views/my_modules/protocols/_protocol_buttons.html.erb
index e10fd2370..92fada32a 100644
--- a/app/views/my_modules/protocols/_protocol_buttons.html.erb
+++ b/app/views/my_modules/protocols/_protocol_buttons.html.erb
@@ -24,7 +24,7 @@
<% if can_export_protocol_from_module(@my_module) %>
- <%= t("my_modules.protocols.buttons.export") %>
+ <%= link_to raw(" " + t('my_modules.protocols.buttons.export') + ""), export_protocols_path(protocol_ids: @protocol.id), class: "btn btn-default" %>
<% else %>
<%= t("my_modules.protocols.buttons.export") %>
<% end %>