diff --git a/Canvas.js b/Canvas.js index 93d131afe..adf250ab3 100644 --- a/Canvas.js +++ b/Canvas.js @@ -312,7 +312,7 @@ function newCanvas() { thisObject.mouse.action = 'key up' } - function onKeyDown(event) { + async function onKeyDown(event) { if (EDITOR_ON_FOCUS === true) { return } thisObject.mouse.event = event thisObject.mouse.action = 'key down' @@ -368,7 +368,7 @@ function newCanvas() { return } - let nodeOnFocus = canvas.designSpace.workspace.getNodeThatIsOnFocus() + let nodeOnFocus = await canvas.designSpace.workspace.getNodeThatIsOnFocus() if (nodeOnFocus !== undefined) { if (nodeOnFocus.payload.uiObject.codeEditor !== undefined) { if (nodeOnFocus.payload.uiObject.codeEditor.visible === true) { @@ -512,36 +512,40 @@ function newCanvas() { return } } - if ((event.ctrlKey === true || event.metaKey === true) && event.altKey === true) { /* Shortcuts to nodes */ if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90)) { /* From here we prevent the default behaviour. Putting it earlier prevents imput box and text area to receive keystrokes */ event.preventDefault() + let nodeUsingThisKey = await canvas.designSpace.workspace.getNodeByShortcutKey(event.key) - let nodeUsingThisKey = canvas.designSpace.workspace.getNodeByShortcutKey(event.key) - - /* If there is a node in focus, we try to assign the key to it. */ - if (nodeUsingThisKey !== undefined && nodeOnFocus !== undefined) { - if (nodeUsingThisKey.id === nodeOnFocus.id) { - nodeOnFocus.payload.uiObject.shortcutKey = '' - nodeOnFocus.payload.uiObject.valueAtAngle = false - nodeOnFocus.payload.uiObject.setValue('Shortcut Key Removed ') - return + if (nodeUsingThisKey !== undefined) { + if (nodeOnFocus !== undefined) { + if (nodeUsingThisKey.id === nodeOnFocus.id) { + nodeOnFocus.payload.uiObject.shortcutKey = '' + nodeOnFocus.payload.uiObject.valueAtAngle = false + nodeOnFocus.payload.uiObject.setValue('Shortcut Key Removed ') + } else { + nodeUsingThisKey.payload.uiObject.shortcutKey = '' + nodeUsingThisKey = undefined + nodeOnFocus.payload.uiObject.shortcutKey = event.key + nodeOnFocus.payload.uiObject.valueAtAngle = false + nodeOnFocus.payload.uiObject.setValue('Shortcut Key: Ctrl + Alt + ' + event.key) + } } else { - /* After the warning, we allow the key to be re-assigned */ - nodeUsingThisKey.payload.uiObject.shortcutKey = '' - nodeUsingThisKey = undefined + canvas.floatingSpace.positionAtNode(nodeUsingThisKey) + } + return + } else { + if (nodeOnFocus !== undefined) { nodeOnFocus.payload.uiObject.shortcutKey = event.key nodeOnFocus.payload.uiObject.valueAtAngle = false nodeOnFocus.payload.uiObject.setValue('Shortcut Key: Ctrl + Alt + ' + event.key) } } - return } } - - if (event.ctrlKey === true && event.altKey === true && nodeOnFocus !== undefined) { + if ((event.ctrlKey === true || event.metaKey === true) && event.altKey === true && nodeOnFocus !== undefined) { if (nodeOnFocus.payload.uiObject.shortcutKey !== undefined && nodeOnFocus.payload.uiObject.shortcutKey !== '') { nodeOnFocus.payload.uiObject.valueAtAngle = false nodeOnFocus.payload.uiObject.setValue('Shortcut Key: Ctrl + Alt + ' + nodeOnFocus.payload.uiObject.shortcutKey) diff --git a/DesignSpace/Workspace/FunctionLibraries/ChainAttachDetach.js b/DesignSpace/Workspace/FunctionLibraries/ChainAttachDetach.js deleted file mode 100644 index faff8bafb..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/ChainAttachDetach.js +++ /dev/null @@ -1,221 +0,0 @@ -function newChainAttachDetach() { - thisObject = { - chainDetachNode: chainDetachNode, - chainAttachNode: chainAttachNode - } - - return thisObject - - function chainDetachNode(node, rootNodes) { - if (node.payload.parentNode === undefined) { return } - switch (node.type) { - case 'Phase': { - let payload = node.payload - for (let i = 0; i < payload.parentNode.phases.length; i++) { - let phase = payload.parentNode.phases[i] - if (phase.id === node.id) { - if (i < payload.parentNode.phases.length - 1) { - let nextPhase = payload.parentNode.phases[i + 1] - if (i > 0) { - let previousPhase = payload.parentNode.phases[i - 1] - nextPhase.payload.chainParent = previousPhase - } else { - nextPhase.payload.chainParent = payload.parentNode - } - } - payload.parentNode.phases.splice(i, 1) - completeDetachment(node, rootNodes) - return - } - } - return - } - default: { - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - /* Detach from parent */ - if (node.payload.parentNode !== undefined) { - let parentNodeDefinition = getNodeDefinition(node.payload.parentNode) - if (parentNodeDefinition !== undefined) { - if (parentNodeDefinition.properties !== undefined) { - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (nodeDefinition.propertyNameAtParent === property.name) { - switch (property.type) { - case 'node': { - node.payload.parentNode[property.name] = undefined - } - break - case 'array': { - let nodePropertyArray = node.payload.parentNode[property.name] - if (nodePropertyArray !== undefined) { - for (let j = 0; j < nodePropertyArray.length; j++) { - let arrayItem = nodePropertyArray[j] - if (arrayItem.id === node.id) { - nodePropertyArray.splice(j, 1) - } - } - } - } - break - } - } - } - } - } - } - completeDetachment(node, rootNodes) - } - } - } - } - - function chainAttachNode(node, attachToNode, rootNodes) { - switch (node.type) { - - case 'Exchange Account Key': { - node.payload.parentNode = attachToNode - node.payload.chainParent = attachToNode - if (node.payload.parentNode.keys !== undefined) { - node.payload.parentNode.keys.push(node) - } else { - node.payload.parentNode.key = node - } - completeAttachment(node, rootNodes) - } - 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) - completeAttachment(node, rootNodes) - } - 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) - 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) { - 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 '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) - completeAttachment(node, rootNodes) - } 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) - completeAttachment(node, rootNodes) - return - } - } - } - } - } - } - break - default: { - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - node.payload.parentNode = attachToNode - node.payload.chainParent = attachToNode - /* Attach to new parent */ - if (node.payload.parentNode !== undefined) { - let parentNodeDefinition = getNodeDefinition(node.payload.parentNode) - if (parentNodeDefinition !== undefined) { - if (parentNodeDefinition.properties !== undefined) { - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (nodeDefinition.propertyNameAtParent === property.name) { - switch (property.type) { - case 'node': { - node.payload.parentNode[property.name] = node - } - break - case 'array': { - if (node.payload.parentNode[property.name] === undefined) { - node.payload.parentNode[property.name] = [] - } - let nodePropertyArray = node.payload.parentNode[property.name] - nodePropertyArray.push(node) - } - break - } - } - } - } - } - } - completeAttachment(node, rootNodes) - } - } - } - } - - function completeDetachment(node, rootNodes) { - node.payload.parentNode = undefined - node.payload.chainParent = undefined - rootNodes.push(node) - } - - function completeAttachment(node, rootNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.id === node.id) { - rootNodes.splice(i, 1) - return - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/ChartingSpaceFunctions.js b/DesignSpace/Workspace/FunctionLibraries/ChartingSpaceFunctions.js deleted file mode 100644 index d549a98da..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/ChartingSpaceFunctions.js +++ /dev/null @@ -1,247 +0,0 @@ -function newChartingSpaceFunctions() { - thisObject = { - addAllMineLayers: addAllMineLayers, - addMissingDashboards: addMissingDashboards, - addMissingTimeMachines: addMissingTimeMachines, - createTimeMachine: createTimeMachine - } - - return thisObject - - function addAllMineLayers(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - - /* Validations to see if we can do this or not. */ - if (node.payload === undefined) { return } - if (node.payload.uiObject === undefined) { return } - if (node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - if (node.payload.referenceParent.payload === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - - /* - We are going to go through the referenced branch and recreate the structure - we find there inside the layers manager. We will end up having at the end - all layers referencing the data products inside the referenced branch. - */ - let dataMine = node.payload.referenceParent - scanBotArray(dataMine.botProducts) - - function scanBotArray(botArray) { - for (let i = 0; i < botArray.length; i++) { - let bot = botArray[i] - let botLayers = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Bot Layers') - botLayers.name = bot.name - - asymetricalFolderStructureCloning( - bot, - botLayers, - 'dataProducts', - 'dataProductFolders', - 'layerFolders', - 'Layer', - 'Layer Folder', - undefined, - functionLibraryUiObjectsFromNodes - ) - /* - There are some layers that should not exist, for example the ones related to Data Products - that do not have a plotter module. Since our previous action created all layers no matter - what, we need now to delete all the ones that do not have a plotter module. - */ - let allLayers = nodeBranchToArray(botLayers, 'Layer') - for (let j = 0; j < allLayers.length; j++) { - let layer = allLayers[j] - layer.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45 - - let plotterModule = findNodeInNodeMesh(layer, 'Plotter Module', undefined, true, false, false, true) - if (plotterModule === undefined) { - functionLibraryNodeDeleter.deleteUIObject(layer, rootNodes) - } - } - } - } - } - - function addMissingTimeMachines(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - if (node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('This node needs to have a Reference Parent for this command tu run.') - return - } - - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Network') { - let networkNode = rootNode - scanNetworkNode(networkNode) - } - } - - function scanNetworkNode(networkNode) { - if (networkNode === undefined) { return } - - let backtestingSessionsArray = nodeBranchToArray(networkNode, 'Backtesting Session') - let fordwardTestingSessionsArray = nodeBranchToArray(networkNode, 'Forward Testing Session') - let paperTradingSessionsArray = nodeBranchToArray(networkNode, 'Paper Trading Session') - let liveTradingSessionsArray = nodeBranchToArray(networkNode, 'Live Trading Session') - - scanSessionArray(backtestingSessionsArray) - scanSessionArray(fordwardTestingSessionsArray) - scanSessionArray(paperTradingSessionsArray) - scanSessionArray(liveTradingSessionsArray) - - function scanSessionArray(sessionsArray) { - for (let i = 0; i < sessionsArray.length; i++) { - let session = sessionsArray[i] - let environment = findNodeInNodeMesh(session, node.payload.referenceParent.type, undefined, true, false, true, false) - if (environment === undefined) { continue } - if (environment.id !== node.payload.referenceParent.id) { continue } - let market = findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false) - if (market.payload.referenceParent === undefined) { continue } - if (isMissingChildren(node, session, true) === true) { - createTimeMachine(node, session, market.payload.referenceParent, networkNode, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - } - } - } - } - - function createTimeMachine(dashboard, session, market, networkNode, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - let mineProducts - let timeMachine = functionLibraryUiObjectsFromNodes.addUIObject(dashboard, 'Time Machine') - timeMachine.payload.referenceParent = session - timeMachine.name = session.name + ' ' + session.type + ' ' + networkNode.name - timeMachine.payload.floatingObject.collapseToggle() - timeMachine.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - timeMachine.timeFrameScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - timeMachine.timeScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - timeMachine.rateScale.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - /* - We need to create a Timeline Chart for each Data Mine Indicators. - */ - mineProducts = nodeBranchToArray(networkNode, 'Data Mine Products') - for (let j = 0; j < mineProducts.length; j++) { - let mineProduct = mineProducts[j] - /* - We need to filter out the ones that do not belong to the market where - the session is running at. - */ - if (mineProduct.payload.parentNode.payload.referenceParent === undefined) { continue } - if (mineProduct.payload.parentNode.payload.referenceParent.id !== market.id) { continue } - - let timelineChart = functionLibraryUiObjectsFromNodes.addUIObject(timeMachine, 'Timeline Chart') - /* - The Mine Product Node might be collapesd and since its creation it never - received the physics call, so we will do the call so that it properly - sets its own name, which we are going to reuse here. - */ - mineProduct.payload.uiObject.invisiblePhysics() - timelineChart.name = mineProduct.name - timelineChart.layerManager.payload.referenceParent = mineProduct - timelineChart.payload.floatingObject.collapseToggle() - timelineChart.layerManager.payload.floatingObject.collapseToggle() - timelineChart.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - timelineChart.layerManager.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - - let menu = timelineChart.layerManager.payload.uiObject.menu - menu.internalClick('Add All Mine Layers') - menu.internalClick('Add All Mine Layers') - } - - mineProducts = nodeBranchToArray(networkNode, 'Trading Mine Products') - for (let j = 0; j < mineProducts.length; j++) { - let mineProduct = mineProducts[j] - /* - The mine products found so far, belongs to any session. To filer all the sessions - that are not the one we are interested in, we do the following: - */ - if (mineProduct.payload.parentNode === undefined) { continue } - if (mineProduct.payload.parentNode.payload.referenceParent.id !== session.id) { continue } - /* - At the current version of Superalgos, beta 6, there is only one Trading Mine, - with only one bot, and it has so many data products that we want to put them - in 3 different timeline charts. So we will create 3 charts, connect them, - and delete from each one 1/3 of the layers. We do all that next: - */ - - for (let k = 0; k < 3; k++) { - let timelineChart = functionLibraryUiObjectsFromNodes.addUIObject(timeMachine, 'Timeline Chart') - - timelineChart.layerManager.payload.referenceParent = mineProduct - timelineChart.payload.floatingObject.collapseToggle() - timelineChart.layerManager.payload.floatingObject.collapseToggle() - timelineChart.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - timelineChart.layerManager.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - - let menu = timelineChart.layerManager.payload.uiObject.menu - menu.internalClick('Add All Mine Layers') - menu.internalClick('Add All Mine Layers') - - switch (k) { - case 0: { - timelineChart.name = 'Trading Engine' - deleteNodeByName('Trading System') - deleteNodeByName('Simulation Objects') - break - } - case 1: { - timelineChart.name = 'Trading System' - deleteNodeByName('Trading Engine') - deleteNodeByName('Simulation Objects') - break - } - case 2: { - timelineChart.name = 'Simulation Objects' - deleteNodeByName('Trading Engine') - deleteNodeByName('Trading System') - break - } - } - function deleteNodeByName(nodeName) { - let nodeToDelete = findNodeInNodeMesh(timelineChart.layerManager, undefined, nodeName, true, true, false, false) - if (nodeToDelete === undefined) { return } - functionLibraryNodeDeleter.deleteUIObject(nodeToDelete, rootNodes) - } - } - } - } - - function addMissingDashboards(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Network') { - let network = rootNode - scanNetwork(network) - } - } - - function scanNetwork(network) { - if (network === undefined) { return } - - for (let j = 0; j < network.networkNodes.length; j++) { - let networkNode = network.networkNodes[j] - scanNetworkNode(networkNode) - } - - function scanNetworkNode(networkNode) { - let testingEnvironment = findInBranch(networkNode, 'Testing Environment', node, true) - let productionEnvironment = findInBranch(networkNode, 'Production Environment', node, true) - - if (isMissingChildren(node, testingEnvironment, true) === true) { - let dashboard = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Dashboard') - dashboard.payload.referenceParent = testingEnvironment - dashboard.name = testingEnvironment.type + ' ' + networkNode.name - } - - if (isMissingChildren(node, productionEnvironment, true) === true) { - let dashboard = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Dashboard') - dashboard.payload.referenceParent = productionEnvironment - dashboard.name = productionEnvironment.type + ' ' + networkNode.name - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js b/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js deleted file mode 100644 index c664577ee..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js +++ /dev/null @@ -1,460 +0,0 @@ -function newCryptoEcosystemFunctions() { - thisObject = { - addMissingExchanges: addMissingExchanges, - addMissingAssets: addMissingAssets, - addMissingMarkets: addMissingMarkets, - installMarket: installMarket, - uninstallMarket: uninstallMarket - } - - return thisObject - - function addMissingExchanges(node, functionLibraryUiObjectsFromNodes) { - currentExchanges = new Map() - let parent = node.payload.parentNode - if (parent !== undefined) { - for (let i = 0; i < parent.cryptoExchanges.length; i++) { - let cryptoExchanges = parent.cryptoExchanges[i] - for (let j = 0; j < cryptoExchanges.exchanges.length; j++) { - let exchange = cryptoExchanges.exchanges[j] - let codeName = loadPropertyFromNodeConfig(exchange.payload, 'codeName') - currentExchanges.set(codeName, exchange) - } - } - } - - let params = { - method: 'listExchanges', - has: { - fetchOHLCV: true, - fetchMarkets: true - } - } - - callWebServer(JSON.stringify(params), 'CCXT', onResponse) - - function onResponse(err, data) { - if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') - return - } - - let exchanges = JSON.parse(data) - for (let i = 0; i < exchanges.length; i++) { - let exchange = exchanges[i] - let existingExchange = currentExchanges.get(exchange.id) - if (existingExchange === undefined) { - let newExchange = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Crypto Exchange') - newExchange.name = exchange.name - newExchange.config = '{ \n\"codeName\": \"' + exchange.id + '\"\n}' - newExchange.payload.floatingObject.collapseToggle() - newExchange.exchangeAssets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeMarkets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeAccounts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeAssets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_050X - newExchange.exchangeMarkets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X - newExchange.exchangeAccounts.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_025X - newExchange.exchangeAssets.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - newExchange.exchangeMarkets.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - newExchange.exchangeAccounts.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - } - } - } - } - - function addMissingAssets(node, functionLibraryUiObjectsFromNodes) { - if (node.payload.parentNode === undefined) { return } - - let currentAssets = new Map() - for (let j = 0; j < node.assets.length; j++) { - let asset = node.assets[j] - let codeName = loadPropertyFromNodeConfig(asset.payload, 'codeName') - currentAssets.set(codeName, asset) - } - - let exchangeId = loadPropertyFromNodeConfig(node.payload.parentNode.payload, 'codeName') - - try { - let params = { - exchangeId: exchangeId, - method: 'fetchMarkets' - } - callWebServer(JSON.stringify(params), 'CCXT', onResponse) - - function onResponse(err, data) { - if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') - return - } - let queryParams = loadPropertyFromNodeConfig(node.payload, 'addMissingAssetsFilter') - - let markets = JSON.parse(data) - for (let i = 0; i < markets.length; i++) { - let market = markets[i] - - if (queryParams !== undefined) { - if (queryParams.baseAsset !== undefined) { - if (market.base.indexOf(queryParams.baseAsset) < 0) { - continue - } - } - if (queryParams.quotedAsset !== undefined) { - if (market.quote.indexOf(queryParams.quotedAsset) < 0) { - continue - } - } - } - if (currentAssets.get(market.base) === undefined) { - addAsset(market.base) - currentAssets.set(market.base, market.base) - } - if (currentAssets.get(market.quote) === undefined) { - addAsset(market.quote) - currentAssets.set(market.quote, market.quote) - } - - function addAsset(name) { - let newAsseet = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Asset') - newAsseet.name = name - newAsseet.config = '{ \n\"codeName\": \"' + name + '\"\n}' - } - } - } - } catch (err) { - node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') - console.log(err.stack) - } - } - - function addMissingMarkets(node, functionLibraryUiObjectsFromNodes, functionLibraryNodeCloning) { - if (node.payload.parentNode === undefined) { return } - if (node.payload.parentNode.exchangeAssets === undefined) { return } - if (node.payload.parentNode.payload.parentNode === undefined) { return } - if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { return } - - let currentAssets = new Map() - let exchangeAssets = node.payload.parentNode.exchangeAssets - for (let j = 0; j < exchangeAssets.assets.length; j++) { - let asset = exchangeAssets.assets[j] - let codeName = loadPropertyFromNodeConfig(asset.payload, 'codeName') - currentAssets.set(codeName, asset) - } - - let currentMarkets = new Map() - let exchangeMarkets = node - for (let j = 0; j < exchangeMarkets.markets.length; j++) { - let asset = exchangeMarkets.markets[j] - let codeName = loadPropertyFromNodeConfig(asset.payload, 'codeName') - currentMarkets.set(codeName, asset) - } - - let exchangeId = loadPropertyFromNodeConfig(node.payload.parentNode.payload, 'codeName') - - try { - let params = { - exchangeId: exchangeId, - method: 'fetchMarkets' - } - callWebServer(JSON.stringify(params), 'CCXT', onResponse) - - function onResponse(err, data) { - if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') - return - } - - let markets = JSON.parse(data) - for (let i = 0; i < markets.length; i++) { - let market = markets[i] - let baseAsset = currentAssets.get(market.base) - let quotedAsset = currentAssets.get(market.quote) - - if (baseAsset === undefined) { - continue - } - if (quotedAsset === undefined) { - continue - } - - if (currentMarkets.get(market.symbol) === undefined) { - addMarket(market.symbol, baseAsset, quotedAsset) - } - - function addMarket(name, baseAsset, quotedAsset) { - let newMarket = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Market') - newMarket.name = name - newMarket.config = '{ \n\"codeName\": \"' + name + '\"\n}' - newMarket.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newMarket.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X - newMarket.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - newMarket.baseAsset.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45 - newMarket.quotedAsset.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_45 - newMarket.baseAsset.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X - newMarket.quotedAsset.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X - newMarket.baseAsset.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - newMarket.quotedAsset.payload.floatingObject.arrangementStyle = ARRANGEMENT_STYLE.CONCAVE - newMarket.baseAsset.payload.referenceParent = baseAsset - newMarket.quotedAsset.payload.referenceParent = quotedAsset - - currentMarkets.set(name, newMarket) - } - } - } - } catch (err) { - node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') - console.log(err.stack) - } - } - - function installMarket(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter, functionLibraryChartingSpaceFunctions, functionLibraryDataStorageFunctions) { - - let market = node - let cryptoExchange = findNodeInNodeMesh(node, 'Crypto Exchange', undefined, true, false, true, false) - if (cryptoExchange === undefined) { - node.payload.uiObject.setErrorMessage('Market must be a descendant of a Crypto Exchange') - return - } - let dashboardsArray = [] - - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Network') { - installInNetwork(rootNode) - } - } - - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Charting Space') { - installInChartingSpace(rootNode) - } - } - - function installInNetwork(network) { - - for (let j = 0; j < network.networkNodes.length; j++) { - let networkNode = network.networkNodes[j] - installInNetworkNode(networkNode) - } - - function installInNetworkNode(networkNode) { - /* - Here we complete the missing stuff at Data Mining - */ - let dataMining = findInBranch(networkNode, 'Data Mining', node, true) - if (dataMining === undefined) { - node.payload.uiObject.setErrorMessage('Data Mining node not found at Network Node ' + networkNode.name) - return - } - - let exchangeDataTasks = findOrCreateChildWithReference(dataMining, 'Exchange Data Tasks', cryptoExchange, functionLibraryUiObjectsFromNodes) - exchangeDataTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - let marketDataTask = findAndRecreateChildWithReference(exchangeDataTasks, 'Market Data Tasks', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - - menuClick(marketDataTask, 'Add Missing Data Mine Tasks', true) - menuClickOfNodeArray(marketDataTask.dataMineTasks, 'Add All Tasks', true) - - let sessionsCreatedArray = [] - /* - Next we complete the missing stuff at Testing Environment - */ - installEnvironment('Testing Environment') - /* - Next we complete the missing stuff at Production Environment - */ - installEnvironment('Production Environment') - - function installEnvironment(environment) { - /* - Now we install the environmnet at the current Network Node - */ - let environmentFound = findInBranch(networkNode, environment, node, true) - if (environmentFound === undefined) { - node.payload.uiObject.setErrorMessage(environment + ' node not found at Network Node ' + networkNode.name) - return - } - - let exchangeTradingTasks = findOrCreateChildWithReference(environmentFound, 'Exchange Trading Tasks', cryptoExchange, functionLibraryUiObjectsFromNodes) - exchangeTradingTasks.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - let marketTradingTask = findAndRecreateChildWithReference(exchangeTradingTasks, 'Market Trading Tasks', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - - menuClick(marketTradingTask, 'Add Missing Trading Mine Tasks', true) - menuClickOfNodeArray(marketTradingTask.tradingMineTasks, 'Add All Tasks', true) - - /* This will be needed at the charging space, for creating Dashboards */ - let backtestingSessionsArray = nodeBranchToArray(marketTradingTask, 'Backtesting Session') - let liveTradingSessionsArray = nodeBranchToArray(marketTradingTask, 'Live Trading Session') - let allSessionsArray = backtestingSessionsArray.concat(liveTradingSessionsArray) - sessionsCreatedArray = sessionsCreatedArray.concat(allSessionsArray) - - dashboardsArray.push({ environmentNode: environmentFound, networkNode: networkNode, sessionsArray: allSessionsArray }) - } - /* - Here we complete the missing stuff at Data Mines Data - */ - let dataMinesData = findInBranch(networkNode, 'Data Mines Data', node, true) - if (dataMinesData === undefined) { - node.payload.uiObject.setErrorMessage('Data Mines Data node not found at Network Node ' + networkNode.name) - return - } - - let exchangeDataProducts = findOrCreateChildWithReference(dataMinesData, 'Exchange Data Products', cryptoExchange, functionLibraryUiObjectsFromNodes) - exchangeDataProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - let marketDataProducts = findAndRecreateChildWithReference(exchangeDataProducts, 'Market Data Products', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - marketDataProducts.payload.floatingObject.collapseToggle() - - menuClick(marketDataProducts, 'Add All Data Mine Products', true) - menuClickOfNodeArray(marketDataProducts.dataMineProducts, 'Add All Data Products', true) - /* - Finally we complete the missing stuff at Trading Mines Data - */ - let tradingMinesData = findInBranch(networkNode, 'Trading Mines Data', node, true) - if (tradingMinesData === undefined) { - node.payload.uiObject.setErrorMessage('Trading Mines Data node not found at Network Node ' + networkNode.name) - return - } - - let exchangeTradingProducts = findOrCreateChildWithReference(tradingMinesData, 'Exchange Trading Products', cryptoExchange, functionLibraryUiObjectsFromNodes) - exchangeTradingProducts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - let marketTradingProducts = findAndRecreateChildWithReference(exchangeTradingProducts, 'Market Trading Products', market, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - marketTradingProducts.payload.floatingObject.collapseToggle() - /* - Create the new session references. - */ - for (let i = 0; i < sessionsCreatedArray.length; i++) { - let session = sessionsCreatedArray[i] - if (isMissingChildren(marketTradingProducts, session, true) === true) { - functionLibraryDataStorageFunctions.createSessionReference(marketTradingProducts, session, functionLibraryUiObjectsFromNodes) - } - } - /* - Create everything inside the session references. - */ - for (let j = 0; j < marketTradingProducts.sessionReferences.length; j++) { - let sessionReference = marketTradingProducts.sessionReferences[j] - menuClick(sessionReference, 'Add All Trading Mine Products', true) - menuClickOfNodeArray(sessionReference.tradingMineProducts, 'Add All Data Products', true) - sessionReference.payload.floatingObject.collapseToggle() - } - } - } - - function installInChartingSpace(chartingSpace) { - - for (let i = 0; i < dashboardsArray.length; i++) { - /* - If the Dashboard we need is not already there we create a new one. - */ - let arrayItem = dashboardsArray[i] - let dashboard = findOrCreateChildWithReference(chartingSpace, 'Dashboard', arrayItem.environmentNode, functionLibraryUiObjectsFromNodes) - dashboard.name = arrayItem.environmentNode.type + ' ' + arrayItem.networkNode.name - /* - We delete all the existing Time Machines related to the market we are currently installing. - For that, we make a new array with the existing Time Machines so that the deleting - of each node does not affect the proccessing of the whole set. - */ - let timeMachines = [] - for (let i = 0; i < dashboard.timeMachines.length; i++) { - let timeMachine = dashboard.timeMachines[i] - timeMachines.push(timeMachine) - } - for (let i = 0; i < timeMachines.length; i++) { - let timeMachine = timeMachines[i] - let session = timeMachine.payload.referenceParent - if (session === undefined || session.cleaned === true) { - /* - This is what usually happens, that the intall process make these - time machines to lose their reference parent since the install - process deletes them. - */ - functionLibraryNodeDeleter.deleteUIObject(timeMachine, rootNodes) - continue - } - let marketTradingTasks = findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false) - if (marketTradingTasks === undefined) { continue } - if (marketTradingTasks.payload === undefined) { continue } - if (marketTradingTasks.payload.referenceParent === undefined) { continue } - if (marketTradingTasks.payload.referenceParent.id === market.id) { - functionLibraryNodeDeleter.deleteUIObject(timeMachine, rootNodes) - } - } - /* - We create a time machine for each session added during the previous processing. - */ - for (let j = 0; j < arrayItem.sessionsArray.length; j++) { - let session = arrayItem.sessionsArray[j] - functionLibraryChartingSpaceFunctions.createTimeMachine(dashboard, session, node, arrayItem.networkNode, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - } - } - } - - function uninstallMarket(node, rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter, functionLibraryChartingSpaceFunctions, functionLibraryDataStorageFunctions) { - let market = node - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Charting Space') { - uninstallInChartingSpace(rootNode) - } - } - - function uninstallInChartingSpace(chartingSpace) { - - /* Delete all time machines which are referencing sessions inside the market being unistalled. */ - let timeMachines = nodeBranchToArray(chartingSpace, 'Time Machine') - for (let i = 0; i < timeMachines.length; i++) { - let timeMachine = timeMachines[i] - let session = timeMachine.payload.referenceParent - if (session === undefined) { continue } - let marketTradingTasks = findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false) - if (marketTradingTasks === undefined) { continue } - if (marketTradingTasks.payload === undefined) { continue } - if (marketTradingTasks.payload.referenceParent === undefined) { continue } - if (marketTradingTasks.payload.referenceParent.id === market.id) { - functionLibraryNodeDeleter.deleteUIObject(timeMachine, rootNodes) - } - } - - /* Delete all Dashboards that does not have time machines inside. */ - let dashboardArray = nodeBranchToArray(chartingSpace, 'Dashboard') - for (let i = 0; i < dashboardArray.length; i++) { - let dashboard = dashboardArray[i] - if (dashboard.timeMachines.length === 0) { - functionLibraryNodeDeleter.deleteUIObject(dashboard, rootNodes) - } - } - - /* Scan Networks for the market being unistalled to delete it. */ - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Network') { - uninstallInNetwork(rootNode) - } - } - } - - function uninstallInNetwork(network) { - - let marketDataTasksArray = nodeBranchToArray(network, 'Market Data Tasks') - let marketTradingTasksArray = nodeBranchToArray(network, 'Market Trading Tasks') - let marketDataProductsArray = nodeBranchToArray(network, 'Market Data Products') - let marketTradingProductsArray = nodeBranchToArray(network, 'Market Trading Products') - - uninstalMarketArray(marketDataTasksArray) - uninstalMarketArray(marketTradingTasksArray) - uninstalMarketArray(marketDataProductsArray) - uninstalMarketArray(marketTradingProductsArray) - - function uninstalMarketArray(marketArray) { - for (let i = 0; i < marketArray.length; i++) { - let marketReference = marketArray[i] - if (marketReference.payload === undefined) { continue } - if (marketReference.payload.referenceParent === undefined) { continue } - if (marketReference.payload.referenceParent.id === market.id) { - functionLibraryNodeDeleter.deleteUIObject(marketReference, rootNodes) - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/DataMineFunctions.js b/DesignSpace/Workspace/FunctionLibraries/DataMineFunctions.js deleted file mode 100644 index 13fae905b..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/DataMineFunctions.js +++ /dev/null @@ -1,103 +0,0 @@ -function newDataMineFunctions() { - thisObject = { - addAllOutputDatasets: addAllOutputDatasets, - addAllDataDependencies: addAllDataDependencies, - addAllDataMineDataDependencies: addAllDataMineDataDependencies - } - - return thisObject - - function addAllOutputDatasets(node, functionLibraryUiObjectsFromNodes) { - - /* Validations to see if we can do this or not. */ - if (node.payload === undefined) { return } - if (node.payload.uiObject === undefined) { return } - if (node.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a parent node to execute this action.') - return - } - if (node.payload.parentNode.payload === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a parent node to execute this action.') - return - } - if (node.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a grand parent node to execute this action.') - return - } - - /* - Next, we are going to scan recursively through all nodes of type Product Definition Folder - and Product Definition. For each Product Definition Folder we will create a counterpart - Output Dataset Folder, and for each Product Definition found we will create a Output Definition - for each Dataset defined inside the Product Definition. - */ - asymetricalFolderStructureCloning( - node.payload.parentNode.payload.parentNode, - node, - 'products', - 'productDefinitionFolders', - 'outputDatasetFolders', - 'Output Dataset', - 'Output Dataset Folder', - 'datasets', - functionLibraryUiObjectsFromNodes - ) - } - - function addAllDataDependencies(node, functionLibraryUiObjectsFromNodes) { - - /* Validations to see if we can do this or not. */ - if (node.payload === undefined) { return } - if (node.payload.uiObject === undefined) { return } - if (node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - if (node.payload.referenceParent.payload === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - - /* - Next, we are going to scan through all the bots of the Data Mine referenced, and for each bot we will - create a Bots Data Dependency node. Later we will scan all the Products Definitions of each bot, and for each - Dataset of each Product we will create a Data Dependency. In case we find Product Definition Folders, we will - recreate that structure too, using in this case Data Dependency Folders. - */ - let dataMine = node.payload.referenceParent - scanBotArray(dataMine.sensorBots) - scanBotArray(dataMine.indicatorBots) - scanBotArray(dataMine.tradingBots) - - function scanBotArray(botArray) { - for (let i = 0; i < botArray.length; i++) { - let bot = botArray[i] - let botProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Bot Data Dependencies') - botProducts.name = bot.name - - asymetricalFolderStructureCloning( - bot, - botProducts, - 'products', - 'productDefinitionFolders', - 'dataDependencyFolders', - 'Data Dependency', - 'Data Dependency Folder', - 'datasets', - functionLibraryUiObjectsFromNodes - ) - } - } - } - - function addAllDataMineDataDependencies(node, rootNodes, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - - if (rootNode.type === 'Data Mine') { - let dataMineDataDependencies = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Data Mine Data Dependencies') - dataMineDataDependencies.payload.referenceParent = rootNode - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js b/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js deleted file mode 100644 index 3eb4e3822..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/DataStorageFunctions.js +++ /dev/null @@ -1,167 +0,0 @@ -function newDataStorageFunctions() { - thisObject = { - addAllDataProducts: addAllDataProducts, - addAllDataMineProducts: addAllDataMineProducts, - addAllTradingMineProducts: addAllTradingMineProducts, - addMissingSessionReferences: addMissingSessionReferences, - addMissingMarketDataProducts: addMissingMarketDataProducts, - addMissingMarketTradingProducts: addMissingMarketTradingProducts, - addMissingExchangeTradingProducts: addMissingExchangeTradingProducts, - addMissingExchangeDataProducts: addMissingExchangeDataProducts, - createSessionReference: createSessionReference - } - - return thisObject - - function addAllDataProducts(node, functionLibraryUiObjectsFromNodes) { - - /* Validations to see if we can do this or not. */ - if (node.payload === undefined) { return } - if (node.payload.uiObject === undefined) { return } - if (node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - if (node.payload.referenceParent.payload === undefined) { - node.payload.uiObject.setErrorMessage('You need to have a reference parent node to execute this action.') - return - } - - /* - Next, we are going to scan through all the bots of the Data Mine referenced, and for each bot we will - create a Bots Products node. Later we will scan all the Products Definitions of each bot, and for each one - we will create a Data Product. In case we find Product Definition Folders, we will recreate that structure - too, using in this case Data Product Folders. - */ - let mine = node.payload.referenceParent - scanBotArray(mine.sensorBots) - scanBotArray(mine.indicatorBots) - scanBotArray(mine.tradingBots) - - function scanBotArray(botArray) { - if (botArray === undefined) { return } - - for (let i = 0; i < botArray.length; i++) { - let bot = botArray[i] - let botProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Bot Products') - botProducts.name = bot.name - botProducts.payload.floatingObject.collapseToggle() - - asymetricalFolderStructureCloning( - bot, - botProducts, - 'products', - 'productDefinitionFolders', - 'dataProductFolders', - 'Data Product', - 'Data Product Folder', - undefined, - functionLibraryUiObjectsFromNodes - ) - } - } - } - - function addAllDataMineProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - - if (rootNode.type === 'Data Mine') { - let dataMineProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Data Mine Products') - dataMineProducts.payload.referenceParent = rootNode - } - } - } - - function addAllTradingMineProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - - if (rootNode.type === 'Trading Mine') { - let tradingMineProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Trading Mine Products') - tradingMineProducts.payload.referenceParent = rootNode - } - } - } - - function addMissingSessionReferences(node, rootNodes, functionLibraryUiObjectsFromNodes) { - let networkNode = findNodeInNodeMesh(node, 'Network Node', undefined, true, false, true, false) - if (networkNode === undefined) { return } - - let backtestingSessionsArray = nodeBranchToArray(networkNode, 'Backtesting Session') - let fordwardTestingSessionsArray = nodeBranchToArray(networkNode, 'Forward Testing Session') - let paperTradingSessionsArray = nodeBranchToArray(networkNode, 'Paper Trading Session') - let liveTradingSessionsArray = nodeBranchToArray(networkNode, 'Live Trading Session') - - addMissingSession(backtestingSessionsArray) - addMissingSession(fordwardTestingSessionsArray) - addMissingSession(paperTradingSessionsArray) - addMissingSession(liveTradingSessionsArray) - - function addMissingSession(sessionsArray) { - for (let i = 0; i < sessionsArray.length; i++) { - let session = sessionsArray[i] - /* We will filter out all the sessions that does not belong to the market we are in */ - let marketTradingTasks = findNodeInNodeMesh(session, 'Market Trading Tasks', undefined, true, false, true, false) - if (node.payload.referenceParent.id !== marketTradingTasks.payload.referenceParent.id) { continue } - if (isMissingChildren(node, session, true) === true) { - createSessionReference(node, session, functionLibraryUiObjectsFromNodes) - } - } - } - } - - function createSessionReference(node, session, functionLibraryUiObjectsFromNodes) { - let sessionReference = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Session Reference') - sessionReference.payload.referenceParent = session - } - - function addMissingMarketDataProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingMarketProducts(node, rootNodes, 'Market Data Products', functionLibraryUiObjectsFromNodes) - } - - function addMissingMarketTradingProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingMarketProducts(node, rootNodes, 'Market Trading Products', functionLibraryUiObjectsFromNodes) - } - - function addMissingMarketProducts(node, rootNodes, newNodeType, functionLibraryUiObjectsFromNodes) { - if (node.payload.referenceParent === undefined) { return } - if (node.payload.referenceParent.exchangeMarkets === undefined) { return } - let marketsArray = node.payload.referenceParent.exchangeMarkets.markets - - for (let i = 0; i < marketsArray.length; i++) { - let market = marketsArray[i] - if (isMissingChildren(node, market, true) === true) { - let marketDataProducts = functionLibraryUiObjectsFromNodes.addUIObject(node, newNodeType) - marketDataProducts.payload.referenceParent = market - } - } - } - - function addMissingExchangeTradingProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingExchange(node, rootNodes, 'Exchange Trading Products', functionLibraryUiObjectsFromNodes) - } - - function addMissingExchangeDataProducts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingExchange(node, rootNodes, 'Exchange Data Products', functionLibraryUiObjectsFromNodes) - } - - function addMissingExchange(node, rootNodes, newNodeType, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Crypto Ecosystem') { - let cryptoEcosystem = rootNode - for (let j = 0; j < cryptoEcosystem.cryptoExchanges.length; j++) { - let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j] - for (let k = 0; k < cryptoExchanges.exchanges.length; k++) { - let cryptoExchange = cryptoExchanges.exchanges[k] - if (isMissingChildren(node, cryptoExchange, true) === true) { - let exchange = functionLibraryUiObjectsFromNodes.addUIObject(node, newNodeType) - exchange.payload.referenceParent = cryptoExchange - } - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/DependenciesFilter.js b/DesignSpace/Workspace/FunctionLibraries/DependenciesFilter.js deleted file mode 100644 index 88b9eb45d..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/DependenciesFilter.js +++ /dev/null @@ -1,74 +0,0 @@ -function newDependenciesFilter() { - thisObject = { - createFilter: createFilter - } - - return thisObject - - function createFilter(node) { - let filters = new Map() - recursiveFilter(node) - - return Array.from(filters.keys()) - - function recursiveFilter(node) { - filter(node.code) - - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - recursiveFilter(node[property.name]) - } - previousPropertyName = property.name - } - } - break - case 'array': { - let nodePropertyArray = node[property.name] - if (nodePropertyArray !== undefined) { - for (let j = 0; j < nodePropertyArray.length; j++) { - let nodeProperty = nodePropertyArray[j] - recursiveFilter(nodeProperty) - } - } - } - break - } - } - } - } - } - - function filter(code) { - if (code === undefined) { return } - - let instructionsArray = code.split(' ') - for (let i = 0; i < instructionsArray.length; i++) { - let instruction = instructionsArray[i] - if (instruction.indexOf('chart') >= 0) { - let parts = instruction.split('.') - let timeFrame = parts[1] - let product = parts[2] - let productParts = product.split(',') - product = productParts[0] - productParts = product.split(')') - product = productParts[0] - - // Example: chart.at01hs.popularSMA.sma200 - chart.at01hs.popularSMA.sma100 < 10 - if (timeFrame !== 'atAnyTimeFrame') { - timeFrame = timeFrame.substring(2, 4) + '-' + timeFrame.substring(4, 7) - } - filters.set(timeFrame + '-' + product, true) - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/NodeChildren.js b/DesignSpace/Workspace/FunctionLibraries/NodeChildren.js deleted file mode 100644 index 30178d28f..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/NodeChildren.js +++ /dev/null @@ -1,67 +0,0 @@ -function newNodeChildren() { - thisObject = { - childrenCount: childrenCount - } - - return thisObject - - function childrenCount(parentNode, childNode) { - return countChildrenUiObject(parentNode, childNode) - } - - function countChildrenUiObject(parentNode, childNode) { - let response = { - childrenCount: 0, - childIndex: undefined - } - let parentNodeDefinition = getNodeDefinition(parentNode) - if (parentNodeDefinition !== undefined) { - if (parentNodeDefinition.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. - - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (parentNode[property.name] !== undefined) { - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - response.childrenCount++ - if (parentNode[property.name].id === childNode.id) { - response.childIndex = response.childrenCount - } - previousPropertyName = property.name - } - } - break - case 'array': { - let nodeDefinition = getNodeDefinition(childNode) - if (nodeDefinition !== undefined) { - let nodePropertyArray = parentNode[property.name] - for (let j = 0; j < nodePropertyArray.length; j++) { - let child = nodePropertyArray[j] - if (nodeDefinition.chainedToSameType === true) { - if (j < 1) { - response.childrenCount++ - if (child.id === childNode.id) { - response.childIndex = response.childrenCount - } - } - } else { - response.childrenCount++ - if (child.id === childNode.id) { - response.childIndex = response.childrenCount - } - } - } - } - } - break - } - } - } - } - } - - return response - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/NodeCloning.js b/DesignSpace/Workspace/FunctionLibraries/NodeCloning.js deleted file mode 100644 index 78d08b249..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/NodeCloning.js +++ /dev/null @@ -1,179 +0,0 @@ -function newNodeCloning() { - const MODULE_NAME = 'Node Cloning' - const ERROR_LOG = true - const logger = newWebDebugLog() - logger.fileName = MODULE_NAME - - thisObject = { - getNodeClone: getNodeClone - } - return thisObject - - function getNodeClone(node) { - let idConversionMap = new Map() - - let inmatureClone = cloneNode(node) - let matureClone = redirectReferenceParents(inmatureClone) - - return matureClone - - function cloneNode(node) { - if (node === undefined) { return } - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - let object = { - type: node.type, - name: node.name, - code: node.code, - config: node.config, - project: node.project - } - - /* Children Nodes */ - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - object[property.name] = cloneNode(node[property.name]) - } - previousPropertyName = property.name - } - break - } - case 'array': { - if (node[property.name] !== undefined) { - let nodePropertyArray = node[property.name] - object[property.name] = [] - for (let m = 0; m < nodePropertyArray.length; m++) { - let protocolNode = cloneNode(nodePropertyArray[m]) - if (protocolNode !== undefined) { - object[property.name].push(protocolNode) - } - } - } - break - } - } - } - } - - object.id = newUniqueId() - idConversionMap.set(node.id, object.id) - - object.savedPayload = getSavedPayload(node) - - return object - } - } - - function redirectReferenceParents(node) { - if (node === undefined) { return } - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - let object = { - type: node.type, - name: node.name, - code: node.code, - config: node.config, - project: node.project - } - - /* Children Nodes */ - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - object[property.name] = redirectReferenceParents(node[property.name]) - } - previousPropertyName = property.name - } - break - } - case 'array': { - if (node[property.name] !== undefined) { - let nodePropertyArray = node[property.name] - object[property.name] = [] - for (let m = 0; m < nodePropertyArray.length; m++) { - let protocolNode = redirectReferenceParents(nodePropertyArray[m]) - if (protocolNode !== undefined) { - object[property.name].push(protocolNode) - } - } - } - break - } - } - } - } - - object.id = node.id - - object.savedPayload = node.savedPayload - - if (object.savedPayload !== undefined) { - if (object.savedPayload.referenceParent !== undefined) { - let newId = idConversionMap.get(object.savedPayload.referenceParent.id) - if (newId !== undefined) { - object.savedPayload.referenceParent.id = newId - } - } - } - - return object - } - } - } - - function getSavedPayload(node) { - if (node.payload === undefined) { return } - let savedPayload = { - position: { - x: node.payload.position.x, - y: node.payload.position.y - }, - targetPosition: { - x: node.payload.targetPosition.x, - y: node.payload.targetPosition.y - }, - floatingObject: { - isPinned: node.payload.floatingObject.isPinned, - isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually), - isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually), - angleToParent: (node.payload.floatingObject.angleToParent), - distanceToParent: (node.payload.floatingObject.distanceToParent), - arrangementStyle: (node.payload.floatingObject.arrangementStyle) - }, - uiObject: { - isPlaying: node.payload.uiObject.isPlaying, - isRunning: node.payload.uiObject.isRunning, - shortcutKey: node.payload.uiObject.shortcutKey - } - } - - /* Next for the ones that have a reference parent, we include it */ - if (node.payload.referenceParent !== undefined) { - savedPayload.referenceParent = { - type: node.payload.referenceParent.type, - name: node.payload.referenceParent.name, - id: node.payload.referenceParent.id - } - } else { - /* The referenceParent property can be inherited from the previous saved payload. */ - if (node.savedPayload !== undefined) { - savedPayload.referenceParent = node.savedPayload.referenceParent - } - } - - return savedPayload - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/NodeDeleter.js b/DesignSpace/Workspace/FunctionLibraries/NodeDeleter.js deleted file mode 100644 index f02631561..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/NodeDeleter.js +++ /dev/null @@ -1,138 +0,0 @@ -function newNodeDeleter() { - thisObject = { - deleteWorkspace: deleteWorkspace, - deleteUIObject: deleteUIObject - } - - return thisObject - - function destroyUiObject(node) { - canvas.floatingSpace.uiObjectConstructor.destroyUiObject(node.payload) - } - - function deleteWorkspace(node, rootNodes) { - if (node.rootNodes !== undefined) { - while (node.rootNodes.length > 0) { - let rootNode = node.rootNodes[0] - deleteUIObject(rootNode, rootNodes) - } - } - - completeDeletion(node, rootNodes) - destroyUiObject(node) - cleanNode(node) - } - - function deleteUIObject(node, rootNodes) { - /* First we restore the reference parent to its default state */ - if (node.payload !== undefined && node.payload.referenceParent !== undefined && node.payload.referenceParent.payload !== undefined && node.payload.referenceParent.payload.uiObject !== undefined) { - node.payload.referenceParent.payload.uiObject.isShowing = false - } - - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - /* Remove all of its own children nodes. */ - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - deleteUIObject(node[property.name], rootNodes) - } - previousPropertyName = property.name - } - } - break - case 'array': { - let nodePropertyArray = node[property.name] - if (nodePropertyArray !== undefined) { - while (nodePropertyArray.length > 0) { - deleteUIObject(nodePropertyArray[0], rootNodes) - } - } - } - break - } - } - } - - /* Remove node from parent */ - if (node.payload !== undefined) { - if (node.payload.parentNode !== undefined) { - let parentNodeDefinition = getNodeDefinition(node.payload.parentNode) - if (parentNodeDefinition !== undefined) { - if (parentNodeDefinition.properties !== undefined) { - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (nodeDefinition.propertyNameAtParent === property.name) { - switch (property.type) { - case 'node': { - node.payload.parentNode[property.name] = undefined - } - break - case 'array': { - let nodePropertyArray = node.payload.parentNode[property.name] - if (nodePropertyArray !== undefined) { - for (let j = 0; j < nodePropertyArray.length; j++) { - let arrayItem = nodePropertyArray[j] - if (arrayItem.id === node.id) { - /* If this object is chained to the ones of the same type we need to give the next in the chain the reference to the current chain parent */ - if (nodeDefinition.chainedToSameType === true) { - if (j < nodePropertyArray.length - 1) { - let nextArrayItem = nodePropertyArray[j + 1] - nextArrayItem.payload.chainParent = node.payload.chainParent - } - } - - nodePropertyArray.splice(j, 1) - } - } - } - } - break - } - } - } - } - } - } - } - - completeDeletion(node, rootNodes) - destroyUiObject(node) - cleanNode(node) - } - } - - function completeDeletion(node, rootNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.id === node.id) { - rootNodes.splice(i, 1) - return - } - } - } - - function cleanNode(node) { - if (node === undefined) { return } - if (node.payload === undefined) { return } - - node.payload.targetPosition.x = undefined - node.payload.targetPosition.y = undefined - node.payload.visible = undefined - node.payload.subTitle = undefined - node.payload.title = 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 - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/NodePath.js b/DesignSpace/Workspace/FunctionLibraries/NodePath.js deleted file mode 100644 index 02dc6362c..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/NodePath.js +++ /dev/null @@ -1,56 +0,0 @@ -function newNodePath() { - thisObject = { - getNodePath: getNodePath - } - - return thisObject - - function getNodePath(node) { - - let nodePath = 'value' - - recursiveGet(node) - - return 'tradingEngine.' + nodePath - - function recursiveGet(node) { - - if (node.payload === undefined) { return } - if (node.payload.parentNode === undefined) { return } - - let nodeDefinition = getNodeDefinition(node.payload.parentNode) - if (nodeDefinition === undefined) { return } - if (nodeDefinition.properties === undefined) { return } - - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - let parentProperty = node.payload.parentNode[property.name] - if (parentProperty === undefined) { continue } - - switch (property.type) { - case 'node': { - if (parentProperty.id === node.id) { - /* We found it */ - nodePath = property.name + '.' + nodePath - recursiveGet(node.payload.parentNode) - } - } - break - case 'array': { - for (let j = 0; j < parentProperty.length; j++) { - let arrayProperty = parentProperty[j] - if (arrayProperty === undefined) {continue} - if (arrayProperty.id === node.id) { - /* We found it */ - nodePath = property.name + '[' + j + ']' + '.' + nodePath - recursiveGet(node.payload.parentNode) - } - } - } - break - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/OnFocus.js b/DesignSpace/Workspace/FunctionLibraries/OnFocus.js deleted file mode 100644 index bbbed3985..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/OnFocus.js +++ /dev/null @@ -1,55 +0,0 @@ -function newOnFocus() { - thisObject = { - getNodeThatIsOnFocus: getNodeThatIsOnFocus - } - return thisObject - - function getNodeThatIsOnFocus(node) { - if (node === undefined || node === null) { return } - if (node.payload === undefined) { return } - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - /* First we ask the question to ourself */ - if (node.payload.uiObject.isOnFocus === true) { - return node - } - - /* Then we check all of its own children nodes. */ - if (node.payload.floatingObject.isCollapsed !== true) { - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - let child = getNodeThatIsOnFocus(node[property.name]) - if (child !== undefined) { - return child - } - } - previousPropertyName = property.name - } - } - break - case 'array': { - let nodePropertyArray = node[property.name] - if (nodePropertyArray !== undefined) { - for (let m = 0; m < nodePropertyArray.length; m++) { - let child = getNodeThatIsOnFocus(nodePropertyArray[m]) - if (child !== undefined) { - return child - } - } - } - } - break - } - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js b/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js deleted file mode 100644 index 362bf28e2..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js +++ /dev/null @@ -1,101 +0,0 @@ -function newPluginsFunctions() { - thisObject = { - pluginMissingProjects: pluginMissingProjects, - pluginMissingDataMines: pluginMissingDataMines, - pluginMissingTradingMines: pluginMissingTradingMines, - pluginMissingTradingSystems: pluginMissingTradingSystems, - pluginMissingTradingEngines: pluginMissingTradingEngines, - pluginMissingSuperScripts: pluginMissingSuperScripts, - pluginMissingTutorials: pluginMissingTutorials - } - return thisObject - - function getPluginFileNames(pluginType, callBack) { - callWebServer(undefined, 'PluginFileNames/' + 'Superalgos' + '/' + pluginType, onResponse) - - function onResponse(err, data) { - if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - console.log('Failed to Fetch Plugin ' + pluginType + ' from the Backend') - return - } - - let pluginFileNames = JSON.parse(data) - callBack(pluginFileNames) - } - } - - function addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < fileNames.length; i++) { - let fileName = fileNames[i] - fileName = fileName.replace('.json', '') - if (isMissingChildrenByName(node, fileName) === true) { - let child = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Plugin File') - child.name = fileName - } - } - } - - function pluginMissingProjects(node, rootNodes, functionLibraryUiObjectsFromNodes) { - let url = 'ProjectNames' - callWebServer(undefined, url, onResponse) - - function onResponse(err, pProjects) { - let projects = JSON.parse(pProjects) - for (let i = 0; i < projects.length; i++) { - let project = projects[i] - if (isMissingChildrenByName(node, project) === true) { - let child = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Plugin Project') - child.name = project - } - } - } - } - - function pluginMissingDataMines(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Data-Mines', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } - - function pluginMissingTradingMines(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Trading-Mines', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } - - function pluginMissingTradingSystems(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Trading-Systems', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } - - function pluginMissingTradingEngines(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Trading-Engines', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } - - function pluginMissingSuperScripts(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Super-Scripts', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } - - function pluginMissingTutorials(node, rootNodes, functionLibraryUiObjectsFromNodes) { - getPluginFileNames('Tutorials', onNamesArrived) - - function onNamesArrived(fileNames) { - addPluginFileIfNeeded(node, fileNames, functionLibraryUiObjectsFromNodes) - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignSpace/Workspace/FunctionLibraries/ProtocolNode.js deleted file mode 100644 index a303b79c4..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ /dev/null @@ -1,207 +0,0 @@ -function newProtocolNode() { - const MODULE_NAME = 'Protocol Node' - const ERROR_LOG = true - const logger = newWebDebugLog() - logger.fileName = MODULE_NAME - - thisObject = { - getProtocolNode: getProtocolNode - } - return thisObject - - function getProtocolNode(node, removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, lightingPath) { - if (node === undefined) { return } - if (node.payload === undefined) { return } - - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - if (removePersonalData === true && nodeDefinition.isPersonalData === true) { return } - let object = { - type: node.type, - name: node.name, - code: node.code, - config: node.config, - project: node.project - } - - /* Children Nodes */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (node[property.name] !== undefined) { - if (lightingPath === undefined) { - object[property.name] = getProtocolNode(node[property.name], removePersonalData, parseConfig, includeIds, includeReferencesInSavedPayload, includePayload) - } else { - let newLightingPath = getNewLightingPath(lightingPath, node.type, property.childType) - if (newLightingPath !== undefined) { - object[property.name] = getProtocolNode(node[property.name], removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, newLightingPath) - } - } - } - break - } - case 'array': { - if (node[property.name] !== undefined) { - if (lightingPath === undefined) { - let nodePropertyArray = node[property.name] - object[property.name] = [] - for (let m = 0; m < nodePropertyArray.length; m++) { - let protocolNode = getProtocolNode(nodePropertyArray[m], removePersonalData, parseConfig, includeIds, includeReferencesInSavedPayload, includePayload) - if (protocolNode !== undefined) { - object[property.name].push(protocolNode) - } - } - } else { - let newLightingPath = getNewLightingPath(lightingPath, node.type, property.childType) - if (newLightingPath !== undefined) { - let nodePropertyArray = node[property.name] - object[property.name] = [] - for (let m = 0; m < nodePropertyArray.length; m++) { - let protocolNode = getProtocolNode(nodePropertyArray[m], removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, newLightingPath) - if (protocolNode !== undefined) { - object[property.name].push(protocolNode) - } - } - } - } - } - break - } - } - } - } - - /* Parent Nodes */ - if (node.payload.parentNode !== undefined) { - let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.parentNode.type) - if (newLightingPath !== undefined) { - object.parentNode = getProtocolNode(node.payload.parentNode, removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, newLightingPath) - } else { - let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.parentNode.type) - } - } - if (node.payload.referenceParent !== undefined) { - let newLightingPath = getNewLightingPath(lightingPath, node.type, node.payload.referenceParent.type) - if (newLightingPath !== undefined) { - object.referenceParent = getProtocolNode(node.payload.referenceParent, removePersonalData, parseConfig, includeIds, includePayload, includeReferencesInSavedPayload, newLightingPath) - } - } - - if (parseConfig && object.config !== undefined && nodeDefinition.editors !== undefined) { - if (nodeDefinition.editors.config === true) { - try { - object.config = JSON.parse(node.config) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> err = ' + err.stack) } - if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.type = ' + node.type) } - if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.name = ' + node.name) } - if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.config = ' + node.config) } - if (ERROR_LOG === true) { logger.write('[ERROR] getProtocolNode -> default -> node.id = ' + node.id) } - } - } - } - - if (includeIds) { - object.id = node.id - } - if (includePayload) { - object.savedPayload = getSavedPayload(node, includeReferencesInSavedPayload) - } - - return object - } - } - - function getNewLightingPath(lightingPath, currentNodeType, nextNodeType) { - if (lightingPath === undefined) { return } - - if (currentNodeType === undefined) { return } - if (nextNodeType === undefined) { return } - - let currentNodePosition = lightingPath.indexOf('->' + currentNodeType + '->') - let nextNodePosition = lightingPath.indexOf('->' + nextNodeType + '->') - - /* - In some situations, the current and next node are of the same type. - When that happens, we need to search for the second instance of that type - at the lighting path. - */ - if (currentNodeType === nextNodeType) { - let tempLightingPath = lightingPath.substring(currentNodePosition + currentNodeType.length, lightingPath.length + 1) - nextNodePosition = tempLightingPath.indexOf('->' + nextNodeType + '->') - } - - let newLightingPath = lightingPath.substring(nextNodePosition, lightingPath.length + 1) - - if (nextNodePosition > currentNodePosition) { - return newLightingPath - } else { - return - } - } - - function getSavedPayload(node, includeReferencesInSavedPayload) { - if (node.payload === undefined) { return } - let savedPayload = { - position: { - x: node.payload.position.x, - y: node.payload.position.y - }, - targetPosition: { - x: node.payload.targetPosition.x, - y: node.payload.targetPosition.y - }, - floatingObject: { - isPinned: node.payload.floatingObject.isPinned, - isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually), - isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually), - angleToParent: (node.payload.floatingObject.angleToParent), - distanceToParent: (node.payload.floatingObject.distanceToParent), - arrangementStyle: (node.payload.floatingObject.arrangementStyle) - }, - uiObject: { - isPlaying: node.payload.uiObject.isPlaying, - isRunning: node.payload.uiObject.isRunning, - shortcutKey: node.payload.uiObject.shortcutKey - } - } - - if (node.payload.frame !== undefined) { - savedPayload.frame = { - position: { - x: node.payload.frame.position.x, - y: node.payload.frame.position.y - }, - width: node.payload.frame.width, - height: node.payload.frame.height, - radius: node.payload.frame.radius - } - } - - if (node.payload.tutorial !== undefined) { - savedPayload.tutorial = { - status: node.payload.tutorial.status - } - } - - if (includeReferencesInSavedPayload) { - /* Next for the ones that have a reference parent, we include it */ - if (node.payload.referenceParent !== undefined) { - savedPayload.referenceParent = { - type: node.payload.referenceParent.type, - name: node.payload.referenceParent.name, - id: node.payload.referenceParent.id - } - } else { - /* The referenceParent property can be inherited from the previous saved payload. */ - if (node.savedPayload !== undefined) { - savedPayload.referenceParent = node.savedPayload.referenceParent - } - } - } - return savedPayload - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js b/DesignSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js deleted file mode 100644 index 5b5aa4b72..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js +++ /dev/null @@ -1,36 +0,0 @@ -function newReferenceAttachDetach() { - thisObject = { - referenceDetachNode: referenceDetachNode, - referenceAttachNode: referenceAttachNode - } - - return thisObject - - function referenceDetachNode(node) { - completeDetachment(node) - } - - function referenceAttachNode(node, attachToNode, rootNodes) { - completeAttachment(node, attachToNode) - } - - function completeAttachment(node, attachToNode) { - node.payload.referenceParent = attachToNode - } - - function completeDetachment(node) { - if (node.payload !== undefined) { - if (node.payload.referenceParent !== undefined) { - if (node.payload.referenceParent.payload !== undefined) { - if (node.payload.referenceParent.payload.uiObject !== undefined) { - node.payload.referenceParent.payload.uiObject.isShowing = false - } - } - } - node.payload.referenceParent = undefined - if (node.savedPayload !== undefined) { - node.savedPayload.referenceParent = undefined - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/SessionFunctions.js b/DesignSpace/Workspace/FunctionLibraries/SessionFunctions.js deleted file mode 100644 index 9bf6c6c14..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/SessionFunctions.js +++ /dev/null @@ -1,235 +0,0 @@ -function newSessionFunctions() { - thisObject = { - syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd, - runSession: runSession, - stopSession: stopSession - } - - return thisObject - - function syncronizeSessionWithBackEnd(node) { - let networkNode = validations(node) - if (networkNode === undefined) { - /* Nodes that do not belong to a network can not get ready. */ - return - } - - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - /* First we setup everything so as to listen to the response from the Task Server */ - let eventSubscriptionIdOnStatus - let key = node.name + '-' + node.type + '-' + node.id - eventsServerClient.listenToEvent(key, 'Status Response', undefined, node.id, onResponse, onStatus) - - function onResponse(message) { - eventSubscriptionIdOnStatus = message.eventSubscriptionId - } - - function onStatus(message) { - eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id) - if (message.event.status === 'Session Runnning' ) { - node.payload.uiObject.menu.internalClick('Run Session') - } - } - - /* Second we ask the Task Server if this Session is Running. */ - eventsServerClient.raiseEvent(key, 'Session Status') - } - - function runSession(node, functionLibraryProtocolNode, functionLibraryDependenciesFilter, resume, callBackFunction) { - let networkNode = validations(node) - if (networkNode === undefined) { - /* This means that the validations failed. */ - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - node.payload.uiObject.run(eventsServerClient, callBackFunction) - - let key = node.name + '-' + node.type + '-' + node.id - - let lightingPath = '' + - 'Trading System->' + - 'Dynamic Indicators->Indicator Function->Formula->' + - 'Trading Strategy->' + - 'Trigger Stage->Trigger On Event->Trigger Off Event->Take Position Event->' + - 'Announcement->Announcement Formula->' + - 'Open Stage->' + - 'Manage Stage->' + - 'Managed Stop Loss->Managed Take Profit->' + - 'Phase->Formula->Next Phase Event->Move To Phase Event->Phase->' + - 'Situation->Condition->Javascript Code->' + - 'Close Stage->' + - 'Initial Targets->Target Size In Base Asset->Target Size In Quoted Asset->Target Rate->Formula->' + - 'Announcement->Announcement Formula->' + - 'Open Execution->Close Execution->' + - 'Execution Algorithm->Market Buy Order->Market Sell Order->Limit Buy Order->Limit Sell Order->' + - 'Order Rate->Formula->' + - 'Create Order Event->Cancel Order Event->' + - 'Size In Base Asset->Size In Quoted Asset->Position Rate->Formula->' + - 'Situation->Condition->Javascript Code->' + - 'Market Order->Limit Order->' + - 'Simulated Exchange Events->Simulated Partial Fill->Simulated Actual Rate->Simulated Fees Paid->Formula->' - - let tradingSystem = functionLibraryProtocolNode.getProtocolNode(node.tradingSystemReference.payload.referenceParent, false, true, true, false, false, lightingPath) - - lightingPath = '' + - 'Trading Engine->' + - 'Dynamic Indicators->Indicator Function->' + - 'Current->Last->Previous->' + - 'Episode->' + - 'Episode Base Asset->Episode Quoted Asset->Episode Counters->Episode Statistics->' + - 'Strategies->Positions->Orders->Hits->Fails->' + - 'Profit Loss->Hit Ratio->Hit Fail->Days->ROI->Annualized Rate Of Return->User Defined Statistic->' + - 'Candle->Cycle->' + - 'Begin->End->Open->Close->Min->Max->Index->' + - 'Distance To Event->' + - 'Head Of The Market->Process Date->' + - 'Trigger On->Trigger Off->Take Position->Close Position->Next Phase->Move To Phase->Create Order->Cancel Order->Close Order->' + - 'Strategy->' + - 'Strategy Counters->' + - 'Position->' + - 'Entry Target Rate->Exit Target Rate->' + - 'Stop Loss->Stop Loss Phase->Stop Loss Position->' + - 'Take Profit->Take Profit Phase->Take Profit Position->' + - 'Position Counters->' + - 'Position Statistics->Days->User Defined Statistic->' + - 'Position Base Asset->Position Quoted Asset->Entry Target Size->Exit Target Size->' + - 'Profit Loss->ROI->Hit Fail->' + - 'Exchange Orders->Market Buy Orders->Market Sell Orders->Limit Buy Orders->Limit Sell Orders->' + - 'Market Order->Limit Order->' + - 'Exchange Id->Rate->Order Name->Algorithm Name->Lock->' + - 'Order Counters->' + - 'Order Base Asset->Order Quoted Asset->' + - 'Size->Size Filled->Fees Paid->' + - 'Order Statistics->Percentage Filled->Actual Rate->Days->User Defined Statistic->' + - 'Strategy Trigger Stage->Strategy Open Stage->Strategy Manage Stage->Strategy Close Stage->' + - 'Begin->End->Exit Type->Status->Begin Rate->End Rate->Stage Base Asset->Stage Quoted Asset->Size Placed->Target Size->Size Filled->Fees Paid->Stage Defined In->' + - 'Serial Number->Identifier->Begin->End->Begin Rate->End Rate->Strategy Name->Status->Exit Type->' + - 'Balance->Begin Balance->End Balance->' + - 'Index->Situation Name->Formula->Periods->' - - let tradingEngine = functionLibraryProtocolNode.getProtocolNode(node.tradingEngineReference.payload.referenceParent, false, true, true, false, false, lightingPath) - - lightingPath = '' + - 'Backtesting Session->Paper Trading Session->Forward Testing Session->Live Trading Session->' + - 'Parameters->' + - 'Session Base Asset->Session Quoted Asset->Time Range->Time Frame->Slippage->Fee Structure->Snapshots->Heartbeats->User Defined Parameters->' + - 'Exchange Account Asset->Asset->' + - 'Social Bots->Telegram Bot->' - - let session = functionLibraryProtocolNode.getProtocolNode(node, false, true, true, false, false, lightingPath) - - let dependencyFilter = functionLibraryDependenciesFilter.createFilter(node.tradingSystemReference.payload.referenceParent) - - /* Raise event to run the session */ - let event = { - session: JSON.stringify(session), - tradingSystem: JSON.stringify(tradingSystem), - tradingEngine: JSON.stringify(tradingEngine), - dependencyFilter: JSON.stringify(dependencyFilter), - resume: resume - } - - if (resume !== true) { - eventsServerClient.raiseEvent(key, 'Run Session', event) - } else { - eventsServerClient.raiseEvent(key, 'Resume Session', event) - } - - if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - } - - function stopSession(node, functionLibraryProtocolNode, callBackFunction) { - let networkNode = validations(node) - if (networkNode === undefined) { - /* This means that the validations failed. */ - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - let key = node.name + '-' + node.type + '-' + node.id - eventsServerClient.raiseEvent(key, 'Stop Session') - - node.payload.uiObject.stop(callBackFunction) - } - - function validations(node) { - if (node.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs a Process Instance parent to be able to run.') - return - } - - if (node.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside a Trading Process Instance.') - return - } - - if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside a Task.') - return - } - - if (node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside a Task Manager.') - return - } - - let taskManager = node.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode - - if (taskManager.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside Mine Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside Market Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside Exchange Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside a Testing or Production Environment.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Session needs to be inside a Network Node.') - return - } - - let networkNode = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode - - if (node.tradingSystemReference === undefined) { - node.payload.uiObject.setErrorMessage('Session needs a child Trading System Reference.') - return - } - - if (node.tradingEngineReference === undefined) { - node.payload.uiObject.setErrorMessage('Session needs a child Trading Engine Reference.') - return - } - - if (node.tradingSystemReference.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('Trading System Reference needs to reference a Trading System.') - return - } - - if (node.tradingEngineReference.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('Trading Engine Reference needs to reference a Trading Engine.') - return - } - return networkNode - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/ShortcutKeys.js b/DesignSpace/Workspace/FunctionLibraries/ShortcutKeys.js deleted file mode 100644 index 6d3a76aa5..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/ShortcutKeys.js +++ /dev/null @@ -1,54 +0,0 @@ -function newShortcutKeys() { - thisObject = { - getNodeByShortcutKey: getNodeByShortcutKey - } - return thisObject - - function getNodeByShortcutKey(node, searchingKey) { - if (node === undefined) { return } - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - /* Check Self first */ - if (node.payload.uiObject.shortcutKey === searchingKey) { - return node - } - - /* Check all of its own children nodes. */ - if (node.payload.floatingObject.isCollapsed !== true) { - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (node[property.name] !== undefined) { - let child = getNodeByShortcutKey(node[property.name], searchingKey) - if (child !== undefined) { - return child - } - } - previousPropertyName = property.name - } - } - break - case 'array': { - let nodePropertyArray = node[property.name] - if (nodePropertyArray !== undefined) { - for (let m = 0; m < nodePropertyArray.length; m++) { - let child = getNodeByShortcutKey(nodePropertyArray[m], searchingKey) - if (child !== undefined) { - return child - } - } - } - } - break - } - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/SuperScripts.js b/DesignSpace/Workspace/FunctionLibraries/SuperScripts.js deleted file mode 100644 index bbb214083..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/SuperScripts.js +++ /dev/null @@ -1,90 +0,0 @@ -function newSuperScriptsFunctions() { - thisObject = { - runSuperScript: runSuperScript - } - - return thisObject - - function runSuperScript(node, rootNodes, functionLibraryNodeCloning, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) { - try { - let clone = functionLibraryNodeCloning.getNodeClone - let executionResult = true - let superAction = node - - function setup(templateClone, target, exchange, exchangeNodeType, arrayPropertyName) { - spawnPosition.x = target.payload.position.x - spawnPosition.y = target.payload.position.y - - if (exchange === undefined) { - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(templateClone, target, target) - } else { - let definition = getNodeDefinition(target) - for (let i = 0; i < definition.properties.length; i++) { - let property = definition.properties[i] - if (property.childType === exchangeNodeType) { - let exchanges = target[property.name] - if (exchanges === undefined) { - exchanges = [] - } - let targetExchange - for (let j = 0; j < exchanges.length; j++) { - let thisExchange = exchanges[j] - if (thisExchange.payload.referenceParent !== undefined) { - if (thisExchange.payload.referenceParent.id === exchange.id) { - targetExchange = thisExchange - } - } - } - if (targetExchange === undefined) { - targetExchange = functionLibraryUiObjectsFromNodes.addUIObject(target, exchangeNodeType) - targetExchange.payload.referenceParent = exchange - } - let nodesArray = targetExchange[arrayPropertyName] - nodesArray.push(templateClone) - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(templateClone, targetExchange, targetExchange) - } - } - } - } - - function deleteNode(node) { - functionLibraryNodeDeleter.deleteUIObject(node, rootNodes) - } - - /* Validations */ - if (executionResult === true && node.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Super Action node needs a Parent Node.') - executionResult = false - } - if (executionResult === true && node.payload.referenceParent === undefined) { - node.payload.uiObject.setErrorMessage('Super Action node needs to reference a Master Script Node.') - executionResult = false - } - if (executionResult === true && node.payload.referenceParent.javascriptCode === undefined) { - node.payload.uiObject.setErrorMessage('Master Script Node needs to have a child Javascript Code Node.') - executionResult = false - } - - let masterScript = node.payload.referenceParent - - eval(masterScript.javascriptCode.code) - - let masterScriptInstance = newNewMasterScriptInstance() - - if (executionResult === true) { - executionResult = masterScriptInstance.runValidations(superAction, masterScript) - } - if (executionResult === true) { - executionResult = masterScriptInstance.runScript(superAction, masterScript) - } - if (executionResult === true) { - superAction.payload.uiObject.setValue('Execution Completed Successfully') - } else { - superAction.payload.uiObject.setValue('Execution Failed') - } - } catch (err) { - superAction.payload.uiObject.setErrorMessage(err.message) - superAction.payload.uiObject.setValue('Execution Failed') - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js b/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js deleted file mode 100644 index 5042fcdee..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js +++ /dev/null @@ -1,619 +0,0 @@ -function newTaskFunctions() { - thisObject = { - syncronizeTaskWithBackEnd: syncronizeTaskWithBackEnd, - - runTask: runTask, - stopTask: stopTask, - runAllTasks: runAllTasks, - stopAllTasks: stopAllTasks, - runAllTaskManagers: runAllTaskManagers, - stopAllTaskManagers: stopAllTaskManagers, - - runAllExchangeDataTasks: runAllExchangeDataTasks, - stopAllExchangeDataTasks: stopAllExchangeDataTasks, - runAllExchangeTradingTasks: runAllExchangeTradingTasks, - stopAllExchangeTradingTasks: stopAllExchangeTradingTasks, - - runAllMarketDataTasks: runAllMarketDataTasks, - stopAllMarketDataTasks: stopAllMarketDataTasks, - runAllMarketTradingTasks: runAllMarketTradingTasks, - stopAllMarketTradingTasks: stopAllMarketTradingTasks, - - runAllDataMineTasks: runAllDataMineTasks, - stopAllDataMineTasks: stopAllDataMineTasks, - runAllTradingMineTasks: runAllTradingMineTasks, - stopAllTradingMineTasks: stopAllTradingMineTasks, - - addMissingExchangeDataTasks: addMissingExchangeDataTasks, - addMissingMarketDataTasks: addMissingMarketDataTasks, - addMissingDataMineTasks: addMissingDataMineTasks, - addMissingExchangeTradingTasks: addMissingExchangeTradingTasks, - addMissingMarketTradingTasks: addMissingMarketTradingTasks, - addMissingTradingMineTasks: addMissingTradingMineTasks, - addAllTasks: addAllTasks - } - - return thisObject - - function syncronizeTaskWithBackEnd(node) { - let networkNode = validations(node) - if (networkNode === undefined) { - /* Nodes that do not belong to a network can not get ready. */ - return - } - - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - /* First we setup everything so as to listen to the response from the Task Manger */ - let eventSubscriptionIdOnStatus - let key = 'Task Client - ' + node.id - eventsServerClient.listenToEvent(key, 'Task Status', undefined, node.id, onResponse, onStatus) - - function onResponse(message) { - eventSubscriptionIdOnStatus = message.eventSubscriptionId - } - - function onStatus(message) { - eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id) - if (message.event.status === 'Task Process Running' ) { - node.payload.uiObject.menu.internalClick('Run Task') - } - } - - /* Second we ask the Task Manager if this Task has a process Running. */ - let event = { - taskId: node.id - } - - eventsServerClient.raiseEvent('Task Manager', 'Task Status', event) - } - - function runTask(node, functionLibraryProtocolNode, isDebugging, callBackFunction) { - - let networkNode = validations(node) - if (networkNode === undefined) { - /* This means that the validations failed. */ - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - for (let i = 0; i < node.bot.processes.length; i++) { - let process = node.bot.processes[i] - process.payload.uiObject.run(eventsServerClient) - } - - let taskLightingPath = '->Task->' + - 'Sensor Bot Instance->' + - 'Indicator Bot Instance->Time Frames Filter->' + - 'Trading Bot Instance->' + - 'Sensor Process Instance->Indicator Process Instance->Trading Process Instance->' + - 'Execution Started Event->' + - 'Key Reference->Exchange Account Key->' + - 'Task Manager->' + - 'Data Mine Tasks->Trading Mine Tasks->' + - 'Market Data Tasks->Market Trading Tasks->' + - 'Exchange Data Tasks->Exchange Trading Tasks->' + - 'Market->Exchange Markets->Crypto Exchange->' + - 'Market Base Asset->Market Quoted Asset->Asset->' + - 'Backtesting Session->Live Trading Session->Paper Trading Session->Forward Testing Session->' + - 'Process Definition->' + - 'Process Output->' + - 'Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->Output Dataset Folder->' + - 'Output Dataset->Dataset Definition->Product Definition->' + - 'Process Dependencies->' + - 'Status Dependency->Status Report->Process Definition->' + - 'Data Mine Data Dependencies->Bot Data Dependencies->' + - 'Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->Data Dependency Folder->' + - 'Data Dependency->Dataset Definition->Product Definition->' + - 'Record Definition->Record Property->Formula->' + - 'Data Building Procedure->' + - 'Procedure Initialization->Javascript Code->' + - 'Procedure Loop->Javascript Code->' + - 'Calculations Procedure->' + - 'Procedure Initialization->Javascript Code->' + - 'Procedure Loop->Javascript Code->' + - 'Status Report->' + - 'Execution Finished Event->' + - 'Execution Started Event->Execution Finished Event->Process Definition->' + - 'Sensor Bot->' + - 'Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->Product Definition Folder->' + - 'Indicator Bot->' + - 'Trading Bot->' + - 'Data Mine->Trading Mine->' - - let taskDefinition = functionLibraryProtocolNode.getProtocolNode(node, false, true, true, false, false, taskLightingPath) - - let networkLightingPath = '->Network->Network Node->' + - 'Data Storage->Data Mines Data->Exchange Data Products->' + - 'Market Data Products->' + - 'Data Mine Products->Bot Products->' + - 'Data Product Folder->Data Product Folder->Data Product Folder->Data Product Folder->Data Product Folder->' + - 'Data Product->Product Definition->' + - 'Data Mining->Testing Environment->Production Environment->' + - 'Exchange Data Tasks->Exchange Trading Tasks->Crypto Exchange->' + - 'Market Data Tasks->Market Trading Tasks->Market->' + - 'Data Mine Tasks->Trading Mine Tasks->' + - 'Task Manager->Task->' + - 'Indicator Bot Instance->Sensor Bot Instance->Trading Bot Instance->' + - 'Indicator Process Instance->Sensor Process Instance->Trading Process Instance->' + - 'Paper Trading Session->Forward Testing Session->Backtesting Session->Live Trading Session->' + - 'Market->' + - 'Process Definition->' - - let networkDefinition = functionLibraryProtocolNode.getProtocolNode(networkNode.payload.parentNode, false, true, true, false, false, networkLightingPath) - - let event = { - appSchema: JSON.stringify(SCHEMAS_BY_PROJECT.get('Superalgos').array.appSchema), - taskId: node.id, - taskName: node.name, - taskDefinition: JSON.stringify(taskDefinition), - networkDefinition: JSON.stringify(networkDefinition) - } - - if (isDebugging === true) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - eventsServerClient.raiseEvent('Task Server', 'Debug Task Started', event) - return - } - - node.payload.uiObject.run(eventsServerClient, callBackFunction) - eventsServerClient.raiseEvent('Task Manager', 'Run Task', event) - } - - function stopTask(node, functionLibraryProtocolNode, callBackFunction) { - let networkNode = validations(node) - if (networkNode === undefined) { - /* This means that the validations failed. */ - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id) - - let event = { - taskId: node.id, - taskName: node.name - } - - node.payload.uiObject.stop(callBackFunction) - eventsServerClient.raiseEvent('Task Manager', 'Stop Task', event) - - if (node.bot === undefined) { return } - if (node.bot.processes.length === 0) { return } - - for (let i = 0; i < node.bot.processes.length; i++) { - let process = node.bot.processes[i] - process.payload.uiObject.stop() - } - } - - function validations(node) { - if (node.bot === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to have a Bot Instance.') - return - } - if (node.bot.processes.length === 0) { - node.payload.uiObject.setErrorMessage('Task Bot Instance needs to have al least once Process Instance.') - return - } - - if (node.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside a Task Manager.') - return - } - - let taskManager = node.payload.parentNode - - if (taskManager.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside Mine Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside Market Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside Exchange Tasks.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside a Data Mining, Testing or Production Environment.') - return - } - - if (taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { - node.payload.uiObject.setErrorMessage('Task needs to be inside a Network Node.') - return - } - - let networkNode = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode - if (loadPropertyFromNodeConfig(networkNode.payload, 'host') === undefined) { - node.payload.uiObject.setErrorMessage('Network Node needs to have a valid Host property at its config.') - return - } - - if (loadPropertyFromNodeConfig(networkNode.payload, 'webPort') === undefined) { - node.payload.uiObject.setErrorMessage('Network Node needs to have a valid webPort property at its config.') - return - } - - if (loadPropertyFromNodeConfig(networkNode.payload, 'webSocketsPort') === undefined) { - node.payload.uiObject.setErrorMessage('Network Node needs to have a valid webSocketsPort property at its config.') - return - } - - return networkNode - } - - function runAllTasks(taskManager, functionLibraryProtocolNode) { - for (let i = 0; i < taskManager.tasks.length; i++) { - let node = taskManager.tasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run Task') - } - } - - function stopAllTasks(taskManager, functionLibraryProtocolNode) { - for (let i = 0; i < taskManager.tasks.length; i++) { - let node = taskManager.tasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop Task') - } - } - - function runAllTaskManagers(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.taskManagers.length; i++) { - let node = parent.taskManagers[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Tasks') - menu.internalClick('Run All Tasks') - } - } - - function stopAllTaskManagers(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.taskManagers.length; i++) { - let node = parent.taskManagers[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Tasks') - menu.internalClick('Stop All Tasks') - } - } - - function runAllExchangeDataTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.exchangeDataTasks.length; i++) { - let node = parent.exchangeDataTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Market Data Tasks') - menu.internalClick('Run All Market Data Tasks') - } - } - - function stopAllExchangeDataTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.exchangeDataTasks.length; i++) { - let node = parent.exchangeDataTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Market Data Tasks') - menu.internalClick('Stop All Market Data Tasks') - } - } - - function runAllExchangeTradingTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.exchangeTradingTasks.length; i++) { - let node = parent.exchangeTradingTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Market Trading Tasks') - menu.internalClick('Run All Market Trading Tasks') - } - } - - function stopAllExchangeTradingTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.exchangeTradingTasks.length; i++) { - let node = parent.exchangeTradingTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Market Trading Tasks') - menu.internalClick('Stop All Market Trading Tasks') - } - } - - function runAllMarketDataTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.marketDataTasks.length; i++) { - let node = parent.marketDataTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Data Mine Tasks') - menu.internalClick('Run All Data Mine Tasks') - } - } - - function stopAllMarketDataTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.marketDataTasks.length; i++) { - let node = parent.marketDataTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Data Mine Tasks') - menu.internalClick('Stop All Data Mine Tasks') - } - } - - function runAllMarketTradingTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.marketTradingTasks.length; i++) { - let node = parent.marketTradingTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Trading Mine Tasks') - menu.internalClick('Run All Trading Mine Tasks') - } - } - - function stopAllMarketTradingTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.marketTradingTasks.length; i++) { - let node = parent.marketTradingTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Trading Mine Tasks') - menu.internalClick('Stop All Trading Mine Tasks') - } - } - - function runAllDataMineTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.dataMineTasks.length; i++) { - let node = parent.dataMineTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Task Managers') - menu.internalClick('Run All Task Managers') - } - } - - function stopAllDataMineTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.dataMineTasks.length; i++) { - let node = parent.dataMineTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Task Managers') - menu.internalClick('Stop All Task Managers') - } - } - - function runAllTradingMineTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.tradingMineTasks.length; i++) { - let node = parent.tradingMineTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Run All Task Managers') - menu.internalClick('Run All Task Managers') - } - } - - function stopAllTradingMineTasks(parent, functionLibraryProtocolNode) { - for (let i = 0; i < parent.tradingMineTasks.length; i++) { - let node = parent.tradingMineTasks[i] - let menu = node.payload.uiObject.menu - - menu.internalClick('Stop All Task Managers') - menu.internalClick('Stop All Task Managers') - } - } - - function addMissingExchangeDataTasks(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingExchangeTasks(node, rootNodes, 'Exchange Data Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingExchangeTradingTasks(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingExchangeTasks(node, rootNodes, 'Exchange Trading Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingExchangeTasks(node, rootNodes, newNodeType, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Crypto Ecosystem') { - let cryptoEcosystem = rootNode - for (let j = 0; j < cryptoEcosystem.cryptoExchanges.length; j++) { - let cryptoExchanges = cryptoEcosystem.cryptoExchanges[j] - for (let k = 0; k < cryptoExchanges.exchanges.length; k++) { - let cryptoExchange = cryptoExchanges.exchanges[k] - if (isMissingChildren(node, cryptoExchange, true) === true) { - let exchangeTasks = functionLibraryUiObjectsFromNodes.addUIObject(node, newNodeType) - exchangeTasks.payload.referenceParent = cryptoExchange - } - } - } - } - } - } - - function addMissingMarketDataTasks(node, functionLibraryUiObjectsFromNodes) { - addMissingMarketTasks(node, 'Market Data Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingMarketTradingTasks(node, functionLibraryUiObjectsFromNodes) { - addMissingMarketTasks(node, 'Market Trading Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingMarketTasks(node, newNodeType, functionLibraryUiObjectsFromNodes) { - if (node.payload === undefined) { return } - if (node.payload.referenceParent === undefined) { return } - if (node.payload.referenceParent.exchangeMarkets === undefined) { return } - - let markets = node.payload.referenceParent.exchangeMarkets.markets - - for (let i = 0; i < markets.length; i++) { - let market = markets[i] - - if (isMissingChildren(node, market, true) === true) { - let marketDataTasks = functionLibraryUiObjectsFromNodes.addUIObject(node, newNodeType) - marketDataTasks.payload.referenceParent = market - } - } - } - - function addMissingDataMineTasks(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingMineTasks(node, rootNodes, 'Data Mine', 'Data Mine Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingTradingMineTasks(node, rootNodes, functionLibraryUiObjectsFromNodes) { - addMissingMineTasks(node, rootNodes, 'Trading Mine', 'Trading Mine Tasks', functionLibraryUiObjectsFromNodes) - } - - function addMissingMineTasks(node, rootNodes, rootNodeType, newNodeType, functionLibraryUiObjectsFromNodes) { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === rootNodeType) { - let dataMine = rootNode - - if (isMissingChildren(node, dataMine, true) === true) { - let dataMineTasks = functionLibraryUiObjectsFromNodes.addUIObject(node, newNodeType) - dataMineTasks.payload.referenceParent = dataMine - } - } - } - } - - function addAllTasks(node, rootNodes, functionLibraryUiObjectsFromNodes) { - if (node.payload === undefined) { return } - if (node.payload.referenceParent === undefined) { return } - - let taskManager = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Task Manager') - taskManager.name = node.payload.referenceParent.name - taskManager.payload.floatingObject.collapseToggle() - - switch (node.type) { - case 'Data Mine Tasks': { - addDataTasks() - break - } - case 'Trading Mine Tasks': { - addTradingTasks() - break - } - } - - function addDataTasks() { - addTaskForTradinSystem() - } - - function addTradingTasks() { - for (let i = 0; i < rootNodes.length; i++) { - let rootNode = rootNodes[i] - if (rootNode.type === 'Trading System') { - addTaskForTradinSystem(rootNode) - } - } - } - - function addTaskForTradinSystem(tradingSystem) { - let mine = node.payload.referenceParent - - addTasksForBotArray(mine.sensorBots) - addTasksForBotArray(mine.indicatorBots) - addTasksForBotArray(mine.tradingBots) - - function addTasksForBotArray(botsArray) { - if (botsArray === undefined) { return } - - for (let i = 0; i < botsArray.length; i++) { - let bot = botsArray[i] - - let task = functionLibraryUiObjectsFromNodes.addUIObject(taskManager, 'Task') - - if (tradingSystem !== undefined) { - task.name = tradingSystem.name - } else { - task.name = bot.name - } - - let botInstance - switch (bot.type) { - case 'Sensor Bot': { - botInstance = functionLibraryUiObjectsFromNodes.addUIObject(task, 'Sensor Bot Instance') - botInstance.name = bot.name - break - } - case 'Indicator Bot': { - botInstance = functionLibraryUiObjectsFromNodes.addUIObject(task, 'Indicator Bot Instance') - botInstance.name = bot.name - break - } - case 'Trading Bot': { - botInstance = functionLibraryUiObjectsFromNodes.addUIObject(task, 'Trading Bot Instance') - botInstance.name = bot.name - break - } - } - - for (let j = 0; j < bot.processes.length; j++) { - let process = bot.processes[j] - let processInstance - switch (bot.type) { - case 'Sensor Bot': { - processInstance = functionLibraryUiObjectsFromNodes.addUIObject(botInstance, 'Sensor Process Instance') - processInstance.payload.referenceParent = process - break - } - case 'Indicator Bot': { - processInstance = functionLibraryUiObjectsFromNodes.addUIObject(botInstance, 'Indicator Process Instance') - processInstance.payload.referenceParent = process - break - } - case 'Trading Bot': { - processInstance = functionLibraryUiObjectsFromNodes.addUIObject(botInstance, 'Trading Process Instance') - processInstance.payload.referenceParent = process - - if (node.payload.parentNode === undefined) { return } - if (node.payload.parentNode.payload === undefined) { return } - if (node.payload.parentNode.payload.parentNode === undefined) { return } - if (node.payload.parentNode.payload.parentNode.payload === undefined) { return } - if (node.payload.parentNode.payload.parentNode.payload.parentNode === undefined) { return } - - let environment = node.payload.parentNode.payload.parentNode.payload.parentNode - let session - - switch (environment.type) { - case 'Testing Environment': { - addSession('Backtesting Session') - break - } - case 'Production Environment': { - addSession('Live Trading Session') - break - } - } - break - - function addSession(sessionType) { - session = functionLibraryUiObjectsFromNodes.addUIObject(processInstance, sessionType) - session.name = task.name - let config = JSON.parse(session.config) - config.folderName = session.name.split(" ").join("-") - session.config = JSON.stringify(config) - - for (let m = 0; m < rootNodes.length; m++) { - let rootNode = rootNodes[m] - if (rootNode.type === 'Trading Engine' && rootNode.isPlugin === true) { - let tradingEngine = rootNode - session.tradingEngineReference.payload.referenceParent = tradingEngine - session.tradingSystemReference.payload.referenceParent = tradingSystem - } - } - } - } - } - processInstance.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_90 - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/TutorialFunctions.js b/DesignSpace/Workspace/FunctionLibraries/TutorialFunctions.js deleted file mode 100644 index f89c89f07..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/TutorialFunctions.js +++ /dev/null @@ -1,5 +0,0 @@ -function newTutorialFunctions() { - thisObject = { - } - return thisObject -} diff --git a/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js deleted file mode 100644 index 60303cb44..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ /dev/null @@ -1,655 +0,0 @@ -function newUiObjectsFromNodes() { - thisObject = { - syncronizeTasksFoundAtWorkspaceWithBackEnd: syncronizeTasksFoundAtWorkspaceWithBackEnd, - syncronizeSessionsFoundAtWorkspaceWithBackEnd: syncronizeSessionsFoundAtWorkspaceWithBackEnd, - playTutorials: playTutorials, - recreateWorkspace: recreateWorkspace, - getNodeById: getNodeById, - tryToConnectChildrenWithReferenceParents: tryToConnectChildrenWithReferenceParents, - createUiObjectFromNode: createUiObjectFromNode, - addUIObject: addUIObject, - addMissingChildren: addMissingChildren - } - - let mapOfReferenceChildren = new Map() - let mapOfNodes - let tasksFoundAtWorkspace - let sessionsFoundAtWorkspace - let tutorialsToPlay - - return thisObject - - function getNodeById(nodeId) { - return mapOfNodes.get(nodeId) - } - - function recreateWorkspace(node, callBackFunction) { - mapOfNodes = new Map() - tasksFoundAtWorkspace = [] - sessionsFoundAtWorkspace = [] - tutorialsToPlay = [] - - removeNullRootNodes() - - function removeNullRootNodes() { - for (let i = 0; i < node.rootNodes.length; i++) { - let rootNode = node.rootNodes[i] - if (rootNode === null) { - node.rootNodes.splice(i, 1) - removeNullRootNodes() - return - } - } - } - - addPluginNodes() - - function addPluginNodes(pluginNames) { - let blobService = newFileStorage() - let totalPlugin = 0 - let totalRead = 0 - - for (let i = 0; i < node.rootNodes.length; i++) { - let rootNode = node.rootNodes[i] - if (rootNode.type === 'Plugins') { - let plugins = rootNode - - for (let j = 0; j < plugins.pluginProjects.length; j++) { - let project = plugins.pluginProjects[j] - if (project.pluginDataMines !== undefined) { - totalPlugin = totalPlugin + project.pluginDataMines.pluginFiles.length - pluginAllTheseFiles(project.pluginDataMines.pluginFiles, 'Data-Mines') - } - if (project.pluginTradingMines !== undefined) { - totalPlugin = totalPlugin + project.pluginTradingMines.pluginFiles.length - pluginAllTheseFiles(project.pluginTradingMines.pluginFiles, 'Trading-Mines') - } - if (project.pluginTradingSystems !== undefined) { - totalPlugin = totalPlugin + project.pluginTradingSystems.pluginFiles.length - pluginAllTheseFiles(project.pluginTradingSystems.pluginFiles, 'Trading-Systems') - } - if (project.pluginTradingEngines !== undefined) { - totalPlugin = totalPlugin + project.pluginTradingEngines.pluginFiles.length - pluginAllTheseFiles(project.pluginTradingEngines.pluginFiles, 'Trading-Engines') - } - if (project.pluginSuperScripts !== undefined) { - totalPlugin = totalPlugin + project.pluginSuperScripts.pluginFiles.length - pluginAllTheseFiles(project.pluginSuperScripts.pluginFiles, 'Super-Scripts') - } - if (project.pluginTutorials !== undefined) { - totalPlugin = totalPlugin + project.pluginTutorials.pluginFiles.length - pluginAllTheseFiles(project.pluginTutorials.pluginFiles, 'Tutorials') - } - } - } - } - - /* - If there is no Plugins node at the workspace, we load it anyways here. - */ - if (totalPlugin === 0) { - addUserDefinedNodes() - } - - function pluginAllTheseFiles(pluginFiles, pluginType) { - for (let i = 0; i < pluginFiles.length; i++) { - let pluginFile = pluginFiles[i] - let name = pluginFile.name - callWebServer(undefined, 'LoadPlugin' + '/' + 'Superalgos' + '/' + pluginType + '/' + name + '.json', onFileReceived) - - function onFileReceived(err, text, response) { - - if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - console.log('[WARN] Cannot load plugin ' + pluginType + ' ' + name + '. The Workspace will be loaded with this plugin file missing.') - } else { - let receivedNode = JSON.parse(text) - /* - If the workspace already contains a root node with the id of the head of the hirierchy - we are loading, we remove it because the plugin file has precedende. - */ - for (let i = 0; i < node.rootNodes.length; i++) { - let rootNode = node.rootNodes[i] - if (rootNode.id === receivedNode.id) { - node.rootNodes.splice(i, 1) - break - } - } - receivedNode.isPlugin = true - - if (pluginFile.pluginFilePosition !== undefined) { - let positionOffset = { - x: pluginFile.pluginFilePosition.savedPayload.position.x - receivedNode.savedPayload.position.x, - y: pluginFile.pluginFilePosition.savedPayload.position.y - receivedNode.savedPayload.position.y - } - receivedNode.positionOffset = positionOffset - } - - node.rootNodes.unshift(receivedNode) - } - - totalRead++ - if (totalPlugin === totalRead) { - addUserDefinedNodes() - } - } - } - } - } - - function addUserDefinedNodes() { - /* Create the workspace UI OBject and then continue with the root nodes. */ - createUiObject(false, 'Workspace', node.name, node, undefined, undefined, 'Workspace') - if (node.rootNodes !== undefined) { - for (let i = 0; i < node.rootNodes.length; i++) { - let rootNode = node.rootNodes[i] - createUiObjectFromNode(rootNode, undefined, undefined) - } - } - - tryToConnectChildrenWithReferenceParents() - - if (callBackFunction !== undefined) { - callBackFunction() // The recreation of the workspace is complete - } - } - } - - function syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions) { - for (let i = 0; i < tasksFoundAtWorkspace.length; i++) { - let node = tasksFoundAtWorkspace[i] - functionLibraryTaskFunctions.syncronizeTaskWithBackEnd(node) - } - tasksFoundAtWorkspace = undefined - } - - function syncronizeSessionsFoundAtWorkspaceWithBackEnd(functionLibrarySessionFunctions) { - for (let i = 0; i < sessionsFoundAtWorkspace.length; i++) { - let node = sessionsFoundAtWorkspace[i] - functionLibrarySessionFunctions.syncronizeSessionWithBackEnd(node) - } - sessionsFoundAtWorkspace = undefined - } - - function playTutorials() { - for (let i = 0; i < tutorialsToPlay.length; i++) { - let node = tutorialsToPlay[i] - node.payload.uiObject.menu.internalClick('Play Tutorial') - } - tutorialsToPlay = undefined - } - - function tryToConnectChildrenWithReferenceParents() { - /* We reconstruct here the reference relationships. */ - for (const [key, node] of mapOfNodes) { - if (node.id === "54854f90-d121-4365-8f40-9a26e7af1097") { - console.log('ACA') - } - if (node.payload === undefined) { continue } - if (node.payload.referenceParent !== undefined) { - if (node.payload.referenceParent.cleaned === true) { - node.payload.referenceParent = mapOfNodes.get(node.payload.referenceParent.id) - if (node.payload.referenceParent === undefined) { - //console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.') - } - continue // We were referencing a deleted node, so we replace it potentially with a newly created one. - } else { - continue // In this case the reference is already good. - } - } - if (node.savedPayload !== undefined) { - if (node.savedPayload.referenceParent !== undefined) { // these are children recreated - node.payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id) - if (node.payload.referenceParent === undefined) { - //console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.') - } - } - } - } - } - - function migrateCodeToConfig(node, nodeDefinition) { - /* Code needed to Migrante from Beta 5 to Beta a Workspace */ - if (nodeDefinition.editors !== undefined) { - if (nodeDefinition.editors.config === true) { - if (node.code !== undefined) { - node.config = node.code - node.code = undefined - } - } - } - } - - function createUiObjectFromNode(node, parentNode, chainParent, positionOffset) { - /* Migration code from beta 6 to beta 7 */ - if (node.project === undefined) { - node.project = 'Superalgos' - } - - /* - This function can be called with a positionOffset to change the node - saved position and all of its descendants positions as well with an - offset. It can also happen that the positionOffset is defined as a property - of the node, in which case it will produce exactly the same effect. - */ - if (node.positionOffset !== undefined) { - positionOffset = node.positionOffset - } - - - /* Get node definition */ - let nodeDefinition = getNodeDefinition(node) - if (nodeDefinition !== undefined) { - migrateCodeToConfig(node, nodeDefinition) - - /* Resolve Initial Values */ - if (nodeDefinition.initialValues !== undefined) { - if (nodeDefinition.initialValues.code !== undefined) { - if (node.code === undefined) { - node.code = nodeDefinition.initialValues.code - } - } - if (nodeDefinition.initialValues.config !== undefined) { - if (node.config === undefined) { - node.config = nodeDefinition.initialValues.config - } - } - } - - /* 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) { - if (parentNode !== undefined) { - let parentNodeDefinition = getNodeDefinition(parentNode) - 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] - } - } - } - } - } - } - } - } - } - } - } - } - /* Create Self */ - createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - - /* Create 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - if (node[property.name] !== undefined) { - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - createUiObjectFromNode(node[property.name], node, node, positionOffset) - previousPropertyName = property.name - } - } - break - case 'array': { - let nodePropertyArray = node[property.name] - for (let m = 0; m < nodePropertyArray.length; m++) { - let arrayItem = nodePropertyArray[m] - createUiObjectFromNode(arrayItem, node, node, positionOffset) - } - } - break - } - } else { - if (property.type === 'array') { - node[property.name] = [] - } - } - } - } - } - } - - function addUIObject(parentNode, type) { - let object = { - name: 'New ' + type, - type: type, - project: parentNode.project - } - - let parentNodeDefinition = getNodeDefinition(parentNode) - if (parentNodeDefinition === undefined) { - console.log('Cannot addUIOBject from parent of ' + type + ' because that type it is not defined at the APP_SCHEMA.') - } - /* Resolve Initial Values */ - let nodeDefinition = getNodeDefinition(object) - - if (nodeDefinition === undefined) { - console.log('Cannot addUIOBject of ' + type + ' because that type it is not defined at the APP_SCHEMA.') - return - } - - if (nodeDefinition.initialValues !== undefined) { - if (nodeDefinition.initialValues.code !== undefined) { - object.code = nodeDefinition.initialValues.code - } - } - if (nodeDefinition.initialValues !== undefined) { - if (nodeDefinition.initialValues.config !== undefined) { - object.config = nodeDefinition.initialValues.config - } - } - - if (nodeDefinition.isHierarchyHead === true) { - parentNode.rootNodes.push(object) - createUiObject(true, object.type, object.name, object, parentNode, undefined) - return object - } - - /* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */ - let chainParent = parentNode - if (nodeDefinition.chainedToSameType === true) { - if (parentNodeDefinition.properties !== undefined) { - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (property.childType === type) { - if (property.type === 'array') { - if (parentNode[property.name] !== undefined) { - if (parentNode[property.name].length > 0) { - let nodeChildren = parentNode[property.name] - chainParent = nodeChildren[nodeChildren.length - 1] - } - } - } - } - } - } - } - - /* Create Empty Arrays for properties of type Array */ - if (nodeDefinition.properties !== undefined) { - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - if (property.type === 'array') { - object[property.name] = [] - } - } - } - - if (nodeDefinition.initialValues !== undefined) { - if (nodeDefinition.initialValues.code !== undefined) { - object.code = nodeDefinition.initialValues.code - } - if (nodeDefinition.initialValues.config !== undefined) { - object.config = nodeDefinition.initialValues.config - } - } - - /* Connect to Parent */ - if (parentNodeDefinition.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. - for (let i = 0; i < parentNodeDefinition.properties.length; i++) { - let property = parentNodeDefinition.properties[i] - if (property.childType === type) { - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - parentNode[property.name] = object - previousPropertyName = property.name - } - } - break - case 'array': { - if (parentNode[property.name] === undefined) { - parentNode[property.name] = [] - } - 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 - } - } - } - } - - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - - switch (property.type) { - case 'node': { - if (property.name !== previousPropertyName) { - if (property.autoAdd === true) { - addUIObject(object, property.childType) - previousPropertyName = property.name - } - } - } - break - case 'array': { - if (property.autoAdd === true) { - if (object[property.name] === undefined) { - object[property.name] = [] - } - addUIObject(object, property.childType) - } - } - break - } - } - } - - return object - } - - function addMissingChildren(node) { - let nodeDefinition = getNodeDefinition(node) - - /* Connect to Parent */ - 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. - for (let i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - if (property.type === 'node') { - if (property.name !== previousPropertyName) { - if (node[property.name] === undefined) { - addUIObject(node, property.childType) - previousPropertyName = property.name - } - } - } - } - } - } - - function createUiObject(userAddingNew, uiObjectType, name, node, parentNode, chainParent, title, positionOffset) { - let payload = {} - - /* Mechanism related to keeping references when cloning */ - if (node.id === undefined) { - node.id = newUniqueId() - } else { - /* - We need to avoid nodes having the same id. If we add nodes to a workspace that already exist with the same Id, - the nodes being added will get a new id at this moment. - */ - let testNode = mapOfNodes.get(node.id) - if (testNode !== undefined && testNode.cleaned !== true) { - console.log(testNode.name + ' already have the id of the node ' + node.name + ' being added.') - node.id = newUniqueId() - } - } - - /* Default Naming */ - if (name === '' || name === undefined) { name = 'My ' + uiObjectType } - - /* If we are creating this object as the result of restoring a backup, share or clone, we will bring some of the saved properties to the new running instance. */ - if (userAddingNew === false && uiObjectType !== 'Workspace') { - /* This following info can not be missing. */ - if (node.savedPayload === undefined) { - console.log('Node ' + node.type + ' without savedPayload.', node) - return - } - if (node.savedPayload.position === undefined) { - console.log('Node ' + node.type + ' without savedPayload.position.', node) - return - } - if (node.savedPayload.targetPosition === undefined) { - console.log('Node ' + node.type + ' without savedPayload.targetPosition.', node) - return - } - - /* If there is not a position offset, which happens when we are dropping a node into the designer, we create a cero vector then. */ - if (positionOffset === undefined) { - positionOffset = { - x: 0, - y: 0 - } - } - - /* Adding the offset to the saved positions. */ - node.savedPayload.targetPosition.x = node.savedPayload.targetPosition.x + positionOffset.x - node.savedPayload.targetPosition.y = node.savedPayload.targetPosition.y + positionOffset.y - node.savedPayload.position.x = node.savedPayload.position.x + positionOffset.x - node.savedPayload.position.y = node.savedPayload.position.y + positionOffset.y - - /* Transferring the saved payload properties into the running instance being created. */ - payload.targetPosition = { - x: node.savedPayload.targetPosition.x, - y: node.savedPayload.targetPosition.y - } - node.savedPayload.targetPosition = undefined - - /* Reference children connection to parents */ - if (node.savedPayload.referenceParent !== undefined) { - payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id) - - if (payload.referenceParent !== undefined) { - mapOfReferenceChildren.set(node.id, node) - } - } - } - - /* If we are adding a new object, then we set the initial values for position and targetPosition */ - if (userAddingNew === true || uiObjectType === 'Workspace') { - /* Workspace allways to the spawn position */ - if (uiObjectType === 'Workspace') { - payload.position = { - x: spawnPosition.x, - y: spawnPosition.y - } - } - - /* Chain parent pointing to the position of the chain parent if defined. */ - if (chainParent === undefined) { - payload.targetPosition = { - x: spawnPosition.x, - y: spawnPosition.y - } - } else { - payload.targetPosition = { - x: chainParent.payload.position.x, - y: chainParent.payload.position.y - } - } - } - - /* Setting the title */ - if (title !== undefined) { - payload.subTitle = title - } else { - payload.subTitle = uiObjectType - } - - payload.visible = true - payload.title = name - payload.node = node - payload.parentNode = parentNode - payload.chainParent = chainParent - payload.onMenuItemClick = canvas.designSpace.workspace.onMenuItemClick - - node.payload = payload - node.type = uiObjectType - - /* - Now we copy the possible frame saved to the payload where it can be used. A saved frame stores the position of a a chartingSpace object related to a node. - This will prevent that if those charting space objects never get activated, that the frame information is lost when the workspace is saved. - */ - if (node.savedPayload !== undefined) { - if (node.savedPayload.frame !== undefined) { - let frame = { - position: { - x: 0, - y: 0 - } - } - frame.position.x = node.savedPayload.frame.position.x - frame.position.y = node.savedPayload.frame.position.y - frame.width = node.savedPayload.frame.width - frame.height = node.savedPayload.frame.height - frame.radius = node.savedPayload.frame.radius - saveFrame(payload, frame) - } - if (node.savedPayload.tutorial !== undefined) { - let tutorial = { - status: node.savedPayload.tutorial.status - } - saveTutorial(payload, tutorial) - } - } - - /* Now we mount the floating object where the UIOBject will be laying on top of */ - canvas.floatingSpace.uiObjectConstructor.createUiObject(userAddingNew, payload) - - /* This is the point where we build a map with all nodes present at the workspace */ - mapOfNodes.set(node.id, node) - - /* We will collect all tasks at the workspace in order to later syncronize them with the backend */ - if (userAddingNew === false && uiObjectType === 'Task' && node.savedPayload !== undefined) { - if (tasksFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a task that was backed up - tasksFoundAtWorkspace.push(node) - } - } - - /* Check if there are sessions to run */ - if (userAddingNew === false && node.savedPayload !== undefined) { - if (uiObjectType === 'Live Trading Session' || uiObjectType === 'Forward Testing Session' || uiObjectType === 'Backtesting Session' || uiObjectType === 'Paper Trading Session') { - if (sessionsFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a session that was running while backed up - sessionsFoundAtWorkspace.push(node) - } - } - } - - /* Check if there are tutorials to play */ - if (userAddingNew === false && node.savedPayload !== undefined) { - if (uiObjectType === 'Tutorial') { - if (node.savedPayload.uiObject.isPlaying === true) { - if (tutorialsToPlay !== undefined) { // it might be undefined when you are spawning a tutorial that was playing while backed up - tutorialsToPlay.push(node) - } - } - } - } - } -} diff --git a/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js b/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js deleted file mode 100644 index 15bd466ff..000000000 --- a/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js +++ /dev/null @@ -1,22 +0,0 @@ -function newWebhookFunctions() { - thisObject = { - sendTestMessage: sendTestMessage - } - - return thisObject - - function sendTestMessage(node, callBackFunction) { - let testMessage = loadPropertyFromNodeConfig(node.payload, 'testMessage') - let letURL = loadPropertyFromNodeConfig(node.payload, 'webhookURL') - - callWebServer(testMessage, letURL, onResponse) - - function onResponse(err) { - if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - } else { - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - } -} diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index b15396adc..99914d692 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -20,30 +20,14 @@ function newWorkspace() { getNodeByShortcutKey: getNodeByShortcutKey, getNodeById: getNodeById, stopAllRunningTasks: stopAllRunningTasks, - onMenuItemClick: onMenuItemClick, + executeAction: executeAction, physics: physics, draw: draw, spawn: spawn, - chainDetachNode: chainDetachNode, - chainAttachNode: chainAttachNode, - referenceDetachNode: referenceDetachNode, - referenceAttachNode: referenceAttachNode, initialize: initialize, finalize: finalize } - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - thisObject.container.isClickeable = false - thisObject.container.isDraggeable = false - thisObject.container.isWheelable = false - thisObject.container.detectMouseOver = false - thisObject.container.frame.radius = 0 - thisObject.container.frame.position.x = 0 - thisObject.container.frame.position.y = 0 - thisObject.container.frame.width = 0 - thisObject.container.frame.height = 0 - spawnPosition = { x: canvas.floatingSpace.container.frame.width / 2, y: canvas.floatingSpace.container.frame.height / 2 @@ -52,27 +36,6 @@ function newWorkspace() { thisObject.workspaceNode = {} thisObject.workspaceNode.rootNodes = [] - let functionLibraryReferenceAttachDetach = newReferenceAttachDetach() - let functionLibraryChainAttachDetach = newChainAttachDetach() - let functionLibraryNodeDeleter = newNodeDeleter() - let functionLibraryUiObjectsFromNodes = newUiObjectsFromNodes() - let functionLibraryProtocolNode = newProtocolNode() - let functionLibraryNodeCloning = newNodeCloning() - let functionLibraryTaskFunctions = newTaskFunctions() - let functionLibrarySessionFunctions = newSessionFunctions() - let functionLibraryShortcutKeys = newShortcutKeys() - let functionLibraryOnFocus = newOnFocus() - let functionLibrarySuperScripts = newSuperScriptsFunctions() - let functionLibraryCryptoEcosystemFunctions = newCryptoEcosystemFunctions() - let functionLibraryWebhookFunctions = newWebhookFunctions() - let functionLibraryDependenciesFilter = newDependenciesFilter() - let functionLibraryNodePath = newNodePath() - let functionLibraryDataMineFunctions = newDataMineFunctions() - let functionLibraryDataStorageFunctions = newDataStorageFunctions() - let functionLibraryChartingSpaceFunctions = newChartingSpaceFunctions() - let functionLibraryTutorialFunctions = newTutorialFunctions() - let functionLibraryPluginsFunctions = newPluginsFunctions() - thisObject.nodeChildren = newNodeChildren() let savingWorkspaceIntervalId @@ -84,19 +47,28 @@ function newWorkspace() { let sessionTimestamp = (new Date()).valueOf() window.localStorage.setItem('Session Timestamp', sessionTimestamp) + let actionSwitchesByProject = new Map() + return thisObject function finalize() { thisObject.definition = undefined - thisObject.container.finalize() - thisObject.container = undefined thisObject.workspaceNode = undefined circularProgressBar.finalize() circularProgressBar = undefined + actionSwitchesByProject = undefined } function initialize() { try { + /* Set up the action switches map */ + for (let i = 0; i < PROJECTS.length; i++) { + let project = PROJECTS[i] + let actionSwitch = eval('new' + project + 'ActionSwitch()') + actionSwitchesByProject.set(project, actionSwitch) + } + + /* Check which was the last workspace. */ let lastUsedWorkspace = window.localStorage.getItem('Last Used Workspace') if (lastUsedWorkspace !== 'undefined' && lastUsedWorkspace !== null && lastUsedWorkspace !== undefined) { @@ -120,7 +92,7 @@ function newWorkspace() { } function recreateWorkspace() { - functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode, finishInitialization) + executeAction({ node: thisObject.workspaceNode, name: 'Recreate Workspace', project: 'Superalgos', callBackFunction: finishInitialization }) } function finishInitialization() { @@ -138,12 +110,9 @@ function newWorkspace() { } function runTasksAndSessions() { - - functionLibraryUiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions) - functionLibraryUiObjectsFromNodes.syncronizeSessionsFoundAtWorkspaceWithBackEnd(functionLibrarySessionFunctions) - - setTimeout(functionLibraryUiObjectsFromNodes.playTutorials, 1000) - + executeAction({ name: 'Syncronize Tasks', project: 'Superalgos' }) + executeAction({ name: 'Syncronize Sessions', project: 'Superalgos' }) + executeAction({ name: 'Play Tutorials', project: 'Superalgos' }) } function setupEventsServerClients() { @@ -163,23 +132,7 @@ function newWorkspace() { } } - function chainDetachNode(node) { - functionLibraryChainAttachDetach.chainDetachNode(node, thisObject.workspaceNode.rootNodes) - } - - function chainAttachNode(node, attachToNode) { - functionLibraryChainAttachDetach.chainAttachNode(node, attachToNode, thisObject.workspaceNode.rootNodes) - } - - function referenceDetachNode(node) { - functionLibraryReferenceAttachDetach.referenceDetachNode(node) - } - - function referenceAttachNode(node, attachToNode) { - functionLibraryReferenceAttachDetach.referenceAttachNode(node, attachToNode, thisObject.workspaceNode.rootNodes) - } - - function saveWorkspace() { + async function saveWorkspace() { let workspace = canvas.designSpace.workspace.workspaceNode /* Validation if it is too early to save. */ @@ -195,7 +148,7 @@ function newWorkspace() { } /* Validation that there is something to save */ - let textToSave = stringifyWorkspace() + let textToSave = await stringifyWorkspace() if (textToSave === undefined) { canvas.cockpitSpace.setStatus( 'Could not save the Workspace. Something is preventing the System to do it at this time.' @@ -230,8 +183,8 @@ function newWorkspace() { } } - function getNodeById(nodeId) { - return functionLibraryUiObjectsFromNodes.getNodeById(nodeId) + async function getNodeById(nodeId) { + return await executeAction({ name: 'Get Node By Id', project: 'Superalgos', relatedNodeId: nodeId }) } function physics() { @@ -264,7 +217,7 @@ function newWorkspace() { switch (workingAtTask) { case 1: canvas.tutorialSpace.stop() - functionLibraryNodeDeleter.deleteWorkspace(thisObject.workspaceNode, thisObject.workspaceNode.rootNodes) + executeAction({ node: thisObject.workspaceNode, name: 'Delete Workspace', project: 'Superalgos' }) workingAtTask++ break case 2: @@ -283,7 +236,7 @@ function newWorkspace() { workingAtTask++ break case 5: - functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode, finishInitialization) + executeAction({ node: thisObject.workspaceNode, name: 'Recreate Workspace', project: 'Superalgos', callBackFunction: finishInitialization }) function finishInitialization() { setupEventsServerClients() runTasksAndSessions() @@ -308,13 +261,13 @@ function newWorkspace() { } } - function stringifyWorkspace(removePersonalData) { + async function stringifyWorkspace(removePersonalData) { let stringifyReadyNodes = [] for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) { let rootNode = thisObject.workspaceNode.rootNodes[i] if (rootNode.isPlugin !== true) { - let node = functionLibraryProtocolNode.getProtocolNode(rootNode, removePersonalData, false, true, true, true) + let node = await executeAction({ node: rootNode, name: 'Get Node Data Structure', project: 'Superalgos', extraParameter: removePersonalData }) stringifyReadyNodes.push(node) } } @@ -361,18 +314,18 @@ function newWorkspace() { } } - function getNodeByShortcutKey(searchingKey) { + async function getNodeByShortcutKey(searchingKey) { for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) { let rootNode = thisObject.workspaceNode.rootNodes[i] - let node = functionLibraryShortcutKeys.getNodeByShortcutKey(rootNode, searchingKey) + let node = await executeAction({ node: rootNode, name: 'Get Node By Shortcut Key', project: 'Superalgos', extraParameter: searchingKey }) if (node !== undefined) { return node } } } - function getNodeThatIsOnFocus() { + async function getNodeThatIsOnFocus() { for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) { let rootNode = thisObject.workspaceNode.rootNodes[i] - let node = functionLibraryOnFocus.getNodeThatIsOnFocus(rootNode) + let node = await executeAction({ node: rootNode, name: 'Get Node On Focus', project: 'Superalgos' }) if (node !== undefined) { return node } } } @@ -470,8 +423,8 @@ function newWorkspace() { } thisObject.workspaceNode.rootNodes.push(droppedNode) - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(droppedNode, undefined, undefined, positionOffset) - functionLibraryUiObjectsFromNodes.tryToConnectChildrenWithReferenceParents() + executeAction({ node: droppedNode, name: 'Create UI Object', project: 'Superalgos', extraParameter: positionOffset }) + executeAction({ name: 'Connect Children to Reference Parents', project: 'Superalgos' }) droppedNode = undefined } catch (err) { @@ -479,459 +432,23 @@ function newWorkspace() { } } - async function onMenuItemClick(payload, action, relatedUiObject, callBackFunction) { - switch (action) { - case 'Copy Node Path': - { - let nodePath = functionLibraryNodePath.getNodePath(payload.node) + async function executeAction(action) { + /* + Supported parameters as part of the action object: - copyTextToClipboard(nodePath) + action.node : It is the node at which the action was taken. If not specific node is involved then it should be the workspace node. + action.relatedNode : It is a secondary node involved with the action. For example the node to which the main node is being attached to. + action.relatedNodeId : It is the id of a node related to the action. + action.relatedNodeType : It is the type of the node related to the action. + action.callBackFunction : A callback function to call when the action is complete. + action.extraParameter : A parameter to send unusual info to the fnction processing the action. - canvas.cockpitSpace.setStatus( - nodePath + ' copied to the Clipboard.' - , 50, canvas.cockpitSpace.statusTypes.ALL_GOOD) - } - break - case 'Add UI Object': - { - functionLibraryUiObjectsFromNodes.addUIObject(payload.node, relatedUiObject) - } - break - case 'Add Missing Children': - { - functionLibraryUiObjectsFromNodes.addMissingChildren(payload.node) - } - break - case 'Delete UI Object': - { - functionLibraryNodeDeleter.deleteUIObject(payload.node, thisObject.workspaceNode.rootNodes) - } - break - case 'Share Workspace': - { - let text = stringifyWorkspace(true) - let fileName = 'Share - ' + payload.node.type + ' - ' + payload.node.name + '.json' - if (text !== undefined) { - downloadText(fileName, text) - } - } - break - case 'Backup Workspace': - { - let text = stringifyWorkspace(false) - let fileName = 'Backup - ' + payload.node.type + ' - ' + payload.node.name + '.json' - if (text !== undefined) { - downloadText(fileName, text) - } - } - break - case 'Edit Code': + We add rootNodes property here. + */ + action.rootNodes = thisObject.workspaceNode.rootNodes - break - case 'Share': - { - let text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, true, false, true, true, true)) + let actionSwitch = actionSwitchesByProject.get(action.project) + return actionSwitch.executeAction(action) - let nodeName = payload.node.name - if (nodeName === undefined) { - nodeName = '' - } else { - nodeName = '.' + nodeName - } - let fileName = 'Share - ' + payload.node.type + ' - ' + nodeName + '.json' - downloadText(fileName, text) - } - - break - case 'Backup': - { - let text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, false, false, true, true, true)) - - let nodeName = payload.node.name - if (nodeName === undefined) { - nodeName = '' - } else { - nodeName = ' ' + nodeName - } - let fileName = 'Backup - ' + payload.node.type + ' - ' + nodeName + '.json' - downloadText(fileName, text) - } - - break - case 'Clone': - { - let text = JSON.stringify(functionLibraryNodeCloning.getNodeClone(payload.node)) - - let nodeName = payload.node.name - if (nodeName === undefined) { - nodeName = '' - } else { - nodeName = ' ' + nodeName - } - let fileName = 'Clone - ' + payload.node.type + ' - ' + nodeName + '.json' - downloadText(fileName, text) - } - - break - case 'Debug Task': - { - functionLibraryTaskFunctions.runTask(payload.node, functionLibraryProtocolNode, true, callBackFunction) - } - break - case 'Run Task': - { - functionLibraryTaskFunctions.runTask(payload.node, functionLibraryProtocolNode, false, callBackFunction) - } - break - case 'Stop Task': - { - functionLibraryTaskFunctions.stopTask(payload.node, functionLibraryProtocolNode, callBackFunction) - } - break - case 'Run All Tasks': - { - functionLibraryTaskFunctions.runAllTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Tasks': - { - functionLibraryTaskFunctions.stopAllTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Task Managers': - { - functionLibraryTaskFunctions.runAllTaskManagers(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Task Managers': - { - functionLibraryTaskFunctions.stopAllTaskManagers(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Exchange Data Tasks': - { - functionLibraryTaskFunctions.runAllExchangeDataTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Exchange Data Tasks': - { - functionLibraryTaskFunctions.stopAllExchangeDataTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Exchange Trading Tasks': - { - functionLibraryTaskFunctions.runAllExchangeTradingTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Exchange Trading Tasks': - { - functionLibraryTaskFunctions.stopAllExchangeTradingTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Market Data Tasks': - { - functionLibraryTaskFunctions.runAllMarketDataTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Market Data Tasks': - { - functionLibraryTaskFunctions.stopAllMarketDataTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Market Trading Tasks': - { - functionLibraryTaskFunctions.runAllMarketTradingTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Market Trading Tasks': - { - functionLibraryTaskFunctions.stopAllMarketTradingTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Data Mine Tasks': - { - functionLibraryTaskFunctions.runAllDataMineTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Data Mine Tasks': - { - functionLibraryTaskFunctions.stopAllDataMineTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Run All Trading Mine Tasks': - { - functionLibraryTaskFunctions.runAllTradingMineTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Stop All Trading Mine Tasks': - { - functionLibraryTaskFunctions.stopAllTradingMineTasks(payload.node, functionLibraryProtocolNode) - } - break - case 'Add Missing Exchange Data Tasks': - { - functionLibraryTaskFunctions.addMissingExchangeDataTasks(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Market Data Tasks': - { - functionLibraryTaskFunctions.addMissingMarketDataTasks(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Data Mine Tasks': - { - functionLibraryTaskFunctions.addMissingDataMineTasks(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Exchange Trading Tasks': - { - functionLibraryTaskFunctions.addMissingExchangeTradingTasks(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Market Trading Tasks': - { - functionLibraryTaskFunctions.addMissingMarketTradingTasks(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Trading Mine Tasks': - { - functionLibraryTaskFunctions.addMissingTradingMineTasks(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Tasks': - { - functionLibraryTaskFunctions.addAllTasks(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Crypto Exchanges': - { - functionLibraryCryptoEcosystemFunctions.addMissingExchanges(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Assets': - { - functionLibraryCryptoEcosystemFunctions.addMissingAssets(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Markets': - { - functionLibraryCryptoEcosystemFunctions.addMissingMarkets(payload.node, functionLibraryUiObjectsFromNodes, functionLibraryNodeCloning) - } - break - case 'Install Market': - { - functionLibraryCryptoEcosystemFunctions.installMarket(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter, functionLibraryChartingSpaceFunctions, functionLibraryDataStorageFunctions) - } - break - case 'Uninstall Market': - { - functionLibraryCryptoEcosystemFunctions.uninstallMarket(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter, functionLibraryChartingSpaceFunctions, functionLibraryDataStorageFunctions) - } - break - case 'Add All Output Datasets': - { - functionLibraryDataMineFunctions.addAllOutputDatasets(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Data Products': - { - functionLibraryDataStorageFunctions.addAllDataProducts(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Data Mine Products': - { - functionLibraryDataStorageFunctions.addAllDataMineProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Trading Mine Products': - { - functionLibraryDataStorageFunctions.addAllTradingMineProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Session References': - { - functionLibraryDataStorageFunctions.addMissingSessionReferences(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Market Data Products': - { - functionLibraryDataStorageFunctions.addMissingMarketDataProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Market Trading Products': - { - functionLibraryDataStorageFunctions.addMissingMarketTradingProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Exchange Trading Products': - { - functionLibraryDataStorageFunctions.addMissingExchangeTradingProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Exchange Data Products': - { - functionLibraryDataStorageFunctions.addMissingExchangeDataProducts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Data Dependencies': - { - functionLibraryDataMineFunctions.addAllDataDependencies(payload.node, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Data Mine Dependencies': - { - functionLibraryDataMineFunctions.addAllDataMineDataDependencies(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add All Mine Layers': - { - functionLibraryChartingSpaceFunctions.addAllMineLayers(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - break - case 'Add Missing Time Machines': - { - functionLibraryChartingSpaceFunctions.addMissingTimeMachines(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - break - case 'Add Missing Dashboards': - { - functionLibraryChartingSpaceFunctions.addMissingDashboards(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - break - case 'Play Tutorial': - { - canvas.tutorialSpace.playTutorial(payload.node) - } - break - case 'Play Tutorial Topic': - { - canvas.tutorialSpace.playTutorialTopic(payload.node) - } - break - case 'Play Tutorial Step': - { - canvas.tutorialSpace.playTutorialStep(payload.node) - } - break - case 'Resume Tutorial': - { - canvas.tutorialSpace.resumeTutorial(payload.node) - } - break - case 'Resume Tutorial Topic': - { - canvas.tutorialSpace.resumeTutorialTopic(payload.node) - } - break - case 'Resume Tutorial Step': - { - canvas.tutorialSpace.resumeTutorialStep(payload.node) - } - break - case 'Reset Tutorial Progress': - { - canvas.tutorialSpace.resetTutorialProgress(payload.node) - } - break - case 'Send Webhook Test Message': - { - functionLibraryWebhookFunctions.sendTestMessage(payload.node, callBackFunction) - } - break - case 'Run Session': - { - functionLibrarySessionFunctions.runSession(payload.node, functionLibraryProtocolNode, functionLibraryDependenciesFilter, false, callBackFunction) - } - break - case 'Resume Session': - { - functionLibrarySessionFunctions.runSession(payload.node, functionLibraryProtocolNode, functionLibraryDependenciesFilter, true, callBackFunction) - } - break - case 'Stop Session': - { - functionLibrarySessionFunctions.stopSession(payload.node, functionLibraryProtocolNode, callBackFunction) - } - break - case 'Run Super Action': - { - functionLibrarySuperScripts.runSuperScript(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryNodeCloning, functionLibraryUiObjectsFromNodes, functionLibraryNodeDeleter) - } - break - case 'Remove Parent': - { - chainDetachNode(payload.node) - } - break - case 'Remove Reference': - { - referenceDetachNode(payload.node) - } - break - case 'Push Code to Javascript Code': - { - payload.node.javascriptCode.code = payload.node.code - } - break - case 'Fetch Code to Javascript Code': - { - payload.node.code = payload.node.javascriptCode.code - } - break - case 'Open Documentation': - { - let definition = getNodeDefinition(payload.node) - if (definition !== undefined) { - if (definition.docURL !== undefined) { - canvas.docSpace.navigateTo(definition.docURL) - } else { - let headName = getHiriarchyHead(payload.node).type - headName = headName.toLowerCase() - headName = headName.split(" ").join("-") - let nodeName = payload.node.type - nodeName = nodeName.toLowerCase() - nodeName = nodeName.split(" ").join("-") - url = DOCUMENTATION_URL_PREFIX + "suite-hierarchy-" + headName + ".html#" + nodeName - canvas.docSpace.navigateTo(url) - } - } - } - break - case 'Add Missing Plugin Projects': - { - functionLibraryPluginsFunctions.pluginMissingProjects(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Data Mines': - { - functionLibraryPluginsFunctions.pluginMissingDataMines(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Trading Mines': - { - functionLibraryPluginsFunctions.pluginMissingTradingMines(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Trading Systems': - { - functionLibraryPluginsFunctions.pluginMissingTradingSystems(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Trading Engines': - { - functionLibraryPluginsFunctions.pluginMissingTradingEngines(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Super Scripts': - { - functionLibraryPluginsFunctions.pluginMissingSuperScripts(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - case 'Add Missing Plugin Tutorials': - { - functionLibraryPluginsFunctions.pluginMissingTutorials(payload.node, thisObject.workspaceNode.rootNodes, functionLibraryUiObjectsFromNodes) - } - break - } } } diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 3d1a6d689..289e4876d 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -302,7 +302,7 @@ function newCircularMenuItem() { if (thisObject.label === undefined) { /* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */ - thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject) + thisObject.actionFunction({ node: thisObject.payload.node, name: thisObject.action, project: thisObject.payload.node.project, relatedNodeType: thisObject.relatedUiObject }) return } @@ -339,7 +339,7 @@ function newCircularMenuItem() { } /* Execute the action and wait for callbacks to update our statuus. */ - thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject, onPrimaryCallBack) + thisObject.actionFunction({ node: thisObject.payload.node, name: thisObject.action, project: thisObject.payload.node.project, relatedNodeType: thisObject.relatedUiObject, callBackFunction: onPrimaryCallBack }) return } if (temporaryStatus === STATUS_PRIMARY_WORK_DONE && thisObject.secondaryAction !== undefined) { @@ -349,7 +349,7 @@ function newCircularMenuItem() { } /* Execute the action and wait for callbacks to update our statuus. */ - thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, thisObject.relatedUiObject, onSecondaryCallBack) + thisObject.actionFunction({ node: thisObject.payload.node, name: thisObject.secondaryAction, project: thisObject.payload.node.project, relatedNodeType: thisObject.relatedUiObject, callBackFunction: onSecondaryCallBack }) return } diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index eceaab53a..aa52fe792 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -581,7 +581,7 @@ function newUiObject() { let THRESHOLD = 1.15 if (ratio > THRESHOLD) { - canvas.designSpace.workspace.chainDetachNode(thisObject.payload.node) + canvas.designSpace.workspace.executeAction({ node: thisObject.payload.node, name: 'Parent Detach', project: 'Superalgos' }) } } @@ -692,7 +692,7 @@ function newUiObject() { let THRESHOLD = 1.15 if (ratio > THRESHOLD) { - canvas.designSpace.workspace.referenceDetachNode(thisObject.payload.node) + canvas.designSpace.workspace.executeAction({ node: thisObject.payload.node, name: 'Reference Detach', project: 'Superalgos' }) } } @@ -1022,9 +1022,9 @@ function newUiObject() { eventSubscriptionIdOnError = message.eventSubscriptionId } - function onError(message) { + async function onError(message) { - let uiObject = getTargetUiObject(message) + let uiObject = await getTargetUiObject(message) uiObject.setErrorMessage(message.event.errorMessage, 10) let event = { @@ -1042,8 +1042,8 @@ function newUiObject() { eventSubscriptionIdOnWarning = message.eventSubscriptionId } - function onWarning(message) { - let uiObject = getTargetUiObject(message) + async function onWarning(message) { + let uiObject = await getTargetUiObject(message) uiObject.setWarningMessage(message.event.warningMessage, 10) } } @@ -1056,17 +1056,17 @@ function newUiObject() { eventSubscriptionIdOnInfo = message.eventSubscriptionId } - function onInfo(message) { - let uiObject = getTargetUiObject(message) + async function onInfo(message) { + let uiObject = await getTargetUiObject(message) uiObject.setInfoMessage(message.event.infoMessage, 10) } } } - function getTargetUiObject(message) { + async function getTargetUiObject(message) { let uiObject = thisObject if (message.event.nodeId !== undefined) { - let targetNode = canvas.designSpace.workspace.getNodeById(message.event.nodeId) + let targetNode = await canvas.designSpace.workspace.getNodeById(message.event.nodeId) if (targetNode !== undefined) { if (targetNode.payload !== undefined) { if (targetNode.payload.uiObject !== undefined) { @@ -1221,12 +1221,12 @@ function newUiObject() { function onDragFinished(event) { if (isChainAttaching === true) { - canvas.designSpace.workspace.chainAttachNode(thisObject.payload.node, chainAttachToNode) + canvas.designSpace.workspace.executeAction({ node: thisObject.payload.node, name: 'Parent Attach', project: 'Superalgos', relatedNode: chainAttachToNode }) chainAttachToNode = undefined isChainAttaching = false } if (isReferenceAttaching === true) { - canvas.designSpace.workspace.referenceAttachNode(thisObject.payload.node, referenceAttachToNode) + canvas.designSpace.workspace.executeAction({ node: thisObject.payload.node, name: 'Reference Attach', project: 'Superalgos', relatedNode: referenceAttachToNode }) referenceAttachToNode = undefined isReferenceAttaching = false } diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index e611c0b3d..ee40fc5f8 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -200,7 +200,7 @@ function newUiObjectConstructor() { } } if (item.actionFunction === undefined) { - // item.actionFunction = 'payload.onMenuItemClick' + // item.actionFunction = 'payload.executeAction' } } @@ -317,7 +317,7 @@ function newUiObjectConstructor() { menuItemsInitialValues.push( { action: 'Backup', - actionFunction: floatingObject.payload.onMenuItemClick, + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'backup', @@ -331,7 +331,7 @@ function newUiObjectConstructor() { menuItemsInitialValues.push( { action: 'Clone', - actionFunction: floatingObject.payload.onMenuItemClick, + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'clone', @@ -346,7 +346,7 @@ function newUiObjectConstructor() { menuItemsInitialValues.push( { action: 'Share', - actionFunction: floatingObject.payload.onMenuItemClick, + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'share', @@ -360,8 +360,8 @@ function newUiObjectConstructor() { } menuItemsInitialValues.push( { - action: 'Remove Parent', - actionFunction: floatingObject.payload.onMenuItemClick, + action: 'Parent Detach', + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'detach', @@ -374,8 +374,8 @@ function newUiObjectConstructor() { ) menuItemsInitialValues.push( { - action: 'Remove Reference', - actionFunction: floatingObject.payload.onMenuItemClick, + action: 'Reference Detach', + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'delink', @@ -390,7 +390,7 @@ function newUiObjectConstructor() { menuItemsInitialValues.push( { action: 'Open Documentation', - actionFunction: floatingObject.payload.onMenuItemClick, + actionFunction: floatingObject.payload.executeAction, label: undefined, visible: true, iconPathOn: 'help', diff --git a/PostLoader.js b/PostLoader.js index 8cc102205..2df110f1f 100644 --- a/PostLoader.js +++ b/PostLoader.js @@ -14,18 +14,12 @@ function newPostLoader() { function start() { try { + /* Moving PROJECTS to the global variable */ + PROJECTS = window.PROJECTS + window.PROJECTS = undefined + setBrowserEvents() - setUpProjects(setUpSchemas) - - function setUpProjects(callBack) { - let url = 'ProjectNames' - callWebServer(undefined, url, onResponse) - - function onResponse(err, projects) { - PROJECTS = JSON.parse(projects) - callBack() - } - } + setUpSchemas() function setUpSchemas() {