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_slider.js 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const statestore = require('../store/state.js')
  2. module.exports = function (RED) {
  3. function SliderNode (config) {
  4. RED.nodes.createNode(this, config)
  5. const node = this
  6. // which group are we rendering this widget
  7. const group = RED.nodes.getNode(config.group)
  8. this.pt = config.passthru
  9. this.state = [' ', ' ']
  10. const thumbLabel = config.thumbLabel
  11. if (thumbLabel === 'false') {
  12. config.thumbLabel = false
  13. } else if (thumbLabel === 'true') {
  14. config.thumbLabel = true
  15. }
  16. const showTicks = config.showTicks
  17. if (showTicks === 'false') {
  18. config.showTicks = false
  19. } else if (showTicks === 'true') {
  20. config.showTicks = true
  21. }
  22. node.status({})
  23. const evts = {
  24. onChange: true,
  25. beforeSend: function (msg) {
  26. // backward compatibility for older selection type
  27. if (typeof msg.payload !== 'undefined') {
  28. if (!node.pt) {
  29. node.state[0] = msg.payload
  30. node.status({ shape: 'dot', fill: 'grey', text: node.state[0] + ' | ' + node.state[1] })
  31. } else if (node._wireCount === 0) {
  32. node.status({ shape: 'dot', fill: 'grey', text: msg.payload })
  33. }
  34. }
  35. /**
  36. * Dynamic Properties
  37. * */
  38. const updates = msg.ui_update
  39. if (updates) {
  40. if (typeof (updates.label) !== 'undefined') {
  41. // dynamically set "label" property
  42. statestore.set(group.getBase(), node, msg, 'label', updates.label)
  43. }
  44. if (typeof (updates.thumbLabel) !== 'undefined') {
  45. statestore.set(group.getBase(), node, msg, 'thumbLabel', updates.thumbLabel)
  46. }
  47. if (typeof (updates.showTicks) !== 'undefined') {
  48. statestore.set(group.getBase(), node, msg, 'showTicks', updates.showTicks)
  49. }
  50. if (typeof (updates.min) !== 'undefined') {
  51. statestore.set(group.getBase(), node, msg, 'min', updates.min)
  52. }
  53. if (typeof (updates.step) !== 'undefined') {
  54. statestore.set(group.getBase(), node, msg, 'step', updates.step)
  55. }
  56. if (typeof (updates.max) !== 'undefined') {
  57. statestore.set(group.getBase(), node, msg, 'max', updates.max)
  58. }
  59. if (typeof (updates.iconPrepend) !== 'undefined') {
  60. statestore.set(group.getBase(), node, msg, 'iconPrepend', updates.iconPrepend)
  61. }
  62. if (typeof (updates.iconAppend) !== 'undefined') {
  63. statestore.set(group.getBase(), node, msg, 'iconAppend', updates.iconAppend)
  64. }
  65. if (typeof (updates.color) !== 'undefined') {
  66. statestore.set(group.getBase(), node, msg, 'color', updates.color)
  67. }
  68. if (typeof (updates.colorTrack) !== 'undefined') {
  69. statestore.set(group.getBase(), node, msg, 'colorTrack', updates.colorTrack)
  70. }
  71. if (typeof (updates.colorThumb) !== 'undefined') {
  72. statestore.set(group.getBase(), node, msg, 'colorThumb', updates.colorThumb)
  73. }
  74. }
  75. return msg
  76. }
  77. }
  78. // inform the dashboard UI that we are adding this node
  79. group.register(node, config, evts)
  80. }
  81. RED.nodes.registerType('ui-slider', SliderNode)
  82. }