From 2365fbdb9c024230767cfe951c98b9124d9062fa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 09:51:06 +0200 Subject: [PATCH 1/8] FIXED: variable for user storage --- Globals.js | 12 ++++++++++-- Spaces/CockpitSpace.js | 5 ++--- StrategySpace/Workspace.js | 8 ++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Globals.js b/Globals.js index 7fb404879..d25a99d1c 100644 --- a/Globals.js +++ b/Globals.js @@ -122,9 +122,17 @@ function convertTimePeriodToName(pTimePeriod) { window.AT_BREAKPOINT = false; +let testUser = window.localStorage.getItem("test_user") +let LOGGED_IN_USER_LOCAL_STORAGE_KEY +let LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY -const LOGGED_IN_USER_LOCAL_STORAGE = "xuser" -const LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE = "xaccess_token" +if (testUser !== null) { + LOGGED_IN_USER_LOCAL_STORAGE_KEY = "test_user" + LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "test_access_token" +} else { + LOGGED_IN_USER_LOCAL_STORAGE_KEY = "user" + LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "access_token" +} const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index 29096fa78..6696a400b 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -61,7 +61,7 @@ thisObject.status = 'MIDDLE' - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user !== null) { // Only if user is logged in thisObject.container.isDraggeable = true } else { @@ -134,7 +134,7 @@ browserCanvasContext.closePath() browserCanvasContext.fill() - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user !== null) { // Only if user is logged in arrow() } @@ -228,4 +228,3 @@ browserCanvasContext.stroke() } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index d03cf2b35..dd9e8b5b5 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -41,9 +41,9 @@ function newWorkspace () { async function saveToStrategyzer () { try { - const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE) + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user === null) { if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> Can not save because user is not logged in. ') } return @@ -253,9 +253,9 @@ function newWorkspace () { async function loadFromStrategyzer () { try { - const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE) + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user === null) { // if there is no user that means that we are logged off, which means this object can not be used. return From 9b346dde8fa33f822126ab796a401274f9c082ac Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 10:19:31 +0200 Subject: [PATCH 2/8] Restart Simulation Buttom partially implemented --- CockpitSpace/RestartSimulation.js | 83 +++++++++++++++++++++++++++++++ Spaces/CockpitSpace.js | 12 +++++ 2 files changed, 95 insertions(+) create mode 100644 CockpitSpace/RestartSimulation.js diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js new file mode 100644 index 000000000..509748b53 --- /dev/null +++ b/CockpitSpace/RestartSimulation.js @@ -0,0 +1,83 @@ + +function newRestartSimulation () { + const MODULE_NAME = 'Restart Simulation' + + let thisObject = { + visible: true, + container: undefined, + physics: physics, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + thisObject.container.isDraggeable = false + thisObject.container.isWheelable = false + thisObject.container.isClickeable = true + + return thisObject + + function finalize () { + thisObject.container.finalize() + thisObject.container = undefined + } + + function initialize () { + thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width * 80 / 100 + thisObject.container.frame.position.y = 6 + thisObject.container.frame.width = 100 + thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12 + } + + function getContainer (point, purpose) { + if (thisObject.visible !== true) { return } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + + function physics () { + + } + + function draw () { + if (thisObject.visible !== true) { return } + + drawRestartSimulation() + } + + function drawRestartSimulation () { + let fontSize + let label + let xOffset + let yOffset + + const OPACITY = 1 + + /* We put the params.VALUE in the middle */ + + fontSize = 15 + + browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY + + label = 'RESTART SIMULATION' + + xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + yOffset = -45 + + labelPoint = { + x: 0 - xOffset + (thisObject.paramsArray[1].LEFT_OFFSET - thisObject.paramsArray[0].LEFT_OFFSET) / 2 + thisObject.paramsArray[0].LEFT_OFFSET - 20, + y: COCKPIT_SPACE_POSITION - COCKPIT_SPACE_HEIGHT / 2 - yOffset + } + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } +} diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index 6696a400b..a47822da3 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -6,6 +6,7 @@ container: undefined, status: 'BOTTOM', assetBalances: undefined, + restartSimulation: undefined, draw: draw, physics: physics, getContainer: getContainer, @@ -34,6 +35,7 @@ thisObject.container.finalize() thisObject.container = undefined thisObject.assetBalances = undefined + thisObject.restartSimulation = undefined } function initialize () { @@ -42,6 +44,10 @@ thisObject.assetBalances = newAssetBalances() thisObject.assetBalances.initialize() + + thisObject.restartSimulation = newRestartSimulation() + thisObject.restartSimulation.initialize() + thisObject.restartSimulation.container.connectToParent(thisObject.container) } function onMouseClick (event) { @@ -89,6 +95,11 @@ } function getContainer (point) { + let container + + container = thisObject.restartSimulation.getContainer(point) + if (container !== undefined) { return container } + if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container } else { @@ -102,6 +113,7 @@ drawBackground() thisObject.assetBalances.draw() + thisObject.restartSimulation.draw() } function drawBackground () { From 0d3f451a0ca7d988005eb5aaf84c6ae922a714b1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 10:40:50 +0200 Subject: [PATCH 3/8] Extensive code cleaning --- Animation.js | 66 +++---------------- Canvas.js | 106 +++++------------------------- CockpitSpace/RestartSimulation.js | 11 ++-- Dashboard.js | 13 ---- Spaces/CockpitSpace.js | 2 +- 5 files changed, 32 insertions(+), 166 deletions(-) diff --git a/Animation.js b/Animation.js index d27dc114c..01ce1f6f5 100644 --- a/Animation.js +++ b/Animation.js @@ -1,7 +1,6 @@ function newAnimation () { const MODULE_NAME = 'Animation' - const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -29,75 +28,31 @@ function newAnimation () { return thisObject function finalize () { - try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - - thisObject.stop() - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } - }s + thisObject.stop() } - function initialize (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } + function initialize () { - /* Nothing to do here yet. */ - callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } } - function start (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') } - - animationLoop() // Inside this function the animation process is started, and at the same time it creates a loop. - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function start () { + animationLoop() // Inside this function the animation process is started, and at the same time it creates a loop. } - function stop (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] stop -> Entering function.') } - - window.cancelAnimationFrame(animationLoopHandle) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] stop -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function stop () { + window.cancelAnimationFrame(animationLoopHandle) } - function addCallBackFunction (key, callBack, callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] addCallBackFunction -> Entering function.') } - - callBackFunctions.set(key, callBack) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] addCallBackFunction -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function addCallBackFunction (key, callBack) { + callBackFunctions.set(key, callBack) } - function removeCallBackFunction (key, callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] removeCallBackFunction -> Entering function.') } - - callBackFunctions.delete(key) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] removeCallBackFunction -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function removeCallBackFunction (key) { + callBackFunctions.delete(key) } function animationLoop () { try { - if (INFO_LOG === true) { logger.write('[INFO] animationLoop -> Entering function.') } - if (window.canvasApp.visible === true) { /* We set the canvas to its normal width and height */ @@ -140,4 +95,3 @@ function newAnimation () { browserCanvasContext.fill() } } - diff --git a/Canvas.js b/Canvas.js index 3bc45b757..e29cecb67 100644 --- a/Canvas.js +++ b/Canvas.js @@ -7,7 +7,6 @@ let splashScreenNeeded = true function newCanvas () { const MODULE_NAME = 'Canvas' - const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -52,8 +51,6 @@ function newCanvas () { function finalize () { try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - thisObject.chartSpace.finalize() thisObject.floatingSpace.finalize() @@ -78,10 +75,8 @@ function newCanvas () { } } - async function initialize (callBackFunction) { + async function initialize () { try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } - initializeBrowserCanvas() addCanvasEvents() @@ -110,12 +105,9 @@ function newCanvas () { function onCharSpaceInitialized (err) { try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCharSpaceInitialized -> Entering function.') } - viewPort.raiseEvents() // These events will impacts on objects just initialized. } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onCharSpaceInitialized -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) } } @@ -125,90 +117,32 @@ function newCanvas () { splashScreen.initialize() let animation = newAnimation() - animation.initialize(onAnimationInitialized) + animation.initialize() - function onAnimationInitialized (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> Entering function.') } - - thisObject.animation = animation + thisObject.animation = animation /* Here we add all the functions that will be called during the animation cycle. */ - animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground, onFunctionAdded) - animation.addCallBackFunction('Chart Space Draw', thisObject.chartSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Chart Space Physics', thisObject.chartSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Panels Space', thisObject.panelsSpace.draw, onFunctionAdded) - animation.addCallBackFunction('ViewPort Animate', viewPort.animate, onFunctionAdded) - animation.addCallBackFunction('CockpitSpace Draw', thisObject.cockpitSpace.draw, onFunctionAdded) - animation.addCallBackFunction('CockpitSpace Physics', thisObject.cockpitSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Top Space Draw', thisObject.topSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Strategy Space Draw', thisObject.strategySpace.draw, onFunctionAdded) - animation.addCallBackFunction('Splash Screen Draw', splashScreen.draw, onFunctionAdded) - animation.start(onStart) - - function onFunctionAdded (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onFunctionAdded -> Entering function.') } - - if (err.result === GLOBAL.DEFAULT_FAIL_RESPONSE.result) { - animation.stop() - - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> Animation Stopped since a vital funtion could not be added.') } - - /* Display some Error Page here. */ - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function onStart (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Entering function.') } - - switch (err.result) { - case GLOBAL.DEFAULT_OK_RESPONSE.result: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received OK Response.') } - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - return - } - - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received FAIL Response.') } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - default: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received Unexpected Response.') } - callBackFunction(err) - return - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onStart -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } + animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw) + animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics) + animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground) + animation.addCallBackFunction('Chart Space Draw', thisObject.chartSpace.draw) + animation.addCallBackFunction('Chart Space Physics', thisObject.chartSpace.physics) + animation.addCallBackFunction('Panels Space', thisObject.panelsSpace.draw) + animation.addCallBackFunction('ViewPort Animate', viewPort.animate) + animation.addCallBackFunction('CockpitSpace Draw', thisObject.cockpitSpace.draw) + animation.addCallBackFunction('CockpitSpace Physics', thisObject.cockpitSpace.physics) + animation.addCallBackFunction('Top Space Draw', thisObject.topSpace.draw) + animation.addCallBackFunction('Strategy Space Draw', thisObject.strategySpace.draw) + animation.addCallBackFunction('Splash Screen Draw', splashScreen.draw) + animation.start() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) } } function initializeBrowserCanvas () { try { - if (INFO_LOG === true) { logger.write('[INFO] initializeBrowserCanvas -> Entering function.') } - browserCanvasContext = browserCanvas.getContext('2d') // browserCanvasContext.font = 'italic small-caps bold 12px Saira' browserCanvasContext.font = 'Saira' @@ -221,8 +155,6 @@ function newCanvas () { function addCanvasEvents () { try { - if (INFO_LOG === true) { logger.write('[INFO] addCanvasEvents -> Entering function.') } - /* Mouse down and up events to control the drag of the canvas. */ browserCanvas.addEventListener('mousedown', onMouseDown, false) @@ -253,8 +185,6 @@ function newCanvas () { function onMouseDown (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseDown -> Entering function.') } - /* There are four types of elements that can be dragged. @@ -362,8 +292,6 @@ function newCanvas () { function onMouseClick (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseClick -> Entering function.') } - if (ignoreNextClick === true) { ignoreNextClick = false return @@ -611,8 +539,6 @@ function newCanvas () { function onMouseWheel (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseWheel -> Entering function.') } - // cross-browser wheel delta var event = window.event || event // old IE support let delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail)) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index 509748b53..1437955a3 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -69,15 +69,14 @@ function newRestartSimulation () { label = 'RESTART SIMULATION' - xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO - yOffset = -45 - - labelPoint = { - x: 0 - xOffset + (thisObject.paramsArray[1].LEFT_OFFSET - thisObject.paramsArray[0].LEFT_OFFSET) / 2 + thisObject.paramsArray[0].LEFT_OFFSET - 20, - y: COCKPIT_SPACE_POSITION - COCKPIT_SPACE_HEIGHT / 2 - yOffset + let labelPoint = { + x: 0, + y: thisObject.container.frame.height - 9 } + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint) browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } } + diff --git a/Dashboard.js b/Dashboard.js index cb57b4fe3..63e3176af 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -6,7 +6,6 @@ let viewPort = newViewPort() function newDashboard () { const MODULE_NAME = 'Dashboard' - const INFO_LOG = false const ERROR_LOG = true const INTENSIVE_LOG = false const logger = newWebDebugLog() @@ -25,8 +24,6 @@ function newDashboard () { function start () { try { - if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') } - /* If this method is executed for a second time, it should finalize the current execution structure */ if (canvas !== undefined) { canvas.finalize() } @@ -40,8 +37,6 @@ function newDashboard () { loadImages(onImagesLoaded) function onImagesLoaded () { - if (INFO_LOG === true) { logger.write('[INFO] start -> onImagesLoaded -> Entering function.') } - /* Next we start the App */ setTimeout(delayedStart, DEBUG_START_UP_DELAY) @@ -53,8 +48,6 @@ function newDashboard () { function delayedStart () { try { - if (INFO_LOG === true) { logger.write('[INFO] delayedStart -> Entering function.') } - /* For now, we are supporting only one market. */ let market = { @@ -76,8 +69,6 @@ function newDashboard () { function userProfileChanged () { try { - if (INFO_LOG === true) { logger.write('[INFO] userProfileChanged -> Entering function.') } - canvas.topSpace.initialize() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] userProfileChanged -> err = ' + err.stack) } @@ -86,8 +77,6 @@ function newDashboard () { function browserResized () { try { - if (INFO_LOG === true) { logger.write('[INFO] browserResized -> Entering function.') } - browserCanvas = document.getElementById('canvas') browserCanvas.width = window.innerWidth @@ -101,8 +90,6 @@ function newDashboard () { function loadImages (callBack) { try { - if (INFO_LOG === true) { logger.write('[INFO] loadImages -> Entering function.') } - const accessToken = '' /* diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index a47822da3..d0bf1a3e9 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -46,8 +46,8 @@ thisObject.assetBalances.initialize() thisObject.restartSimulation = newRestartSimulation() - thisObject.restartSimulation.initialize() thisObject.restartSimulation.container.connectToParent(thisObject.container) + thisObject.restartSimulation.initialize() } function onMouseClick (event) { From 716163a574ddada50b231a99afa3b12265d6aaa9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 11:19:43 +0200 Subject: [PATCH 4/8] Restart Simulation Button with mouse over / out working --- CockpitSpace/RestartSimulation.js | 60 ++++++++++++++++++++++++++++--- Spaces/CockpitSpace.js | 1 + 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index 1437955a3..a5c4c3286 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -18,10 +18,21 @@ function newRestartSimulation () { thisObject.container.isDraggeable = false thisObject.container.isWheelable = false thisObject.container.isClickeable = true + thisObject.container.detectMouseOver = true + + let selfMouseOverEventSubscriptionId + let selfMouseClickEventSubscriptionId + let selfMouseNotOverEventSubscriptionId + + let isMouseOver = false return thisObject function finalize () { + thisObject.container.eventHandler.stopListening(selfMouseOverEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfMouseNotOverEventSubscriptionId) + thisObject.container.finalize() thisObject.container = undefined } @@ -29,8 +40,12 @@ function newRestartSimulation () { function initialize () { thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width * 80 / 100 thisObject.container.frame.position.y = 6 - thisObject.container.frame.width = 100 + thisObject.container.frame.width = 200 thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12 + + selfMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) + selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick) + selfMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver) } function getContainer (point, purpose) { @@ -43,17 +58,52 @@ function newRestartSimulation () { } } + function onMouseOver (point) { + if (thisObject.container.frame.isThisPointHere(point, true, false) === true) { + isMouseOver = true + } else { + isMouseOver = false + } + } + + function onMouseNotOver (point) { + isMouseOver = false + } + + async function onMouseClick (event) { + + } + function physics () { } function draw () { if (thisObject.visible !== true) { return } - - drawRestartSimulation() + drawBackground() + drawText() } - function drawRestartSimulation () { + function drawBackground () { + let params = { + cornerRadius: 3, + lineWidth: 0.01, + container: thisObject.container, + borderColor: UI_COLOR.DARK, + castShadow: false, + opacity: 1 + } + + if (isMouseOver === true) { + params.backgroundColor = UI_COLOR.TURQUOISE + } else { + params.backgroundColor = UI_COLOR.DARK_TURQUOISE + } + + roundedCornersBackground(params) + } + + function drawText () { let fontSize let label let xOffset @@ -70,7 +120,7 @@ function newRestartSimulation () { label = 'RESTART SIMULATION' let labelPoint = { - x: 0, + x: 21, y: thisObject.container.frame.height - 9 } labelPoint = thisObject.container.frame.frameThisPoint(labelPoint) diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index d0bf1a3e9..ce5ec6420 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -17,6 +17,7 @@ thisObject.container = newContainer() thisObject.container.initialize(MODULE_NAME) thisObject.container.isClickeable = false + thisObject.container.detectMouseOver = true thisObject.container.isDraggeable = true thisObject.container.notDraggingOnX = true From 920d16a8888e6da5cf39cdd19bd08c2c643ea101 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 13:02:04 +0200 Subject: [PATCH 5/8] Restart Simulation Mutation implemented --- CockpitSpace/GraphQLRestartSimulation.js | 64 ++++++++++++++++++++++++ CockpitSpace/RestartSimulation.js | 9 +++- StrategySpace/Workspace.js | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 CockpitSpace/GraphQLRestartSimulation.js diff --git a/CockpitSpace/GraphQLRestartSimulation.js b/CockpitSpace/GraphQLRestartSimulation.js new file mode 100644 index 000000000..e066a5cbb --- /dev/null +++ b/CockpitSpace/GraphQLRestartSimulation.js @@ -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) } + } +} diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index a5c4c3286..efb0350ed 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -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) } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index dd9e8b5b5..d533d8c14 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -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) }) }) From e0db4ec80b0091a80e5388f67030cf77f1ec0479 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 15:39:55 +0200 Subject: [PATCH 6/8] 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 () { From 562bc0dc52ece2972787c1e16eea81847420be2f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 17:50:26 +0200 Subject: [PATCH 7/8] Restarting Simulation at right date and timePeriod --- ChartsSpace/TimeMachine.js | 60 ++++++++++++++++--------------- ChartsSpace/TimelineChart.js | 14 ++++++++ CockpitSpace/RestartSimulation.js | 30 +++++++++++++--- Scales/RateScale.js | 9 +++-- Scales/TimePeriodScale.js | 1 + Scales/TimeScale.js | 17 +++++++-- Spaces/ChartSpace.js | 12 +++++++ 7 files changed, 106 insertions(+), 37 deletions(-) diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index b5a373126..b511509aa 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -11,15 +11,15 @@ each one with it own charts, and each one positioned at an especific point in ti function newTimeMachine () { const MODULE_NAME = 'Time Machine' - const INFO_LOG = false const logger = newWebDebugLog() logger.fileName = MODULE_NAME let thisObject = { container: undefined, + charts: [], + physics: physics, drawBackground: drawBackground, draw: draw, - charts: [], getContainer: getContainer, // returns the inner most container that holds the point received by parameter. initialize: initialize, finalize: finalize @@ -41,28 +41,20 @@ function newTimeMachine () { const SEPARATION_BETWEEN_TIMELINE_CHARTS = 1.5 let timeScale - let rigthScale + let rateScale let timeLineCoordinateSystem = newTimeLineCoordinateSystem() return thisObject function finalize () { - try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - - for (let i = 0; i < thisObject.charts.length; i++) { - let chart = thisObject.charts[i] - chart.finalize() - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } + for (let i = 0; i < thisObject.charts.length; i++) { + let chart = thisObject.charts[i] + chart.finalize() } } function initialize (callBackFunction) { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } - /* Each Time Machine has a Control Panel. */ let panelOwner = 'Global' @@ -114,21 +106,19 @@ function newTimeMachine () { timeScale.initialize(timeLineCoordinateSystem) - rigthScale = newRateScale() - rigthScale.container.connectToParent(thisObject.container, false, false, false, true, true, true) - rigthScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) { + rateScale = newRateScale() + rateScale.container.connectToParent(thisObject.container, false, false, false, true, true, true) + rateScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) { thisObject.container.frame.height = TIME_MACHINE_HEIGHT * event.heightPercentage / 100 thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) }) - rigthScale.initialize(timeLineCoordinateSystem) + rateScale.initialize(timeLineCoordinateSystem) initializeTheRest() } function initializeTheRest () { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> Entering function.') } - let leftToInitialize = SUPPORTED_EXCHANGES.length * SUPPORTED_MARKETS.length - 1 // The default exchange and market was already initialized. let alreadyInitialized = 0 @@ -153,8 +143,6 @@ function newTimeMachine () { } function initializeTimelineChart (exchange, market) { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> Entering function.') } - let timelineChart = newTimelineChart() timelineChart.container.connectToParent(thisObject.container, true, true, false, true, true, true) @@ -169,8 +157,6 @@ function newTimeMachine () { timelineChart.initialize(exchange, market, timeLineCoordinateSystem, finalSteps) function finalSteps () { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> finalSteps -> Entering function.') } - thisObject.charts.push(timelineChart) controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined) @@ -198,8 +184,8 @@ function newTimeMachine () { } } - if (rigthScale !== undefined) { - container = rigthScale.getContainer(point) + if (rateScale !== undefined) { + container = rateScale.getContainer(point) if (container !== undefined) { if (container.isForThisPurpose(purpose)) { return container @@ -228,6 +214,24 @@ function newTimeMachine () { } } + function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { + + } + + function childrenPhysics () { + timeScale.physics() + rateScale.physics() + for (let i = 0; i < thisObject.charts.length; i++) { + let chart = thisObject.charts[i] + chart.physics() + } + } + function drawBackground () { thisBackground() @@ -247,7 +251,7 @@ function newTimeMachine () { } if (timeScale !== undefined) { timeScale.draw() } - if (rigthScale !== undefined) { rigthScale.draw() } + if (rateScale !== undefined) { rateScale.draw() } // thisObject.container.frame.draw(false, true, false) } @@ -269,8 +273,6 @@ function newTimeMachine () { } function recalculateScale () { - if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') } - let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), y: 0 diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index f9d1aad60..bce46cf18 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -14,6 +14,7 @@ function newTimelineChart () { let thisObject = { container: undefined, fitFunction: undefined, + physics: physics, setDatetime: setDatetime, drawBackground: drawBackground, draw: draw, @@ -239,6 +240,19 @@ function newTimelineChart () { return container } + function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { + + } + + function childrenPhysics () { + + } + function tooTiny () { if (viewPort.zoomLevel < Math.trunc(-28.25 * 100) / 100) { return true diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index ae5372145..8515fd996 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -71,11 +71,32 @@ function newRestartSimulation () { } async function onMouseClick (event) { + let dateAtScreenCorner = new Date(window.localStorage.getItem('Date @ Screen Corner')) + let currentTimePeriod = JSON.parse(window.localStorage.getItem('Current Time Period')) + + let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods] + let timePeriodArray = timePeriodsMasterArray[currentTimePeriod.filePeriodIndex] + let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1] + + let timePeriodDailyArray = [] + let timePeriodMarketArray = [] + + switch (currentTimePeriod.filePeriodIndex) { + case 0: { + timePeriodMarketArray.push(timePeriod) + break + } + case 1: { + timePeriodDailyArray.push(timePeriod) + break + } + } + let simulationParams = { - beginDatetime: 1554087600, - resumeExecution: true, - timePeriodDailyArray: ['05-min', '10-min'], - timePeriodMarketArray: ['01-hs', '02-hs'] + beginDatetime: dateAtScreenCorner.valueOf() / 1000 | 0, + resumeExecution: false, + timePeriodDailyArray: timePeriodDailyArray, + timePeriodMarketArray: timePeriodMarketArray } let result = await graphQlRestartSimulation(simulationParams) @@ -136,3 +157,4 @@ function newRestartSimulation () { browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } } + diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 300587042..4d5a08252 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -2,11 +2,12 @@ function newRateScale () { const MODULE_NAME = 'Right Scale' let thisObject = { + heightPercentage: 100, container: undefined, + physics: physics, draw: draw, getContainer: getContainer, - initialize: initialize, - heightPercentage: 100 + initialize: initialize } const HEIGHT_PERCENTAGE_DEFAULT_VALUE = 50 @@ -101,6 +102,10 @@ function newRateScale () { } } + function physics () { + + } + function draw () { if (visible === false) { return } diff --git a/Scales/TimePeriodScale.js b/Scales/TimePeriodScale.js index 55ba9a6b8..705e4fafe 100644 --- a/Scales/TimePeriodScale.js +++ b/Scales/TimePeriodScale.js @@ -292,6 +292,7 @@ to be visible at the top of the viewPort. */ let event = {} event.timePeriod = thisObject.timePeriod thisObject.container.eventHandler.raiseEvent('Time Period Changed', event) + window.localStorage.setItem('Current Time Period', JSON.stringify({filePeriodIndex: filePeriodIndex, timePeriodIndex: timePeriodIndex})) } } diff --git a/Scales/TimeScale.js b/Scales/TimeScale.js index 5cc926436..631cdb697 100644 --- a/Scales/TimeScale.js +++ b/Scales/TimeScale.js @@ -2,11 +2,12 @@ function newTimeScale () { const MODULE_NAME = 'Time Scale' let thisObject = { + lenghtPercentage: undefined, container: undefined, + physics: physics, draw: draw, getContainer: getContainer, - initialize: initialize, - lenghtPercentage: undefined + initialize: initialize } const LENGHT_PERCENTAGE_DEFAULT_VALUE = 5 @@ -96,6 +97,17 @@ function newTimeScale () { } } + function physics () { + let point = { + x: 0, + y: 0 + } + + let date = getDateFromPoint(point, thisObject.container.parentContainer, timeLineCoordinateSystem) + date = new Date(date) + window.localStorage.setItem('Date @ Screen Corner', date.toUTCString()) + } + function draw () { if (visible === false) { return } @@ -206,3 +218,4 @@ to be visible at the top of the viewPort. */ browserCanvasContext.stroke() } } + diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index 2af37d1d0..96aaa7bbc 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -149,6 +149,11 @@ function newChartSpace () { } function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { thisObject.container.frame.height = COCKPIT_SPACE_POSITION if (thisObject.container.frame.height <= 0 / 100) { @@ -160,6 +165,13 @@ function newChartSpace () { viewPort.resize() } + function childrenPhysics () { + for (let i = 0; i < thisObject.timeMachines.length; i++) { + let timeMachine = thisObject.timeMachines[i] + timeMachine.physics() + } + } + function drawBackground () { if (thisObject.visible !== true) { return } From 5181f2fcd8d9b733be9ec5555a62bb689a5694cd Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 15 May 2019 19:07:19 +0200 Subject: [PATCH 8/8] Different states on Restart Simulation Button done --- CockpitSpace/GraphQLRestartSimulation.js | 3 + CockpitSpace/RestartSimulation.js | 78 ++++++++++++++++++++---- Spaces/CockpitSpace.js | 8 +++ 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/CockpitSpace/GraphQLRestartSimulation.js b/CockpitSpace/GraphQLRestartSimulation.js index b71b8fa48..53c5d2e37 100644 --- a/CockpitSpace/GraphQLRestartSimulation.js +++ b/CockpitSpace/GraphQLRestartSimulation.js @@ -28,9 +28,12 @@ async function graphQlRestartSimulation (simulationParams) { }) if (graphQLServer.data.errors) { + console.log(err.stack) throw new Error(graphQLServer.data.errors[0].message) } } catch (err) { + console.log(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 8515fd996..f82de480c 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -5,6 +5,7 @@ function newRestartSimulation () { let thisObject = { visible: true, container: undefined, + status: undefined, physics: physics, draw: draw, getContainer: getContainer, @@ -25,6 +26,7 @@ function newRestartSimulation () { let selfMouseNotOverEventSubscriptionId let isMouseOver = false + let counterTillNextState = 0 return thisObject @@ -40,16 +42,18 @@ function newRestartSimulation () { function initialize () { thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width * 80 / 100 thisObject.container.frame.position.y = 6 - thisObject.container.frame.width = 200 + thisObject.container.frame.width = 250 thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12 selfMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick) selfMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver) + + thisObject.status = 'Ready' } function getContainer (point, purpose) { - if (thisObject.visible !== true) { return } + if (thisObject.visible !== true || thisObject.status !== 'Ready') { return } if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container @@ -98,12 +102,38 @@ function newRestartSimulation () { timePeriodDailyArray: timePeriodDailyArray, timePeriodMarketArray: timePeriodMarketArray } - - let result = await graphQlRestartSimulation(simulationParams) + try { + thisObject.status = 'Restarting' + await graphQlRestartSimulation(simulationParams) + thisObject.status = 'Calculating' + counterTillNextState = 1000 + } catch (err) { + thisObject.status = 'Error' + counterTillNextState = 500 + } } function physics () { + if (counterTillNextState > 0) { + counterTillNextState-- + if (counterTillNextState === 0) { + switch (thisObject.status) { + case 'Ready': + + break + case 'Restarting': + + break + case 'Calculating': + thisObject.status = 'Ready' + break + case 'Error': + thisObject.status = 'Ready' + break + } + } + } } function draw () { @@ -122,10 +152,24 @@ function newRestartSimulation () { opacity: 1 } - if (isMouseOver === true) { - params.backgroundColor = UI_COLOR.TURQUOISE - } else { - params.backgroundColor = UI_COLOR.DARK_TURQUOISE + switch (thisObject.status) { + case 'Ready': { + if (isMouseOver === true) { + params.backgroundColor = UI_COLOR.TURQUOISE + } else { + params.backgroundColor = UI_COLOR.DARK_TURQUOISE + } + break + } + case 'Restarting': + params.backgroundColor = UI_COLOR.GREY + break + case 'Calculating': + params.backgroundColor = UI_COLOR.TITANIUM_YELLOW + break + case 'Error': + params.backgroundColor = UI_COLOR.RUSTED_RED + break } roundedCornersBackground(params) @@ -145,10 +189,23 @@ function newRestartSimulation () { browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY - label = 'RESTART SIMULATION' + switch (thisObject.status) { + case 'Ready': + label = 'RESTART SIMULATION' + break + case 'Restarting': + label = 'RESTARTING...' + break + case 'Calculating': + label = 'CALCULATING...' + break + case 'Error': + label = 'NOT POSSIBLE NOW' + break + } let labelPoint = { - x: 21, + x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 15, y: thisObject.container.frame.height - 9 } labelPoint = thisObject.container.frame.frameThisPoint(labelPoint) @@ -157,4 +214,3 @@ function newRestartSimulation () { browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } } - diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index ce5ec6420..36d5477ff 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -64,6 +64,14 @@ } function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function childrenPhysics () { + thisObject.restartSimulation.physics() + } + function thisObjectPhysics () { /* Check the limits */ thisObject.status = 'MIDDLE'