Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_text.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const statestore = require('../store/state.js')
  2. module.exports = function (RED) {
  3. function TextNode (config) {
  4. const node = this
  5. RED.nodes.createNode(this, config)
  6. let style = ''
  7. if (config.style) {
  8. if (config.color) {
  9. style += `color: ${config.color};`
  10. }
  11. if (config.fontSize) {
  12. style += `font-size: ${config.fontSize}px;`
  13. style += `line-height: ${config.fontSize}px;`
  14. }
  15. if (config.font) {
  16. style += `font-family: ${config.font};`
  17. }
  18. config.style = style
  19. }
  20. const beforeSend = function (msg) {
  21. const updates = msg.ui_update
  22. if (updates) {
  23. if (typeof updates.label !== 'undefined') {
  24. // dynamically set "label" property
  25. statestore.set(group.getBase(), node, msg, 'label', updates.label)
  26. }
  27. if (typeof updates.layout !== 'undefined') {
  28. // dynamically set "label" property
  29. statestore.set(group.getBase(), node, msg, 'layout', updates.layout)
  30. }
  31. if (typeof updates.font !== 'undefined') {
  32. // dynamically set "label" property
  33. statestore.set(group.getBase(), node, msg, 'font', updates.font)
  34. }
  35. if (typeof updates.fontSize !== 'undefined') {
  36. // dynamically set "label" property
  37. statestore.set(group.getBase(), node, msg, 'fontSize', updates.fontSize)
  38. }
  39. if (typeof updates.color !== 'undefined') {
  40. // dynamically set "label" property
  41. statestore.set(group.getBase(), node, msg, 'color', updates.color)
  42. }
  43. }
  44. return msg
  45. }
  46. // which group are we rendering this widget
  47. const group = RED.nodes.getNode(config.group)
  48. // inform the dashboard UI that we are adding this node
  49. group.register(node, config, {
  50. beforeSend
  51. })
  52. }
  53. RED.nodes.registerType('ui-text', TextNode)
  54. }