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_link.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. module.exports = function (RED) {
  2. /**
  3. *
  4. * @param {*} config
  5. */
  6. function UILinkNode (config) {
  7. RED.nodes.createNode(this, config)
  8. const node = this
  9. node.on('close', function (removed, done) {
  10. node.deregister() // deregister self
  11. done()
  12. })
  13. // handle bad typing in Node-RED
  14. if (!('disabled' in config)) {
  15. // ensure we have a value
  16. config.disabled = false
  17. } else {
  18. // ensure we have a boolean
  19. config.disabled = (config.disabled === 'true' || config.disabled === true)
  20. }
  21. if (!('visible' in config)) {
  22. // ensure we have a value
  23. config.visible = true
  24. } else {
  25. // ensure we have a boolean
  26. config.visible = (config.visible === 'true' || config.visible === true)
  27. }
  28. const ui = RED.nodes.getNode(config.ui)
  29. // register self
  30. ui.register(config)
  31. /**
  32. * Function for widgets to register themselves with this page
  33. * Calls the parent UI Base "register" function and registers this page,
  34. * along with the widget
  35. * @param {*} widget
  36. */
  37. node.register = function (group, widgetNode, widgetConfig, widgetEvents) {
  38. const link = config
  39. if (ui) {
  40. ui.register(link, group, widgetNode, widgetConfig, widgetEvents)
  41. } else {
  42. node.error(`Error registering Widget - ${widgetNode.name || widgetNode.id}. No parent ui-base node found for ui-link node: ${(link.name || link.id)}`)
  43. }
  44. }
  45. node.deregister = function (group, widgetNode) {
  46. const link = config
  47. if (ui) {
  48. ui.deregister(link, group, widgetNode)
  49. }
  50. }
  51. // Return the UI Base Node this page lives in
  52. node.getBase = function () {
  53. return RED.nodes.getNode(config.ui)
  54. }
  55. }
  56. RED.nodes.registerType('ui-link', UILinkNode)
  57. }