From fe06c50b9c396210f5691689a9fd9d1a95c71243 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Mar 2020 19:27:15 +0100 Subject: [PATCH] status bar implementation --- CanvasApp/Canvas.js | 10 ++++ CanvasApp/DesignSpace/Workspace/Workspace.js | 18 ++++-- CanvasApp/Globals.js | 1 + CanvasApp/Spaces/CockpitSpace.js | 59 ++++++++++++++++++- CanvasApp/SystemEventHandler.js | 13 ++++ .../Plotters-Trading-Simulation/Strategies.js | 6 +- .../Plotters-Trading-Simulation/Trades.js | 10 ++-- 7 files changed, 103 insertions(+), 14 deletions(-) diff --git a/CanvasApp/Canvas.js b/CanvasApp/Canvas.js index 70bda0737..29d8cc855 100644 --- a/CanvasApp/Canvas.js +++ b/CanvasApp/Canvas.js @@ -274,6 +274,16 @@ function newCanvas () { return } + if (event.shiftKey === true && (event.ctrlKey === true || event.metaKey === true) && (event.key === 'S' || event.key === 's')) { + let saved = canvas.designSpace.workspace.save() + if (saved === true) { + canvas.cockpitSpace.setStatus('Workspace Saved.', 50, canvas.cockpitSpace.statusTypes.ALL_GOOD) + } + + event.preventDefault() + return + } + let nodeOnFocus = canvas.designSpace.workspace.getNodeThatIsOnFocus() if (nodeOnFocus !== undefined) { if (nodeOnFocus.payload.uiObject.codeEditor !== undefined) { diff --git a/CanvasApp/DesignSpace/Workspace/Workspace.js b/CanvasApp/DesignSpace/Workspace/Workspace.js index 48e48b21c..9762c19fc 100644 --- a/CanvasApp/DesignSpace/Workspace/Workspace.js +++ b/CanvasApp/DesignSpace/Workspace/Workspace.js @@ -7,10 +7,10 @@ function newWorkspace () { let thisObject = { workspaceNode: undefined, - tradingSystem: undefined, container: undefined, enabled: false, nodeChildren: undefined, + save: saveWorkspace, getHierarchyHeads: getHierarchyHeads, getNodeThatIsOnFocus: getNodeThatIsOnFocus, getNodeByShortcutKey: getNodeByShortcutKey, @@ -66,6 +66,9 @@ function newWorkspace () { let circularProgressBar = newBusyProgressBar() circularProgressBar.fitFunction = canvas.floatingSpace.fitIntoVisibleArea let droppedNode + let sessionTimestamp = (new Date()).valueOf() + window.localStorage.setItem('Session Timestamp', sessionTimestamp) + console.log(sessionTimestamp) return thisObject @@ -90,7 +93,7 @@ function newWorkspace () { functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode) thisObject.enabled = true - setInterval(saveWorkspace, 10000) + setInterval(saveWorkspace, 60000) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } } @@ -113,8 +116,15 @@ function newWorkspace () { } function saveWorkspace () { - let textToSave = stringifyWorkspace() - window.localStorage.setItem(CANVAS_APP_NAME + '.' + 'Workspace', textToSave) + let savedSessionTimestamp = window.localStorage.getItem('Session Timestamp') + if (Number(savedSessionTimestamp) !== sessionTimestamp) { + canvas.cockpitSpace.setStatus('Could not save the Workspace. You have more that one instance of the Superlagos User Interface open at the same time. Plese close this instance as it is older than the others.', 150, canvas.cockpitSpace.statusTypes.WARNING) + } else { + let textToSave = stringifyWorkspace() + window.localStorage.setItem(CANVAS_APP_NAME + '.' + 'Workspace', textToSave) + window.localStorage.setItem('Session Timestamp', sessionTimestamp) + return true + } } function physics () { diff --git a/CanvasApp/Globals.js b/CanvasApp/Globals.js index dfe29698b..c27c27f98 100644 --- a/CanvasApp/Globals.js +++ b/CanvasApp/Globals.js @@ -38,6 +38,7 @@ const DOUBLE_CLICK_ZOOM_IN_IN_LEVEL = 7 const DEBUG = {} const ZOOM_OUT_THRESHOLD_FOR_NOT_HIDDING_PANELS = 12 const ZOOM_OUT_THRESHOLD_FOR_HIDDING_PANELS = 7 +const ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS = 7 const ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME = 3 // This help regulate when to change the Time Frame base on the level of zoom out. const ZOOM_OUT_THRESHOLD_FOR_PACKING_OBJECTS_AT_THE_BOTTOM_OR_TOP_OF_VIEWPORT = 2 const ZOOM_OUT_THRESHOLD_FOR_PLOTTING_IN_LOW_RESOLUTION = 3 diff --git a/CanvasApp/Spaces/CockpitSpace.js b/CanvasApp/Spaces/CockpitSpace.js index 3291428ec..248e07c39 100644 --- a/CanvasApp/Spaces/CockpitSpace.js +++ b/CanvasApp/Spaces/CockpitSpace.js @@ -1,11 +1,16 @@ function newCockpitSpace () { const MODULE_NAME = 'CockpitSpace' - + const STATUS_TYPES = { + ALL_GOOD: 1, + WARNING: 2 + } let thisObject = { container: undefined, status: 'BOTTOM', fullscreen: undefined, + statusTypes: STATUS_TYPES, + setStatus: setStatus, toTop: toTop, toBottom: toBottom, toMiddle: toMiddle, @@ -31,6 +36,10 @@ let selfMouseClickEventSubscriptionId let canvasBrowserResizedEventSubscriptionId + let statusCounter = 0 + let statusText + let statusType + return thisObject function finalize () { @@ -72,6 +81,12 @@ } + function setStatus (text, counter, type) { + statusCounter = counter + statusText = text + statusType = type + } + function resize () { thisObject.container.frame.width = browserCanvas.width thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT @@ -114,9 +129,19 @@ } } + function statusPhysics () { + statusCounter-- + if (statusCounter < 0) { + statusCounter = 0 + statusText = undefined, + statusType = undefined + } + } + function physics () { thisObjectPhysics() childrenPhysics() + statusPhysics() } function childrenPhysics () { @@ -195,9 +220,29 @@ zeroPoint = thisObject.container.frame.frameThisPoint(zeroPoint) + let barColor = UI_COLOR.DARK_TURQUOISE // default + let textColor + + if (statusType !== undefined) { + switch (statusType) { + case STATUS_TYPES.ALL_GOOD: + { + barColor = UI_COLOR.PATINATED_TURQUOISE + textColor = UI_COLOR.WHITE + break + } + case STATUS_TYPES.WARNING: + { + barColor = UI_COLOR.RED + textColor = UI_COLOR.TITANIUM_YELLOW + break + } + } + } + browserCanvasContext.beginPath() browserCanvasContext.rect(zeroPoint.x, zeroPoint.y, thisObject.container.frame.width, thisObject.container.frame.height) - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK_TURQUOISE + ', ' + opacity + ')' + browserCanvasContext.fillStyle = 'rgba(' + barColor + ', ' + opacity + ')' browserCanvasContext.closePath() browserCanvasContext.fill() @@ -213,7 +258,15 @@ browserCanvasContext.closePath() browserCanvasContext.fill() - if (canvas.designSpace.workspace.enabled === true) { + if (statusText !== undefined) { + let position = { + x: thisObject.container.frame.width / 2, + y: thisObject.container.frame.height / 2 + 5 + } + printLabel(statusText, position.x, position.y, 1, 15, textColor, true, thisObject.container) + } + + if (canvas.designSpace.workspace.enabled === true && statusText === undefined) { arrow() } } diff --git a/CanvasApp/SystemEventHandler.js b/CanvasApp/SystemEventHandler.js index b200cc1b2..dfc1de006 100644 --- a/CanvasApp/SystemEventHandler.js +++ b/CanvasApp/SystemEventHandler.js @@ -12,6 +12,7 @@ function newSystemEventHandler () { let WEB_SOCKETS_CONNECTION let thisObject = { + isConnected: isConnected, initialize: initialize, physics: physics, createEventHandler: createEventHandler, @@ -30,6 +31,14 @@ function newSystemEventHandler () { setuptWebSockets(callBackFunction) } + function isConnected () { + if (WEB_SOCKETS_CONNECTION.readyState === 1) { + return true + } else { + return false + } + } + function sendCommand (command, responseCallBack, eventsCallBack) { if (command.action === 'listenToEvent') { let key @@ -110,6 +119,10 @@ function newSystemEventHandler () { } } } + + if (thisObject.isConnected() !== true) { + canvas.cockpitSpace.setStatus('Lost connection with the local backend. Please check that all localhost servers are running.', 100, canvas.cockpitSpace.statusTypes.WARNING) + } } function setuptWebSockets (callBackFunction) { diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js index a42d0b823..c522c7a82 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js @@ -581,8 +581,10 @@ /* Situation Name */ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) - if (record.triggerOnSituation !== "My Situation") { - printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { + if (record.triggerOnSituation !== "My Situation") { + printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); + } } /* Draw the Sticks */ diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js index 1d99ee700..f90c577bc 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js @@ -602,11 +602,11 @@ // we do not write any text } else { - printLabel(line0, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y - 15, '1', 12); - printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); - printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); - - + if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { + printLabel(line0, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y - 15, '1', 12); + printLabel(line1, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line1.length * FONT_ASPECT_RATIO, point.y, '1', 12); + printLabel(line2, recordPoint2.x - (recordPoint2.x - recordPoint1.x) / 2 - line2.length * FONT_ASPECT_RATIO, point.y + 15, '1', 12); + } } }