mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-09 06:35:37 +08:00
Add export to protocol management page and code style improvements [SCI-742]
This commit is contained in:
parent
14a6705b55
commit
d555ba7905
5 changed files with 32 additions and 23 deletions
|
@ -1,5 +1,4 @@
|
|||
//= require protocols/import_export/import
|
||||
//= require protocols/import_export/export
|
||||
//= require datatables
|
||||
|
||||
// Global variables
|
||||
|
@ -547,6 +546,20 @@ function updateButtons() {
|
|||
}
|
||||
}
|
||||
|
||||
function exportProtocols(ids) {
|
||||
if (ids.length > 0) {
|
||||
var exportLink = document.createElement('a');
|
||||
exportLink.id = 'protocolExportLink';
|
||||
var params = '?protocol_ids[]=' + ids[0];
|
||||
for (var i = 1; i < ids.length; i++) {
|
||||
params += '&protocol_ids[]=' + ids[i];
|
||||
}
|
||||
params = encodeURI(params);
|
||||
exportLink.href = $("[data-action='export']").data('export-url') + params;
|
||||
exportLink.click();
|
||||
}
|
||||
}
|
||||
|
||||
function editSelectedProtocol() {
|
||||
if (rowsSelected.length && rowsSelected.length == 1) {
|
||||
var row = $("tr[data-row-id='" + rowsSelected[0] + "']");
|
||||
|
|
|
@ -577,21 +577,19 @@ class ProtocolsController < ApplicationController
|
|||
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
|
||||
next if protocol.steps.count <= 0
|
||||
protocol.steps.order(:id).each do |step|
|
||||
step_guid = get_guid(step.id)
|
||||
step_dir = "#{protocol_dir}/#{step_guid}"
|
||||
next 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
|
||||
|
@ -605,8 +603,8 @@ class ProtocolsController < ApplicationController
|
|||
# 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]
|
||||
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
|
||||
.downcase[0..Constants::NAME_MAX_LENGTH]
|
||||
file_name = escaped_name + '.eln' unless escaped_name.empty?
|
||||
end
|
||||
elsif @protocols.length > 1
|
||||
|
|
|
@ -6,9 +6,7 @@ module ProtocolsExporter
|
|||
def get_guid(id)
|
||||
str1 = '00000000-0000-'
|
||||
str2 = id.to_s
|
||||
(19 - str2.size).times do
|
||||
str2 = '0' + str2
|
||||
end
|
||||
str2 = '0' * (19 - str2.size) + str2
|
||||
str2 = '4' + str2
|
||||
str2n = str2[0..3] + '-' + str2[4..7] + '-' + str2[8..-1]
|
||||
str1 + str2n
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
<% if can_export_protocol_from_module(@my_module) %>
|
||||
<%= link_to raw("<span class=\"glyphicon glyphicon-export\"></span><span class=\"hidden-xs-custom\"> " + t('my_modules.protocols.buttons.export') + "</span>"), export_protocols_path(protocol_ids: @protocol.id), class: "btn btn-default" %>
|
||||
<%= link_to raw("<span class=\"glyphicon glyphicon-export\"></span><span class=\"hidden-xs-custom\"> " + t('my_modules.protocols.buttons.export') + "</span>"), export_protocols_path(protocol_ids: @protocol.id), class: "btn btn-default", data: {no_turbolink: true} %>
|
||||
<% else %>
|
||||
<a href="#" class="btn btn-default disabled"><span class="glyphicon glyphicon-export"></span><span class="hidden-xs-custom"> <%= t("my_modules.protocols.buttons.export") %></span></a>
|
||||
<% end %>
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
data-type="<%= @type %>" data-import-url="<%= import_protocols_path %>"
|
||||
<%= 'disabled="disabled"' unless can_import_protocols(@current_organization) %>>
|
||||
</a>
|
||||
<a class="btn btn-default" data-action="export">
|
||||
<a class="btn btn-default" data-action="export" data-export-url="<%= export_protocols_path() %>">
|
||||
<span class="glyphicon glyphicon-export"></span>
|
||||
<span class="hidden-xs"> <%= t("protocols.index.export") %></span>
|
||||
</a>
|
||||
|
|
Loading…
Add table
Reference in a new issue