diff --git a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js b/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js index 7948f8fdf..c664577ee 100644 --- a/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/CryptoEcosystemFunctions.js @@ -31,7 +31,7 @@ function newCryptoEcosystemFunctions() { } } - callServer(JSON.stringify(params), 'CCXT', onResponse) + callWebServer(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -79,7 +79,7 @@ function newCryptoEcosystemFunctions() { exchangeId: exchangeId, method: 'fetchMarkets' } - callServer(JSON.stringify(params), 'CCXT', onResponse) + callWebServer(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -155,7 +155,7 @@ function newCryptoEcosystemFunctions() { exchangeId: exchangeId, method: 'fetchMarkets' } - callServer(JSON.stringify(params), 'CCXT', onResponse) + callWebServer(JSON.stringify(params), 'CCXT', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js b/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js index 8787b0040..cf265bd83 100644 --- a/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/PluginsFunctions.js @@ -10,7 +10,7 @@ function newPluginsFunctions() { return thisObject function getPluginFileNames(pluginType, callBack) { - callServer(undefined, 'PluginFileNames/' + pluginType, onResponse) + callWebServer(undefined, 'PluginFileNames/' + pluginType, onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js b/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js index 1b0d9d467..5042fcdee 100644 --- a/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/TaskFunctions.js @@ -145,7 +145,7 @@ function newTaskFunctions() { let networkDefinition = functionLibraryProtocolNode.getProtocolNode(networkNode.payload.parentNode, false, true, true, false, false, networkLightingPath) let event = { - appSchema: JSON.stringify(APP_SCHEMA_ARRAY), + appSchema: JSON.stringify(SCHEMAS_BY_PROJECT.get('Superalgos').array.appSchema), taskId: node.id, taskName: node.name, taskDefinition: JSON.stringify(taskDefinition), diff --git a/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js b/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js index 609a94c5a..15bd466ff 100644 --- a/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/WebhookFunctions.js @@ -9,7 +9,7 @@ function newWebhookFunctions() { let testMessage = loadPropertyFromNodeConfig(node.payload, 'testMessage') let letURL = loadPropertyFromNodeConfig(node.payload, 'webhookURL') - callServer(testMessage, letURL, onResponse) + callWebServer(testMessage, letURL, onResponse) function onResponse(err) { if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index 2dc255463..4c7e2ff84 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -215,7 +215,7 @@ function newWorkspace() { } let url = 'SaveWorkspace/' + workspace.name - callServer(textToSave, url, onResponse) + callWebServer(textToSave, url, onResponse) return true function onResponse(err) { diff --git a/Globals.js b/Globals.js index 38a6d4964..79595a7f4 100644 --- a/Globals.js +++ b/Globals.js @@ -1,12 +1,7 @@ /* Canvas is the root object that will contain all spaces and everything inside. */ let canvas - -let APP_SCHEMA_MAP = new Map() -let APP_SCHEMA_ARRAY = [] -let DOC_SCHEMA_MAP = new Map() -let DOC_SCHEMA_ARRAY = [] -let CONCEPT_SCHEMA_MAP = new Map() -let CONCEPT_SCHEMA_ARRAY = [] +let PROJECTS +let SCHEMAS_BY_PROJECT = new Map() /* User Interface Colors */ const UI_COLOR = { diff --git a/PostLoader.js b/PostLoader.js index fb5fd562e..8cc102205 100644 --- a/PostLoader.js +++ b/PostLoader.js @@ -15,33 +15,103 @@ function newPostLoader() { function start() { try { setBrowserEvents() - setUpSchemas() + setUpProjects(setUpSchemas) + + function setUpProjects(callBack) { + let url = 'ProjectNames' + callWebServer(undefined, url, onResponse) + + function onResponse(err, projects) { + PROJECTS = JSON.parse(projects) + callBack() + } + } function setUpSchemas() { - APP_SCHEMA_ARRAY = getAppSchema() - for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) { - let nodeDefinition = APP_SCHEMA_ARRAY[i] - let key = nodeDefinition.type - APP_SCHEMA_MAP.set(key, nodeDefinition) + + let totalWebServerCalls = 0 + let webServerResponses = 0 + + for (let i = 0; i < PROJECTS.length; i++) { + let project = PROJECTS[i] + let schemas = { + array: { + appSchema: [], + docSchema: [], + conceptSchema: [] + }, + map: { + appSchema: new Map(), + docSchema: new Map(), + conceptSchema: new Map() + } + } + SCHEMAS_BY_PROJECT.set(project, schemas) + + totalWebServerCalls++ + callWebServer(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) + + function onResponseAppSchema(err, schema) { + try { + schemas.array.appSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.appSchema.length; j++) { + let nodeDefinition = schemas.array.appSchema[j] + let key = nodeDefinition.type + schemas.map.appSchema.set(key, nodeDefinition) + } + } catch(err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) {startCanvas()} + } + + totalWebServerCalls++ + callWebServer(undefined, 'Schema/' + project + '/DocSchema', onResponseDocSchema) + + function onResponseDocSchema(err, schema) { + try { + schemas.array.docSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docSchema.length; j++) { + let nodeDefinition = schemas.array.docSchema[j] + let key = nodeDefinition.type + schemas.map.docSchema.set(key, nodeDefinition) + } + } catch(err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) {startCanvas()} + } + + totalWebServerCalls++ + callWebServer(undefined, 'Schema/' + project + '/ConceptSchema', onResponseConceptSchema) + + function onResponseConceptSchema(err, schema) { + try { + schemas.array.conceptSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.conceptSchema.length; j++) { + let nodeDefinition = schemas.array.conceptSchema[j] + let key = nodeDefinition.type + schemas.map.conceptSchema.set(key, nodeDefinition) + } + } catch(err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) {startCanvas()} + } } - DOC_SCHEMA_ARRAY = getDocSchema() - for (let i = 0; i < DOC_SCHEMA_ARRAY.length; i++) { - let nodeDefinition = DOC_SCHEMA_ARRAY[i] - let key = nodeDefinition.type - DOC_SCHEMA_MAP.set(key, nodeDefinition) - } - CONCEPT_SCHEMA_ARRAY = getConceptSchema() - for (let i = 0; i < CONCEPT_SCHEMA_ARRAY.length; i++) { - let nodeDefinition = CONCEPT_SCHEMA_ARRAY[i] - let key = nodeDefinition.type - CONCEPT_SCHEMA_MAP.set(key, nodeDefinition) - } - startCanvas() } function startCanvas() { /* If this method is executed for a second time, it should finalize the current execution structure */ - if (canvas !== undefined) { canvas.finalize() } canvas = newCanvas() diff --git a/SideSpace/ListView.js b/SideSpace/ListView.js index 3f8b77b37..9e6ebe747 100644 --- a/SideSpace/ListView.js +++ b/SideSpace/ListView.js @@ -90,7 +90,7 @@ function newListView() { function turnOn() { firstVisibleListItem = 1 - callServer(undefined, 'ListWorkspaces', onResponse) + callWebServer(undefined, 'ListWorkspaces', onResponse) function onResponse(err, text) { if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/Spaces/DesignSpace.js b/Spaces/DesignSpace.js index 805fcdd23..f61df46d5 100644 --- a/Spaces/DesignSpace.js +++ b/Spaces/DesignSpace.js @@ -6,7 +6,7 @@ function newDesignSpace() { iconsByProjectAndName: undefined, iconsByProjectAndType: undefined, workspace: undefined, - getIconByProjectAndName: getIconByProjectAndName, + getIconByProjectAndName: getIconByProjectAndName, getIconByProjectAndType: getIconByProjectAndType, physics: physics, draw: draw, @@ -38,16 +38,21 @@ function newDesignSpace() { function buildIconByProjectAndTypeMap() { /* Take types-icons relationships defined at the schema */ - for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) { - let nodeDefinition = APP_SCHEMA_ARRAY[i] - let iconName = nodeDefinition.icon - if (iconName === undefined) { - iconName = nodeDefinition.type.toLowerCase() - iconName = iconName.split(" ").join("-") - } - let icon = thisObject.getIconByProjectAndName('Superalgos', iconName) - if (icon !== undefined) { - thisObject.iconsByProjectAndType.set('Superalgos' + '-' + nodeDefinition.type, icon) + for (let i = 0; i < PROJECTS.length; i++) { + let project = PROJECTS[i] + let appSchema = SCHEMAS_BY_PROJECT.get(project).array.appSchema + for (let j = 0; j < appSchema.length; j++) { + let nodeDefinition = appSchema[j] + let iconName = nodeDefinition.icon + if (iconName === undefined) { + iconName = nodeDefinition.type.toLowerCase() + iconName = iconName.split(" ").join("-") + } + let icon = thisObject.getIconByProjectAndName(project, iconName) + if (icon !== undefined) { + let key = project + '-' + nodeDefinition.type + thisObject.iconsByProjectAndType.set(key, icon) + } } } } @@ -55,7 +60,7 @@ function newDesignSpace() { function loadIconCollection(callBack) { - callServer(undefined, 'IconNames', onResponse) + callWebServer(undefined, 'IconNames', onResponse) function onResponse(err, data) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { diff --git a/Spaces/TutorialSpace.js b/Spaces/TutorialSpace.js index 41402a9f1..e21b0c7aa 100644 --- a/Spaces/TutorialSpace.js +++ b/Spaces/TutorialSpace.js @@ -1187,9 +1187,9 @@ function newTutorialSpace() { if (nodeType === undefined) { return resultingText + firstPart } - let definitionNode = DOC_SCHEMA_MAP.get(nodeType) + let definitionNode = SCHEMAS_BY_PROJECT.get(currentNode.project).map.docSchema.get(nodeType) if (definitionNode === undefined) { - definitionNode = CONCEPT_SCHEMA_MAP.get(nodeType) + definitionNode = SCHEMAS_BY_PROJECT.get(currentNode.project).map.conceptSchema.get(nodeType) if (definitionNode === undefined) { currentNode.payload.uiObject.setErrorMessage(nodeType + ' not found at Doc Schema or Concept Schema.') return diff --git a/Utilities.js b/Utilities.js index 5c68b4b3a..1841052cc 100644 --- a/Utilities.js +++ b/Utilities.js @@ -1,6 +1,5 @@ function getNodeDefinition(node) { - let key = node.type - return APP_SCHEMA_MAP.get(key) + return SCHEMAS_BY_PROJECT.get(node.project).map.appSchema.get(node.type) } function dynamicDecimals(value, minDecimals) {