From 52d1127b93c61021137ac35465fca8f95b859dd0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 13 Dec 2019 15:51:43 +0100 Subject: [PATCH] References can be deleted and automatically restablished --- .../FunctionLibraries/NodeDeleter.js | 21 -- .../Workspace/FunctionLibraries/OnFocus.js | 1 + .../FunctionLibraries/ProtocolNode.js | 29 +- .../ReferenceAttachDetach.js | 11 - .../FunctionLibraries/UiObjectsFromNodes.js | 351 ++---------------- DesignerSpace/Workspace/Workspace.js | 43 +-- FloatingSpace/UiObjectConstructor.js | 6 +- 7 files changed, 62 insertions(+), 400 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js index 75c6363a5..c5765dc79 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -445,14 +445,6 @@ function newNodeDeleter () { } } - /* Remove from Reference Children. */ - if (node.referenceChildren !== undefined) { - for (let i = 0; i < node.referenceChildren.length; i++) { - let child = node.referenceChildren[i] - child.payload.referenceParent = undefined - } - } - completeDeletion(node, rootNodes) destroyUiObject(node) cleanNode(node) @@ -468,10 +460,6 @@ function newNodeDeleter () { if (node.personalData !== undefined) { deletePersonalData(node.personalData, rootNodes) } - for (let i = 0; i < node.referenceChildren.length; i++) { - let child = node.referenceChildren[i] - child.payload.referenceParent = undefined - } completeDeletion(node, rootNodes) destroyUiObject(node) cleanNode(node) @@ -1216,15 +1204,6 @@ function newNodeDeleter () { if (node.socialBots !== undefined) { deleteSocialBots(node.socialBots, rootNodes) } - if (node.payload.referenceParent !== undefined) { - for (let i = 0; i < node.payload.referenceParent.referenceChildren.length; i++) { - let child = node.payload.referenceParent.referenceChildren[i] - if (child.id === node.id) { - node.payload.referenceParent.referenceChildren.splice(i, 1) - return - } - } - } completeDeletion(node, rootNodes) destroyUiObject(node) diff --git a/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js b/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js index 2773fef45..481e3983b 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js +++ b/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js @@ -1076,6 +1076,7 @@ function newOnFocus () { } } default: { + if (node.payload === undefined) { return } let nodeDefinition = APP_SCHEMA_MAP.get(node.type) if (nodeDefinition !== undefined) { /* First we ask the question to ourself */ diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 1f6c067be..facc97d35 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1637,6 +1637,8 @@ function newProtocolNode () { followAncestors = true excludeChildren = true object.parentNode = getProtocolNode(node.payload.parentNode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + followAncestors = false + includeParent = false } if (node.panels !== undefined) { for (let m = 0; m < node.panels.length; m++) { @@ -1753,9 +1755,7 @@ function newProtocolNode () { } function getSavedPayload (node, includeReferences) { - if (node.payload === undefined) { - console.log('HERE') - } + if (node.payload === undefined) { return } let savedPayload = { position: { x: node.payload.position.x, @@ -1778,24 +1778,6 @@ function newProtocolNode () { } if (includeReferences) { - /* For the ones that have reference children, we include them. */ - if (node.referenceChildren !== undefined) { - let referenceChildren = [] - for (let i = 0; i < node.referenceChildren.length; i++) { - let child = node.referenceChildren[i] - if (child !== undefined) { - let referencedChild = { - type: child.type, - subType: child.subType, - name: child.name, - id: child.id - } - referenceChildren.push(referencedChild) - } - } - savedPayload.referenceChildren = referenceChildren - } - /* Next for the ones that have a reference parent, we include it */ if (node.payload.referenceParent !== undefined) { savedPayload.referenceParent = { @@ -1804,6 +1786,11 @@ function newProtocolNode () { name: node.payload.referenceParent.name, id: node.payload.referenceParent.id } + } else { + /* The referenceParent property can be inherited from the previous saved payload. */ + if (node.savedPayload !== undefined) { + savedPayload.referenceParent = node.savedPayload.referenceParent + } } } return savedPayload diff --git a/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js b/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js index f0f6dc9df..cdf5385dc 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js @@ -16,20 +16,9 @@ function newReferenceAttachDetach () { function completeAttachment (node, attachToNode) { node.payload.referenceParent = attachToNode - if (attachToNode.referenceChildren === undefined) { - attachToNode.referenceChildren = [] - } - attachToNode.referenceChildren.push(node) } function completeDetachment (node) { - for (let i = 0; i < node.payload.referenceParent.referenceChildren.length; i++) { - let child = node.payload.referenceParent.referenceChildren[i] - if (child.id === node.id) { - node.payload.referenceParent.referenceChildren.splice(i, 1) - return - } - } node.payload.referenceParent = undefined } } diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 350fd55d9..4c89e0007 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1,6 +1,7 @@ function newUiObjectsFromNodes () { thisObject = { recreateWorkspace: recreateWorkspace, + tryToConnectChildrenWithReferenceParents: tryToConnectChildrenWithReferenceParents, createUiObjectFromNode: createUiObjectFromNode, addUIObject: addUIObject, addTeam: addTeam, @@ -68,44 +69,41 @@ function newUiObjectsFromNodes () { addJavascriptCode: addJavascriptCode } - let mapOfReferenceParents - let mapOfReferenceChildren + let mapOfReferenceChildren = new Map() + let mapOfNodes = new Map() return thisObject function recreateWorkspace (node) { - mapOfReferenceParents = new Map() - mapOfReferenceChildren = new Map() - let workspace = node - createUiObject(false, 'Workspace', workspace.name, workspace, undefined, undefined, 'Workspace') + /* Create the workspace UI OBject and then continue with the root nodes. */ + createUiObject(false, 'Workspace', node.name, node, undefined, undefined, 'Workspace') if (node.rootNodes !== undefined) { for (let i = 0; i < node.rootNodes.length; i++) { let rootNode = node.rootNodes[i] createUiObjectFromNode(rootNode, undefined, undefined) } } + + tryToConnectChildrenWithReferenceParents() + } + + function tryToConnectChildrenWithReferenceParents () { /* We reconstruct here the reference relationships. */ - for (const [key, childNode] of mapOfReferenceChildren) { - childNode.payload.referenceParent = mapOfReferenceParents.get(childNode.savedPayload.referenceParent.id) - childNode.savedPayload = undefined - } - for (const [key, parentNode] of mapOfReferenceParents) { - if (parentNode.referenceChildren === undefined) { - parentNode.referenceChildren = [] + for (const [key, node] of mapOfNodes) { + if (node.payload.referenceParent !== undefined) { + if (node.payload.referenceParent.cleaned === true) { + node.payload.referenceParent = mapOfNodes.get(node.payload.referenceParent.id) + continue // We were referencing a deleted node, so we replace it potentially with a newly created one. + } else { + continue // In this case the reference is already good. + } } - for (let i = 0; i < parentNode.savedPayload.referenceChildren.length; i++) { - let savedChild = parentNode.savedPayload.referenceChildren[i] - if (savedChild.id !== undefined) { - let referenceChild = mapOfReferenceChildren.get(savedChild.id) - parentNode.referenceChildren.push(referenceChild) + if (node.savedPayload !== undefined) { + if (node.savedPayload.referenceParent !== undefined) { // these are children recreated + node.payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id) } } - parentNode.savedPayload = undefined } - mapOfReferenceChildren = undefined - mapOfReferenceParents = undefined - - return } function createUiObjectFromNode (node, parentNode, chainParent, positionOffset) { @@ -444,14 +442,6 @@ function newUiObjectsFromNodes () { return } case 'Definition': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, 'Definition', node.name, node, parentNode, chainParent, 'Definition', positionOffset) if (node.tradingSystem !== undefined) { createUiObjectFromNode(node.tradingSystem, node, node, positionOffset) @@ -459,16 +449,6 @@ function newUiObjectsFromNodes () { if (node.personalData !== undefined) { createUiObjectFromNode(node.personalData, node, node, positionOffset) } - if (node.referenceChildren === undefined) { - node.referenceChildren = [] - } - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } case 'Network': { @@ -566,15 +546,6 @@ function newUiObjectsFromNodes () { return } case 'Process Instance': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } if (parentNode !== undefined) { switch (parentNode.type) { case 'Sensor Bot Instance': { @@ -595,23 +566,9 @@ function newUiObjectsFromNodes () { if (node.session !== undefined) { createUiObjectFromNode(node.session, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Backtesting Session': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, 'Backtesting Session', node.name, node, parentNode, chainParent, 'Backtesting Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) @@ -622,23 +579,9 @@ function newUiObjectsFromNodes () { if (node.socialBots !== undefined) { createUiObjectFromNode(node.socialBots, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Live Trading Session': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, 'Live Trading Session', node.name, node, parentNode, chainParent, 'Live Trading Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) @@ -649,23 +592,9 @@ function newUiObjectsFromNodes () { if (node.socialBots !== undefined) { createUiObjectFromNode(node.socialBots, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Fordward Testing Session': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, 'Fordward Testing Session', node.name, node, parentNode, chainParent, 'Fordward Testing Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) @@ -676,23 +605,9 @@ function newUiObjectsFromNodes () { if (node.socialBots !== undefined) { createUiObjectFromNode(node.socialBots, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Paper Trading Session': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, 'Paper Trading Session', node.name, node, parentNode, chainParent, 'Paper Trading Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) @@ -703,11 +618,6 @@ function newUiObjectsFromNodes () { if (node.socialBots !== undefined) { createUiObjectFromNode(node.socialBots, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } @@ -768,14 +678,6 @@ function newUiObjectsFromNodes () { return } case 'Process Definition': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.processOutput !== undefined) { createUiObjectFromNode(node.processOutput, node, node, positionOffset) @@ -792,13 +694,6 @@ function newUiObjectsFromNodes () { if (node.executionFinishedEvent !== undefined) { createUiObjectFromNode(node.executionFinishedEvent, node, node, positionOffset) } - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } case 'Process Output': { @@ -822,59 +717,15 @@ function newUiObjectsFromNodes () { return } case 'Status Report': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } case 'Execution Started Event': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Execution Finished Event': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } case 'Calculations Procedure': { @@ -914,69 +765,18 @@ function newUiObjectsFromNodes () { return } case 'Output Dataset': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Status Dependency': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Data Dependency': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Product Definition': { - let referenceParent - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.record !== undefined) { createUiObjectFromNode(node.record, node, node, positionOffset) @@ -991,11 +791,6 @@ function newUiObjectsFromNodes () { if (node.dataBuilding !== undefined) { createUiObjectFromNode(node.dataBuilding, node, node, positionOffset) } - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } return } case 'Record Definition': { @@ -1014,22 +809,7 @@ function newUiObjectsFromNodes () { return } case 'Dataset Definition': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } case 'Plotter': { @@ -1041,14 +821,6 @@ function newUiObjectsFromNodes () { return } case 'Plotter Module': { - let referenceChildren - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.javascriptCode !== undefined) { @@ -1063,13 +835,6 @@ function newUiObjectsFromNodes () { let panel = node.panels[m] createUiObjectFromNode(panel, node, node, positionOffset) } - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } return } @@ -1077,31 +842,6 @@ function newUiObjectsFromNodes () { /* Get node definition */ let nodeDefinition = APP_SCHEMA_MAP.get(node.type) if (nodeDefinition !== undefined) { - /* Open Check for reference Children. */ - let referenceChildren - if (nodeDefinition.isReferenceParent === true) { - if (mapOfReferenceParents !== undefined) { - if (node.savedPayload.referenceChildren !== undefined) { - referenceChildren = [] - mapOfReferenceParents.set(node.id, node) - referenceChildren = node.savedPayload.referenceChildren - } - } - } - - /* Open Check Reference Parent */ - let referenceParent - if (nodeDefinition.isReferenceChildren === true) { - if (mapOfReferenceChildren !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { - if (node.savedPayload.referenceParent.id !== undefined) { - mapOfReferenceChildren.set(node.id, node) - referenceParent = node.savedPayload.referenceParent - } - } - } - } - /* Resolve Initial Values */ if (nodeDefinition.initialValues !== undefined) { if (nodeDefinition.initialValues.code !== undefined) { @@ -1136,29 +876,6 @@ function newUiObjectsFromNodes () { } } } - - /* Close Reference Children Check. */ - if (nodeDefinition.isReferenceParent === true) { - if (node.referenceChildren === undefined) { - node.referenceChildren = [] - } - if (referenceChildren !== undefined) { - node.savedPayload = { - referenceChildren: referenceChildren - } - } else { - node.referenceChildren = [] - } - } - - /* Close Reference Parent Check */ - if (nodeDefinition.isReferenceChildren === true) { - if (referenceParent !== undefined) { - node.savedPayload = { - referenceParent: referenceParent - } - } - } } return @@ -1281,8 +998,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Process Definition', name: 'New Process Definition', - code: '{}', - referenceChildren: [] + code: '{}' } if (node.processes === undefined) { node.processes = [] @@ -1335,8 +1051,7 @@ function newUiObjectsFromNodes () { if (node.statusReport === undefined) { node.statusReport = { type: 'Status Report', - name: 'New Status Report', - referenceChildren: [] + name: 'New Status Report' } createUiObject(true, node.statusReport.type, node.statusReport.name, node.statusReport, node, node) } @@ -1358,8 +1073,7 @@ function newUiObjectsFromNodes () { if (node.executionFinishedEvent === undefined) { node.executionFinishedEvent = { type: 'Execution Finished Event', - name: 'New Execution Finished Event', - referenceChildren: [] + name: 'New Execution Finished Event' } createUiObject(true, node.executionFinishedEvent.type, node.executionFinishedEvent.name, node.executionFinishedEvent, node, node) } @@ -1504,8 +1218,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Dataset Definition', name: 'New Dataset Definition', - code: '{}', - referenceChildren: [] + code: '{}' } if (node.datasets === undefined) { node.datasets = [] @@ -1765,8 +1478,7 @@ function newUiObjectsFromNodes () { function addDefinition (node) { let definition = { - name: 'New Definition', - referenceChildren: [] + name: 'New Definition' } node.rootNodes.push(definition) createUiObject(true, 'Definition', definition.name, definition, node, undefined, 'Definition') @@ -2250,6 +1962,15 @@ function newUiObjectsFromNodes () { if (payload.targetPosition.x === null) { payload.targetPosition.x = spawnPosition.x } if (payload.targetPosition.y === null) { payload.targetPosition.y = spawnPosition.y } + + /* Reference children connection to parents */ + if (node.savedPayload.referenceParent !== undefined) { + payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id) + + if (payload.referenceParent !== undefined) { + mapOfReferenceChildren.set(node.id, node) + } + } } else { if (chainParent === undefined) { payload.targetPosition = { @@ -2289,5 +2010,7 @@ function newUiObjectsFromNodes () { node.payload = payload node.type = uiObjectType canvas.floatingSpace.uiObjectConstructor.createUiObject(userAddingNew, payload) + + mapOfNodes.set(node.id, node) } } diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index c36212303..dfae4f326 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -209,38 +209,17 @@ function newWorkspace () { canvas.chartSpace.finalize() canvas.chartSpace.initialize() return - } else { - if ( - droppedNode.type === 'Definition' || - droppedNode.type === 'Network' || - droppedNode.type === 'Team' - ) { - /* We will only respect the state of each object on these structures, if the structure does not yet exist inside the workspace */ - let alreadyExists = false - for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) { - let rootNode = thisObject.workspaceNode.rootNodes[i] - if (droppedNode.id === rootNode.id) { - alreadyExists = true - } - } - if (alreadyExists === false) { - /* It does not exist, so we recreeate it respecting the inner state of each object. */ - let positionOffset = { - x: spawnPosition.x - droppedNode.savedPayload.targetPosition.x, - y: spawnPosition.y - droppedNode.savedPayload.targetPosition.y - } - - thisObject.workspaceNode.rootNodes.push(droppedNode) - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(droppedNode, undefined, undefined, positionOffset) - return - } - } } - /* This is the default behaviour, which consists of cleaning all nodes that are not supported and then creating the UIObjects that remains on the data structure. */ - let rootNode = functionLibraryProtocolNode.getProtocolNode(droppedNode) - thisObject.workspaceNode.rootNodes.push(rootNode) - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(rootNode, undefined, undefined) + /* It does not exist, so we recreeate it respecting the inner state of each object. */ + let positionOffset = { + x: spawnPosition.x - droppedNode.savedPayload.targetPosition.x, + y: spawnPosition.y - droppedNode.savedPayload.targetPosition.y + } + + thisObject.workspaceNode.rootNodes.push(droppedNode) + functionLibraryUiObjectsFromNodes.createUiObjectFromNode(droppedNode, undefined, undefined, positionOffset) + functionLibraryUiObjectsFromNodes.tryToConnectChildrenWithReferenceParents() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] spawn -> err = ' + err.stack) } } @@ -285,7 +264,7 @@ function newWorkspace () { ) { text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, true, false, true, true, true)) } else { - text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, true)) + text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, true, false, true, true, true)) } let nodeName = payload.node.name @@ -309,7 +288,7 @@ function newWorkspace () { ) { text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, false, false, true, true, true)) } else { - text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, false)) + text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, false, false, true, true, true)) } let nodeName = payload.node.name diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 8dae08e62..16952bd47 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -78,7 +78,6 @@ function newUiObjectConstructor () { payload.uiObject.shortcutKey = payload.node.savedPayload.uiObject.shortcutKey } } - payload.node.savedPayload = undefined floatingLayer.addFloatingObject(floatingObject) @@ -5149,5 +5148,10 @@ function newUiObjectConstructor () { payload.uiObject.finalize() payload.uiObject = undefined + + payload.referenceParent = undefined + payload.parent = undefined + payload.chainParent = undefined + payload.node.savedPayload = undefined } }