@@ -353,14 +353,54 @@ qx.Class.define("osparc.data.model.StudyUI", {
353353 const value = patch . value ;
354354 const annotationId = path . split ( "/" ) [ 3 ] ;
355355 console . log ( "Updating annotation from patch" , patch ) ;
356- if ( op === "add" ) {
357- this . addAnnotation ( value , annotationId ) ;
358- } else if ( op === "remove" ) {
359- // it was removed
360- this . removeAnnotation ( annotationId ) ;
361- } else if ( op === "replace" && value ) {
362- // it was updated
363- console . log ( "Updating annotation" , annotationId , "with value" , value ) ;
356+ switch ( op ) {
357+ case "add" : {
358+ const annotation = this . addAnnotation ( value , annotationId ) ;
359+ this . fireDataEvent ( "annotationAdded" , annotation ) ;
360+ break ;
361+ }
362+ case "remove" :
363+ this . removeAnnotation ( annotationId ) ;
364+ this . fireDataEvent ( "annotationRemoved" , annotationId ) ;
365+ break ;
366+ case "replace" :
367+ if ( annotationId in this . getAnnotations ( ) ) {
368+ const annotation = this . getAnnotations ( ) [ annotationId ] ;
369+ if ( annotation ) {
370+ if ( path . includes ( "/color" ) ) {
371+ annotation . setColor ( value ) ;
372+ } else if ( path . includes ( "/attributes" ) ) {
373+ this . __updateAnnotationAttributesFromPatch ( annotation , path , value ) ;
374+ }
375+ }
376+ }
377+ break ;
378+ }
379+ } ,
380+
381+ __updateAnnotationAttributesFromPatch : function ( annotation , path , value ) {
382+ if ( annotation ) {
383+ const attribute = path . split ( "/" ) [ 5 ] ;
384+ switch ( attribute ) {
385+ case "x" : {
386+ const newPos = annotation . getPosition ( ) ;
387+ newPos . x = value ;
388+ annotation . setPosition ( newPos . x , newPos . y ) ;
389+ break ;
390+ }
391+ case "y" : {
392+ const newPos = annotation . getPosition ( ) ;
393+ newPos . y = value ;
394+ annotation . setPosition ( newPos . x , newPos . y ) ;
395+ break ;
396+ }
397+ case "fontSize" :
398+ annotation . setFontSize ( value ) ;
399+ break ;
400+ case "text" :
401+ annotation . setText ( value ) ;
402+ break ;
403+ }
364404 }
365405 } ,
366406
0 commit comments