From 2073effdd3882f32abff91a3a8d461242a7d4a5e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Sep 2019 16:03:26 +0200 Subject: [PATCH] Bug Fixes and Improvements to better respond to UI --- CockpitSpace/RestartSimulation.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index 98e7eb14e..edfa45127 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -35,9 +35,9 @@ function newRestartSimulation () { let executionFocusExists = false let idleLabel = '' - let refreshCounter = 0 let isRunning = false - let eventSubscriptionId + let eventSubscriptionIdSimulationFilesUpdated + let eventSubscriptionIdProcessStopped return thisObject @@ -46,7 +46,8 @@ function newRestartSimulation () { thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfMouseNotOverEventSubscriptionId) - systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionId) + systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionIdSimulationFilesUpdated) + systemEventHandler.stopListening('Jason-Multi-Period', eventSubscriptionIdProcessStopped) thisObject.container.finalize() thisObject.container = undefined @@ -68,16 +69,17 @@ function newRestartSimulation () { We will start listening to the event that is triggered when the simulation process finishes processing one day in the case of daily files or the whole market in the case of market files. */ - eventSubscriptionId = systemEventHandler.listenToEvent('Jason-Multi-Period', 'Status Report Updated', undefined, undefined, undefined, onEvent) + eventSubscriptionIdSimulationFilesUpdated = systemEventHandler.listenToEvent('Jason-Multi-Period', 'Simulation Files Updated', undefined, undefined, undefined, onFilesUpdated) - function onEvent (message) { - refreshCounter++ + function onFilesUpdated (message) { + turnOffProductCards() + turnOnProductCards() + } - if (refreshCounter === 1) { - refreshCounter = 0 - turnOffProductCards() - turnOnProductCards() - } + eventSubscriptionIdProcessStopped = systemEventHandler.listenToEvent('Jason-Multi-Period', 'Process Stopped', undefined, undefined, undefined, onProcessStopped) + + function onProcessStopped (message) { + thisObject.status = 'Ready' } } @@ -144,7 +146,6 @@ function newRestartSimulation () { systemEventHandler.raiseEvent('Cockpit-Restart-Button', 'Stop Requested') isRunning = false thisObject.status = 'Stopping' - counterTillNextState = 200 } } catch (err) { thisObject.status = 'Error' @@ -200,7 +201,7 @@ function newRestartSimulation () { break case 'Stopping': - thisObject.status = 'Ready' + break case 'Error': thisObject.status = 'Ready'