From e4323deb83a28bf8deebbd6cebd8541a76643d52 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 7 Oct 2019 14:51:58 +0200 Subject: [PATCH] Session Concept Introduced into Product Storage --- ChartsSpace/PlottersManager.js | 2 +- ProductStorage.js | 10 +-- .../FunctionLibraries/LayerFunctions.js | 61 +++++++++++++++++++ .../FunctionLibraries/TaskFunctions.js | 10 ++- StrategySpace/Workspace/Workspace.js | 21 +++++++ 5 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 StrategySpace/Workspace/FunctionLibraries/LayerFunctions.js diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index 13d85f703..2f02369f2 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -335,7 +335,7 @@ function newPlottersManager () { } } - storage.initialize(pProductCard.devTeam, pProductCard.bot, pProductCard.product, exchange, market, datetime, timePeriod, onProductStorageInitialized) + storage.initialize(pProductCard.devTeam, pProductCard.bot, undefined, pProductCard.product, exchange, market, datetime, timePeriod, onProductStorageInitialized) function onProductStorageInitialized (err) { try { diff --git a/ProductStorage.js b/ProductStorage.js index 371270b90..8cd70d1b7 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -74,7 +74,7 @@ function newProductStorage (pName) { } } - function initialize (pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize (pDevTeam, pBot, pSession, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { try { datetime = pDatetime timePeriod = pTimePeriod @@ -90,7 +90,7 @@ function newProductStorage (pName) { dataSetsToLoad++ let marketFiles = newMarketFiles() - marketFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onMarketFileReady) + marketFiles.initialize(pDevTeam, pBot, pSession, pProduct, thisSet, pExchange, pMarket, onMarketFileReady) thisObject.marketFiles.push(marketFiles) } break @@ -99,7 +99,7 @@ function newProductStorage (pName) { dataSetsToLoad++ let dailyFiles = newDailyFiles() - dailyFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onDailyFileReady) + dailyFiles.initialize(pDevTeam, pBot, pSession, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onDailyFileReady) thisObject.dailyFiles.push(dailyFiles) } break @@ -108,7 +108,7 @@ function newProductStorage (pName) { dataSetsToLoad++ let singleFile = newSingleFile() - singleFile.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady) + singleFile.initialize(pDevTeam, pBot, pSession, pProduct, thisSet, pExchange, pMarket, onSingleFileReady) thisObject.singleFile.push(singleFile) } break @@ -117,7 +117,7 @@ function newProductStorage (pName) { dataSetsToLoad++ let fileSequences = newFileSequence() - fileSequences.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady) + fileSequences.initialize(pDevTeam, pBot, pSession, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady) thisObject.fileSequences.push(fileSequences) } break diff --git a/StrategySpace/Workspace/FunctionLibraries/LayerFunctions.js b/StrategySpace/Workspace/FunctionLibraries/LayerFunctions.js new file mode 100644 index 000000000..20996c66e --- /dev/null +++ b/StrategySpace/Workspace/FunctionLibraries/LayerFunctions.js @@ -0,0 +1,61 @@ +function newLayerFunctions () { + thisObject = { + turnLayerOn: turnLayerOn, + turnLayerOff: turnLayerOff, + turnAllLayersOn: turnAllLayersOn, + turnAllLayersOff: turnAllLayersOff + } + + return thisObject + + function turnLayerOn (node, functionLibraryProtocolNode, callBackFunction) { + /* Check if it is possible to turn on or not */ + let code + try { + code = JSON.parse(node.code) + } catch (err) { + { + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + } + + /* Ok, we are going to turn the layer on */ + } + + function turnLayerOff (node, functionLibraryProtocolNode, callBackFunction) { + let event = { + taskId: node.id, + taskName: node.name + } + systemEventHandler.raiseEvent('Layer Manager', 'Turn Layer Off', event) + + node.payload.uiObject.stop(callBackFunction) + + 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 turnAllLayersOn (taskManager, functionLibraryProtocolNode) { + for (let i = 0; i < taskManager.tasks.length; i++) { + let node = taskManager.tasks[i] + let menu = node.payload.uiObject.menu + + menu.internalClick('Turn Layer On') + } + } + + function turnAllLayersOff (taskManager, functionLibraryProtocolNode) { + for (let i = 0; i < taskManager.tasks.length; i++) { + let node = taskManager.tasks[i] + let menu = node.payload.uiObject.menu + + menu.internalClick('Turn Layer Off') + } + } +} diff --git a/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js b/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js index 341f386dc..4d8f9bf83 100644 --- a/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js +++ b/StrategySpace/Workspace/FunctionLibraries/TaskFunctions.js @@ -10,8 +10,14 @@ function newTaskFunctions () { function runTask (node, functionLibraryProtocolNode, callBackFunction) { /* Check if it is possible to Run or not */ - if (node.bot === undefined) { return } - if (node.bot.processes.length === 0) { return } + if (node.bot === undefined) { + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } + if (node.bot.processes.length === 0) { + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + return + } for (let i = 0; i < node.bot.processes.length; i++) { let process = node.bot.processes[i] diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index 5686c26e9..a67f3d93c 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -47,6 +47,7 @@ function newWorkspace () { let functionLibraryProtocolNode = newProtocolNode() let functionLibraryWorkspaceNodes = newStringifyNode() let functionLibraryTaskFunctions = newTaskFunctions() + let functionLibraryLayerFunctions = newLayerFunctions() let functionLibrarySessionFunctions = newSessionFunctions() thisObject.nodeChildren = newNodeChildren() @@ -233,6 +234,26 @@ function newWorkspace () { download(fileName, text) } + break + case 'Turn Layer On': + { + functionLibraryLayerFunctions.turnLayerOn(payload.node, functionLibraryProtocolNode, callBackFunction) + } + break + case 'Turn Layer Off': + { + functionLibraryLayerFunctions.turnLayerOff(payload.node, functionLibraryProtocolNode, callBackFunction) + } + break + case 'Turn All Layers On': + { + functionLibraryLayerFunctions.turnAllLayersOn(payload.node, functionLibraryProtocolNode) + } + break + case 'Turn All Layers Off': + { + functionLibraryLayerFunctions.turnAllLayersOff(payload.node, functionLibraryProtocolNode) + } break case 'Run Task': {