From c1b7da23d408e41012efb5f62ced42fed6218114 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 09:33:06 +0200 Subject: [PATCH] Logic moved to workspace --- FloatingSpace/StrategyPart.js | 67 +-------------------------------- StrategySpace/Workspace.js | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 66 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index c459212e3..3ebd69607 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -293,72 +293,7 @@ function newStrategyPart () { } if (isAttaching === true) { - switch (thisObject.payload.node.type) { - case 'Strategy': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.strategies.push(thisObject.payload.node) - } - break - case 'Phase': { - switch (attachToNode.type) { - case 'Stop': { - thisObject.payload.parentNode = attachToNode - if (attachToNode.phases.length > 0) { - let phase = attachToNode.phases[attachToNode.phases.length - 1] - thisObject.payload.chainParent = phase - } else { - thisObject.payload.chainParent = attachToNode - } - attachToNode.phases.push(thisObject.payload.node) - } - break - case 'Take Profit': { - thisObject.payload.parentNode = attachToNode - if (attachToNode.phases.length > 0) { - let phase = attachToNode.phases[attachToNode.phases.length - 1] - thisObject.payload.chainParent = phase - } else { - thisObject.payload.chainParent = attachToNode - } - attachToNode.phases.push(thisObject.payload.node) - } - break - case 'Phase': { - thisObject.payload.parentNode = attachToNode.payload.parentNode - for (let i = 0; i < thisObject.payload.parentNode.phases.length; i++) { - let phase = thisObject.payload.parentNode.phases[i] - if (attachToNode.id === phase.id) { - if (i === thisObject.payload.parentNode.phases.length - 1) { - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.phases.push(thisObject.payload.node) - } else { - thisObject.payload.chainParent = attachToNode - let nextPhase = thisObject.payload.parentNode.phases[i + 1] - nextPhase.payload.chainParent = thisObject.payload.node - thisObject.payload.parentNode.phases.splice(i + 1, 0, thisObject.payload.node) - break - } - } - } - } - break - } - } - break - case 'Situation': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.situations.push(thisObject.payload.node) - } - break - case 'Condition': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.conditions.push(thisObject.payload.node) - } - break - } + canvas.strategySpace.workspace.attachNode(thisObject.payload.node, attachToNode) } } diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 2a6e5008c..0a94f54bf 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -6,6 +6,7 @@ function newWorkspace () { tradingSystem: undefined, container: undefined, detachNode: detachNode, + attachNode: attachNode, getContainer: getContainer, initialize: initialize, finalize: finalize @@ -123,6 +124,75 @@ function newWorkspace () { node.payload.parentNode = undefined } + function attachNode (node, attachToNode) { + switch (node.type) { + case 'Strategy': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.strategies.push(node) + } + break + case 'Phase': { + switch (attachToNode.type) { + case 'Stop': { + 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) + } + break + case 'Take Profit': { + 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) + } + break + case 'Phase': { + node.payload.parentNode = attachToNode.payload.parentNode + for (let i = 0; i < node.payload.parentNode.phases.length; i++) { + let phase = node.payload.parentNode.phases[i] + if (attachToNode.id === phase.id) { + if (i === node.payload.parentNode.phases.length - 1) { + node.payload.chainParent = attachToNode + node.payload.parentNode.phases.push(node) + } else { + node.payload.chainParent = attachToNode + let nextPhase = node.payload.parentNode.phases[i + 1] + nextPhase.payload.chainParent = node + node.payload.parentNode.phases.splice(i + 1, 0, node) + break + } + } + } + } + break + } + } + break + case 'Situation': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.situations.push(node) + } + break + case 'Condition': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.conditions.push(node) + } + break + } + } + function createPart (partType, name, node, parentNode, chainParent, title) { let payload = {} if (chainParent === undefined) {