From 44332a13de04406037d8f41e78d72145591b26d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 8 Sep 2021 14:14:27 +0200 Subject: [PATCH] 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 @@ - - + +