From 12568602aa29c194264e3cd7530ac3063ac7e4ef Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 28 Mar 2020 17:40:32 +0100 Subject: [PATCH] Data Mines Includes --- .../FunctionLibraries/UiObjectsFromNodes.js | 75 +++++++++++++++---- DesignSpace/Workspace/Workspace.js | 16 +++- Spaces/ChartingSpace.js | 10 ++- 3 files changed, 83 insertions(+), 18 deletions(-) diff --git a/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 772681f5c..df7391fee 100644 --- a/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -19,26 +19,69 @@ function newUiObjectsFromNodes () { tasksToRun = [] sessionsToRun = [] - /* 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) + addIncludedNodes() + + function addIncludedNodes () { + blobService = newFileStorage() + + if (node.code === undefined) { + node.code = '{ \n"includeDataMines": ["Masters", "Sparta", "TradingEngines"]\n}' + } + + let code = JSON.parse(node.code) + let includeDataMines = code.includeDataMines + + let totalIncluded = 0 + + for (let i = 0; i < includeDataMines.length; i++) { + let dataMine = includeDataMines[i] + blobService.getBlobToText('DataMines' + '/' + dataMine, undefined, onFileReceived, true) + function onFileReceived (err, text, response) { + if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + console.log('Cannot load included Data Mine ' + dataMine + '. The workspace can not be loaded.') + return + } + let includedDataMine = JSON.parse(text) + for (let i = 0; i < node.rootNodes.length; i++) { + let rootNode = node.rootNodes[i] + if (rootNode.type === 'Data Mine') { + let code = JSON.parse(rootNode.code) + if (code.name === dataMine) { + rootNodes.splice(i, 1) + } + } + } + node.rootNodes.push(includedDataMine) + totalIncluded++ + if (totalIncluded === includeDataMines.length) { + addUserDefinedNodes() + } + } } } - tryToConnectChildrenWithReferenceParents() + 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) + } + } - if (replacingCurrentWorkspace === true) { - // We need to wait all tasks that were potentially running to stop - setTimeout(runTasks, 70000) - // We give a few seconds for the tasks to start - setTimeout(runSessions, 80000) - } else { - runTasks() - // We give a few seconds for the tasks to start - setTimeout(runSessions, 10000) + tryToConnectChildrenWithReferenceParents() + + if (replacingCurrentWorkspace === true) { + // We need to wait all tasks that were potentially running to stop + setTimeout(runTasks, 70000) + // We give a few seconds for the tasks to start + setTimeout(runSessions, 80000) + } else { + runTasks() + // We give a few seconds for the tasks to start + setTimeout(runSessions, 10000) + } } } diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index 45fbf03d7..debbc7ed2 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -169,12 +169,26 @@ function newWorkspace () { } function stringifyWorkspace (removePersonalData) { + let code + if (thisObject.workspaceNode.code === undefined) { + thisObject.workspaceNode.code = '{ \n"includeDataMines": ["Masters", "Sparta", "TradingEngines"]\n}' + } + code = JSON.parse(thisObject.workspaceNode.code) + let includeDataMines = code.includeDataMines + let stringifyReadyNodes = [] for (let i = 0; i < thisObject.workspaceNode.rootNodes.length; i++) { let rootNode = thisObject.workspaceNode.rootNodes[i] let node = functionLibraryProtocolNode.getProtocolNode(rootNode, removePersonalData, false, true, true, true) if (node) { - stringifyReadyNodes.push(node) + if (node.type !== 'Data Mine') { + stringifyReadyNodes.push(node) + } else { + code = JSON.parse(node.code) + if (includeDataMines.includes(code.codeName) === false) { + stringifyReadyNodes.push(node) + } + } } } let workspace = { diff --git a/Spaces/ChartingSpace.js b/Spaces/ChartingSpace.js index dba998962..b120852e0 100644 --- a/Spaces/ChartingSpace.js +++ b/Spaces/ChartingSpace.js @@ -41,6 +41,9 @@ function newChartingSpace () { const PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT = 25 initialSetup() + + let isInitialized = false + return thisObject function reset () { @@ -87,6 +90,8 @@ function newChartingSpace () { } function initialize () { + if (isInitialized === true) { return } + let rootNodes = canvas.designSpace.workspace.workspaceNode.rootNodes for (let i = 0; i < rootNodes.length; i++) { let rootNode = rootNodes[i] @@ -96,7 +101,7 @@ function newChartingSpace () { } if (thisObject.payload === undefined) { - if (ERROR_LOG === true) { logger.write('[WARN] initialize -> There must exist a Charting Space at the Design Space in order to enable Charts. PLease create one and refreash your browser. ') } + // if (ERROR_LOG === true) { logger.write('[WARN] initialize -> There must exist a Charting Space at the Design Space in order to enable Charts. PLease create one and refreash your browser. ') } return } @@ -111,6 +116,8 @@ function newChartingSpace () { thisObject.viewport.initialize() canvasBrowserResizedEventSubscriptionId = canvas.eventHandler.listenToEvent('Browser Resized', resize) + + isInitialized = true } function getContainer (point, purpose) { @@ -263,6 +270,7 @@ function newChartingSpace () { } function physics () { + initialize() thisObjectPhysics() if (thisObject.visible !== true) { return } if (thisObject.viewport !== undefined) {