-
-
Save AlexDoanTB/c6665bc58c076a1a76082961bc575f3a to your computer and use it in GitHub Desktop.
//Configuration code for HTML widget// | |
<div class='card'> | |
<div class='content'> | |
<div class='column'> | |
<h1>Current entity</h1> | |
<div class='value'> | |
${entityName} | |
</div> | |
</div> | |
</div> | |
</div> | |
//To make your nodes in hierarchy coloured (red)// | |
var entity = nodeCtx.entity; | |
var text = entity.name; | |
var data = nodeCtx.data; | |
if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true') { | |
text = "<font color=\"red\">" + text + "</font>"; | |
} | |
//To add some text (exclamations for example) to nodes appearance// | |
var entity = nodeCtx.entity; | |
var text = entity.name; | |
var data = nodeCtx.data; | |
if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true') { | |
text = "<b> !!!</b>"; | |
} | |
//To change icon of particular node. You may choose any pic from MaterialIcons set or input URL to image file// | |
var data = nodeCtx.data; | |
if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true ') { | |
return {materialIcon: 'settings_remote'}; | |
} else { | |
return 'default'; | |
} | |
//Disabling makes your node inactive in hierarchy// | |
var data = nodeCtx.data; | |
if (data.hasOwnProperty('nodeDisabled') && data['nodeDisabled'] !== null) { | |
return data['nodeDisabled'] === 'true'; | |
} else { | |
return false; | |
} | |
Do you have the respective attribute (hasAlarm)? This code example uses the attribute datasource.
https://www.youtube.com/watch?v=bc07ys-azqw
No, I thought that the "hasAlarm" could reach the actual Alarms associated to he Devices/Assets. It would be convenient as the actual Alarms are nicely created by Rule Chain Alarm block and propagated automatically in the full device and assets hierarchy relations.
While, if I understand correctly, I have to create an "hasAlarm" or whatever field as attribute and set it by Rule Chain when an Alarm is created or cancelled and propagate by Rule Chain to all parent devices/assets. Is it correct?
Hey Alex - can we use entity "Description" field to change the text? Trying to use additionalInfo, but not working. Thanks!
Hey Alex - can we use entity "Description" field to change the text? Trying to use additionalInfo, but not working. Thanks!
What text do you mean? Entity description field is not accessible for and from widgets. It is just an internal note
Hi, Alex
I want the sort function to be able to sort based on the widget data.
But I used console.log to print the received data, and found that besides entity and name, the data of nodeCtx1 and nodeCtx2 are often empty. Unlike text functions or other functions that often fetch data.
May I ask what settings do I need to make for the hierarchy widget so that the data can be obtained normally in the sort function?
Hi Alex,
In Community Edition 3.0.1 I tried to configure the hierarchy widget in order to red color the Asset/Device name in case of Alarm according to the configuration reported in Screenshot 1.
However the "if" statement is always false as you can see in the Screenshot 1, although you can see an active alarm in IMSAR01-JV2012100437-D0 DEVICE in the screenshot 2.
What am I missing?
SCREENSHOT 1

SCREENSHOT 2
