From a596068600c88bf2e3c698015cd1ce57ee31e4c1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Dec 2019 13:59:03 +0100 Subject: [PATCH] Bug Fixed attaching and detaching phases --- .../FunctionLibraries/ChainAttachDetach.js | 39 +++++++++++++---- .../FunctionLibraries/UiObjectsFromNodes.js | 42 ++++++++++++------- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js index 10d5d09b2..c147dd7a2 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js @@ -96,11 +96,6 @@ function newChainAttachDetach () { case 'Phase': { switch (attachToNode.type) { case 'Stop': { - if (attachToNode.maxPhases !== undefined) { - if (attachToNode.phases.length >= attachToNode.maxPhases) { - return - } - } node.payload.parentNode = attachToNode if (attachToNode.phases.length > 0) { let phase = attachToNode.phases[attachToNode.phases.length - 1] @@ -113,10 +108,36 @@ function newChainAttachDetach () { } break case 'Take Profit': { - if (attachToNode.maxPhases !== undefined) { - if (attachToNode.phases.length >= attachToNode.maxPhases) { - return - } + node.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + node.payload.chainParent = phase + } else { + node.payload.chainParent = attachToNode + } + attachToNode.phases.push(node) + completeAttachment(node, rootNodes) + } + break + case 'Initial Stop': { + if (attachToNode.phases.length >= 1) { + return + } + + node.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + node.payload.chainParent = phase + } else { + node.payload.chainParent = attachToNode + } + attachToNode.phases.push(node) + completeAttachment(node, rootNodes) + } + break + case 'Initial Take Profit': { + if (attachToNode.phases.length >= 1) { + return } node.payload.parentNode = attachToNode if (attachToNode.phases.length > 0) { diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 9844134df..9278eaa6a 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -62,21 +62,23 @@ function newUiObjectsFromNodes () { /* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */ if (nodeDefinition.chainedToSameType === true) { - let parentNodeDefinition = APP_SCHEMA_MAP.get(parentNode.type) - if (parentNodeDefinition !== undefined) { - if (parentNodeDefinition.properties !== undefined) { - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (property.childType === node.type) { - if (property.type === 'array') { - if (parentNode[property.name] !== undefined) { - if (parentNode[property.name].length > 1) { - let nodeChildren = parentNode[property.name] - for (let j = 0; j < nodeChildren.length; j++) { - if (node.id === nodeChildren[j].id) { - if (j > 0) { + if (parentNode !== undefined) { + let parentNodeDefinition = APP_SCHEMA_MAP.get(parentNode.type) + if (parentNodeDefinition !== undefined) { + if (parentNodeDefinition.properties !== undefined) { + for (let i = 0; i < parentNodeDefinition.properties.length; i++) { + let property = parentNodeDefinition.properties[i] + if (property.childType === node.type) { + if (property.type === 'array') { + if (parentNode[property.name] !== undefined) { + if (parentNode[property.name].length > 1) { + let nodeChildren = parentNode[property.name] + for (let j = 0; j < nodeChildren.length; j++) { + if (node.id === nodeChildren[j].id) { + if (j > 0) { chainParent = nodeChildren[j - 1] } + } } } } @@ -156,8 +158,6 @@ function newUiObjectsFromNodes () { } } - createUiObject(true, object.type, object.name, object, parentNode, chainParent) - if (nodeDefinition !== undefined) { if (nodeDefinition.initialValues !== undefined) { if (nodeDefinition.initialValues.code !== undefined) { @@ -184,7 +184,15 @@ function newUiObjectsFromNodes () { if (parentNode[property.name] === undefined) { parentNode[property.name] = [] } - parentNode[property.name].push(object) + if (property.maxItems !== undefined) { + if (parentNode[property.name].length < property.maxItems) { + parentNode[property.name].push(object) + } else { + return // Object can not be created. + } + } else { + parentNode[property.name].push(object) + } } break } @@ -192,6 +200,8 @@ function newUiObjectsFromNodes () { } } + createUiObject(true, object.type, object.name, object, parentNode, chainParent) + /* Auto Add more Children */ if (nodeDefinition.properties !== undefined) { let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.