@@ -38,8 +38,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
3838
3939 if ( studyDataUI [ "annotations" ] ) {
4040 Object . entries ( studyDataUI [ "annotations" ] ) . forEach ( ( [ annotationId , annotationData ] ) => {
41- const annotation = new osparc . workbench . Annotation ( annotationData , annotationId ) ;
42- this . addAnnotation ( annotation ) ;
41+ this . addAnnotation ( annotationData , annotationId ) ;
4342 } ) ;
4443 }
4544
@@ -96,6 +95,8 @@ qx.Class.define("osparc.data.model.StudyUI", {
9695
9796 events : {
9897 "projectDocumentChanged" : "qx.event.type.Data" ,
98+ "annotationAdded" : "qx.event.type.Data" ,
99+ "annotationRemoved" : "qx.event.type.Data" ,
99100 } ,
100101
101102 statics : {
@@ -121,7 +122,8 @@ qx.Class.define("osparc.data.model.StudyUI", {
121122 }
122123 } ,
123124
124- addAnnotation : function ( annotation ) {
125+ addAnnotation : function ( annotationData , annotationId ) {
126+ const annotation = new osparc . workbench . Annotation ( annotationData , annotationId ) ;
125127 this . getAnnotations ( ) [ annotation . getId ( ) ] = annotation ;
126128 this . fireDataEvent ( "projectDocumentChanged" , {
127129 "op" : "add" ,
@@ -137,6 +139,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
137139 "osparc-resource" : "study-ui" ,
138140 } ) ;
139141 } , this ) ;
142+ return annotation ;
140143 } ,
141144
142145 removeAnnotation : function ( annotationId ) {
@@ -172,6 +175,9 @@ qx.Class.define("osparc.data.model.StudyUI", {
172175 }
173176 } ) ;
174177 }
178+ } else if ( "annotations" in uiDiff ) {
179+ const annotationsDiff = uiDiff [ "annotations" ] ;
180+ this . __updateAnnotationsFromDiff ( annotationsDiff ) ;
175181 }
176182 } ,
177183
@@ -206,6 +212,23 @@ qx.Class.define("osparc.data.model.StudyUI", {
206212 }
207213 } ,
208214
215+ __updateAnnotationsFromDiff : function ( annotationsData ) {
216+ // check if annotation data is an object or an array
217+ if ( annotationsData instanceof Object ) {
218+ Object . entries ( annotationsData ) . forEach ( ( [ annotationId , annotationData ] ) => {
219+ if ( annotationData . length === 1 ) {
220+ // it was added
221+ const annotation = this . addAnnotation ( annotationData [ 0 ] , annotationId ) ;
222+ this . fireDataEvent ( "annotationAdded" , annotation ) ;
223+ } else if ( annotationData . length === 3 && annotationData [ 1 ] === null ) {
224+ // it was removed
225+ this . removeAnnotation ( annotationId ) ;
226+ this . fireDataEvent ( "annotationRemoved" , annotationId ) ;
227+ }
228+ } ) ;
229+ }
230+ } ,
231+
209232 listenToChanges : function ( ) {
210233 const propertyKeys = Object . keys ( qx . util . PropertyUtil . getProperties ( osparc . data . model . StudyUI ) ) ;
211234 this . self ( ) . ListenChangesProps . forEach ( key => {
0 commit comments