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_template.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = function (RED) {
  2. function TemplateNode (config) {
  3. const node = this
  4. // create node in Node-RED
  5. RED.nodes.createNode(this, config)
  6. const evts = {
  7. onAction: true // TODO: think we need an onSend event for template nodes that matches up with a `widget-send` message
  8. }
  9. if (config.templateScope === 'local') {
  10. config.page = ''
  11. config.ui = ''
  12. } else if (config.templateScope === 'widget:page') {
  13. config.ui = ''
  14. config.group = ''
  15. } else if (config.templateScope === 'widget:ui') {
  16. config.page = ''
  17. config.group = ''
  18. } else if (config.templateScope === 'page:style') {
  19. config.ui = ''
  20. config.group = ''
  21. } else if (config.templateScope === 'site:style') {
  22. config.page = ''
  23. config.group = ''
  24. }
  25. // ensure we have a value for passthru (default to true)
  26. if (typeof config.passthru === 'undefined') {
  27. config.passthru = true
  28. }
  29. // which group are we rendering this widget
  30. if (config.group) {
  31. const group = RED.nodes.getNode(config.group)
  32. // inform the dashboard UI that we are adding this node
  33. group.register(node, config, evts)
  34. } else if (config.page) {
  35. const page = RED.nodes.getNode(config.page)
  36. // inform the dashboard UI that we are adding this node
  37. page.register(null, node, config, evts)
  38. } else if (config.ui) {
  39. const ui = RED.nodes.getNode(config.ui)
  40. // inform the dashboard UI that we are adding this node
  41. ui.register(null, null, node, config, evts)
  42. }
  43. }
  44. RED.nodes.registerType('ui-template', TemplateNode)
  45. }