Awaits to get the clones id first so that the panel gets the cloneId

This commit is contained in:
Luis Fernando Molina committed 2019-03-24 20:02:36 +01:00
1 parent a212c6b582
commit 3d7a335070
5 files changed
+57 -38

No files matched your search

+2 -2
View File
@@ -107,7 +107,7 @@ function newCanvas () {
}
}
function initialize (callBackFunction) {
async function initialize (callBackFunction) {
try {
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
@@ -118,7 +118,7 @@ function newCanvas () {
/* Instantiate all the children spaces of Canvas object */
thisObject.topSpace = newTopSpace()
thisObject.topSpace.initialize()
await thisObject.topSpace.initialize()
thisObject.bottomSpace = newBottomSpace()
thisObject.bottomSpace.initialize()
+1 -1
View File
@@ -59,7 +59,7 @@
for (let j = 0; j < devTeam.bots.length; j++) {
let bot = devTeam.bots[j]
if (bot.type !== 'Indicator') { continue }
if (bot.type !== 'Indicator' && bot.cloneId === undefined) { continue }
if (bot.products !== undefined) {
for (let k = 0; k < bot.products.length; k++) {
+16 -13
View File
@@ -25,7 +25,7 @@ function newTopSpace () {
return thisObject
function initialize () {
async function initialize () {
let sharedStatus = {
currentDevTeamIndex: 0,
currentEventIndex: 0,
@@ -36,8 +36,9 @@ function newTopSpace () {
}
thisObject.login = newLogin()
thisObject.login.initialize(sharedStatus, onLoginInitialized)
await thisObject.login.initialize(sharedStatus)
/*
thisObject.companyLogo = newCompanyLogo()
thisObject.endUser = newEndUser()
thisObject.currentBot = newCurrentBot()
@@ -45,18 +46,17 @@ function newTopSpace () {
thisObject.currentStartMode = newCurrentStartMode()
thisObject.currentEvent = newCurrentEvent()
thisObject.devTeam = newDevTeam()
*/
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
function onLoginInitialized () {
thisObject.companyLogo.initialize()
thisObject.endUser.initialize()
thisObject.currentBot.initialize(sharedStatus)
thisObject.currentProcess.initialize(sharedStatus)
thisObject.currentStartMode.initialize(sharedStatus)
thisObject.currentEvent.initialize(sharedStatus)
thisObject.devTeam.initialize(sharedStatus)
}
/*
thisObject.companyLogo.initialize()
thisObject.endUser.initialize()
thisObject.currentBot.initialize(sharedStatus)
thisObject.currentProcess.initialize(sharedStatus)
thisObject.currentStartMode.initialize(sharedStatus)
thisObject.currentEvent.initialize(sharedStatus)
thisObject.devTeam.initialize(sharedStatus)
*/
}
function resize () {
@@ -69,6 +69,7 @@ function newTopSpace () {
function getContainer (point) {
let container
return
container = thisObject.companyLogo.getContainer(point)
if (container !== undefined) { return container }
@@ -103,6 +104,8 @@ function newTopSpace () {
thisObject.container.frame.draw(false, false)
drawBackground()
return
thisObject.companyLogo.draw()
thisObject.endUser.draw()
thisObject.devTeam.draw()
+2
View File
@@ -28,6 +28,8 @@ function newCurrentBot () {
function initialize (pSharedStatus) {
sharedStatus = pSharedStatus
if (window.USER_PROFILE === undefined) { return }
if (window.USER_PROFILE.devTeams.length === 0) {
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND
} else {
+36 -22
View File
@@ -26,7 +26,7 @@ function newLogin () {
return thisObject
function initialize (pSharedStatus, callBackFunction) {
async function initialize (pSharedStatus) {
const accessToken = window.localStorage.getItem('access_token')
let user = window.localStorage.getItem('user')
@@ -296,7 +296,21 @@ function newLogin () {
})
.then(response => {
window.localStorage.setItem('userClones', JSON.stringify(response.data.operations_Clones))
resolve({ teams: response.data.operations_Clones})
let clones = response.data.operations_Clones
for (let i = 0; i < clones.length; i++) {
let clone = clones[i]
if (clone.botType === 'Trading') {
let teamSlug = clone.teamName.toLowerCase()
teamSlug = teamSlug.replace(' ', '-')
let devTeam = ecosystem.getTeam(teamSlug)
let bot = ecosystem.getBot(devTeam, clone.botSlug)
if (bot !== undefined) {
bot.cloneId = clone.id
}
}
}
resolve({ clones: response.data.operations_Clones})
})
.catch(error => {
console.log('apolloClient error getting user clones', error)
@@ -308,42 +322,42 @@ function newLogin () {
// To avoid race conditions, add asynchronous fetches to array
let fetchDataPromises = []
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones())
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones(), authenticateUser())
// When all asynchronous fetches resolve, authenticate user or throw error.
Promise.all(fetchDataPromises).then(result => {
/* this is the time to authenticate the user at AAWeb */
await Promise.all(fetchDataPromises).then(result => {
authenticateUser()
}, err => {
console.error('fetchData error', err)
console.error('[ERROR] Login -> GraphQL Fetch Error -> err = ', err)
})
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
function authenticateUser () {
async function authenticateUser () {
if (sessionToken === undefined) { sessionToken = '' }
let path = window.canvasApp.urlPrefix + 'AABrowserAPI/authenticateUser/' + sessionToken
callServer(undefined, path, onServerReponded)
return new Promise(
function (resolve, reject) {
callServer(undefined, path, (result) => {
let responseFromServer = JSON.parse(result)
function onServerReponded (pResponseFromServer) {
let responseFromServer = JSON.parse(pResponseFromServer)
err = responseFromServer.err
err = responseFromServer.err
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Please make sure you create a new team!')
reject(err)
}
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Please make sure you create a new team!')
return
}
window.USER_PROFILE = responseFromServer.userProfile
window.localStorage.setItem('sessionToken', sessionToken)
window.USER_PROFILE = responseFromServer.userProfile
window.localStorage.setItem('sessionToken', sessionToken)
currentLabel = 'Logged In'
callBackFunction()
}
currentLabel = 'Logged In'
resolve()
})
}
)
}
}