Restart Simulation Mutation implemented

This commit is contained in:
Luis Fernando Molina committed 2019-05-15 13:02:04 +02:00
1 parent 716163a574
commit 920d16a888
3 files changed
+73 -2

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
const GRAPHQL_MUTATION_RESTART_SIMULATION = Apollo.gql`
mutation operations_RunSimulation(
$simulation: operations_SimulationInput)
{
operations_RunSimulation(simulation: $simulation)
}
`
async function restartSimulation (simulationParams) {
try {
const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY)
if (accessToken === null) {
if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> Can not restart the simulation because the user is not logged in. ') }
return
}
const apolloClient = new Apollo.lib.ApolloClient({
networkInterface: Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl,
transportBatching: true
}),
connectToDevTools: true
})
const networkInterface = Apollo.lib.createNetworkInterface({
uri: window.canvasApp.graphQL.masterAppApiUrl
})
networkInterface.use([{
applyMiddleware (req, next) {
req.options.headers = {
authorization: `Bearer ${accessToken}`
}
next()
}
}])
const graphQlRestartSimuulation = () => {
return new Promise((resolve, reject) => {
apolloClient.mutate({
mutation: GRAPHQL_MUTATION_RESTART_SIMULATION,
variables: {
simulation: simulationParams
}
})
.then(response => {
resolve(true)
})
.catch(err => {
if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> ApolloClient error restarting simulation -> err = ' + err.stack) }
reject(err)
})
})
}
let result = await graphQlRestartSimuulation()
return result
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> err = ' + err.stack) }
}
}
+8 -1
View File
@@ -71,7 +71,15 @@ function newRestartSimulation () {
}
async function onMouseClick (event) {
let simulationParams = {
beginDatetime: 1554087600,
resumeExecution: true,
timePeriodDailyArray: ['05-min', '10-min'],
timePeriodMarketArray: ['01-hs', '02-hs']
}
let result = await restartSimulation(simulationParams)
console.log('GRAPH QL EXECUTION ' + result)
}
function physics () {
@@ -129,4 +137,3 @@ function newRestartSimulation () {
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
}
}
+1 -1
View File
@@ -91,7 +91,7 @@ function newWorkspace () {
resolve(true)
})
.catch(err => {
if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error getting user strategies -> err = ' + err.stack) }
if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error updating user strategies -> err = ' + err.stack) }
reject(err)
})
})