From 0ff2809f0d26a30875445e83d9315ae4ddf340d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 6 Sep 2021 14:11:54 +0200 Subject: [PATCH 01/20] Reorg of UI loader --- Desktop/{ => Client}/httpInterface.js | 2 +- Desktop/DesktopApp.js | 4 +- Desktop/UI/AppPostLoader.js | 232 ++++++++++++++++++++++++++ Desktop/UI/AppPreLoader.js | 181 ++++++++++++++++++++ Platform/UI/AppLoader.js | 22 +-- 5 files changed, 427 insertions(+), 14 deletions(-) rename Desktop/{ => Client}/httpInterface.js (95%) create mode 100644 Desktop/UI/AppPostLoader.js create mode 100644 Desktop/UI/AppPreLoader.js diff --git a/Desktop/httpInterface.js b/Desktop/Client/httpInterface.js similarity index 95% rename from Desktop/httpInterface.js rename to Desktop/Client/httpInterface.js index ddbddda7e..22a202645 100644 --- a/Desktop/httpInterface.js +++ b/Desktop/Client/httpInterface.js @@ -37,7 +37,7 @@ exports.newHttpInterface = function newHttpInterface() { switch (endpointOrFile) { case 'Images': // This means the Images folder. { - let path = global.env.PATH_TO_CLIENT + '/WebServer/Images/' + requestPath[2] + let path = global.env.PATH_TO_DESKTOP + '/WebServer/Images/' + requestPath[2] if (requestPath[3] !== undefined) { path = path + '/' + requestPath[3] diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index d2bb686db..e04a0ddad 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -19,8 +19,8 @@ exports.newDesktopApp = function newDesktopApp() { //await DK.webSocketsClient.initialize() /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ - //let WEB_SOCKETS_INTERFACE = require('./webSocketsInterface.js') - let HTTP_INTERFACE = require('./httpInterface.js') + //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') + let HTTP_INTERFACE = require('./Client/httpInterface.js') /* WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface() diff --git a/Desktop/UI/AppPostLoader.js b/Desktop/UI/AppPostLoader.js new file mode 100644 index 000000000..b73803e3c --- /dev/null +++ b/Desktop/UI/AppPostLoader.js @@ -0,0 +1,232 @@ + + +function newAppPostLoader() { + const MODULE_NAME = 'Post Loader' + const ERROR_LOG = true + const logger = newWebDebugLog() + + + let thisObject = { + start: start + } + + return thisObject + + function start() { + try { + + // autoSaveWhenClosingTheBrowser() + setupProjectsSchema() + + function setupProjectsSchema() { + httpRequest(undefined, 'ProjectsSchema', onResponse) + + function onResponse(err, file) { + PROJECTS_SCHEMA = JSON.parse(file) + setupSchemas() + } + } + + function setupSchemas() { + + let totalWebServerCalls = 0 + let webServerResponses = 0 + + for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { + let project = PROJECTS_SCHEMA[i].name + let schemas = { + array: { + appSchema: [], + docsNodeSchema: [], + docsConceptSchema: [], + docsTopicSchema: [], + docsTutorialSchema: [], + docsReviewSchema: [], + docsBookSchema: [] + }, + map: { + appSchema: new Map(), + docsNodeSchema: new Map(), + docsConceptSchema: new Map(), + docsTopicSchema: new Map(), + docsTutorialSchema: new Map(), + docsReviewSchema: new Map(), + docsBookSchema: new Map() + } + } + SCHEMAS_BY_PROJECT.set(project, schemas) + + totalWebServerCalls++ + httpRequest(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 schemaDocument = schemas.array.appSchema[j] + let key = schemaDocument.type + schemas.map.appSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsNodeSchema', onResponseDocSchema) + + function onResponseDocSchema(err, schema) { + try { + schemas.array.docsNodeSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsNodeSchema.length; j++) { + let schemaDocument = schemas.array.docsNodeSchema[j] + let key = schemaDocument.type + schemas.map.docsNodeSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsConceptSchema', onResponseConceptSchema) + + function onResponseConceptSchema(err, schema) { + try { + schemas.array.docsConceptSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsConceptSchema.length; j++) { + let schemaDocument = schemas.array.docsConceptSchema[j] + let key = schemaDocument.type + schemas.map.docsConceptSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsTopicSchema', onResponseTopicSchema) + + function onResponseTopicSchema(err, schema) { + try { + schemas.array.docsTopicSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsTopicSchema.length; j++) { + let schemaDocument = schemas.array.docsTopicSchema[j] + let key = schemaDocument.type + schemas.map.docsTopicSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsTutorialSchema', onResponseTutorialSchema) + + function onResponseTutorialSchema(err, schema) { + try { + schemas.array.docsTutorialSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsTutorialSchema.length; j++) { + let schemaDocument = schemas.array.docsTutorialSchema[j] + let key = schemaDocument.type + schemas.map.docsTutorialSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsReviewSchema', onResponseReviewSchema) + + function onResponseReviewSchema(err, schema) { + try { + schemas.array.docsReviewSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsReviewSchema.length; j++) { + let schemaDocument = schemas.array.docsReviewSchema[j] + let key = schemaDocument.type + schemas.map.docsReviewSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsBookSchema', onResponseBookSchema) + + function onResponseBookSchema(err, schema) { + try { + schemas.array.docsBookSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsBookSchema.length; j++) { + let schemaDocument = schemas.array.docsBookSchema[j] + let key = schemaDocument.type + schemas.map.docsBookSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { 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() + canvas.initialize() + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } + } + } + + function autoSaveWhenClosingTheBrowser() { + window.onbeforeunload = saveWorkspace + + /* handles backspace and refresh(F5) from keyboard */ + window.manageBackRefresh = function (event) { + var tag = event.target.tagName.toLowerCase() + if (event.keyCode === 8 && tag !== 'input' && tag !== 'textarea') { // Backbutton pressed + saveWorkspace() + } else if (event.keyCode === 116) { // F5 pressed + saveWorkspace() + } + } + + window.addEventListener('keydown', window.manageBackRefresh) + + function saveWorkspace() { + UI.projects.foundations.spaces.designSpace.workspace.save() + } + } +} diff --git a/Desktop/UI/AppPreLoader.js b/Desktop/UI/AppPreLoader.js new file mode 100644 index 000000000..09002d258 --- /dev/null +++ b/Desktop/UI/AppPreLoader.js @@ -0,0 +1,181 @@ + +/* Callbacks default responses. */ + +let GLOBAL = {} + +GLOBAL.DEFAULT_OK_RESPONSE = { + result: "Ok", + message: "Operation Succeeded" +} + +GLOBAL.DEFAULT_FAIL_RESPONSE = { + result: "Fail", + message: "Operation Failed" +} + +GLOBAL.DEFAULT_RETRY_RESPONSE = { + result: "Retry", + message: "Retry Later" +} + +GLOBAL.CUSTOM_OK_RESPONSE = { + result: "Ok, but check Message", + message: "Custom Message" +} + +GLOBAL.CUSTOM_FAIL_RESPONSE = { + result: "Fail Because", + message: "Custom Message" +} + +let browserCanvas // This is the canvas object of the browser. + +function spacePad(str, max) { + str = str.toString() + return str.length < max ? spacePad(" " + str, max) : str +} + +function loadSuperalgos() { + + const MODULE_NAME = "App Pre-Loader" + const INFO_LOG = false + + let browser = checkBrowserVersion() + setupHTMLTextArea() + setupHTMLInput() + setupHTMLCanvas() + loadDebugModule() + + if ((browser.name !== "Chrome" && browser.name!=="Safari") || (browser.name === "Chrome" && parseInt(browser.version) < 85) || (browser.name === "Safari" && parseInt(browser.version) < 13)) { + alert("Superalgos is officially supported on Google Chrome 85 or Safari 13.1 and above. Your browser version has been detected as potentially beneath this. If you continue you may experience some functionaility issues.\n\nDetected Browser: " + browser.name + "\nVersion: " + browser.version) + } + + function checkBrowserVersion () { + + let ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [] + if(/trident/i.test(M[1])){ + tem=/\brv[ :]+(\d+)/g.exec(ua) || [] + return {name:'IE',version:(tem[1]||'')} + } + if(M[1]==='Chrome'){ + tem=ua.match(/\bOPR|Edge\/(\d+)/) + if(tem!=null) {return {name:'Opera', version:tem[1]}} + } + M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'] + if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1])} + return { + name: M[0], + version: M[1] + } + } + + function setupHTMLTextArea() { + let textArea = document.createElement('textarea') + textArea.id = "textArea" + textArea.spellcheck = false + textArea.style = 'resize: none;' + + ' border: none;' + + ' outline: none;' + + 'box-shadow: none;' + + 'overflow:hidden;' + + 'font-family: ' + 'Saira' + ';' + + 'font-size: 12px;' + + 'background-color: rgb(255, 255, 255);' + + 'color:rgb(255, 255, 255);' + + 'width: ' + 600 + 'px;' + + 'height: ' + 400 + 'px' + + let textAreaDiv = document.getElementById('textAreaDiv') + textAreaDiv.appendChild(textArea) + textAreaDiv.style = 'position:fixed; top:' + -1500 + 'px; left:' + 500 + 'px; z-index:10; ' + } + + function setupHTMLInput() { + let input = document.createElement('input') + input.id = "input" + input.spellcheck = false + input.style = "border: none; outline: none; box-shadow: none; overflow:hidden; width: 0px; height: 0px;" + + let inputDiv = document.getElementById('inputDiv') + inputDiv.appendChild(input) + } + + function setupHTMLCanvas() { + let canvas = document.createElement('canvas') + + canvas.id = "canvas" + canvas.width = 1400 + canvas.height = 600 + canvas.style.border = "0" + canvas.style = "position:absolute; top:0px; left:0px; z-index:1" + + let canvasApp = document.getElementById('canvasApp') + canvasApp.appendChild(canvas) + + browserCanvas = document.getElementById('canvas') + + browserCanvas.width = window.innerWidth + browserCanvas.height = window.innerHeight + browserCanvas.style.border = "none" + + browserCanvas.style.top = 0 + 'px' + } + + function loadDebugModule() { + let path = "WebDebugLog.js" + REQUIREJS([path], onRequired) + + function onRequired(pModule) { + if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } + loadModules() + } + } + + /* And Finally, we start loading all the scripts we will inmediatelly need. */ + function loadModules() { + let path = "AppLoader.js" + REQUIREJS([path], onRequired) + + function onRequired(pModule) { + if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } + let APP_LOADER_MODULE = newAppLoader() + APP_LOADER_MODULE.loadModules() + } + } +} + +function httpRequest(pContentToSend, pPath, callBackFunction) { + let xmlHttpRequest = new XMLHttpRequest() + xmlHttpRequest.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + try { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText) + } catch(err) { + console.log('[ERROR] httpRequest -> httpRequest -> err.stack = '+ err.stack) + console.log('[ERROR] httpRequest -> httpRequest -> pContentToSend = '+ pContentToSend) + console.log('[ERROR] httpRequest -> httpRequest -> pPath = '+ pPath) + console.log('[ERROR] httpRequest -> httpRequest -> xmlHttpRequest.responseText = '+ xmlHttpRequest.responseText) + console.log('[ERROR] httpRequest -> httpRequest -> callBackFunction = '+ callBackFunction) + + } + return + } else if (this.readyState === 4 && this.status === 404) { + callBackFunction({ result: "Fail", message: xmlHttpRequest.responseText.trim(), code: xmlHttpRequest.responseText.trim() }) + return + } + } + + if (pContentToSend === undefined) { + xmlHttpRequest.open("GET", pPath, true) + xmlHttpRequest.send() + } else { + try { + let blob = new Blob([pContentToSend], { type: 'text/plain' }) + xmlHttpRequest.open("POST", pPath, true) + xmlHttpRequest.send(blob) + } catch (err) { + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message) } + callBackFunction({ result: "Fail", message: err.message }) + } + } +} diff --git a/Platform/UI/AppLoader.js b/Platform/UI/AppLoader.js index b17587624..eb8f87864 100644 --- a/Platform/UI/AppLoader.js +++ b/Platform/UI/AppLoader.js @@ -5,7 +5,7 @@ function newAppLoader() { const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() - + let thisObject = { loadModules: loadModules @@ -64,16 +64,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) utilities() } - } + } function utilities() { let url = 'ListUtilitiesFiles' @@ -84,16 +84,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) globals() } - } + } function globals() { let url = 'ListGlobalFiles' @@ -104,16 +104,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) spaces() } - } + } function spaces() { let url = 'ListSpaceFiles' @@ -138,7 +138,7 @@ function newAppLoader() { for (let i = 0; i < modulesArray.length; i++) { let path = modulesArray[i] - + console.log(path) REQUIREJS([path], onRequired) if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') } From ecc7b7d7b641955801f230ea47c1fd02b94f5adb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 6 Sep 2021 17:59:44 +0200 Subject: [PATCH 02/20] Web App basic code --- Desktop/UI/AppLoader.js | 84 +++----------- Desktop/UI/AppPostLoader.js | 220 +----------------------------------- Desktop/UI/AppPreLoader.js | 112 +----------------- Desktop/UI/Globals.js | 9 ++ Desktop/UI/WebApp.js | 63 +++++++++++ 5 files changed, 91 insertions(+), 397 deletions(-) create mode 100644 Desktop/UI/Globals.js create mode 100644 Desktop/UI/WebApp.js diff --git a/Desktop/UI/AppLoader.js b/Desktop/UI/AppLoader.js index b17587624..1f8de0d3e 100644 --- a/Desktop/UI/AppLoader.js +++ b/Desktop/UI/AppLoader.js @@ -1,58 +1,22 @@ -let postLoader function newAppLoader() { - const MODULE_NAME = 'App Loader' - const INFO_LOG = false - const ERROR_LOG = true - const logger = newWebDebugLog() - let thisObject = { loadModules: loadModules } + let postLoader return thisObject async function loadModules() { try { - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Entering function.') } - - let plotters let modulesArray = [] - plotters = defaultPlotters() - modulesArray = modulesArray.concat([ - 'Globals.js', - 'Workspace.js', - - 'Files/SingleFile.js', - 'Files/FileCloud.js', - 'Files/MarketFiles.js', - 'Files/DailyFiles.js', - 'Files/FileCursor.js', - 'Files/FileSequence.js', - 'Files/FileStorage.js', - - 'EventsServerClient.js', - - 'LegacyPlotter.js', - 'PlotterPanel.js', - - 'VideoRecorder.js', - 'ProductStorage.js', - 'Canvas.js', - 'EventHandler.js', - 'Frame.js', - 'Animation.js', - 'Container.js', - 'Utilities.js', - 'AppPostLoader.js' + 'WebApp.js' ]) - modulesArray = modulesArray.concat(plotters) - functionLibraries() function functionLibraries() { @@ -64,16 +28,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) utilities() } - } + } function utilities() { let url = 'ListUtilitiesFiles' @@ -84,16 +48,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) globals() } - } + } function globals() { let url = 'ListGlobalFiles' @@ -104,16 +68,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) spaces() } - } + } function spaces() { let url = 'ListSpaceFiles' @@ -141,22 +105,12 @@ function newAppLoader() { REQUIREJS([path], onRequired) - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') } - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> path = ' + path) } - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> total requested = ' + (i + 1)) } - function onRequired(pModule) { try { - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Entering function.') } - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Module Downloaded.') } - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> path = ' + path) } downloadedCounter++ - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> downloadedCounter = ' + downloadedCounter) } - if (downloadedCounter === modulesArray.length) { - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> onRequired -> Starting Advanced Algos Platform.') } setTimeout(() => { postLoader = newAppPostLoader() postLoader.start() @@ -164,27 +118,15 @@ function newAppLoader() { } } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> onRequired -> err = ' + err.stack) } + console.log('[ERROR] loadModules -> onRequired -> err = ' + err.stack) } } } } } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> err = ' + err.stack) } + console.log('[ERROR] loadModules -> err = ' + err.stack) } } - - function defaultPlotters() { - return [ - 'Plotters/Foundations/Candles/Plotters-Candles-Volumes/Candles.js', - 'Plotters/Foundations/Candles/Plotters-Candles-Volumes/CandlePanel.js', - 'Plotters/Foundations/Candles/Plotters-Candles-Volumes/Volumes.js', - 'Plotters/Foundations/Candles/Plotters-Candles-Volumes/VolumePanel.js', - 'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/BollingerBands.js', - 'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/BollingerBandsPanel.js', - 'Plotters/Foundations/Bollinger/Plotters-Bollinger-Bands/PercentageBandwidth.js' - ] - } } diff --git a/Desktop/UI/AppPostLoader.js b/Desktop/UI/AppPostLoader.js index b73803e3c..3e962a181 100644 --- a/Desktop/UI/AppPostLoader.js +++ b/Desktop/UI/AppPostLoader.js @@ -1,232 +1,18 @@ function newAppPostLoader() { - const MODULE_NAME = 'Post Loader' - const ERROR_LOG = true - const logger = newWebDebugLog() - let thisObject = { start: start } - return thisObject function start() { try { - - // autoSaveWhenClosingTheBrowser() - setupProjectsSchema() - - function setupProjectsSchema() { - httpRequest(undefined, 'ProjectsSchema', onResponse) - - function onResponse(err, file) { - PROJECTS_SCHEMA = JSON.parse(file) - setupSchemas() - } - } - - function setupSchemas() { - - let totalWebServerCalls = 0 - let webServerResponses = 0 - - for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { - let project = PROJECTS_SCHEMA[i].name - let schemas = { - array: { - appSchema: [], - docsNodeSchema: [], - docsConceptSchema: [], - docsTopicSchema: [], - docsTutorialSchema: [], - docsReviewSchema: [], - docsBookSchema: [] - }, - map: { - appSchema: new Map(), - docsNodeSchema: new Map(), - docsConceptSchema: new Map(), - docsTopicSchema: new Map(), - docsTutorialSchema: new Map(), - docsReviewSchema: new Map(), - docsBookSchema: new Map() - } - } - SCHEMAS_BY_PROJECT.set(project, schemas) - - totalWebServerCalls++ - httpRequest(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 schemaDocument = schemas.array.appSchema[j] - let key = schemaDocument.type - schemas.map.appSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsNodeSchema', onResponseDocSchema) - - function onResponseDocSchema(err, schema) { - try { - schemas.array.docsNodeSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsNodeSchema.length; j++) { - let schemaDocument = schemas.array.docsNodeSchema[j] - let key = schemaDocument.type - schemas.map.docsNodeSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsConceptSchema', onResponseConceptSchema) - - function onResponseConceptSchema(err, schema) { - try { - schemas.array.docsConceptSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsConceptSchema.length; j++) { - let schemaDocument = schemas.array.docsConceptSchema[j] - let key = schemaDocument.type - schemas.map.docsConceptSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsTopicSchema', onResponseTopicSchema) - - function onResponseTopicSchema(err, schema) { - try { - schemas.array.docsTopicSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsTopicSchema.length; j++) { - let schemaDocument = schemas.array.docsTopicSchema[j] - let key = schemaDocument.type - schemas.map.docsTopicSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsTutorialSchema', onResponseTutorialSchema) - - function onResponseTutorialSchema(err, schema) { - try { - schemas.array.docsTutorialSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsTutorialSchema.length; j++) { - let schemaDocument = schemas.array.docsTutorialSchema[j] - let key = schemaDocument.type - schemas.map.docsTutorialSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsReviewSchema', onResponseReviewSchema) - - function onResponseReviewSchema(err, schema) { - try { - schemas.array.docsReviewSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsReviewSchema.length; j++) { - let schemaDocument = schemas.array.docsReviewSchema[j] - let key = schemaDocument.type - schemas.map.docsReviewSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { startCanvas() } - } - - totalWebServerCalls++ - httpRequest(undefined, 'Schema/' + project + '/DocsBookSchema', onResponseBookSchema) - - function onResponseBookSchema(err, schema) { - try { - schemas.array.docsBookSchema = JSON.parse(schema) - - for (let j = 0; j < schemas.array.docsBookSchema.length; j++) { - let schemaDocument = schemas.array.docsBookSchema[j] - let key = schemaDocument.type - schemas.map.docsBookSchema.set(key, schemaDocument) - } - } catch (err) { - console.log(err.stack) - } - - webServerResponses++ - if (webServerResponses === totalWebServerCalls) { 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() - canvas.initialize() - } + webApp = newWebApp() + webApp.initialize() } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } - } - } - - function autoSaveWhenClosingTheBrowser() { - window.onbeforeunload = saveWorkspace - - /* handles backspace and refresh(F5) from keyboard */ - window.manageBackRefresh = function (event) { - var tag = event.target.tagName.toLowerCase() - if (event.keyCode === 8 && tag !== 'input' && tag !== 'textarea') { // Backbutton pressed - saveWorkspace() - } else if (event.keyCode === 116) { // F5 pressed - saveWorkspace() - } - } - - window.addEventListener('keydown', window.manageBackRefresh) - - function saveWorkspace() { - UI.projects.foundations.spaces.designSpace.workspace.save() + console.log('[ERROR] err.stack = ' + err.stack) } } } diff --git a/Desktop/UI/AppPreLoader.js b/Desktop/UI/AppPreLoader.js index 09002d258..a21df4ccb 100644 --- a/Desktop/UI/AppPreLoader.js +++ b/Desktop/UI/AppPreLoader.js @@ -1,55 +1,13 @@  -/* Callbacks default responses. */ - -let GLOBAL = {} - -GLOBAL.DEFAULT_OK_RESPONSE = { - result: "Ok", - message: "Operation Succeeded" -} - -GLOBAL.DEFAULT_FAIL_RESPONSE = { - result: "Fail", - message: "Operation Failed" -} - -GLOBAL.DEFAULT_RETRY_RESPONSE = { - result: "Retry", - message: "Retry Later" -} - -GLOBAL.CUSTOM_OK_RESPONSE = { - result: "Ok, but check Message", - message: "Custom Message" -} - -GLOBAL.CUSTOM_FAIL_RESPONSE = { - result: "Fail Because", - message: "Custom Message" -} - -let browserCanvas // This is the canvas object of the browser. - -function spacePad(str, max) { - str = str.toString() - return str.length < max ? spacePad(" " + str, max) : str -} - function loadSuperalgos() { - const MODULE_NAME = "App Pre-Loader" - const INFO_LOG = false - let browser = checkBrowserVersion() - setupHTMLTextArea() - setupHTMLInput() - setupHTMLCanvas() - loadDebugModule() - if ((browser.name !== "Chrome" && browser.name!=="Safari") || (browser.name === "Chrome" && parseInt(browser.version) < 85) || (browser.name === "Safari" && parseInt(browser.version) < 13)) { alert("Superalgos is officially supported on Google Chrome 85 or Safari 13.1 and above. Your browser version has been detected as potentially beneath this. If you continue you may experience some functionaility issues.\n\nDetected Browser: " + browser.name + "\nVersion: " + browser.version) } + loadModules() + function checkBrowserVersion () { let ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [] @@ -69,75 +27,11 @@ function loadSuperalgos() { } } - function setupHTMLTextArea() { - let textArea = document.createElement('textarea') - textArea.id = "textArea" - textArea.spellcheck = false - textArea.style = 'resize: none;' + - ' border: none;' + - ' outline: none;' + - 'box-shadow: none;' + - 'overflow:hidden;' + - 'font-family: ' + 'Saira' + ';' + - 'font-size: 12px;' + - 'background-color: rgb(255, 255, 255);' + - 'color:rgb(255, 255, 255);' + - 'width: ' + 600 + 'px;' + - 'height: ' + 400 + 'px' - - let textAreaDiv = document.getElementById('textAreaDiv') - textAreaDiv.appendChild(textArea) - textAreaDiv.style = 'position:fixed; top:' + -1500 + 'px; left:' + 500 + 'px; z-index:10; ' - } - - function setupHTMLInput() { - let input = document.createElement('input') - input.id = "input" - input.spellcheck = false - input.style = "border: none; outline: none; box-shadow: none; overflow:hidden; width: 0px; height: 0px;" - - let inputDiv = document.getElementById('inputDiv') - inputDiv.appendChild(input) - } - - function setupHTMLCanvas() { - let canvas = document.createElement('canvas') - - canvas.id = "canvas" - canvas.width = 1400 - canvas.height = 600 - canvas.style.border = "0" - canvas.style = "position:absolute; top:0px; left:0px; z-index:1" - - let canvasApp = document.getElementById('canvasApp') - canvasApp.appendChild(canvas) - - browserCanvas = document.getElementById('canvas') - - browserCanvas.width = window.innerWidth - browserCanvas.height = window.innerHeight - browserCanvas.style.border = "none" - - browserCanvas.style.top = 0 + 'px' - } - - function loadDebugModule() { - let path = "WebDebugLog.js" - REQUIREJS([path], onRequired) - - function onRequired(pModule) { - if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } - loadModules() - } - } - - /* And Finally, we start loading all the scripts we will inmediatelly need. */ function loadModules() { let path = "AppLoader.js" REQUIREJS([path], onRequired) function onRequired(pModule) { - if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } let APP_LOADER_MODULE = newAppLoader() APP_LOADER_MODULE.loadModules() } @@ -174,7 +68,7 @@ function httpRequest(pContentToSend, pPath, callBackFunction) { xmlHttpRequest.open("POST", pPath, true) xmlHttpRequest.send(blob) } catch (err) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message) } + if (ERROR_LOG === true) { console.log("[ERROR] callServer -> err.message = " & err.message) } callBackFunction({ result: "Fail", message: err.message }) } } diff --git a/Desktop/UI/Globals.js b/Desktop/UI/Globals.js new file mode 100644 index 000000000..219cf4764 --- /dev/null +++ b/Desktop/UI/Globals.js @@ -0,0 +1,9 @@ +/* Global Constatns */ + +let webApp +let PROJECTS_SCHEMA + +/* New Root object*/ +let UI = { + projects: {} +} diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js new file mode 100644 index 000000000..2a6f3a66a --- /dev/null +++ b/Desktop/UI/WebApp.js @@ -0,0 +1,63 @@ +function newWebApp() { + + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize() { + try { + /* + Here we will setup the UI object, with all the + projects and spaces. + */ + for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { + let projectDefinition = PROJECTS_SCHEMA[i] + UI.projects[projectDefinition.propertyName] = {} + let projectInstance = UI.projects[projectDefinition.propertyName] + + projectInstance.utilities = {} + projectInstance.globals = {} + projectInstance.functionLibraries = {} + + + if (projectDefinition.UI === undefined) { continue } + + /* Set up Globals of this Project */ + if (projectDefinition.UI.globals !== undefined) { + for (let j = 0; j < projectDefinition.UI.globals.length; j++) { + let globalDefinition = projectDefinition.UI.globals[j] + + projectInstance.globals[globalDefinition.propertyName] = eval(globalDefinition.functionName + '()') + } + } + + /* Set up Utilities of this Project */ + if (projectDefinition.UI.utilities !== undefined) { + for (let j = 0; j < projectDefinition.UI.utilities.length; j++) { + let utilityDefinition = projectDefinition.UI.utilities[j] + + projectInstance.utilities[utilityDefinition.propertyName] = eval(utilityDefinition.functionName + '()') + } + } + + /* Set up Function Libraries of this Project */ + if (projectDefinition.UI.functionLibraries !== undefined) { + for (let j = 0; j < projectDefinition.UI.functionLibraries.length; j++) { + let functionLibraryDefinition = projectDefinition.UI.functionLibraries[j] + + projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = eval(functionLibraryDefinition.functionName + '()') + } + } + } + } catch (err) { + console.log('[ERROR] initialize -> err.stack = ' + err.stack) + } + } +} From 373f0307d8995861fd36f1fe9bb3a738c2192e52 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 6 Sep 2021 20:30:05 +0200 Subject: [PATCH 03/20] WebApp Loading all modules declared at Project Schema --- Desktop/Client/httpInterface.js | 51 +++++++++++++++++++++++----- Desktop/UI/AppLoader.js | 25 +++----------- Desktop/UI/AppPostLoader.js | 14 ++++++-- Desktop/UI/AppPreLoader.js | 2 +- Desktop/UI/WebDebugLog.js | 21 ++++++++++++ Desktop/{WebServer => UI}/require.js | 0 Desktop/WebServer/index.html | 2 +- 7 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 Desktop/UI/WebDebugLog.js rename Desktop/{WebServer => UI}/require.js (100%) diff --git a/Desktop/Client/httpInterface.js b/Desktop/Client/httpInterface.js index 22a202645..86ae51201 100644 --- a/Desktop/Client/httpInterface.js +++ b/Desktop/Client/httpInterface.js @@ -19,13 +19,13 @@ exports.newHttpInterface = function newHttpInterface() { /* We will create an HTTP Server and leave it running forever. */ - SA.nodeModules.http.createServer(onHttpRequest).listen(global.env.DESKTOP_HTTP_INTERFACE_PORT) - /* Starting the browser now is optional */ - if (process.argv.includes("noBrowser")) { - //Running Client only with no UI. - } else { - SA.nodeModules.open('http://localhost:' + global.env.DESKTOP_HTTP_INTERFACE_PORT) - } + SA.nodeModules.http.createServer(onHttpRequest).listen(global.env.DESKTOP_HTTP_INTERFACE_PORT) + /* Starting the browser now is optional */ + if (process.argv.includes("noBrowser")) { + //Running Client only with no UI. + } else { + SA.nodeModules.open('http://localhost:' + global.env.DESKTOP_HTTP_INTERFACE_PORT) + } } function onHttpRequest(httpRequest, httpResponse) { @@ -35,6 +35,41 @@ exports.newHttpInterface = function newHttpInterface() { let endpointOrFile = requestPath[1] switch (endpointOrFile) { + case 'ProjectsSchema': + { + let path = global.env.PATH_TO_PROJECTS + '/' + 'ProjectsSchema.json' + SA.projects.foundations.utilities.httpResponses.respondWithFile(path, httpResponse) + } + break + case 'ListFunctionLibraries': + { + SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Function-Libraries', 'UI') + } + break + case 'ListUtilitiesFiles': + { + SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Utilities', 'UI') + } + break + case 'ListGlobalFiles': + { + SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Globals', 'UI') + } + break + case 'Projects': + { + let path = '' + for (let i = 2; i < 10; i++) { + if (requestPath[i] !== undefined) { + let parameter = unescape(requestPath[i]) + path = path + '/' + parameter + } + + } + let filePath = global.env.PATH_TO_PROJECTS + path + SA.projects.foundations.utilities.httpResponses.respondWithFile(filePath, httpResponse) + } + break case 'Images': // This means the Images folder. { let path = global.env.PATH_TO_DESKTOP + '/WebServer/Images/' + requestPath[2] @@ -58,7 +93,7 @@ exports.newHttpInterface = function newHttpInterface() { break default: { - SA.projects.foundations.utilities.httpResponses.respondWithWebFile(httpResponse, endpointOrFile, global.env.PATH_TO_DESKTOP) + SA.projects.foundations.utilities.httpResponses.respondWithWebFile(httpResponse, endpointOrFile, global.env.PATH_TO_DESKTOP) } } } catch (err) { diff --git a/Desktop/UI/AppLoader.js b/Desktop/UI/AppLoader.js index 1f8de0d3e..24c5ccd21 100644 --- a/Desktop/UI/AppLoader.js +++ b/Desktop/UI/AppLoader.js @@ -10,12 +10,12 @@ function newAppLoader() { async function loadModules() { try { - let modulesArray = [] - - modulesArray = modulesArray.concat([ + let modulesArray = [ + 'WebDebugLog.js', + 'AppPostLoader.js', 'Globals.js', 'WebApp.js' - ]) + ] functionLibraries() @@ -74,23 +74,6 @@ function newAppLoader() { urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) } - modulesArray = modulesArray.concat(urlArray) - spaces() - } - } - - function spaces() { - let url = 'ListSpaceFiles' - httpRequest(undefined, url, onResponse) - - function onResponse(err, fileList) { - let urlArray = [] - let fileArray = JSON.parse(fileList) - for (let i = 0; i < fileArray.length; i++) { - let path = fileArray[i] - urlArray.push('Projects' + '/' + path) - } - modulesArray = modulesArray.concat(urlArray) downloadIncludedFiles() } diff --git a/Desktop/UI/AppPostLoader.js b/Desktop/UI/AppPostLoader.js index 3e962a181..e0040e951 100644 --- a/Desktop/UI/AppPostLoader.js +++ b/Desktop/UI/AppPostLoader.js @@ -9,8 +9,18 @@ function newAppPostLoader() { function start() { try { - webApp = newWebApp() - webApp.initialize() + + setupProjectsSchema() + + function setupProjectsSchema() { + httpRequest(undefined, 'ProjectsSchema', onResponse) + + function onResponse(err, file) { + PROJECTS_SCHEMA = JSON.parse(file) + webApp = newWebApp() + webApp.initialize() + } + } } catch (err) { console.log('[ERROR] err.stack = ' + err.stack) } diff --git a/Desktop/UI/AppPreLoader.js b/Desktop/UI/AppPreLoader.js index a21df4ccb..8897aa49d 100644 --- a/Desktop/UI/AppPreLoader.js +++ b/Desktop/UI/AppPreLoader.js @@ -43,7 +43,7 @@ function httpRequest(pContentToSend, pPath, callBackFunction) { xmlHttpRequest.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { try { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText) + callBackFunction(undefined, xmlHttpRequest.responseText) } catch(err) { console.log('[ERROR] httpRequest -> httpRequest -> err.stack = '+ err.stack) console.log('[ERROR] httpRequest -> httpRequest -> pContentToSend = '+ pContentToSend) diff --git a/Desktop/UI/WebDebugLog.js b/Desktop/UI/WebDebugLog.js new file mode 100644 index 000000000..2a6bc1af1 --- /dev/null +++ b/Desktop/UI/WebDebugLog.js @@ -0,0 +1,21 @@ +function newWebDebugLog() { + try { + let thisObject = { + write: write, + fileName: 'undefined' + } + + return thisObject + + function write(pText) { + console.log(spacePad(thisObject.fileName, 50) + ' : ' + pText) + + function spacePad(str, max) { + str = str.toString() + return str.length < max ? spacePad(' ' + str, max) : str + } + } + } catch (err) { + console.log(spacePad(MODULE_NAME, 50) + ' : ' + '[ERROR] WebDebugLog --> err = ' + err.stack) + } +} diff --git a/Desktop/WebServer/require.js b/Desktop/UI/require.js similarity index 100% rename from Desktop/WebServer/require.js rename to Desktop/UI/require.js diff --git a/Desktop/WebServer/index.html b/Desktop/WebServer/index.html index afeb95d14..793a8c5f3 100644 --- a/Desktop/WebServer/index.html +++ b/Desktop/WebServer/index.html @@ -6,7 +6,7 @@ - + + - + Hello World! -
-
- +
+
+
+ + From bac140cf92ec046e5d614fbbeda6a6e00bcb49e4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 7 Sep 2021 13:05:58 +0200 Subject: [PATCH 05/20] sockets connections and disconnections plus callers ordered arrays. --- Desktop/DesktopApp.js | 7 +- .../Network/NT/Modules/WebSocketsInterface.js | 145 ++++++++++++++---- .../NT/Modules/Social-Graph/SocialGraph.js | 20 +++ 3 files changed, 141 insertions(+), 31 deletions(-) create mode 100644 Projects/Social-Trading/NT/Modules/Social-Graph/SocialGraph.js diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index e04a0ddad..8fa39fafc 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -15,9 +15,10 @@ exports.newDesktopApp = function newDesktopApp() { /* This is the Web Sockets client that interacts with the Superalgos Network. */ - //DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() - //await DK.webSocketsClient.initialize() - + DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() + await DK.webSocketsClient.initialize() + return + /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') let HTTP_INTERFACE = require('./Client/httpInterface.js') diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index 003e6798b..baded6584 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -1,6 +1,9 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSocketsInterface() { let thisObject = { + networkClients: undefined, + networkPeers: undefined, + callersMap: undefined, initialize: initialize, finalize: finalize } @@ -14,6 +17,10 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock return thisObject function finalize() { + thisObject.networkClients = undefined + thisObject.networkPeers = undefined + callersMap = undefined + socketServer = undefined clientInterface = undefined peerInterface = undefined @@ -26,18 +33,35 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock clientInterface = NT.projects.socialTrading.modules.clientInterface.newSocialTradingModulesClientInterface() peerInterface = NT.projects.socialTrading.modules.peerInterface.newSocialTradingModulesPeerInterface() + thisObject.networkClients = [] + thisObject.networkPeers = [] + thisObject.callersMap = new Map() + setUpWebSocketServer() } function setUpWebSocketServer() { try { - socketServer.on('connection', onConnection) + socketServer.on('connection', onConnectionOpened) + + function onConnectionOpened(socket) + + /* + This function is executed every time a new Websockets connection + is stablished. + */ { + let caller = { + socket: socket, + userProfile: undefined, + role: undefined + } + + caller.socket.id = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + caller.socket.on('close', onConnectionClosed) - function onConnection(socket) { - let caller = {} let calledTimestamp = (new Date()).valueOf() - socket.on('message', onMenssage) + caller.socket.on('message', onMenssage) async function onMenssage(message) { try { @@ -49,7 +73,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'messageHeader Not Coorrect JSON Format.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -60,13 +84,13 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'messageType Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } switch (messageHeader.messageType) { case "Handshake": { - handshakeProducedure(socket, caller, calledTimestamp, messageHeader) + handshakeProducedure(caller, calledTimestamp, messageHeader) break } case "Request": { @@ -76,19 +100,19 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'Handshake Not Done Yet.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } switch (caller.role) { case 'Network Client': { let response = await clientInterface.messageReceived(messageHeader.payload, caller.userProfile) - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) break } case 'Network Peer': { let response = await peerInterface.messageReceived(messageHeader.payload) - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) break } } @@ -99,7 +123,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'messageType Not Supported.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) break } } @@ -109,7 +133,13 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock } } - function handshakeProducedure(socket, caller, calledTimestamp, messageHeader) { + function onConnectionClosed() { + let socketId = this.id + let caller = thisObject.callersMap.get(socketId) + removeCaller(caller) + } + + function handshakeProducedure(caller, calledTimestamp, messageHeader) { /* The handshage producedure have 2 steps, we need to know now which one we are at. @@ -119,7 +149,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'step Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } if (messageHeader.step !== 'One' && messageHeader.step !== 'Two') { @@ -127,7 +157,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'step Not Supported.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } switch (messageHeader.step) { @@ -149,7 +179,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerRole Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } @@ -158,7 +188,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerRole Not Supported.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } @@ -171,7 +201,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerProfileHandle Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } @@ -184,7 +214,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerTimestamp Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -195,7 +225,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerTimestamp Too Old.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -215,7 +245,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock message: 'Handshake Step One Complete', signature: JSON.stringify(signature) } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) } function handshakeStepTwo() { @@ -227,7 +257,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'Handshake Step One Not Completed.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -238,7 +268,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'signature Not Provided.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } @@ -250,7 +280,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'Bad Signature.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -263,7 +293,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'userProfile Not Found.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -277,7 +307,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'callerProfileHandle Does Not Match witnessUserProfile.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -289,7 +319,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'calledProfileHandle Does Not Match This Network Node Handle.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -300,7 +330,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock result: 'Error', message: 'calledTimestamp Does Not Match calledTimestamp On Record.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) return } /* @@ -310,15 +340,74 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock We will remember the user profile behind this caller. */ caller.userProfile = witnessUserProfile + /* + We will remember the caller itself. + */ + addCaller(caller) let response = { result: 'Ok', message: 'Handshake Successful.' } - socket.send(JSON.stringify(response)) + caller.socket.send(JSON.stringify(response)) } } + function addCaller(caller) { + + thisObject.callersMap.set(caller.socket.id, caller) + + switch (caller.role) { + case 'Network Client': { + addToArray(thisObject.networkClients, caller) + break + } + case 'Network Peer': { + addToArray(thisObject.networkPeers, caller) + break + } + } + + function addToArray(callersArray, caller) { + /* + We will add the caller to the existing array, first the ones with highest ranking. + */ + for (let i = 0; i < callersArray.length; i++) { + let callerInArray = callersArray[i] + if (caller.userProfile.ranking > callerInArray.userProfile.ranking) { + callersArray.splice(i, 0, caller) + return + } + } + callersArray.push(caller) + } + } + + function removeCaller(caller) { + + thisObject.callersMap.delete(caller.socket.id) + + switch (caller.role) { + case 'Network Client': { + removeFromArray(thisObject.networkClients, caller) + break + } + case 'Network Peer': { + removeFromArray(thisObject.networkPeers, caller) + break + } + } + + function removeFromArray(callersArray, caller) { + for (let i = 0; i < callersArray.length; i++) { + let callerInArray = callersArray[i] + if (caller.socket.id === callerInArray.socket.id) { + callersArray.splice(i, 1) + return + } + } + } + } } catch (err) { console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack) } diff --git a/Projects/Social-Trading/NT/Modules/Social-Graph/SocialGraph.js b/Projects/Social-Trading/NT/Modules/Social-Graph/SocialGraph.js new file mode 100644 index 000000000..864add3cd --- /dev/null +++ b/Projects/Social-Trading/NT/Modules/Social-Graph/SocialGraph.js @@ -0,0 +1,20 @@ +exports.newSocialTradingModulesSocialGraph = function newSocialTradingModulesSocialGraph() { + /* + This object represent the entire Social Graph. + */ + let thisObject = { + + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize() { + + } +} \ No newline at end of file From 4e92ff174074a507179a71af54d20d8e17550196 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 7 Sep 2021 16:57:48 +0200 Subject: [PATCH 06/20] Event Broadcasting --- .../Network/NT/Modules/WebSocketsInterface.js | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index baded6584..6a48a8a8a 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -104,18 +104,23 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock return } + let response switch (caller.role) { case 'Network Client': { - let response = await clientInterface.messageReceived(messageHeader.payload, caller.userProfile) + response = await clientInterface.messageReceived(messageHeader.payload, caller.userProfile) caller.socket.send(JSON.stringify(response)) break } case 'Network Peer': { - let response = await peerInterface.messageReceived(messageHeader.payload) + response = await peerInterface.messageReceived(messageHeader.payload) caller.socket.send(JSON.stringify(response)) break } } + if (response.result === 'Ok' && messageHeader.payload.requestType === 'Event') { + broadcastToPeers(messageHeader, caller) + broadcastToClients(messageHeader, caller) + } break } default: { @@ -408,6 +413,31 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock } } } + + function broadcastToPeers(messageHeader, caller) { + let callerIdToAVoid + if (caller.role === 'Network Peer') { + callerIdToAVoid = caller.socket.id + } + for (let i = 0; i < thisObject.networkPeers.length; i++) { + let networkPeer = thisObject.networkPeers[i] + if (networkPeer.socket.id === callerIdToAVoid) { continue } + networkPeer.socket.send(messageHeader) + } + } + + function broadcastToClients(messageHeader, caller) { + let callerIdToAVoid + if (caller.role === 'Network Client') { + callerIdToAVoid = caller.socket.id + } + for (let i = 0; i < thisObject.networkClients.length; i++) { + let networkClient = thisObject.networkClients[i] + if (networkClient.socket.id === callerIdToAVoid) { continue } + networkClient.socket.send(messageHeader) + } + } + } catch (err) { console.log('[ERROR] Web Sockets Interface -> setUpWebSocketServer -> err.stack = ' + err.stack) } From 020e01237a2d749df1f811497c8a45b328554add Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 8 Sep 2021 11:03:43 +0200 Subject: [PATCH 07/20] html layout --- Desktop/DesktopApp.js | 10 +- Desktop/WebServer/css/main.css | 135 +++++++++++++++++- Desktop/WebServer/index.html | 71 ++++++++- .../TradingSimulation.js | 3 +- 4 files changed, 202 insertions(+), 17 deletions(-) diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 8fa39fafc..e05811c30 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -15,10 +15,11 @@ exports.newDesktopApp = function newDesktopApp() { /* This is the Web Sockets client that interacts with the Superalgos Network. */ - DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() - await DK.webSocketsClient.initialize() - return - + /* + DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() + await DK.webSocketsClient.initialize() + */ + /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') let HTTP_INTERFACE = require('./Client/httpInterface.js') @@ -35,7 +36,6 @@ exports.newDesktopApp = function newDesktopApp() { return - let queryMessage let query /* diff --git a/Desktop/WebServer/css/main.css b/Desktop/WebServer/css/main.css index 5e3eedde8..fe419c965 100644 --- a/Desktop/WebServer/css/main.css +++ b/Desktop/WebServer/css/main.css @@ -22,13 +22,134 @@ font-style: normal; } - kbd { - padding: 2px 8px; - font-size: 125%; - font-weight: 500; + .page-table { + position:fixed; + top:0px; + left:18%; + width: 64%; + height: 100%; + color: #000; + background-color: #ffffff; + border-width: 1px; + } + + .left-column { + position:relative; + top:0px; + width: 20%; + height: 100%; + color: #000; + border-width: 1px; + } + + .middle-column { + position:relative; + top:0px; + width: 50%; + height: 100%; + color: #000; + border-width: 1px; + } + + .right-column { + position:relative; + top:0px; + left:0px; + width: 30%; + height: 100%; + color: #000; + border-width: 1px; + } + + .left-table { + position:relative; + width: 100%; + height: 100%; + color: #000; + border-width: 1px; + } + + .logo-cell { + vertical-align: top; + width: 100%; + height: 70px; + color: #000; + border-width: 1px; + } + + .menu-cell { + vertical-align: top; + width: 100%; + color: #000; + border-width: 1px; + } + + .profile-cell { + vertical-align: bottom; + width: 100%; + height: 50px; + color: #000; + border-width: 1px; + } + + .middle-table { + position:relative; + width: 100%; + height: 100%; + color: #000; + border-width: 1px; + } + + .content-title-cell { + vertical-align: top; + width: 100%; + height: 50px; + color: #000; + border-width: 1px; + } + + .content-cell { + vertical-align: top; + width: 100%; + color: #000; + border-width: 1px; + } + + .right-table { + position:relative; + width: 100%; + height: 100%; + color: #000; + border-width: 1px; + } + + .search-cell { + vertical-align: top; + width: 100%; + height: 50px; + color: #000; + border-width: 1px; + } + + .context-cell { + vertical-align: top; + width: 100%; + color: #000; + border-width: 1px; + } + + .menu-table { + position:relative; + width: 100%; + height: 65%; + color: #000; + border-width: 1px; + } + + .menu-item-cell { + vertical-align: top; + width: 100%; + height: 50px; color: #000; - background-color: #bcd643; - border-radius: 5px; - border-style: outset; border-width: 1px; } \ No newline at end of file diff --git a/Desktop/WebServer/index.html b/Desktop/WebServer/index.html index 362ffc495..6d6572c60 100644 --- a/Desktop/WebServer/index.html +++ b/Desktop/WebServer/index.html @@ -42,11 +42,74 @@ Hello World! -
-
-
- + + + + + + +
+ + + + + + + + + + +
LOGO
PROFILE
+
+ + + + + + + +
CONTENT TITLE
CONTENT
+
+ + + + + + + +
SEARCH
CONTEXT
+
diff --git a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js index 0be553078..3e8d114ae 100644 --- a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js +++ b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js @@ -88,7 +88,8 @@ exports.newFoundationsBotModulesTradingSimulation = function (processIndex) { This will happen when the sessionParameters.timeRange.config.initialDatetime is beyond the last candle available, meaning that the dataSet needs to be updated with more up-to-date data. */ - TS.projects.foundations.functionLibraries.sessionFunctions.stopSession(processIndex, 'Data is not up-to-date enough. Please start the Masters Data Mining Operation.') + console.log('DEBUGGING ..................', initialCandle, candles.length) + TS.projects.foundations.functionLibraries.sessionFunctions.stopSession(processIndex, 'Data is not up-to-date enough. Please start the Data Mining Operation.') TS.projects.foundations.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME, '[IMPORTANT] runSimulation -> Data is not up-to-date enough. Stopping the Session now. ') return From c01c9bbca629e479ae0f92fb9ec77b23a369722a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 8 Sep 2021 13:48:48 +0200 Subject: [PATCH 08/20] who to follow --- Desktop/WebServer/css/main.css | 123 ++++++++++++++++++++++++++++----- Desktop/WebServer/index.html | 40 +++++++++-- 2 files changed, 141 insertions(+), 22 deletions(-) diff --git a/Desktop/WebServer/css/main.css b/Desktop/WebServer/css/main.css index fe419c965..a44c65f3f 100644 --- a/Desktop/WebServer/css/main.css +++ b/Desktop/WebServer/css/main.css @@ -22,15 +22,57 @@ font-style: normal; } + .scroll-div { + position:absolute; + overflow-y: scroll; + overflow-x: hidden; + top:0px; + left:0px; + vertical-align: top; + height: 100%; + width: 100%; + color: #000; + border-color: blue; + background-color: #ffffff; + border-width: 0px; + } + + .content-div { + position:relative; + vertical-align: top; + height: 100%; + width: 30%; + left: 31.2%; + color: #000; + border-color: blue; + background-color: transparent; + border-width: 0px; + } + + .post-div { + vertical-align: top; + height: 300px; + width: 100%; + color: #000; + border-color: blue; + background-color: transparent; + border-width: 0px; + } + .page-table { + pointer-events: none; position:fixed; + position: absolute; top:0px; left:18%; width: 64%; height: 100%; + padding: 0; + margin: 0; color: #000; - background-color: #ffffff; - border-width: 1px; + background:transparent; + border-width: 0px; + border-collapse: collapse; } .left-column { @@ -38,8 +80,10 @@ top:0px; width: 20%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .middle-column { @@ -47,8 +91,10 @@ top:0px; width: 50%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .right-column { @@ -57,99 +103,142 @@ left:0px; width: 30%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .left-table { position:relative; width: 100%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + border-collapse: collapse; } .logo-cell { vertical-align: top; width: 100%; height: 70px; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .menu-cell { vertical-align: top; width: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .profile-cell { vertical-align: bottom; width: 100%; height: 50px; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .middle-table { position:relative; width: 100%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + border-collapse: collapse; } .content-title-cell { vertical-align: top; width: 100%; height: 50px; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + background-color: #ffffff; } .content-cell { vertical-align: top; width: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .right-table { position:relative; width: 100%; height: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + border-collapse: collapse; } .search-cell { vertical-align: top; width: 100%; height: 50px; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; } .context-cell { vertical-align: top; width: 100%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + background:transparent; } .menu-table { position:relative; width: 100%; height: 65%; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + border-collapse: collapse; } .menu-item-cell { vertical-align: top; width: 100%; height: 50px; + padding: 0; + margin: 0; color: #000; - border-width: 1px; + border-width: 0px; + } + + .who-to-follow-table { + position:relative; + width: 100%; + height: 30%; + padding: 0; + margin: 0; + color: #000; + border-width: 0px; + border-collapse: collapse; } \ No newline at end of file diff --git a/Desktop/WebServer/index.html b/Desktop/WebServer/index.html index 6d6572c60..30b874280 100644 --- a/Desktop/WebServer/index.html +++ b/Desktop/WebServer/index.html @@ -41,9 +41,26 @@ - Hello World! - - +
+
+
+ POST 1 +
+
+ POST 2 +
+
+ POST 3 +
+
+ POST 4 +
+
+ POST 5 +
+
+
+
@@ -104,7 +122,19 @@ - +
@@ -94,7 +111,8 @@ - +
CONTENT TITLE
CONTENT +
SEARCH
CONTEXT + + + + + + + + + + +
+
From 44332a13de04406037d8f41e78d72145591b26d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 8 Sep 2021 14:14:27 +0200 Subject: [PATCH 09/20] Initializing the Web App --- Desktop/DesktopApp.js | 6 +- Desktop/UI/WebApp.js | 172 ++++++++++++++---- Desktop/UI/{AppLoader.js => WebAppLoader.js} | 6 +- .../{AppPostLoader.js => WebAppPostLoader.js} | 2 +- .../{AppPreLoader.js => WebAppPreLoader.js} | 4 +- Desktop/WebServer/index.html | 6 +- 6 files changed, 144 insertions(+), 52 deletions(-) rename Desktop/UI/{AppLoader.js => WebAppLoader.js} (96%) rename Desktop/UI/{AppPostLoader.js => WebAppPostLoader.js} (94%) rename Desktop/UI/{AppPreLoader.js => WebAppPreLoader.js} (97%) diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index e05811c30..300baff29 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -15,10 +15,8 @@ exports.newDesktopApp = function newDesktopApp() { /* This is the Web Sockets client that interacts with the Superalgos Network. */ - /* - DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() - await DK.webSocketsClient.initialize() - */ + DK.webSocketsClient = SA.projects.network.modules.webSocketsClient.newNetworkModulesWebSocketsClient() + await DK.webSocketsClient.initialize() /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index 2a6f3a66a..449764ac2 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -13,51 +13,145 @@ function newWebApp() { function initialize() { try { - /* - Here we will setup the UI object, with all the - projects and spaces. - */ - for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { - let projectDefinition = PROJECTS_SCHEMA[i] - UI.projects[projectDefinition.propertyName] = {} - let projectInstance = UI.projects[projectDefinition.propertyName] - - projectInstance.utilities = {} - projectInstance.globals = {} - projectInstance.functionLibraries = {} + setupRootObject() + //setupHomePage() + } catch (err) { + console.log('[ERROR] initialize -> err.stack = ' + err.stack) + } + } + + function setupRootObject() { + /* + Here we will setup the UI object, with all the + projects and spaces. + */ + for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { + let projectDefinition = PROJECTS_SCHEMA[i] + UI.projects[projectDefinition.propertyName] = {} + let projectInstance = UI.projects[projectDefinition.propertyName] + + projectInstance.utilities = {} + projectInstance.globals = {} + projectInstance.functionLibraries = {} - if (projectDefinition.UI === undefined) { continue } + if (projectDefinition.UI === undefined) { continue } - /* Set up Globals of this Project */ - if (projectDefinition.UI.globals !== undefined) { - for (let j = 0; j < projectDefinition.UI.globals.length; j++) { - let globalDefinition = projectDefinition.UI.globals[j] + /* Set up Globals of this Project */ + if (projectDefinition.UI.globals !== undefined) { + for (let j = 0; j < projectDefinition.UI.globals.length; j++) { + let globalDefinition = projectDefinition.UI.globals[j] - projectInstance.globals[globalDefinition.propertyName] = eval(globalDefinition.functionName + '()') - } - } - - /* Set up Utilities of this Project */ - if (projectDefinition.UI.utilities !== undefined) { - for (let j = 0; j < projectDefinition.UI.utilities.length; j++) { - let utilityDefinition = projectDefinition.UI.utilities[j] - - projectInstance.utilities[utilityDefinition.propertyName] = eval(utilityDefinition.functionName + '()') - } - } - - /* Set up Function Libraries of this Project */ - if (projectDefinition.UI.functionLibraries !== undefined) { - for (let j = 0; j < projectDefinition.UI.functionLibraries.length; j++) { - let functionLibraryDefinition = projectDefinition.UI.functionLibraries[j] - - projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = eval(functionLibraryDefinition.functionName + '()') - } + projectInstance.globals[globalDefinition.propertyName] = eval(globalDefinition.functionName + '()') } } - } catch (err) { - console.log('[ERROR] initialize -> err.stack = ' + err.stack) + + /* Set up Utilities of this Project */ + if (projectDefinition.UI.utilities !== undefined) { + for (let j = 0; j < projectDefinition.UI.utilities.length; j++) { + let utilityDefinition = projectDefinition.UI.utilities[j] + + projectInstance.utilities[utilityDefinition.propertyName] = eval(utilityDefinition.functionName + '()') + } + } + + /* Set up Function Libraries of this Project */ + if (projectDefinition.UI.functionLibraries !== undefined) { + for (let j = 0; j < projectDefinition.UI.functionLibraries.length; j++) { + let functionLibraryDefinition = projectDefinition.UI.functionLibraries[j] + + projectInstance.functionLibraries[functionLibraryDefinition.propertyName] = eval(functionLibraryDefinition.functionName + '()') + } + } + } + } + + async function setupHomePage() { + let queryMessage + let query + /* + Test Query User Profiles. + */ + queryMessage = { + queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES, + emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, + initialIndex: 'Last', + amountRequested: 10, + direction: 'Past' + } + + query = { + requestType: 'Query', + queryMessage: JSON.stringify(queryMessage) + } + + await DK.webSocketsClient.sendMessage( + JSON.stringify(query) + ) + .then(showProfiles) + .catch(onError) + + async function showProfiles(profiles) { + console.log(profiles) + + for (let i = 0; i < profiles.length; i++) { + let profile = profiles[i] + + /* + Test Following Profiles. + */ + let eventMessage = { + eventId: SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId(), + eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, + emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, + targetUserProfileId: profile.userProfileId + } + + let event = { + requestType: 'Event', + eventMessage: JSON.stringify(eventMessage) + } + + await DK.webSocketsClient.sendMessage( + JSON.stringify(event) + ) + .then(followAdded) + .catch(onError) + + function followAdded() { + console.log("User Profile " + profile.userProfileHandle + " followed.") + } + } + } + /* + Test Query User Profile Stats. + */ + queryMessage = { + queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILE_STATS, + emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, + targetUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID + } + + query = { + requestType: 'Query', + queryMessage: JSON.stringify(queryMessage) + } + + await DK.webSocketsClient.sendMessage( + JSON.stringify(query) + ) + .then(showProfilesStats) + .catch(onError) + + function showProfilesStats(profile) { + console.log(profile) + } + + /* + Error Handling + */ + function onError(errorMessage) { + console.log('[ERROR] Query not executed. ' + errorMessage) } } } diff --git a/Desktop/UI/AppLoader.js b/Desktop/UI/WebAppLoader.js similarity index 96% rename from Desktop/UI/AppLoader.js rename to Desktop/UI/WebAppLoader.js index 24c5ccd21..e7d5fb02e 100644 --- a/Desktop/UI/AppLoader.js +++ b/Desktop/UI/WebAppLoader.js @@ -1,5 +1,5 @@ -function newAppLoader() { +function newWebAppLoader() { let thisObject = { loadModules: loadModules @@ -12,7 +12,7 @@ function newAppLoader() { try { let modulesArray = [ 'WebDebugLog.js', - 'AppPostLoader.js', + 'WebAppPostLoader.js', 'Globals.js', 'WebApp.js' ] @@ -95,7 +95,7 @@ function newAppLoader() { if (downloadedCounter === modulesArray.length) { setTimeout(() => { - postLoader = newAppPostLoader() + postLoader = newWebAppPostLoader() postLoader.start() }, 500) diff --git a/Desktop/UI/AppPostLoader.js b/Desktop/UI/WebAppPostLoader.js similarity index 94% rename from Desktop/UI/AppPostLoader.js rename to Desktop/UI/WebAppPostLoader.js index e0040e951..b22b7796d 100644 --- a/Desktop/UI/AppPostLoader.js +++ b/Desktop/UI/WebAppPostLoader.js @@ -1,6 +1,6 @@ -function newAppPostLoader() { +function newWebAppPostLoader() { let thisObject = { start: start diff --git a/Desktop/UI/AppPreLoader.js b/Desktop/UI/WebAppPreLoader.js similarity index 97% rename from Desktop/UI/AppPreLoader.js rename to Desktop/UI/WebAppPreLoader.js index 8897aa49d..12e5fa54f 100644 --- a/Desktop/UI/AppPreLoader.js +++ b/Desktop/UI/WebAppPreLoader.js @@ -28,11 +28,11 @@ function loadSuperalgos() { } function loadModules() { - let path = "AppLoader.js" + let path = "WebAppLoader.js" REQUIREJS([path], onRequired) function onRequired(pModule) { - let APP_LOADER_MODULE = newAppLoader() + let APP_LOADER_MODULE = newWebAppLoader() APP_LOADER_MODULE.loadModules() } } diff --git a/Desktop/WebServer/index.html b/Desktop/WebServer/index.html index 30b874280..e5ddba267 100644 --- a/Desktop/WebServer/index.html +++ b/Desktop/WebServer/index.html @@ -6,8 +6,8 @@ - - + +