From fd5d0b4da383c8bdee8ecff05ccdfd3b6d1e5abb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 12 Sep 2020 13:45:45 +0200 Subject: [PATCH] Cleaning --- FloatingSpace/UiObject.js | 164 +++++++++++++++++++------------------- Plotting/Plotter.js | 8 +- 2 files changed, 88 insertions(+), 84 deletions(-) diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index d0e86f13c..5595b7891 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -973,48 +973,96 @@ function newUiObject() { setupErrorEventListener(callBackFunction) setupWarningEventListener() setupInfoEventListener() - } - function setupRunningEventListener(callBackFunction) { - /* We will wait to hear the Running event in order to confirm the execution was really started */ - let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - eventsServerClient.listenToEvent(key, 'Running', undefined, 'UiObject', onResponse, onRunning) - - onRunningCallBackFunction = callBackFunction - - function onResponse(message) { - eventSubscriptionIdOnRunning = message.eventSubscriptionId + function setupRunningEventListener(callBackFunction) { + /* We will wait to hear the Running event in order to confirm the execution was really started */ + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + eventsServerClient.listenToEvent(key, 'Running', undefined, 'UiObject', onResponse, onRunning) + + onRunningCallBackFunction = callBackFunction + + function onResponse(message) { + eventSubscriptionIdOnRunning = message.eventSubscriptionId + } + + function onRunning() { + if (thisObject.payload === undefined) { return } + + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + eventsServerClient.stopListening(key, eventSubscriptionIdOnRunning, 'UiObject') + + thisObject.isRunning = true + + if (callBackFunction !== undefined) { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + onRunningCallBackFunctionWasCalled = true + } + } + + /* + While it is running, it can happen that it naturally stops or is stopped not from the UI but from other means. + In those cases, the stop function would never be called (from the UI). So what we will do is to call it from + here with and event, and passing our own callBackFunction. In case there is an external source stopping this, + this will produce an execution of the callback with our event, which will produce that the menu item is restored + to its default stage. + + If on the other side, it is executed from the UI, then we will be processing the Stopped event twice, which in + both cases will reset the menu item to its default state. + */ + + let event = { + type: 'Secondary Action Already Executed' + } + stop(callBackFunction, event) } - function onRunning() { - if (thisObject.payload === undefined) { return } - + function setupErrorEventListener(callBackFunction) { let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - eventsServerClient.stopListening(key, eventSubscriptionIdOnRunning, 'UiObject') - - thisObject.isRunning = true - - if (callBackFunction !== undefined) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - onRunningCallBackFunctionWasCalled = true + eventsServerClient.listenToEvent(key, 'Error', undefined, key, onResponse, onError) + + function onResponse(message) { + eventSubscriptionIdOnError = message.eventSubscriptionId + } + + function onError(message) { + + let uiObject = getTargetUiObject(message) + uiObject.setErrorMessage(message.event.errorMessage, 10) + + let event = { + type: 'Secondary Action Already Executed' + } + completeStop(callBackFunction, event) } } - - /* - While it is running, it can happen that it naturally stops or is stopped not from the UI but from other means. - In those cases, the stop function would never be called (from the UI). So what we will do is to call it from - here with and event, and passing our own callBackFunction. In case there is an external source stopping this, - this will produce an execution of the callback with our event, which will produce that the menu item is restored - to its default stage. - If on the other side, it is executed from the UI, then we will be processing the Stopped event twice, which in - both cases will reset the menu item to its default state. - */ - - let event = { - type: 'Secondary Action Already Executed' + function setupWarningEventListener() { + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + eventsServerClient.listenToEvent(key, 'Warning', undefined, key, onResponse, onWarning) + + function onResponse(message) { + eventSubscriptionIdOnWarning = message.eventSubscriptionId + } + + function onWarning(message) { + let uiObject = getTargetUiObject(message) + uiObject.setWarningMessage(message.event.warningMessage, 10) + } + } + + function setupInfoEventListener() { + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + eventsServerClient.listenToEvent(key, 'Info', undefined, key, onResponse, onInfo) + + function onResponse(message) { + eventSubscriptionIdOnInfo = message.eventSubscriptionId + } + + function onInfo(message) { + let uiObject = getTargetUiObject(message) + uiObject.setInfoMessage(message.event.infoMessage, 10) + } } - stop(callBackFunction, event) } function getTargetUiObject(message) { @@ -1032,54 +1080,6 @@ function newUiObject() { return uiObject } - function setupErrorEventListener(callBackFunction) { - let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - eventsServerClient.listenToEvent(key, 'Error', undefined, key, onResponse, onError) - - function onResponse(message) { - eventSubscriptionIdOnError = message.eventSubscriptionId - } - - function onError(message) { - - let uiObject = getTargetUiObject(message) - uiObject.setErrorMessage(message.event.errorMessage, 10) - - let event = { - type: 'Secondary Action Already Executed' - } - completeStop(callBackFunction, event) - } - } - - function setupWarningEventListener() { - let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - eventsServerClient.listenToEvent(key, 'Warning', undefined, key, onResponse, onWarning) - - function onResponse(message) { - eventSubscriptionIdOnWarning = message.eventSubscriptionId - } - - function onWarning(message) { - let uiObject = getTargetUiObject(message) - uiObject.setWarningMessage(message.event.warningMessage, 10) - } - } - - function setupInfoEventListener() { - let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - eventsServerClient.listenToEvent(key, 'Info', undefined, key, onResponse, onInfo) - - function onResponse(message) { - eventSubscriptionIdOnInfo = message.eventSubscriptionId - } - - function onInfo(message) { - let uiObject = getTargetUiObject(message) - uiObject.setInfoMessage(message.event.infoMessage, 10) - } - } - function stop(callBackFunction, event) { /* We will wait to the event that the execution was terminated in order to call back the menu item */ let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id diff --git a/Plotting/Plotter.js b/Plotting/Plotter.js index f2fdccf6c..96cb8c927 100644 --- a/Plotting/Plotter.js +++ b/Plotting/Plotter.js @@ -822,8 +822,12 @@ function newPlotter() { imagePosition.x = dataPoint.x imagePosition.y = dataPoint.y let imageToDraw = canvas.designSpace.iconCollection.get(imageName) - if (imageToDraw.canDrawIcon === true) { - browserCanvasContext.drawImage(imageToDraw, imagePosition.x - imageSize / 2 + offsetX, imagePosition.y - imageSize / 2 - offsetY, imageSize, imageSize) + if (imageToDraw !== undefined) { + if (imageToDraw.canDrawIcon === true) { + browserCanvasContext.drawImage(imageToDraw, imagePosition.x - imageSize / 2 + offsetX, imagePosition.y - imageSize / 2 - offsetY, imageSize, imageSize) + } + } else { + console.log('Can not plot image named '+ imageName + ' of product ' + productDefinition.name + ' because it does not exist.') } }