Skip to content
Snippets Groups Projects
Commit 7698e0d9 authored by Anthony's avatar Anthony
Browse files

Refactoring saving annotation + savning in jpeg

parent c60a48be
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1917 failed
...@@ -50,27 +50,27 @@ export function isShapesTool(activeTool) { ...@@ -50,27 +50,27 @@ export function isShapesTool(activeTool) {
} }
/** Save annotation in the storage adapter */ /** Save annotation in the storage adapter */
export async function saveAnnotation(canvas, storageAdapter, receiveAnnotation, annotationToSaved, isNewAnnotation) { export async function saveAnnotation(canvas, storageAdapter, receiveAnnotation, annotation, isNewAnnotation) {
if (isNewAnnotation) { if (!isNewAnnotation) {
storageAdapter.update(annotationToSaved) storageAdapter.update(annotation)
.then((annoPage) => { .then((annoPage) => {
receiveAnnotation(canvas.id, storageAdapter.annotationPageId, annoPage); receiveAnnotation(canvas.id, storageAdapter.annotationPageId, annoPage);
}); });
} else { } else {
storageAdapter.create(annotationToSaved) storageAdapter.create(annotation)
.then((annoPage) => { .then((annoPage) => {
receiveAnnotation(canvas.id, storageAdapter.annotationPageId, annoPage); receiveAnnotation(canvas.id, storageAdapter.annotationPageId, annoPage);
}); });
} }
} }
export async function saveAnnotationInEachCanvas(canvases, config, receiveAnnotation, annotationToSaved, target, isNewAnnotation) { export async function saveAnnotationInEachCanvas(canvases, config, receiveAnnotation, annotation, target, isNewAnnotation) {
canvases.forEach(async (canvas) => { canvases.forEach(async (canvas) => {
// Adapt target to the canvas // Adapt target to the canvas
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
annotationToSaved.target = `${canvas.id}#xywh=${target.xywh}&t=${target.t}`; annotation.target = `${canvas.id}#xywh=${target.xywh}&t=${target.t}`;
const storageAdapter = config.annotation.adapter(canvas.id); const storageAdapter = config.annotation.adapter(canvas.id);
saveAnnotation(canvas, storageAdapter, receiveAnnotation, annotationToSaved, isNewAnnotation); saveAnnotation(canvas, storageAdapter, receiveAnnotation, annotation, isNewAnnotation);
}); });
} }
... ...
......
...@@ -61,8 +61,7 @@ function AnnotationFormFooter({ ...@@ -61,8 +61,7 @@ function AnnotationFormFooter({
// const filename = await sendFile(drawingImageExport); // const filename = await sendFile(drawingImageExport);
// const annotationBodyImageId = fileReaderUrl + filename; // const annotationBodyImageId = fileReaderUrl + filename;
// Save jpg image of the drawing in a data url
const annotationBodyImageId = getKonvaAsDataURL(windowId);
// Temporal target of the annotation // Temporal target of the annotation
const target = { const target = {
...@@ -72,11 +71,9 @@ function AnnotationFormFooter({ ...@@ -72,11 +71,9 @@ function AnnotationFormFooter({
const annotationText = (!textBody.length && target.t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody; const annotationText = (!textBody.length && target.t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody;
console.log('annotationBodyImageId:', annotationBodyImageId);
const annotationToSaved = { const annotationToSaved = {
body: { body: {
id: annotationBodyImageId, id: null, // Will be updated after
type: 'Image', type: 'Image',
format: 'image/svg+xml', format: 'image/svg+xml',
value: annotationText, value: annotationText,
...@@ -93,11 +90,15 @@ function AnnotationFormFooter({ ...@@ -93,11 +90,15 @@ function AnnotationFormFooter({
const isNewAnnotation = !annotation; const isNewAnnotation = !annotation;
saveAnnotationInEachCanvas(canvases, config, receiveAnnotation, annotationToSaved, target, isNewAnnotation); // Save jpg image of the drawing in a data url
getKonvaAsDataURL(windowId).then((dataURL) => {
console.log('dataURL:', dataURL);
const annotation = { ...annotationToSaved };
annotation.body.id = dataURL
saveAnnotationInEachCanvas(canvases, config, receiveAnnotation, annotation, target, isNewAnnotation);
closeFormCompanionWindow(); closeFormCompanionWindow();
resetStateAfterSave(); resetStateAfterSave();
});
}; };
return ( return (
... ...
......
...@@ -14,7 +14,10 @@ export async function getSvg(windowId) { ...@@ -14,7 +14,10 @@ export async function getSvg(windowId) {
/** Export the stage as a JPG image in a data url */ /** Export the stage as a JPG image in a data url */
export async function getKonvaAsDataURL(windowId) { export async function getKonvaAsDataURL(windowId) {
const stage = window.Konva.stages.find((s) => s.attrs.id === windowId); const stage = window.Konva.stages.find((s) => s.attrs.id === windowId);
const dataURL = await stage.toDataURL({ mimeType: 'image/png', quality: 1 }); const dataURL = stage.toDataURL({
mimeType: 'image/png',
quality: 1,
});
console.log('dataURL:', dataURL); console.log('dataURL:', dataURL);
return dataURL; return dataURL;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment