diff --git a/Scripts/AppLoader.js b/Scripts/AppLoader.js index f8c30ee64..642884082 100644 --- a/Scripts/AppLoader.js +++ b/Scripts/AppLoader.js @@ -1,194 +1,194 @@ let dashboard function newAppLoader() { - const MODULE_NAME = 'App Loader' - const INFO_LOG = false - const ERROR_LOG = true - const logger = newWebDebugLog() - logger.fileName = MODULE_NAME + const MODULE_NAME = 'App Loader' + const INFO_LOG = false + const ERROR_LOG = true + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME - let thisObject = { - loadModules: loadModules - } - - return thisObject - - async function loadModules() { - try { - if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Entering function.') } - - window.localStorage.removeItem('ecosystem') - - let plotters - let modulesArray = [] - - if (window.canvasApp.executingAt !== 'Local') { - let ecosystem = await loadEcosystem() - if (ecosystem) { - window.localStorage.setItem('ecosystem', JSON.stringify(ecosystem)) - plotters = getPlotters(ecosystem) - } else { - plotters = defaultPlotters() - modulesArray = ['UserEcosystem.js'] - } - } else { - plotters = defaultPlotters() - modulesArray = ['UserEcosystem.js'] - } - - - - modulesArray = modulesArray.concat([ - 'ChartsSpace/ViewPort.js', - - 'Globals.js', - 'Ecosystem.js', - 'UserEcosystem.js', - 'MQService', - - 'ChartsSpace/ChartUtilities.js', - 'ChartsSpace/PlottersManager.js', - 'ChartsSpace/TimelineChart.js', - 'ChartsSpace/TimeMachine.js', - 'ChartsSpace/TimeLineCoordinateSystem.js', - - 'TopSpace/CurrentEvent.js', - 'TopSpace/Login.js', - - 'StrategySpace/StrategizerGateway.js', - - 'StrategySpace/Workspace/Workspace.js', - 'StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js', - 'StrategySpace/Workspace/FunctionLibraries/AttachDetach.js', - 'StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js', - 'StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js', - 'StrategySpace/Workspace/FunctionLibraries/StringifyNode.js', - 'StrategySpace/Workspace/FunctionLibraries/NodeChildren.js', - - 'Utilities/RoundedCornersBackground.js', - - 'Panels/TimeControlPanel.js', - 'Panels/ProductsPanel.js', - 'Panels/PanelTabButton.js', - 'Panels/ProductCard.js', - - 'ControlsToolBox/SidePanel.js', - 'ControlsToolBox/SidePanelTab.js', - - 'Spaces/CockpitSpace.js', - 'Spaces/TopSpace.js', - 'Spaces/PanelsSpace.js', - 'Spaces/ChartSpace.js', - 'Spaces/FloatingSpace.js', - 'Spaces/StrategySpace.js', - - 'Files/SingleFile.js', - 'Files/FileCloud.js', - 'Files/MarketFiles.js', - 'Files/DailyFiles.js', - 'Files/FileCursor.js', - 'Files/FileSequence.js', - 'Files/FileStorage.js', - - 'FloatingSpace/NoteSets.js', - 'FloatingSpace/Note.js', - 'FloatingSpace/ProfileBalls.js', - 'FloatingSpace/ProfileBall.js', - 'FloatingSpace/FloatingObject.js', - 'FloatingSpace/FloatingLayer.js', - 'FloatingSpace/StrategyPartConstructor.js', - 'FloatingSpace/StrategyPart.js', - 'FloatingSpace/StrategyPartTitle.js', - 'FloatingSpace/CircularMenu.js', - 'FloatingSpace/CircularMenuItem.js', - 'FloatingSpace/CodeEditor.js', - - 'Scales/RateScale.js', - 'Scales/TimeScale.js', - 'Scales/TimePeriodScale.js', - 'Scales/Commons.js', - - 'CockpitSpace/AssetBalances.js', - 'CockpitSpace/Speedometer.js', - 'CockpitSpace/RestartSimulation.js', - 'CockpitSpace/GraphQLRestartSimulation.js', - 'CockpitSpace/FullScreen.js', - - 'Plotter.js', - 'PlotterPanel.js', - - 'ProductStorage.js', - 'CompetitionStorage.js', - - 'SplashScreen.js', - 'Canvas.js', - 'EventHandler.js', - 'Frame.js', - - 'Animation.js', - - 'Container.js', - 'Displace.js', - - 'Utilities.js', - 'Dashboard.js' - ]) - - modulesArray = modulesArray.concat(plotters) - - let downloadedCounter = 0 - let versionParam = window.canvasApp.version - if (versionParam === undefined) { versionParam = '' } else { - versionParam = '?' + versionParam - } - - for (let i = 0; i < modulesArray.length; i++) { - let path = window.canvasApp.urlPrefix + modulesArray[i] + versionParam - - 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(() => { - dashboard = newDashboard() - dashboard.start() - }, 500) - - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> onRequired -> err = ' + err.stack) } - } - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> err = ' + err.stack) } + let thisObject = { + loadModules: loadModules } - } - async function loadEcosystem() { - if (INFO_LOG === true) { logger.write('[INFO] loadEcosystem -> Entering function.') } + return thisObject - let accessToken = window.localStorage.getItem('access_token') - if (accessToken !== null) { - let response = await axios({ - url: window.canvasApp.graphQL.masterAppApiUrl, - method: 'post', - data: { - query: ` + async function loadModules() { + try { + if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Entering function.') } + + window.localStorage.removeItem('ecosystem') + + let plotters + let modulesArray = [] + + if (window.canvasApp.executingAt !== 'Local') { + let ecosystem = await loadEcosystem() + if (ecosystem) { + window.localStorage.setItem('ecosystem', JSON.stringify(ecosystem)) + plotters = getPlotters(ecosystem) + } else { + plotters = defaultPlotters() + modulesArray = ['UserEcosystem.js'] + } + } else { + plotters = defaultPlotters() + modulesArray = ['UserEcosystem.js'] + } + + + + modulesArray = modulesArray.concat([ + 'ChartsSpace/ViewPort.js', + + 'Globals.js', + 'Ecosystem.js', + 'UserEcosystem.js', + 'MQService', + + 'ChartsSpace/ChartUtilities.js', + 'ChartsSpace/PlottersManager.js', + 'ChartsSpace/TimelineChart.js', + 'ChartsSpace/TimeMachine.js', + 'ChartsSpace/TimeLineCoordinateSystem.js', + + 'TopSpace/CurrentEvent.js', + 'TopSpace/Login.js', + + 'StrategySpace/StrategizerGateway.js', + + 'StrategySpace/Workspace/Workspace.js', + 'StrategySpace/Workspace/FunctionLibraries/PartsFromNodes.js', + 'StrategySpace/Workspace/FunctionLibraries/AttachDetach.js', + 'StrategySpace/Workspace/FunctionLibraries/NodeDeleter.js', + 'StrategySpace/Workspace/FunctionLibraries/ProtocolNode.js', + 'StrategySpace/Workspace/FunctionLibraries/StringifyNode.js', + 'StrategySpace/Workspace/FunctionLibraries/NodeChildren.js', + + 'Utilities/RoundedCornersBackground.js', + + 'Panels/TimeControlPanel.js', + 'Panels/ProductsPanel.js', + 'Panels/PanelTabButton.js', + 'Panels/ProductCard.js', + + 'ControlsToolBox/SidePanel.js', + 'ControlsToolBox/SidePanelTab.js', + + 'Spaces/CockpitSpace.js', + 'Spaces/TopSpace.js', + 'Spaces/PanelsSpace.js', + 'Spaces/ChartSpace.js', + 'Spaces/FloatingSpace.js', + 'Spaces/StrategySpace.js', + + 'Files/SingleFile.js', + 'Files/FileCloud.js', + 'Files/MarketFiles.js', + 'Files/DailyFiles.js', + 'Files/FileCursor.js', + 'Files/FileSequence.js', + 'Files/FileStorage.js', + + 'FloatingSpace/NoteSets.js', + 'FloatingSpace/Note.js', + 'FloatingSpace/ProfileBalls.js', + 'FloatingSpace/ProfileBall.js', + 'FloatingSpace/FloatingObject.js', + 'FloatingSpace/FloatingLayer.js', + 'FloatingSpace/StrategyPartConstructor.js', + 'FloatingSpace/StrategyPart.js', + 'FloatingSpace/StrategyPartTitle.js', + 'FloatingSpace/CircularMenu.js', + 'FloatingSpace/CircularMenuItem.js', + 'FloatingSpace/CodeEditor.js', + + 'Scales/RateScale.js', + 'Scales/TimeScale.js', + 'Scales/TimePeriodScale.js', + 'Scales/Commons.js', + + 'CockpitSpace/AssetBalances.js', + 'CockpitSpace/Speedometer.js', + 'CockpitSpace/RestartSimulation.js', + 'CockpitSpace/GraphQLRestartSimulation.js', + 'CockpitSpace/FullScreen.js', + + 'Plotter.js', + 'PlotterPanel.js', + + 'ProductStorage.js', + 'CompetitionStorage.js', + + 'SplashScreen.js', + 'Canvas.js', + 'EventHandler.js', + 'Frame.js', + + 'Animation.js', + + 'Container.js', + 'Displace.js', + + 'Utilities.js', + 'Dashboard.js' + ]) + + modulesArray = modulesArray.concat(plotters) + + let downloadedCounter = 0 + let versionParam = window.canvasApp.version + if (versionParam === undefined) { versionParam = '' } else { + versionParam = '?' + versionParam + } + + for (let i = 0; i < modulesArray.length; i++) { + let path = window.canvasApp.urlPrefix + modulesArray[i] + versionParam + + 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(() => { + dashboard = newDashboard() + dashboard.start() + }, 500) + + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> onRequired -> err = ' + err.stack) } + } + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] loadModules -> err = ' + err.stack) } + } + } + + async function loadEcosystem() { + if (INFO_LOG === true) { logger.write('[INFO] loadEcosystem -> Entering function.') } + + let accessToken = window.localStorage.getItem('access_token') + if (accessToken !== null) { + let response = await axios({ + url: window.canvasApp.graphQL.masterAppApiUrl, + method: 'post', + data: { + query: ` query { web_GetEcosystem { id @@ -308,104 +308,104 @@ function newAppLoader() { } } ` - }, - headers: { - authorization: 'Bearer ' + accessToken - } - }) + }, + headers: { + authorization: 'Bearer ' + accessToken + } + }) - if (response.data.errors) { - if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + ' : ' + '[ERROR] AppPreLoader -> loadEcosystem -> response.text = ' + JSON.stringify(response.data.errors)) } - throw error - } - - return response.data.data.web_GetEcosystem - } - } - - function defaultPlotters() { - return [ - 'Plotters/AAMasters/Plotters-Candles-Volumes/Candles.js', - 'Plotters/AAMasters/Plotters-Candles-Volumes/CandlePanel.js', - 'Plotters/AAMasters/Plotters-Candles-Volumes/Volumes.js', - 'Plotters/AAMasters/Plotters-Candles-Volumes/VolumePanel.js', - 'Plotters/AAMasters/Plotters-Stairs-Patterns/CandleStairs.js', - 'Plotters/AAMasters/Plotters-Stairs-Patterns/VolumeStairs.js', - 'Plotters/AAMasters/Plotters-Trading/Details.js', - 'Plotters/AAMasters/Plotters-Trading/History.js', - 'Plotters/AAMasters/Plotters-Bollinger-Bands/BollingerBands.js', - 'Plotters/AAMasters/Plotters-Bollinger-Bands/BollingerBandsPanel.js', - 'Plotters/AAMasters/Plotters-Bollinger-Bands/PercentageBandwidth.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/TradingSimulation.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/TradingSimulationPanel.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/Conditions.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/Strategies.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/Trades.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/SimulationExecution.js', - 'Plotters/AAMasters/Plotters-Trading-Simulation/SimulationExecutionPanel.js', - 'Plotters/AAMasters/Plotters-Bollinger-Channels/BollingerChannels.js', - 'Plotters/AAMasters/Plotters-Bollinger-Channels/ChannelPanel.js', - 'Plotters/AAMasters/Plotters-Bollinger-Channels/BollingerSubChannels.js', - 'Plotters/AAMasters/Plotters-Bollinger-Channels/SubChannelPanel.js', - // 'Plotters/AAVikings/plotters/Plotters-Linear-Regression-Curve/LRC.js', - // 'Plotters/AAVikings/plotters/Plotters-Linear-Regression-Curve/ChannelPanel.js', - 'Plotters/AAArena/Plotters-ROI/CombinedProfits.js' - ] - } - - function getPlotters(ecosystem) { - if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> Entering function.') } - - let plotters = [] - let devTeams = ecosystem.devTeams - let hosts = ecosystem.hosts - - plotters = plotters.concat(addScript(devTeams)) - plotters = plotters.concat(addScript(hosts)) - - return plotters - } - - function addScript(pDevTeamsOrHosts) { - if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> addScript -> Entering function.') } - const htmlLinePlotter = 'Plotters/@devTeam@/@repo@/@module@.js' - const htmlLinePlotterPanel = 'PlotterPanels/@devTeam@/@repo@/@module@.js' - let plotters = [] - - for (let i = 0; i < pDevTeamsOrHosts.length; i++) { - let devTeam = pDevTeamsOrHosts[i] - for (let j = 0; j < devTeam.plotters.length; j++) { - let plotter = devTeam.plotters[j] - if (plotter.modules !== undefined) { - for (let k = 0; k < plotter.modules.length; k++) { - let module = plotter.modules[k] - let htmlLineCopy = htmlLinePlotter - - let stringToInsert - stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName) - stringToInsert = stringToInsert.replace('@repo@', plotter.repo) - stringToInsert = stringToInsert.replace('@module@', module.moduleName) - - plotters.push(stringToInsert) - - if (module.panels !== undefined) { - for (let l = 0; l < module.panels.length; l++) { - let panel = module.panels[l] - let htmlLineCopy = htmlLinePlotterPanel - - let stringToInsert - stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName) - stringToInsert = stringToInsert.replace('@repo@', plotter.repo) - stringToInsert = stringToInsert.replace('@module@', panel.moduleName) - - plotters.push(stringToInsert) - } + if (response.data.errors) { + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + ' : ' + '[ERROR] AppPreLoader -> loadEcosystem -> response.text = ' + JSON.stringify(response.data.errors)) } + throw error } - } - } - } - } - return plotters - } + return response.data.data.web_GetEcosystem + } + } + + function defaultPlotters() { + return [ // TODO This should be at te ecosystem file. + 'Plotters/AAMasters/Plotters-Candles-Volumes/Candles.js', + 'Plotters/AAMasters/Plotters-Candles-Volumes/CandlePanel.js', + 'Plotters/AAMasters/Plotters-Candles-Volumes/Volumes.js', + 'Plotters/AAMasters/Plotters-Candles-Volumes/VolumePanel.js', + 'Plotters/AAMasters/Plotters-Stairs-Patterns/CandleStairs.js', + 'Plotters/AAMasters/Plotters-Stairs-Patterns/VolumeStairs.js', + //'Plotters/AAMasters/Plotters-Trading/Details.js', + //'Plotters/AAMasters/Plotters-Trading/History.js', + 'Plotters/AAMasters/Plotters-Bollinger-Bands/BollingerBands.js', + 'Plotters/AAMasters/Plotters-Bollinger-Bands/BollingerBandsPanel.js', + 'Plotters/AAMasters/Plotters-Bollinger-Bands/PercentageBandwidth.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/TradingSimulation.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/TradingSimulationPanel.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/Conditions.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/Strategies.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/Trades.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/SimulationExecution.js', + 'Plotters/AAMasters/Plotters-Trading-Simulation/SimulationExecutionPanel.js', + 'Plotters/AAMasters/Plotters-Bollinger-Channels/BollingerChannels.js', + 'Plotters/AAMasters/Plotters-Bollinger-Channels/ChannelPanel.js', + 'Plotters/AAMasters/Plotters-Bollinger-Channels/BollingerSubChannels.js', + 'Plotters/AAMasters/Plotters-Bollinger-Channels/SubChannelPanel.js', + // 'Plotters/AAVikings/plotters/Plotters-Linear-Regression-Curve/LRC.js', + // 'Plotters/AAVikings/plotters/Plotters-Linear-Regression-Curve/ChannelPanel.js', + // 'Plotters/AAArena/Plotters-ROI/CombinedProfits.js' + ] + } + + function getPlotters(ecosystem) { + if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> Entering function.') } + + let plotters = [] + let devTeams = ecosystem.devTeams + let hosts = ecosystem.hosts + + plotters = plotters.concat(addScript(devTeams)) + plotters = plotters.concat(addScript(hosts)) + + return plotters + } + + function addScript(pDevTeamsOrHosts) { + if (INFO_LOG === true) { console.log('[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> addScript -> Entering function.') } + const htmlLinePlotter = 'Plotters/@devTeam@/@repo@/@module@.js' + const htmlLinePlotterPanel = 'PlotterPanels/@devTeam@/@repo@/@module@.js' + let plotters = [] + + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { + let devTeam = pDevTeamsOrHosts[i] + for (let j = 0; j < devTeam.plotters.length; j++) { + let plotter = devTeam.plotters[j] + if (plotter.modules !== undefined) { + for (let k = 0; k < plotter.modules.length; k++) { + let module = plotter.modules[k] + let htmlLineCopy = htmlLinePlotter + + let stringToInsert + stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName) + stringToInsert = stringToInsert.replace('@repo@', plotter.repo) + stringToInsert = stringToInsert.replace('@module@', module.moduleName) + + plotters.push(stringToInsert) + + if (module.panels !== undefined) { + for (let l = 0; l < module.panels.length; l++) { + let panel = module.panels[l] + let htmlLineCopy = htmlLinePlotterPanel + + let stringToInsert + stringToInsert = htmlLineCopy.replace('@devTeam@', devTeam.codeName) + stringToInsert = stringToInsert.replace('@repo@', plotter.repo) + stringToInsert = stringToInsert.replace('@module@', panel.moduleName) + + plotters.push(stringToInsert) + } + } + } + } + } + } + return plotters + } } + diff --git a/index.html b/index.html index afed971db..c410f01c4 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,7 @@ executingAt: 'Local', visible: true, topMargin: 60, - urlPrefix: 'http://localhost:1337/', + urlPrefix: 'http://localhost:9999/', graphQL: { masterAppApiUrl: 'https://demo-api-dev.superalgos.org/graphql', },