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_notification.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const statestore = require('../store/state.js')
  2. module.exports = function (RED) {
  3. function NotificationNode (config) {
  4. const node = this
  5. RED.nodes.createNode(this, config)
  6. // Which ui are we rendering this widget.
  7. // In contradiction to other ui nodes (which belong to a group), the notification node belongs to a ui instead.
  8. const ui = RED.nodes.getNode(config.ui)
  9. const evts = {
  10. onAction: true,
  11. beforeSend: function (msg) {
  12. if (msg.ui_update) {
  13. const updates = msg.ui_update
  14. const allowedPositions = ['top right', 'top center', 'top left', 'bottom right', 'bottom center', 'bottom left', 'center center']
  15. if (updates) {
  16. if (typeof updates.allowConfirm !== 'undefined') {
  17. // dynamically set "allowConfirm" property
  18. statestore.set(ui, node, msg, 'allowConfirm', updates.allowConfirm)
  19. }
  20. if (typeof updates.allowDismiss !== 'undefined') {
  21. // dynamically set "allowDismiss" property
  22. statestore.set(ui, node, msg, 'allowDismiss', updates.allowDismiss)
  23. }
  24. if (typeof updates.color !== 'undefined') {
  25. // dynamically set "color" property
  26. statestore.set(ui, node, msg, 'color', updates.color)
  27. }
  28. if (typeof updates.confirmText !== 'undefined') {
  29. // dynamically set "confirmText" property
  30. statestore.set(ui, node, msg, 'confirmText', updates.confirmText)
  31. }
  32. if (typeof updates.dismissText !== 'undefined') {
  33. // dynamically set "dismissText" property
  34. statestore.set(ui, node, msg, 'dismissText', updates.dismissText)
  35. }
  36. if (typeof updates.displayTime !== 'undefined') {
  37. // dynamically set "displayTime" property
  38. statestore.set(ui, node, msg, 'displayTime', updates.displayTime)
  39. }
  40. if (typeof updates.position !== 'undefined' && allowedPositions.includes(updates.position)) {
  41. // dynamically set "position" property
  42. statestore.set(ui, node, msg, 'position', updates.position)
  43. }
  44. if (typeof updates.raw !== 'undefined') {
  45. // dynamically set "raw" property
  46. statestore.set(ui, node, msg, 'raw', updates.raw)
  47. }
  48. if (typeof updates.showCountdown !== 'undefined') {
  49. // dynamically set "showCountdown" property
  50. statestore.set(ui, node, msg, 'showCountdown', updates.showCountdown)
  51. }
  52. // Note that update.close will NOT be stored in the data store,
  53. // since it does not need to be remembered
  54. }
  55. }
  56. return msg
  57. }
  58. }
  59. // inform the dashboard UI that we are adding this node
  60. ui.register(null, null, node, config, evts)
  61. }
  62. RED.nodes.registerType('ui-notification', NotificationNode)
  63. }