UiObject Message Implementation part 1

This commit is contained in:
Luis Fernando Molina committed 2021-01-17 13:28:28 +01:00
1 parent 3554d061f3
commit 6c15c5c1c6
4 files changed
+278 -82

No files matched your search

@@ -0,0 +1,16 @@
{
"topic": "UI Websockets Errors",
"pageNumber": "1",
"type": "UI Websockets Error - Bad Configuration",
"definition": {
"text": "To enable websockets communications from the UI to Superalgos Clients, we need to read the config of the Network Node. In this case this configuration is unreadable because is not correctly formatted in JSON.",
"updated": 1610882552794
},
"paragraphs": [
{
"style": "Success",
"text": "Edit the configuration and double check that is correctly formatted. If needed copy the text to an online JSON formatter to see clearly which is the problem.",
"updated": 1610882640511
}
]
}
@@ -4,7 +4,7 @@ function newUiObject() {
const ERROR_LOG = true
const logger = newWebDebugLog()
let thisObject = {
fitFunction: undefined,
@@ -19,6 +19,7 @@ function newUiObject() {
conditionEditor: undefined,
formulaEditor: undefined,
uiObjectTitle: undefined,
uiObjectMessage: undefined,
circularProgressBar: undefined,
isRunning: undefined,
isPlaying: undefined,
@@ -171,6 +172,8 @@ function newUiObject() {
thisObject.menu = undefined
thisObject.uiObjectTitle.finalize()
thisObject.uiObjectTitle = undefined
thisObject.uiObjectMessage.finalize()
thisObject.uiObjectMessage = undefined
thisObject.fitFunction = undefined
thisObject.isVisibleFunction = undefined
@@ -237,10 +240,18 @@ function newUiObject() {
thisObject.uiObjectTitle = newUiObjectTitle()
thisObject.uiObjectTitle.isVisibleFunction = thisObject.isVisibleFunction
thisObject.uiObjectTitle.container.connectToParent(thisObject.container, false, false, true, true, false, false, true, true)
thisObject.uiObjectTitle.container.connectToParent(thisObject.container, false, false, true, true, false, false, true, true)
thisObject.uiObjectTitle.fitFunction = thisObject.fitFunction
thisObject.uiObjectTitle.initialize(thisObject.payload)
/* Initialize UI Object Message */
thisObject.uiObjectMessage = newUiObjectMessage()
thisObject.uiObjectMessage.isVisibleFunction = thisObject.isVisibleFunction
thisObject.uiObjectMessage.container.connectToParent(thisObject.container, false, false, true, true, false, false, false, true)
thisObject.uiObjectMessage.fitFunction = thisObject.fitFunction
thisObject.uiObjectMessage.initialize(thisObject.payload)
/* Load UI Object Image */
iconPhysics()
@@ -305,6 +316,9 @@ function newUiObject() {
if (container !== undefined) { return container }
}
container = thisObject.uiObjectMessage.getContainer(point)
if (container !== undefined) { return container }
container = thisObject.menu.getContainer(point)
if (container !== undefined) { return container }
}
@@ -320,12 +334,16 @@ function newUiObject() {
thisObject.menu.invisiblePhysics()
childrenRunningPhysics()
thisObject.uiObjectTitle.physics()
thisObject.uiObjectMessage.physics()
}
function physics() {
thisObject.menu.physics()
thisObject.uiObjectTitle.physics()
thisObject.menu.physics()
thisObject.uiObjectMessage.physics()
if (thisObject.codeEditor !== undefined) {
thisObject.codeEditor.physics()
}
@@ -676,6 +694,11 @@ function newUiObject() {
if (errorMessageCounter < 0) {
errorMessageCounter = 0
thisObject.hasError = false
if (thisObject.uiObjectMessage.type === 'Error') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
}
@@ -684,6 +707,11 @@ function newUiObject() {
if (warningMessageCounter < 0) {
warningMessageCounter = 0
thisObject.hasWarning = false
if (thisObject.uiObjectMessage.type === 'Warning') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
}
@@ -692,6 +720,11 @@ function newUiObject() {
if (infoMessageCounter < 0) {
infoMessageCounter = 0
thisObject.hasInfo = false
if (thisObject.uiObjectMessage.type === 'Info') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
}
@@ -831,6 +864,11 @@ function newUiObject() {
function resetErrorMessage() {
errorMessage = undefined
thisObject.hasError = false
if (thisObject.uiObjectMessage.type === 'Error') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
function setWarningMessage(message, duration) {
@@ -866,6 +904,11 @@ function newUiObject() {
function resetWarningMessage() {
warningMessage = undefined
thisObject.hasWarning = false
if (thisObject.uiObjectMessage.type === 'Warning') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
function setInfoMessage(message, duration) {
@@ -901,6 +944,11 @@ function newUiObject() {
function resetInfoMessage() {
infoMessage = undefined
thisObject.hasInfo = false
if (thisObject.uiObjectMessage.type === 'Info') {
thisObject.uiObjectMessage.text = undefined
thisObject.uiObjectMessage.type = undefined
}
}
function getValue() {
@@ -1346,6 +1394,7 @@ function newUiObject() {
drawPercentage()
drawStatus()
thisObject.uiObjectTitle.draw()
thisObject.uiObjectMessage.draw()
drawNodeType()
}
}
@@ -1431,6 +1480,7 @@ function newUiObject() {
if (drawTitle === true) {
thisObject.uiObjectTitle.draw()
thisObject.uiObjectMessage.draw()
}
}
}
@@ -1677,94 +1727,26 @@ function newUiObject() {
function drawErrorMessage() {
if (thisObject.hasError === false) { return }
drawMessage(errorMessage, UI_COLOR.RUSTED_RED)
thisObject.uiObjectMessage.text = errorMessage
thisObject.uiObjectMessage.type = 'Error'
}
function drawWarningMessage() {
if (thisObject.hasError === true) { return }
if (thisObject.hasWarning !== true) { return }
drawMessage(warningMessage, UI_COLOR.TITANIUM_YELLOW)
thisObject.uiObjectMessage.text = errorMessage
thisObject.uiObjectMessage.type = 'Warning'
}
function drawInfoMessage() {
if (thisObject.hasError === true) { return }
if (thisObject.hasWarning === true) { return }
if (thisObject.hasInfo !== true) { return }
drawMessage(infoMessage, UI_COLOR.TURQUOISE)
}
function drawMessage(message, textColor) {
if (UI.projects.superalgos.spaces.floatingSpace.inMapMode === true) {
return
}
if (thisObject.codeEditor !== undefined && thisObject.codeEditor.visible === true) { return }
if (thisObject.formulaEditor !== undefined && thisObject.formulaEditor.visible === true) { return }
if (thisObject.confitionEditor !== undefined && thisObject.confitionEditor.visible === true) { return }
if (thisObject.configEditor !== undefined && thisObject.configEditor.visible === true) { return }
/* Text Follows */
let position = {
x: 0,
y: 0
}
position = thisObject.container.frame.frameThisPoint(position)
if (UI.projects.superalgos.spaces.floatingSpace.inMapMode === true) {
position = UI.projects.superalgos.spaces.floatingSpace.transformPointToMap(position)
}
let radius = thisObject.payload.floatingObject.container.frame.radius
/* Label Text */
let labelPoint
let fontSize = thisObject.payload.floatingObject.currentFontSize * 3 / 4
let lineSeparator = thisObject.payload.floatingObject.currentFontSize * 1.2
let label
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
if (radius > 6) {
const IDEAL_LABEL_LENGTH = 80
label = message
if (label !== undefined && label !== null) {
if (label.length > IDEAL_LABEL_LENGTH) {
if (label.length > IDEAL_LABEL_LENGTH * 3) {
label = label.substring(0, IDEAL_LABEL_LENGTH * 3) + '...'
}
fontSize = thisObject.payload.floatingObject.currentFontSize * 2 / 4
}
if (thisObject.isOnFocus === true) {
/* Split the line into Phrases */
let phrases = splitTextIntoPhrases(label, 5)
for (let i = 0; i < phrases.length; i++) {
let phrase = phrases[i]
labelPoint = {
x: position.x - getTextWidth(phrase) / 2,
y: position.y + lineSeparator * (6 - phrases.length + 1 + i) + 30
}
printMessage(phrase)
}
} else {
if (label.length < 50) {
labelPoint = {
x: position.x - getTextWidth(label) / 2,
y: position.y + thisObject.payload.floatingObject.currentImageSize / 2 + lineSeparator * 6
}
printMessage(label)
}
}
function printMessage(text) {
browserCanvasContext.fillStyle = 'rgba(' + textColor + ', 1)'
browserCanvasContext.fillText(text, labelPoint.x, labelPoint.y)
}
}
}
thisObject.uiObjectMessage.text = errorMessage
thisObject.uiObjectMessage.type = 'Info'
}
function drawValue() {
@@ -0,0 +1,202 @@
function newUiObjectMessage() {
const MODULE_NAME = 'UI Object Message'
let thisObject = {
fitFunction: undefined,
isVisibleFunction: undefined,
allwaysVisible: undefined,
container: undefined,
payload: undefined,
type: undefined,
text: undefined,
docs: undefined,
physics: physics,
draw: draw,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isClickeable = true
thisObject.container.isDraggeable = false
thisObject.container.frame.radius = 0
let selfMouseClickEventSubscriptionId
return thisObject
function finalize() {
thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.payload = undefined
thisObject.isVisibleFunction = undefined
thisObject.fitFunction = undefined
thisObject.type = undefined
thisObject.text = undefined
thisObject.docs = undefined
}
function initialize(payload) {
thisObject.payload = payload
selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
}
function getContainer(point) {
if (thisObject.text === undefined) { return }
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
} else {
return undefined
}
}
function physics() {
if (thisObject.text === undefined) { return }
let text = trimMessageText(thisObject.text)
/* Here we set the dimensions and position of this object */
const FRAME_HEIGHT = 120
const FRAME_WIDTH = 300
thisObject.container.frame.position.x = - FRAME_WIDTH / 2
thisObject.container.frame.position.y = + 160
thisObject.container.frame.width = FRAME_WIDTH
thisObject.container.frame.height = FRAME_HEIGHT
}
function onMouseClick(event) {
if (thisObject.text === undefined) { return }
let checkPoint = {
x: 0,
y: 0
}
checkPoint = thisObject.container.frame.frameThisPoint(checkPoint)
if (thisObject.isVisibleFunction(checkPoint) === true) {
// Open the docs and navigate.
}
}
function draw() {
if (thisObject.text === undefined) { return }
if (thisObject.payload.floatingObject.isOnFocus !== true) { return }
switch (thisObject.type) {
case 'Info': {
drawMessageBackground(UI_COLOR.TURQUOISE)
drawMessage(thisObject.text, UI_COLOR.TURQUOISE)
break
}
case 'Warning': {
drawMessageBackground(UI_COLOR.TITANIUM_YELLOW)
drawMessage(thisObject.text, UI_COLOR.TITANIUM_YELLOW)
break
}
case 'Error': {
drawMessageBackground(UI_COLOR.RUSTED_RED)
drawMessage(thisObject.text, UI_COLOR.RUSTED_RED)
break
}
}
}
function drawMessageBackground(borderColor) {
if (thisObject.text === undefined) { return }
let params = {
cornerRadius: 5,
lineWidth: 0.5,
container: thisObject.container,
borderColor: borderColor,
backgroundColor: UI.projects.superalgos.spaces.floatingSpace.style.backgroundColor,
castShadow: false,
opacity: 0.75
}
UI.projects.superalgos.utilities.drawPrint.roundedCornersBackground(params)
}
function drawMessage(message, textColor) {
if (UI.projects.superalgos.spaces.floatingSpace.inMapMode === true) {
return
}
/* Text Follows */
let position = {
x: 0,
y: 0
}
position = thisObject.container.frame.frameThisPoint(position)
if (UI.projects.superalgos.spaces.floatingSpace.inMapMode === true) {
position = UI.projects.superalgos.spaces.floatingSpace.transformPointToMap(position)
}
let radius = thisObject.payload.floatingObject.container.frame.radius
/* Label Text */
let labelPoint
let fontSize = 20
let lineSeparator = 25
let label
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
if (radius > 6) {
const IDEAL_LABEL_LENGTH = 80
label = message
if (label !== undefined && label !== null) {
if (label.length > IDEAL_LABEL_LENGTH) {
if (label.length > IDEAL_LABEL_LENGTH * 3) {
label = label.substring(0, IDEAL_LABEL_LENGTH * 3) + '...'
}
fontSize = 15
}
/* Split the line into Phrases */
let phrases = splitTextIntoPhrases(label, 5)
if (phrases.length === 1) {
phrases.push("")
}
if (phrases.length === 2) {
phrases.push("")
}
for (let i = 0; i < phrases.length; i++) {
let phrase = phrases[i]
labelPoint = {
x: position.x - getTextWidth(phrase) / 2 + thisObject.container.frame.width / 2,
y: position.y + lineSeparator * (4 - phrases.length + 1 + i)
}
printMessage(phrase)
}
function printMessage(text) {
browserCanvasContext.fillStyle = 'rgba(' + textColor + ', 1)'
browserCanvasContext.fillText(text, labelPoint.x, labelPoint.y)
}
}
}
}
function trimMessageText(text) {
if (text === undefined) { return }
const MAX_LABEL_LENGTH = 35
if (text.length > MAX_LABEL_LENGTH) {
text = text.substring(0, MAX_LABEL_LENGTH) + '...'
}
return text
}
}
@@ -1,10 +1,6 @@
function newUiObjectTitle() {
const MODULE_NAME = 'UI Object Title'
const ERROR_LOG = true
const logger = newWebDebugLog()
let thisObject = {
fitFunction: undefined,