Simulation Restarted using Axios

This commit is contained in:
Luis Fernando Molina committed 2019-05-15 15:39:55 +02:00
1 parent 920d16a888
commit e0db4ec80b
3 files changed
+23 -65

No files matched your search

-13
View File
@@ -185,19 +185,6 @@ function newCanvas () {
function onMouseDown (event) {
try {
/*
There are four types of elements that can be dragged.
1. Panels.
2. Floating Elements (Currently only FloatingObjects).
3. Charts.
4. The Viewport.
We eveluate each space in order to see if they are holding the element being dragged, and we fallout at the Viewport.
*/
let point = {
x: event.pageX,
y: event.pageY - window.canvasApp.topMargin
+22 -50
View File
@@ -1,64 +1,36 @@
const GRAPHQL_MUTATION_RESTART_SIMULATION = Apollo.gql`
mutation operations_RunSimulation(
$simulation: operations_SimulationInput)
{
operations_RunSimulation(simulation: $simulation)
}
`
async function restartSimulation (simulationParams) {
async function graphQlRestartSimulation (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
throw new Error('Can not restart the simulation because the user is not logged in. ')
}
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}`
const graphQLServer = await axios({
url: window.canvasApp.graphQL.masterAppApiUrl,
method: 'post',
data: {
query: `
mutation operations_RunSimulation(
$simulation: operations_SimulationInput)
{
operations_RunSimulation(simulation: $simulation)
}
`,
variables: {
simulation: simulationParams
}
next()
},
headers: {
authorization: 'Bearer ' + accessToken
}
}])
})
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)
})
})
if (graphQLServer.data.errors) {
throw new Error(graphQLServer.data.errors[0].message)
}
let result = await graphQlRestartSimuulation()
return result
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] restartSimulation -> err = ' + err.stack) }
throw new Error('There has been an error restarting the simulation. Error: ' + err.stack)
}
}
+1 -2
View File
@@ -78,8 +78,7 @@ function newRestartSimulation () {
timePeriodMarketArray: ['01-hs', '02-hs']
}
let result = await restartSimulation(simulationParams)
console.log('GRAPH QL EXECUTION ' + result)
let result = await graphQlRestartSimulation(simulationParams)
}
function physics () {