mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +08:00
Merge pull request #927 from ZmagoD/zd_SCI_1867
fix import protocol preview [fixes SCI-1867]
This commit is contained in:
commit
4e4cae9a48
3 changed files with 23 additions and 7 deletions
|
@ -232,18 +232,31 @@ function importProtocolFromFile(
|
||||||
function displayTinyMceAssetInDescription(node, folder, stepGuid) {
|
function displayTinyMceAssetInDescription(node, folder, stepGuid) {
|
||||||
if (node.children('descriptionAssets').length === 0) {
|
if (node.children('descriptionAssets').length === 0) {
|
||||||
var description = node.children('description').html();
|
var description = node.children('description').html();
|
||||||
return description.replace(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/,
|
return $('<div></div>').html(
|
||||||
'<strong>Can\'t import image</strong>');
|
description.replace(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/,
|
||||||
|
'<strong>Can\'t import image</strong>')
|
||||||
|
.replace('<!--[CDATA[ ', '')
|
||||||
|
.replace(' ]]-->', '')
|
||||||
|
.replace(' ]]-->','')
|
||||||
|
.replace(' ]]>', '')
|
||||||
|
).html();
|
||||||
}
|
}
|
||||||
var description = node.children('description').html();
|
var description = node.children('description').html();
|
||||||
node.find('descriptionAssets > tinyMceAsset').each(function(i, element) {
|
node.find('descriptionAssets > tinyMceAsset').each(function(i, element) {
|
||||||
var match = '[~tiny_mce_id:' + element.getAttribute('tokenId') + ']';
|
var match = '[~tiny_mce_id:' + element.getAttribute('tokenId') + ']';
|
||||||
var assetBytes = getAssetBytes(folder, stepGuid, element.getAttribute('fileref'));
|
var assetBytes = getAssetBytes(folder,
|
||||||
|
stepGuid,
|
||||||
|
element.getAttribute('fileref'));
|
||||||
var image_tag = "<img style='max-width:300px; max-height:300px;' src='data:" + element.children[1].innerHTML + ";base64," + assetBytes + "' />"
|
var image_tag = "<img style='max-width:300px; max-height:300px;' src='data:" + element.children[1].innerHTML + ";base64," + assetBytes + "' />"
|
||||||
description = description.replace(match, image_tag); // replace the token with image
|
description = description.replace(match, image_tag); // replace the token with image
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
// I know is crazy but is the only way I found to pass valid HTML
|
// I know is crazy but is the only way I found to pass valid HTML
|
||||||
return $('<div></div>').html(description.replace('<!--[CDATA[', '').replace(']]>', '')).html();
|
return $('<div></div>').html(
|
||||||
|
description.replace('<!--[CDATA[ ', '')
|
||||||
|
.replace(' ]]-->', '')
|
||||||
|
.replace(' ]]-->','')
|
||||||
|
.replace(' ]]>', '')
|
||||||
|
).html();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Navigation functions */
|
/* Navigation functions */
|
||||||
|
|
|
@ -66,7 +66,7 @@ module ProtocolsExporter
|
||||||
protocol_xml = "<eln xmlns=\"http://www.scinote.net\" version=\"1.0\">\n"
|
protocol_xml = "<eln xmlns=\"http://www.scinote.net\" version=\"1.0\">\n"
|
||||||
protocol_xml << "<protocol id=\"#{protocol.id}\" " \
|
protocol_xml << "<protocol id=\"#{protocol.id}\" " \
|
||||||
"guid=\"#{get_guid(protocol.id)}\">\n"
|
"guid=\"#{get_guid(protocol.id)}\">\n"
|
||||||
protocol_xml << "<name>#{protocol_name}</name>\n"
|
protocol_xml << "<name><![CDATA[ #{protocol_name} ]]></name>\n"
|
||||||
protocol_xml << "<authors>#{protocol.authors}</authors>\n"
|
protocol_xml << "<authors>#{protocol.authors}</authors>\n"
|
||||||
protocol_xml << "<description>#{protocol.description}</description>\n"
|
protocol_xml << "<description>#{protocol.description}</description>\n"
|
||||||
protocol_xml << "<created_at>#{protocol.created_at.as_json}</created_at>\n"
|
protocol_xml << "<created_at>#{protocol.created_at.as_json}</created_at>\n"
|
||||||
|
@ -80,9 +80,10 @@ module ProtocolsExporter
|
||||||
step_xml = "<step id=\"#{step.id}\" guid=\"#{step_guid}\" " \
|
step_xml = "<step id=\"#{step.id}\" guid=\"#{step_guid}\" " \
|
||||||
"position=\"#{step.position}\">\n"
|
"position=\"#{step.position}\">\n"
|
||||||
step_xml << "<name>#{step.name}</name>\n"
|
step_xml << "<name>#{step.name}</name>\n"
|
||||||
step_xml << "<description><![CDATA[#{
|
# uses 2 spaces to make more difficult to remove user data on import
|
||||||
|
step_xml << "<description><!--[CDATA[ #{
|
||||||
Nokogiri::HTML::DocumentFragment.parse(step.description).to_s
|
Nokogiri::HTML::DocumentFragment.parse(step.description).to_s
|
||||||
}]]></description>\n"
|
} ]]--></description>\n"
|
||||||
|
|
||||||
if tiny_mce_asset_present?(step)
|
if tiny_mce_asset_present?(step)
|
||||||
step_xml << get_tiny_mce_assets(step.description)
|
step_xml << get_tiny_mce_assets(step.description)
|
||||||
|
|
|
@ -162,6 +162,7 @@ module ProtocolsImporter
|
||||||
tiny_mce_img.save!
|
tiny_mce_img.save!
|
||||||
description.gsub!("[~tiny_mce_id:#{tiny_mce_img_json['tokenId']}]",
|
description.gsub!("[~tiny_mce_id:#{tiny_mce_img_json['tokenId']}]",
|
||||||
"[~tiny_mce_id:#{tiny_mce_img.id}]")
|
"[~tiny_mce_id:#{tiny_mce_img.id}]")
|
||||||
|
.gsub!(' ]]-->', '')
|
||||||
|
|
||||||
end
|
end
|
||||||
description
|
description
|
||||||
|
@ -171,5 +172,6 @@ module ProtocolsImporter
|
||||||
def populate_rte_legacy(step_json)
|
def populate_rte_legacy(step_json)
|
||||||
return unless step_json['description'] && step_json['description'].present?
|
return unless step_json['description'] && step_json['description'].present?
|
||||||
step_json['description'].gsub(Constants::TINY_MCE_ASSET_REGEX, '')
|
step_json['description'].gsub(Constants::TINY_MCE_ASSET_REGEX, '')
|
||||||
|
.gsub(' ]]-->', '')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue