@@ -54,6 +54,7 @@ qx.Class.define("osparc.data.model.Workbench", {
5454 "projectDocumentChanged" : "qx.event.type.Data" ,
5555 "restartAutoSaveTimer" : "qx.event.type.Event" ,
5656 "pipelineChanged" : "qx.event.type.Event" ,
57+ "nodeRemoved" : "qx.event.type.Data" ,
5758 "reloadModel" : "qx.event.type.Event" ,
5859 "retrieveInputs" : "qx.event.type.Data" ,
5960 "fileRequested" : "qx.event.type.Data" ,
@@ -539,11 +540,11 @@ qx.Class.define("osparc.data.model.Workbench", {
539540
540541 removeNode : async function ( nodeId ) {
541542 if ( ! osparc . data . Permissions . getInstance ( ) . canDo ( "study.node.delete" , true ) ) {
542- return false ;
543+ return ;
543544 }
544545 if ( this . getStudy ( ) . isPipelineRunning ( ) ) {
545546 osparc . FlashMessenger . logAs ( this . self ( ) . CANT_DELETE_NODE , "ERROR" ) ;
546- return false ;
547+ return ;
547548 }
548549
549550 this . fireEvent ( "restartAutoSaveTimer" ) ;
@@ -552,26 +553,33 @@ qx.Class.define("osparc.data.model.Workbench", {
552553 // remove the node in the backend first
553554 const removed = await node . removeNode ( ) ;
554555 if ( removed ) {
555- this . fireEvent ( "restartAutoSaveTimer" ) ;
556+ this . __nodeRemoved ( nodeId ) ;
557+ }
558+ }
559+ } ,
556560
557- delete this . __nodes [ nodeId ] ;
561+ __nodeRemoved : function ( nodeId ) {
562+ this . fireEvent ( "restartAutoSaveTimer" ) ;
558563
559- // remove first the connected edges
560- const connectedEdges = this . getConnectedEdges ( nodeId ) ;
561- connectedEdges . forEach ( connectedEdgeId => {
562- this . removeEdge ( connectedEdgeId ) ;
563- } ) ;
564+ delete this . __nodes [ nodeId ] ;
564565
565- // remove it from ui model
566- if ( this . getStudy ( ) ) {
567- this . getStudy ( ) . getUi ( ) . removeNode ( nodeId ) ;
568- }
566+ // remove first the connected edges
567+ const connectedEdgeIds = this . getConnectedEdges ( nodeId ) ;
568+ connectedEdgeIds . forEach ( connectedEdgeId => {
569+ this . removeEdge ( connectedEdgeId ) ;
570+ } ) ;
569571
570- this . fireEvent ( "pipelineChanged" ) ;
571- return true ;
572- }
572+ // remove it from ui model
573+ if ( this . getStudy ( ) ) {
574+ this . getStudy ( ) . getUi ( ) . removeNode ( nodeId ) ;
573575 }
574- return false ;
576+
577+ this . fireEvent ( "pipelineChanged" ) ;
578+
579+ this . fireDataEvent ( "nodeRemoved" , {
580+ nodeId,
581+ connectedEdgeIds,
582+ } ) ;
575583 } ,
576584
577585 addServiceBetween : async function ( service , leftNodeId , rightNodeId ) {
@@ -831,14 +839,42 @@ qx.Class.define("osparc.data.model.Workbench", {
831839
832840 updateWorkbenchFromPatches : function ( workbenchPatches ) {
833841 // group the patches by nodeId
842+ const nodesAdded = [ ] ;
843+ const nodesRemoved = [ ] ;
834844 const workbenchPatchesByNode = { } ;
835845 workbenchPatches . forEach ( workbenchPatch => {
836846 const nodeId = workbenchPatch . path . split ( "/" ) [ 2 ] ;
847+
848+ const pathParts = workbenchPatch . path . split ( "/" ) ;
849+ if ( pathParts . length === 3 ) {
850+ if ( workbenchPatch . op === "add" ) {
851+ // node was added
852+ nodesAdded . push ( nodeId ) ;
853+ } else if ( workbenchPatch . op === "remove" ) {
854+ // node was removed
855+ nodesRemoved . push ( nodeId ) ;
856+ }
857+ }
858+
837859 if ( ! ( nodeId in workbenchPatchesByNode ) ) {
838860 workbenchPatchesByNode [ nodeId ] = [ ] ;
839861 }
840862 workbenchPatchesByNode [ nodeId ] . push ( workbenchPatch ) ;
841863 } ) ;
864+
865+ // first remove nodes
866+ nodesRemoved . forEach ( nodeId => {
867+ const node = this . getNode ( nodeId ) ;
868+ if ( node ) {
869+ node . nodeRemoved ( nodeId ) ;
870+ }
871+ this . __nodeRemoved ( nodeId ) ;
872+ } ) ;
873+
874+ // second add nodes
875+ console . log ( "Adding nodes" , nodesAdded ) ;
876+
877+ // third update nodes
842878 Object . keys ( workbenchPatchesByNode ) . forEach ( nodeId => {
843879 const node = this . getNode ( nodeId ) ;
844880 if ( node === null ) {
@@ -848,7 +884,6 @@ qx.Class.define("osparc.data.model.Workbench", {
848884 const nodePatches = workbenchPatchesByNode [ nodeId ] ;
849885 node . updateNodeFromPatch ( nodePatches ) ;
850886 } ) ;
851- this . getNode ( )
852887 } ,
853888 }
854889} ) ;
0 commit comments