Storing IdAtStrategizer across sessions

This commit is contained in:
Luis Fernando Molina committed 2019-05-25 10:52:09 +02:00
1 parent e05085b8ed
commit b079bf1bef
5 files changed
+35 -31

No files matched your search

+1 -1
View File
@@ -108,7 +108,7 @@ function newRestartSimulation () {
}
try {
thisObject.status = 'Saving'
let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer(canvas.strategySpace.workspace.tradingSystem)
let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer()
if (result === true) {
thisObject.status = 'Restarting'
await graphQlRestartSimulation(simulationParams)
+3 -1
View File
@@ -47,7 +47,9 @@
thisObject.container.frame.position.x = 0
let INITIAL_POSITION
if (canvas.strategySpace.isInitialized === true) {
const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY)
if (accessToken !== null) {
INITIAL_POSITION = 55
} else {
INITIAL_POSITION = 100
+2 -14
View File
@@ -8,7 +8,6 @@ function newStrategySpace () {
iconCollection: undefined,
iconByPartType: undefined,
workspace: undefined,
isInitialized: false,
physics: physics,
draw: draw,
getContainer: getContainer,
@@ -35,19 +34,8 @@ function newStrategySpace () {
thisObject.strategizerGateway = newStrategizerGateway()
thisObject.strategizerGateway.initialize()
let savedWorkspace = window.localStorage.getItem('workspace')
if (savedWorkspace === null) {
await thisObject.strategizerGateway.loadFromStrategyzer()
if (thisObject.strategizerGateway.strategizerData !== undefined) {
thisObject.isInitialized = true
thisObject.workspace = newWorkspace()
thisObject.workspace.initialize(thisObject.strategizerGateway.strategizerData)
}
} else {
thisObject.isInitialized = true
thisObject.workspace = newWorkspace()
thisObject.workspace.initialize()
}
thisObject.workspace = newWorkspace()
thisObject.workspace.initialize()
}
function buildIconByPartTypeMap () {
+4 -2
View File
@@ -36,7 +36,7 @@ function newStrategizerGateway () {
}
async function saveToStrategyzer (tradingSystem) {
async function saveToStrategyzer () {
try {
const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY)
@@ -73,6 +73,8 @@ function newStrategizerGateway () {
}
}])
let tradingSystem = canvas.strategySpace.workspace.tradingSystem
let idAtStrategizer = canvas.strategySpace.workspace.idAtStrategizer
let dataToSave = buildGraphQLDataToSave(tradingSystem)
const updateStrategies = () => {
@@ -80,7 +82,7 @@ function newStrategizerGateway () {
apolloClient.mutate({
mutation: GRAPHQL_MUTATION_UPDATE_STRATEGIES,
variables: {
id: tradingSystem.id,
id: idAtStrategizer,
strategy: dataToSave.strategy
}
})
+25 -13
View File
@@ -5,6 +5,7 @@ function newWorkspace () {
let thisObject = {
tradingSystem: undefined,
container: undefined,
idAtStrategizer: undefined,
physics: physics,
spawn: spawn,
detachNode: detachNode,
@@ -41,19 +42,26 @@ function newWorkspace () {
thisObject.container = undefined
}
function initialize (tradingSystem) {
let savedWorkspace = window.localStorage.getItem('workspace')
function initialize () {
let savedWorkspace = window.localStorage.getItem('xxxworkspace')
if (savedWorkspace === null) {
let adaptedTradingSystem = {
id: tradingSystem.id,
strategies: tradingSystem.subStrategies
await canvas.strategySpace.strategizerGateway.loadFromStrategyzer()
let tradingSystem = canvas.strategySpace.strategizerGateway.strategizerData
if (tradingSystem !== undefined) {
let adaptedTradingSystem = {
strategies: tradingSystem.subStrategies
}
thisObject.idAtStrategizer = tradingSystem.id
rootNodes.push(adaptedTradingSystem)
generateStrategyParts(adaptedTradingSystem)
thisObject.tradingSystem = adaptedTradingSystem
thisObject.tradingSystem.payload.uiObject.setRunningStatus()
}
rootNodes.push(adaptedTradingSystem)
generateStrategyParts(adaptedTradingSystem)
thisObject.tradingSystem = adaptedTradingSystem
thisObject.tradingSystem.payload.uiObject.setRunningStatus()
} else {
rootNodes = JSON.parse(savedWorkspace)
} else {
workspace = JSON.parse(savedWorkspace)
rootNodes = workspace.rootNodes
thisObject.idAtStrategizer = workspace.idAtStrategizer
for (let i = 0; i < rootNodes.length; i++) {
let rootNode = rootNodes[i]
createPartFromNode(rootNode, undefined, undefined)
@@ -73,7 +81,11 @@ function newWorkspace () {
let workspaceNode = getWorkspaceNode(rootNode)
stringifyReadyNodes.push(workspaceNode)
}
let textToSave = JSON.stringify(stringifyReadyNodes)
let workspace = {
idAtStrategizer: thisObject.idAtStrategizer,
rootNodes: stringifyReadyNodes
}
let textToSave = JSON.stringify(workspace)
window.localStorage.setItem('workspace', textToSave)
}
@@ -513,7 +525,7 @@ function newWorkspace () {
switch (action) {
case 'Save Trading System':
{
let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer(canvas.strategySpace.workspace.tradingSystem)
let result = await canvas.strategySpace.strategizerGateway.saveToStrategyzer()
return result
break
}