Delete Phases Working

This commit is contained in:
Luis Fernando Molina committed 2019-05-07 09:58:45 +02:00
1 parent b66ccc8182
commit f5b5f4b852
3 files changed
+73 -37

No files matched your search

+8 -4
View File
@@ -1,6 +1,10 @@
function newStrategyPart () {
const MODULE_NAME = 'Strategy Part'
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let thisObject = {
type: undefined,
@@ -83,7 +87,7 @@ function newStrategyPart () {
}]
break
}
case 'Strategy Entry': {
case 'Strategy Entry Event': {
imagePath = 'Images/icons/style-01/startup.png'
menuItemsInitialValues = [
{
@@ -99,7 +103,7 @@ function newStrategyPart () {
}]
break
}
case 'Strategy Exit': {
case 'Strategy Exit Event': {
imagePath = 'Images/icons/style-01/support.png'
menuItemsInitialValues = [
{
@@ -115,7 +119,7 @@ function newStrategyPart () {
}]
break
}
case 'Trade Entry': {
case 'Trade Entry Event': {
imagePath = 'Images/icons/style-01/compass.png'
menuItemsInitialValues = [
{
@@ -324,7 +328,7 @@ function newStrategyPart () {
if (pFloatingObject.payload.parentNode === undefined) { return }
/* Here we do the trick of recalculation the position of the anchor by setting it to the position of its parent */
let parentFloatingObject = floatingLayer.getFloatingObject(pFloatingObject.payload.parentNode.handle)
let parentFloatingObject = floatingLayer.getFloatingObject(pFloatingObject.payload.chainParent.handle)
if (parentFloatingObject === undefined) {
console.log(pFloatingObject)
+4 -4
View File
@@ -39,19 +39,19 @@ function newStrategyParts () {
level_1()
break
}
case 'Strategy Entry': {
case 'Strategy Entry Event': {
level_2()
break
}
case 'Strategy Exit': {
case 'Strategy Exit Event': {
level_2()
break
}
case 'Trade Entry': {
case 'Trade Entry Event': {
level_2()
break
}
case 'Trade Exit': {
case 'Trade Exit Event': {
level_2()
break
}
+61 -29
View File
@@ -37,7 +37,7 @@ function newStrategy () {
}
function createPart (partType, name, node, parentNode, title) {
function createPart (partType, name, node, parentNode, chainParent, title) {
let payload = {
position: {
x: (viewPort.width - SIDE_PANEL_WIDTH) / 2 + SIDE_PANEL_WIDTH,
@@ -55,6 +55,7 @@ function newStrategy () {
payload.downLabel = name
payload.node = node
payload.parentNode = parentNode
payload.chainParent = chainParent
payload.onMenuItemClick = onMenuItemClick
node.handle = canvas.floatingSpace.strategyParts.createNewStrategyPart(partType, payload)
@@ -68,84 +69,84 @@ function newStrategy () {
function generateStrategyParts () {
let lastPhase
let strategy = thisObject.strategySource
createPart('Strategy', strategy.name, strategy, undefined)
createPart('Strategy', strategy.name, strategy, undefined, undefined)
createPart('Strategy Entry', '', strategy.entryPoint, strategy)
createPart('Strategy Entry Event', '', strategy.entryPoint, strategy, strategy)
for (let k = 0; k < strategy.entryPoint.situations.length; k++) {
let situation = strategy.entryPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.entryPoint, 'Strategy Entry' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.entryPoint, strategy.entryPoint, 'Strategy Entry' + ' ' + 'Situation' + ' #' + (k + 1))
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
}
}
createPart('Strategy Exit', '', strategy.exitPoint, strategy)
createPart('Strategy Exit Event', '', strategy.exitPoint, strategy, strategy)
for (let k = 0; k < strategy.exitPoint.situations.length; k++) {
let situation = strategy.exitPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.exitPoint, 'Strategy Exit' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.exitPoint, strategy.exitPoint, 'Strategy Exit' + ' ' + 'Situation' + ' #' + (k + 1))
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
}
}
createPart('Trade Entry', '', strategy.sellPoint, strategy)
createPart('Trade Entry Event', '', strategy.sellPoint, strategy, strategy)
for (let k = 0; k < strategy.sellPoint.situations.length; k++) {
let situation = strategy.sellPoint.situations[k]
createPart('Situation', situation.name, situation, strategy.sellPoint, 'Trade Entry' + ' ' + 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, strategy.sellPoint, strategy.sellPoint, 'Trade Entry' + ' ' + 'Situation' + ' #' + (k + 1))
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
}
}
createPart('Stop', '', strategy.stopLoss, strategy)
createPart('Stop', '', strategy.stopLoss, strategy, strategy)
for (let p = 0; p < strategy.stopLoss.phases.length; p++) {
let phase = strategy.stopLoss.phases[p]
let parent
let chainParent
if (p === 0) {
parent = strategy.stopLoss
chainParent = strategy.stopLoss
} else {
parent = lastPhase
chainParent = lastPhase
}
lastPhase = phase
createPart('Phase', phase.name, phase, parent, 'Stop Phase' + ' #' + (p + 1))
createPart('Phase', phase.name, phase, strategy.stopLoss, chainParent, 'Stop Phase' + ' #' + (p + 1))
for (let k = 0; k < phase.situations.length; k++) {
let situation = phase.situations[k]
createPart('Situation', situation.name, situation, phase, 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, phase, phase, 'Situation' + ' #' + (k + 1))
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
}
}
}
createPart('Take Profit', '', strategy.buyOrder, strategy)
createPart('Take Profit', '', strategy.buyOrder, strategy, strategy)
for (let p = 0; p < strategy.buyOrder.phases.length; p++) {
let phase = strategy.buyOrder.phases[p]
let parent
let chainParent
if (p === 0) {
parent = strategy.buyOrder
chainParent = strategy.buyOrder
} else {
parent = lastPhase
chainParent = lastPhase
}
lastPhase = phase
createPart('Phase', phase.name, phase, parent, 'Take Profit Phase' + ' #' + (p + 1))
createPart('Phase', phase.name, phase, strategy.buyOrder, chainParent, 'Take Profit Phase' + ' #' + (p + 1))
for (let k = 0; k < phase.situations.length; k++) {
let situation = phase.situations[k]
createPart('Situation', situation.name, situation, phase, 'Situation' + ' #' + (k + 1))
createPart('Situation', situation.name, situation, phase, phase, 'Situation' + ' #' + (k + 1))
for (let m = 0; m < situation.conditions.length; m++) {
let condition = situation.conditions[m]
createPart('Condition', condition.name, condition, situation, 'Condition' + ' #' + (m + 1))
createPart('Condition', condition.name, condition, situation, situation, 'Condition' + ' #' + (m + 1))
}
}
}
@@ -238,14 +239,14 @@ function newStrategy () {
case 'Edit Code':
break
case 'Delete Phase':
case 'Delete Phase': {
deletePhase(payload.node)
break
}
case 'Delete Situation': {
deleteSituation(payload.node)
break
}
break
case 'Delete Condition': {
deleteCondition(payload.node)
break
@@ -255,6 +256,37 @@ function newStrategy () {
}
}
function deletePhase (node) {
let payload = node.payload
for (let k = 0; k < payload.parentNode.phases.length; k++) {
let phase = payload.parentNode.phases[k]
if (phase.name === node.name) {
for (let j = 0; j < phase.situations.length; j++) {
let situation = phase.situations[j]
for (let i = 0; i < situation.conditions.length; i++) {
let condition = situation.conditions[i]
destroyPart(condition)
cleanNode(condition)
}
situation.conditions = []
destroyPart(situation)
phase.situations.splice(j, 1)
cleanNode(situation)
}
phase.situations = []
/* Before deleting this phase we need to give its chainParent to the next phase down the chain */
if (k < payload.parentNode.phases.length - 1) {
payload.parentNode.phases[k + 1].payload.chainParent = payload.chainParent
}
/* Continue destroying this phase */
destroyPart(phase)
payload.parentNode.phases.splice(k, 1)
cleanNode(phase)
return
}
}
}
function deleteSituation (node) {
let payload = node.payload
for (let j = 0; j < payload.parentNode.situations.length; j++) {
@@ -295,10 +327,10 @@ function newStrategy () {
node.payload.downLabel = undefined
node.payload.node = undefined
node.payload.parentNode = undefined
node.payload.chainParent = undefined
node.payload.onMenuItemClick = undefined
node.handle = undefined
node.payload = undefined
node.cleaned = true
}
}