From ef06f7bc8b0291c8ab955d56a8c659e62b171744 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 13 May 2019 15:56:24 +0200 Subject: [PATCH] Reorganization to clean strategyPart object --- FloatingSpace/StrategyPart.js | 292 +--------------------- FloatingSpace/StrategyPartConstructor.js | 305 ++++++++++++++++++++++- Globals.js | 4 +- 3 files changed, 305 insertions(+), 296 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 6417fb09e..3bd8d5f24 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -67,295 +67,9 @@ function newStrategyPart () { imagePath = undefined } - function initialize (payload) { + function initialize (payload, menuItemsInitialValues) { thisObject.payload = payload - let menuItemsInitialValues = [] - switch (thisObject.payload.node.type) { - case 'Trading System': { - imagePath = 'Images/icons/style-01/analysis.png' - menuItemsInitialValues = [ - { - action: 'Reload Trading System', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Reload', - visible: false, - imagePathOn: 'Images/icons/style-01/vector.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -60 - }, - { - action: 'Save Trading System', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Save Changes', - workingLabel: 'Saving...', - workDoneLabel: 'Saved', - workFailedLabel: 'Not Saved', - visible: false, - imagePathOn: 'Images/icons/style-01/upload.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -20 - }, - { - action: 'New Strategy', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'New Strategy', - visible: false, - imagePathOn: 'Images/icons/style-01/quality.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - }, - { - action: 'Open Settings', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Settings', - visible: false, - imagePathOn: 'Images/icons/style-01/tools.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 60 - }] - break - } - case 'Strategy': { - imagePath = 'Images/icons/style-01/quality.png' - menuItemsInitialValues = [ - { - action: 'Delete Strategy', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Delete This Strategy', - visible: false, - imagePathOn: 'Images/icons/style-01/trash.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -20 - }, - { - action: 'Open Settings', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Settings', - visible: false, - imagePathOn: 'Images/icons/style-01/tools.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - }] - break - } - case 'Strategy Entry Event': { - imagePath = 'Images/icons/style-01/startup.png' - menuItemsInitialValues = [ - { - action: 'Add Situation', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Situation', - visible: false, - imagePathOn: 'Images/icons/style-01/attractive.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }] - break - } - case 'Strategy Exit Event': { - imagePath = 'Images/icons/style-01/support.png' - menuItemsInitialValues = [ - { - action: 'Add Situation', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Situation', - visible: false, - imagePathOn: 'Images/icons/style-01/attractive.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }] - break - } - case 'Trade Entry Event': { - imagePath = 'Images/icons/style-01/compass.png' - menuItemsInitialValues = [ - { - action: 'Add Situation', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Situation', - visible: false, - imagePathOn: 'Images/icons/style-01/attractive.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }] - break - } - case 'Stop': { - imagePath = 'Images/icons/style-01/pixel.png' - menuItemsInitialValues = [ - { - action: 'Add Phase', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Phase', - visible: false, - imagePathOn: 'Images/icons/style-01/placeholder.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }] - break - } - case 'Take Profit': { - imagePath = 'Images/icons/style-01/competition.png' - menuItemsInitialValues = [ - { - action: 'Add Phase', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Phase', - visible: false, - imagePathOn: 'Images/icons/style-01/placeholder.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }] - break - } - case 'Phase': { - imagePath = 'Images/icons/style-01/testing.png' - thisObject.codeEditor = newCodeEditor() - thisObject.codeEditor.isVisibleFunction = thisObject.isVisibleFunction - thisObject.codeEditor.initialize() - thisObject.codeEditor.container.connectToParent(thisObject.container, false, false, true, true, false, false, false, false) - - imagePath = 'Images/icons/style-01/placeholder.png' - menuItemsInitialValues = [ - { - action: 'Edit Code', - actionFunction: thisObject.codeEditor.activate, - label: 'Edit Code', - visible: false, - imagePathOn: 'Images/icons/style-01/html.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 40 - }, - { - action: 'Add Situation', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Situation', - visible: false, - imagePathOn: 'Images/icons/style-01/attractive.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 0 - }, - { - action: 'Delete Phase', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Delete This Phase', - visible: false, - imagePathOn: 'Images/icons/style-01/trash.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -40 - }] - break - } - case 'Situation': { - imagePath = 'Images/icons/style-01/attractive.png' - menuItemsInitialValues = [ - { - action: 'Add Condition', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Add Condition', - visible: false, - imagePathOn: 'Images/icons/style-01/testing.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - }, - { - action: 'Delete Situation', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Delete This Situation', - visible: false, - imagePathOn: 'Images/icons/style-01/trash.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -20 - }] - break - } - case 'Condition': { - imagePath = 'Images/icons/style-01/testing.png' - thisObject.codeEditor = newCodeEditor() - thisObject.codeEditor.isVisibleFunction = thisObject.isVisibleFunction - thisObject.codeEditor.initialize() - thisObject.codeEditor.container.connectToParent(thisObject.container, false, false, true, true, false, false, false, false) - menuItemsInitialValues = [ - { - action: 'Edit Code', - actionFunction: thisObject.codeEditor.activate, - label: 'Edit Code', - visible: false, - imagePathOn: 'Images/icons/style-01/html.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - }, - { - action: 'Delete Condition', - actionFunction: thisObject.payload.onMenuItemClick, - label: 'Delete This Condition', - visible: false, - imagePathOn: 'Images/icons/style-01/trash.png', - imagePathOff: 'Images/icons/style-01/target.png', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -20 - }] - break - } - default: { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Part Type not Recognized -> type = ' + thisObject.payload.node.type) } - } - } - /* Initialize the Menu */ thisObject.menu = newCircularMenu() @@ -371,14 +85,14 @@ function newStrategyPart () { /* Load Part Image */ - if (imagePath !== undefined) { + if (thisObject.imagePath !== undefined) { image = new Image() image.onload = onImageLoad function onImageLoad () { image.canDrawIcon = true } - image.src = window.canvasApp.urlPrefix + imagePath + image.src = window.canvasApp.urlPrefix + thisObject.imagePath } selfFocusEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onFocus', onFocus) diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 662c806b2..1a46ff08f 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -39,10 +39,309 @@ function newStrategyPartConstructor () { let strategyPart = newStrategyPart() strategyPart.fitFunction = canvas.floatingSpace.fitIntoVisibleArea strategyPart.isVisibleFunction = canvas.floatingSpace.isThisPointVisible - strategyPart.initialize(payload) + let menuItemsInitialValues = getMenuItemsInitialValues(strategyPart, payload) + strategyPart.initialize(payload, menuItemsInitialValues) strategyPart.container.connectToParent(floatingObject.container, false, false, true, true, false, false, true, true, true) payload.uiObject = strategyPart + setFloatingObjectBasicProperties(floatingObject, payload) + + floatingLayer.addFloatingObject(floatingObject) + + return + } + + function getMenuItemsInitialValues (strategyPart, payload) { + let menuItemsInitialValues = [] + switch (payload.node.type) { + case 'Trading System': { + strategyPart.imagePath = 'Images/icons/style-01/analysis.png' + menuItemsInitialValues = [ + { + action: 'Reload Trading System', + actionFunction: payload.onMenuItemClick, + label: 'Reload', + visible: false, + imagePathOn: 'Images/icons/style-01/vector.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -60 + }, + { + action: 'Save Trading System', + actionFunction: payload.onMenuItemClick, + label: 'Save Changes', + workingLabel: 'Saving...', + workDoneLabel: 'Saved', + workFailedLabel: 'Not Saved', + visible: false, + imagePathOn: 'Images/icons/style-01/upload.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + }, + { + action: 'New Strategy', + actionFunction: payload.onMenuItemClick, + label: 'New Strategy', + visible: false, + imagePathOn: 'Images/icons/style-01/quality.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + }, + { + action: 'Open Settings', + actionFunction: payload.onMenuItemClick, + label: 'Settings', + visible: false, + imagePathOn: 'Images/icons/style-01/tools.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 60 + }] + break + } + case 'Strategy': { + strategyPart.imagePath = 'Images/icons/style-01/quality.png' + menuItemsInitialValues = [ + { + action: 'Delete Strategy', + actionFunction: payload.onMenuItemClick, + label: 'Delete This Strategy', + visible: false, + imagePathOn: 'Images/icons/style-01/trash.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + }, + { + action: 'Open Settings', + actionFunction: payload.onMenuItemClick, + label: 'Settings', + visible: false, + imagePathOn: 'Images/icons/style-01/tools.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + }] + break + } + case 'Strategy Entry Event': { + strategyPart.imagePath = 'Images/icons/style-01/startup.png' + menuItemsInitialValues = [ + { + action: 'Add Situation', + actionFunction: payload.onMenuItemClick, + label: 'Add Situation', + visible: false, + imagePathOn: 'Images/icons/style-01/attractive.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }] + break + } + case 'Strategy Exit Event': { + strategyPart.imagePath = 'Images/icons/style-01/support.png' + menuItemsInitialValues = [ + { + action: 'Add Situation', + actionFunction: payload.onMenuItemClick, + label: 'Add Situation', + visible: false, + imagePathOn: 'Images/icons/style-01/attractive.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }] + break + } + case 'Trade Entry Event': { + strategyPart.imagePath = 'Images/icons/style-01/compass.png' + menuItemsInitialValues = [ + { + action: 'Add Situation', + actionFunction: payload.onMenuItemClick, + label: 'Add Situation', + visible: false, + imagePathOn: 'Images/icons/style-01/attractive.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }] + break + } + case 'Stop': { + strategyPart.imagePath = 'Images/icons/style-01/pixel.png' + menuItemsInitialValues = [ + { + action: 'Add Phase', + actionFunction: payload.onMenuItemClick, + label: 'Add Phase', + visible: false, + imagePathOn: 'Images/icons/style-01/placeholder.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }] + break + } + case 'Take Profit': { + strategyPart.imagePath = 'Images/icons/style-01/competition.png' + menuItemsInitialValues = [ + { + action: 'Add Phase', + actionFunction: payload.onMenuItemClick, + label: 'Add Phase', + visible: false, + imagePathOn: 'Images/icons/style-01/placeholder.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }] + break + } + case 'Phase': { + strategyPart.imagePath = 'Images/icons/style-01/placeholder.png' + strategyPart.codeEditor = newCodeEditor() + strategyPart.codeEditor.isVisibleFunction = strategyPart.isVisibleFunction + strategyPart.codeEditor.initialize() + strategyPart.codeEditor.container.connectToParent(strategyPart.container, false, false, true, true, false, false, false, false) + + menuItemsInitialValues = [ + { + action: 'Edit Code', + actionFunction: strategyPart.codeEditor.activate, + label: 'Edit Code', + visible: false, + imagePathOn: 'Images/icons/style-01/html.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 40 + }, + { + action: 'Add Situation', + actionFunction: payload.onMenuItemClick, + label: 'Add Situation', + visible: false, + imagePathOn: 'Images/icons/style-01/attractive.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + }, + { + action: 'Delete Phase', + actionFunction: payload.onMenuItemClick, + label: 'Delete This Phase', + visible: false, + imagePathOn: 'Images/icons/style-01/trash.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -40 + }] + break + } + case 'Situation': { + strategyPart.imagePath = 'Images/icons/style-01/attractive.png' + menuItemsInitialValues = [ + { + action: 'Add Condition', + actionFunction: payload.onMenuItemClick, + label: 'Add Condition', + visible: false, + imagePathOn: 'Images/icons/style-01/testing.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + }, + { + action: 'Delete Situation', + actionFunction: payload.onMenuItemClick, + label: 'Delete This Situation', + visible: false, + imagePathOn: 'Images/icons/style-01/trash.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + }] + break + } + case 'Condition': { + strategyPart.imagePath = 'Images/icons/style-01/testing.png' + strategyPart.codeEditor = newCodeEditor() + strategyPart.codeEditor.isVisibleFunction = strategyPart.isVisibleFunction + strategyPart.codeEditor.initialize() + strategyPart.codeEditor.container.connectToParent(strategyPart.container, false, false, true, true, false, false, false, false) + + menuItemsInitialValues = [ + { + action: 'Edit Code', + actionFunction: strategyPart.codeEditor.activate, + label: 'Edit Code', + visible: false, + imagePathOn: 'Images/icons/style-01/html.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + }, + { + action: 'Delete Condition', + actionFunction: payload.onMenuItemClick, + label: 'Delete This Condition', + visible: false, + imagePathOn: 'Images/icons/style-01/trash.png', + imagePathOff: 'Images/icons/style-01/target.png', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + }] + break + } + default: { + if (ERROR_LOG === true) { logger.write('[ERROR] getMenuItemsInitialValues -> Part Type not Recognized -> type = ' + payload.node.type) } + } + } + + return menuItemsInitialValues + } + + function setFloatingObjectBasicProperties (floatingObject, payload) { const FRICTION = 0.97 switch (payload.node.type) { @@ -163,10 +462,6 @@ function newStrategyPartConstructor () { } floatingObject.labelStrokeStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)' - - floatingLayer.addFloatingObject(floatingObject) - - return } function destroyStrategyPart (payload) { diff --git a/Globals.js b/Globals.js index 77d9ed28c..039d5dbcd 100644 --- a/Globals.js +++ b/Globals.js @@ -121,8 +121,8 @@ function convertTimePeriodToName(pTimePeriod) { window.AT_BREAKPOINT = false; -const LOGGED_IN_USER_LOCAL_STORAGE = "user" -const LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE = "access_token" +const LOGGED_IN_USER_LOCAL_STORAGE = "xuser" +const LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE = "xaccess_token" const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line.