From e0db4ec80b0091a80e5388f67030cf77f1ec0479 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 15:39:55 +0200 Subject: [PATCH] Simulation Restarted using Axios --- Canvas.js | 13 ----- CockpitSpace/GraphQLRestartSimulation.js | 72 ++++++++---------------- CockpitSpace/RestartSimulation.js | 3 +- 3 files changed, 23 insertions(+), 65 deletions(-) diff --git a/Canvas.js b/Canvas.js index e29cecb67..33e8e77d4 100644 --- a/Canvas.js +++ b/Canvas.js @@ -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 diff --git a/CockpitSpace/GraphQLRestartSimulation.js b/CockpitSpace/GraphQLRestartSimulation.js index e066a5cbb..b71b8fa48 100644 --- a/CockpitSpace/GraphQLRestartSimulation.js +++ b/CockpitSpace/GraphQLRestartSimulation.js @@ -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) } } diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index efb0350ed..ae5372145 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -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 () {