@@ -198,6 +198,9 @@ qx.Class.define("osparc.data.model.Node", {
198198 "reloadModel" : "qx.event.type.Event" ,
199199 "retrieveInputs" : "qx.event.type.Data" ,
200200 "keyChanged" : "qx.event.type.Event" ,
201+ "changePosition" : "qx.event.type.Data" ,
202+ "createEdge" : "qx.event.type.Data" ,
203+ "removeEdge" : "qx.event.type.Data" ,
201204 "fileRequested" : "qx.event.type.Data" ,
202205 "parameterRequested" : "qx.event.type.Data" ,
203206 "filePickerRequested" : "qx.event.type.Data" ,
@@ -237,6 +240,10 @@ qx.Class.define("osparc.data.model.Node", {
237240 "progress" , // !! not a property but goes into the model
238241 ] ,
239242
243+ getProperties : function ( ) {
244+ return Object . keys ( qx . util . PropertyUtil . getProperties ( osparc . data . model . Node ) ) ;
245+ } ,
246+
240247 isFrontend : function ( metadata ) {
241248 return ( metadata && metadata . key && metadata . key . includes ( "/frontend/" ) ) ;
242249 } ,
@@ -524,7 +531,7 @@ qx.Class.define("osparc.data.model.Node", {
524531 this . setPosition ( nodeUIData . position ) ;
525532 }
526533 if ( "marker" in nodeUIData ) {
527- this . __addMarker ( nodeUIData . marker ) ;
534+ this . addMarker ( nodeUIData . marker ) ;
528535 }
529536 } ,
530537
@@ -682,11 +689,11 @@ qx.Class.define("osparc.data.model.Node", {
682689 if ( this . getMarker ( ) ) {
683690 this . __removeMarker ( ) ;
684691 } else {
685- this . __addMarker ( ) ;
692+ this . addMarker ( ) ;
686693 }
687694 } ,
688695
689- __addMarker : function ( marker ) {
696+ addMarker : function ( marker ) {
690697 if ( marker === undefined ) {
691698 marker = {
692699 color : osparc . utils . Utils . getRandomColor ( )
@@ -922,13 +929,14 @@ qx.Class.define("osparc.data.model.Node", {
922929
923930 removeInputNode : function ( inputNodeId ) {
924931 const index = this . __inputNodes . indexOf ( inputNodeId ) ;
925- if ( index > - 1 ) {
926- // remove node connection
927- this . __inputNodes . splice ( index , 1 ) ;
928- this . fireEvent ( "changeInputNodes" ) ;
929- return true ;
932+ // make sure index is valid
933+ if ( index < 0 || index >= this . __inputNodes . length ) {
934+ return false ;
930935 }
931- return false ;
936+ // remove node connection
937+ this . __inputNodes . splice ( index , 1 ) ;
938+ this . fireEvent ( "changeInputNodes" ) ;
939+ return true ;
932940 } ,
933941
934942 isInputNode : function ( inputNodeId ) {
@@ -1198,7 +1206,7 @@ qx.Class.define("osparc.data.model.Node", {
11981206 this . __deleteInBackend ( )
11991207 . then ( ( ) => {
12001208 resolve ( true ) ;
1201- this . removeIFrame ( ) ;
1209+ this . nodeRemoved ( ) ;
12021210 } )
12031211 . catch ( err => {
12041212 console . error ( err ) ;
@@ -1207,6 +1215,10 @@ qx.Class.define("osparc.data.model.Node", {
12071215 } ) ;
12081216 } ,
12091217
1218+ nodeRemoved : function ( ) {
1219+ this . removeIFrame ( ) ;
1220+ } ,
1221+
12101222 __deleteInBackend : function ( ) {
12111223 // remove node in the backend
12121224 const params = {
@@ -1250,6 +1262,11 @@ qx.Class.define("osparc.data.model.Node", {
12501262 } ,
12511263 "osparc-resource" : "ui" ,
12521264 } ) ;
1265+
1266+ this . fireDataEvent ( "changePosition" , {
1267+ x : this . __posX ,
1268+ y : this . __posY
1269+ } ) ;
12531270 } ,
12541271
12551272 getPosition : function ( ) {
@@ -1300,7 +1317,7 @@ qx.Class.define("osparc.data.model.Node", {
13001317
13011318 listenToChanges : function ( ) {
13021319 const nodeId = this . getNodeId ( ) ;
1303- const propertyKeys = Object . keys ( qx . util . PropertyUtil . getProperties ( osparc . data . model . Node ) ) ;
1320+ const nodePropertyKeys = this . self ( ) . getProperties ( ) ;
13041321 this . self ( ) . ListenChangesProps . forEach ( key => {
13051322 switch ( key ) {
13061323 case "inputs" :
@@ -1394,7 +1411,7 @@ qx.Class.define("osparc.data.model.Node", {
13941411 }
13951412 break ;
13961413 default :
1397- if ( propertyKeys . includes ( key ) ) {
1414+ if ( nodePropertyKeys . includes ( key ) ) {
13981415 this . addListener ( "change" + qx . lang . String . firstUp ( key ) , e => {
13991416 const data = e . getData ( ) ;
14001417 this . fireDataEvent ( "projectDocumentChanged" , {
@@ -1412,14 +1429,87 @@ qx.Class.define("osparc.data.model.Node", {
14121429 } ) ;
14131430 } ,
14141431
1432+ updateNodeFromPatch : function ( nodePatches ) {
1433+ const nodePropertyKeys = this . self ( ) . getProperties ( ) ;
1434+ nodePatches . forEach ( patch => {
1435+ const op = patch . op ;
1436+ const path = patch . path ;
1437+ const value = patch . value ;
1438+ const nodeProperty = path . split ( "/" ) [ 3 ] ;
1439+ switch ( nodeProperty ) {
1440+ case "inputs" : {
1441+ const updatedPortKey = path . split ( "/" ) [ 4 ] ;
1442+ const currentInputs = this . __getInputData ( ) ;
1443+ currentInputs [ updatedPortKey ] = value ;
1444+ this . __setInputData ( currentInputs ) ;
1445+ break ;
1446+ }
1447+ case "inputsUnits" : {
1448+ // this is never transmitted by the frontend
1449+ const updatedPortKey = path . split ( "/" ) [ 4 ] ;
1450+ const currentInputUnits = this . __getInputUnits ( ) ;
1451+ currentInputUnits [ updatedPortKey ] = value ;
1452+ this . __setInputUnits ( currentInputUnits ) ;
1453+ break ;
1454+ }
1455+ case "inputNodes" :
1456+ if ( op === "add" ) {
1457+ const inputNodeId = value ;
1458+ this . fireDataEvent ( "createEdge" , {
1459+ nodeId1 : inputNodeId ,
1460+ nodeId2 : this . getNodeId ( ) ,
1461+ } ) ;
1462+ } else if ( op === "remove" ) {
1463+ // we don't have more information about the input node, so we just remove it by index
1464+ const index = path . split ( "/" ) [ 4 ] ;
1465+ // make sure index is valid
1466+ if ( index >= 0 && index < this . __inputNodes . length ) {
1467+ this . fireDataEvent ( "removeEdge" , {
1468+ nodeId1 : this . __inputNodes [ index ] ,
1469+ nodeId2 : this . getNodeId ( ) ,
1470+ } ) ;
1471+ }
1472+ }
1473+ break ;
1474+ case "inputsRequired" :
1475+ console . warn ( `To be implemented: patching ${ nodeProperty } is not supported yet` ) ;
1476+ break ;
1477+ case "outputs" : {
1478+ const updatedPortKey = path . split ( "/" ) [ 4 ] ;
1479+ const currentOutputs = this . isFilePicker ( ) ? osparc . file . FilePicker . serializeOutput ( this . getOutputs ( ) ) : this . __getOutputsData ( ) ;
1480+ currentOutputs [ updatedPortKey ] = value ;
1481+ this . setOutputData ( currentOutputs ) ;
1482+ break ;
1483+ }
1484+ case "progress" :
1485+ if ( this . isFilePicker ( ) ) {
1486+ this . getStatus ( ) . setProgress ( value ) ;
1487+ } else {
1488+ console . warn ( `To be implemented: patching ${ nodeProperty } is not supported yet` ) ;
1489+ }
1490+ break ;
1491+ default :
1492+ if ( nodePropertyKeys . includes ( nodeProperty ) ) {
1493+ const setter = "set" + qx . lang . String . firstUp ( nodeProperty ) ;
1494+ if ( this [ setter ] ) {
1495+ this [ setter ] ( value ) ;
1496+ } else {
1497+ console . warn ( `Property "${ nodeProperty } " does not have a setter in osparc.data.model.Node` ) ;
1498+ }
1499+ }
1500+ break ;
1501+ }
1502+ } ) ;
1503+ } ,
1504+
14151505 serialize : function ( ) {
14161506 // node generic
14171507 let nodeEntry = {
14181508 key : this . getKey ( ) ,
14191509 version : this . getVersion ( ) ,
14201510 label : this . getLabel ( ) ,
14211511 inputs : this . __getInputData ( ) ,
1422- inputsUnits : this . __getInputUnits ( ) ,
1512+ inputsUnits : this . __getInputUnits ( ) , // this is not working
14231513 inputNodes : this . getInputNodes ( ) ,
14241514 inputsRequired : this . getInputsRequired ( ) ,
14251515 bootOptions : this . getBootOptions ( )
0 commit comments