Fix import for eln (#1741)

This commit is contained in:
aignatov-bio 2019-05-13 10:22:30 +02:00 committed by GitHub
parent 364f903b3c
commit 3633274c8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View file

@ -293,17 +293,16 @@ function importProtocolFromFile(
stepGuid,
element.getAttribute('fileref'));
if (description.includes('[~tiny_mce_id')) {
// old format load
imageTag = '<img style="max-width:300px; max-height:300px;" src="data:' + element.children[1].innerHTML + ';base64,' + assetBytes + '" />';
description = description.replace(match, imageTag);
} else {
// new format load
description = $('<div>' + description + '</div>').find('img[data-mce-token="' + element.getAttribute('tokenId') + '"]')
.attr('src', 'data:' + element.children[1].innerHTML + ';base64,' + assetBytes).prop('outerHTML');
}
});
// new format load
description = $('<div>' + description + '</div>');
description.find('img[data-mce-token="' + element.getAttribute('tokenId') + '"]')
.attr('src', 'data:' + element.children[1].innerHTML + ';base64,' + assetBytes);
description = description.prop('outerHTML');
// old format load
imageTag = '<img style="max-width:300px; max-height:300px;" src="data:' + element.children[1].innerHTML + ';base64,' + assetBytes + '" />';
description = description.replace(match, imageTag);
});
// I know is crazy but is the only way I found to pass valid HTML
return $('<div></div>').html(description).html();
}

View file

@ -158,10 +158,14 @@ module ProtocolsImporter
)
tiny_mce_img.image_content_type = tiny_mce_img_json['fileType']
tiny_mce_img.save!
if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
description.gsub!(' ]]--&gt;', '')
description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
.gsub!(' ]]--&gt;', '')
else
description.gsub!("data-mce-token=\"#{Base62.encode(tiny_mce_img_json['tokenId'].to_i)}\"",
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"").gsub!(' ]]--&gt;', '')
end
end
description
end