Initializing the Web App

This commit is contained in:
Luis Fernando Molina committed 2021-09-08 14:14:27 +02:00
1 parent c01c9bbca6
commit 44332a13de
6 files changed
+144 -52

No files matched your search

+2 -4
View File
@@ -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')
+133 -39
View File
@@ -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)
}
}
}
@@ -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)
@@ -1,6 +1,6 @@
function newAppPostLoader() {
function newWebAppPostLoader() {
let thisObject = {
start: start
@@ -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()
}
}
+3 -3
View File
@@ -6,8 +6,8 @@
<meta name="description" content="Free and Open Source Crypto Social Trading">
<link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
<link rel="shortcut icon" type="image/png/ico" href="Images/favicon.ico" />
<script type="text/javascript" src="require.js"></script>
<script type="text/javascript" src="AppPreLoader.js"></script>
<script type="text/javascript" src="Require.js"></script>
<script type="text/javascript" src="WebAppPreLoader.js"></script>
<script type="text/javascript">
function loadApp() {
@@ -123,7 +123,7 @@
</tr>
<tr>
<td class="context-cell">
<table class="who-to-follow-table">
<table id="who-to-follow-table" class="who-to-follow-table">
<tr>
<td class="menu-item-cell">User Profile 1</td>
</tr>