diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 92583dfb7..498ce0834 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -152,18 +152,6 @@ function newStrategyPartConstructor () { currentRadius: 0, angle: -135 }, - { - action: 'Delete Strategy', - actionFunction: payload.onMenuItemClick, - label: 'Delete This Strategy', - visible: false, - iconPathOn: 'trash', - iconPathOff: 'trash', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -40 - }, { action: 'Open Settings', actionFunction: payload.onMenuItemClick, @@ -174,7 +162,19 @@ function newStrategyPartConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 + angle: -40 + }, + { + action: 'Delete Strategy', + actionFunction: payload.onMenuItemClick, + label: 'Delete This Strategy', + visible: false, + iconPathOn: 'trash', + iconPathOff: 'trash', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -0 }, { action: 'Download', diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index d0e5dc976..693d55112 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -326,6 +326,10 @@ function newWorkspace () { createPart('Condition', condition.name, condition, situation, situation, 'Condition') } break + case 'Delete Strategy': { + deleteStrategy(payload.node) + break + } case 'Delete Phase': { deletePhase(payload.node) break @@ -343,6 +347,40 @@ function newWorkspace () { } } + function deleteStrategy (node) { + let payload = node.payload + for (let j = 0; j < payload.parentNode.strategies.length; j++) { + let strategy = payload.parentNode.strategies[j] + if (strategy.id === node.id) { + deleteEvent(strategy.entryPoint) + deleteEvent(strategy.exitPoint) + deleteEvent(strategy.sellPoint) + deleteManagedItem(strategy.stopLoss) + deleteManagedItem(strategy.buyOrder) + destroyPart(strategy) + payload.parentNode.strategies.splice(j, 1) + cleanNode(strategy) + return + } + } + } + + function deleteEvent (node) { + while (node.situations.length > 0) { + deleteSituation(node.situations[0]) + } + destroyPart(node) + cleanNode(node) + } + + function deleteManagedItem (node) { + while (node.phases.length > 0) { + deletePhase(node.phases[0]) + } + destroyPart(node) + cleanNode(node) + } + function deletePhase (node) { let payload = node.payload for (let k = 0; k < payload.parentNode.phases.length; k++) {