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 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. function SliderNode(config) {
  4. RED.nodes.createNode(this, config);
  5. this.pt = config.passthru;
  6. this.state = [" "," "];
  7. var node = this;
  8. node.status({});
  9. var group = RED.nodes.getNode(config.group);
  10. if (!group) { return; }
  11. var tab = RED.nodes.getNode(group.config.tab);
  12. if (!tab) { return; }
  13. node.on("input", function(msg) {
  14. node.topi = msg.topic;
  15. });
  16. var done = ui.add({
  17. node: node,
  18. tab: tab,
  19. group: group,
  20. forwardInputMessages: config.passthru,
  21. control: {
  22. type: 'slider',
  23. label: config.label,
  24. tooltip: config.tooltip,
  25. order: config.order,
  26. value: config.min,
  27. min: Math.min(config.min, config.max),
  28. max: Math.max(config.max, config.min),
  29. invert: (parseFloat(config.min) > parseFloat(config.max)) ? true : undefined,
  30. step: Math.abs(config.step) || 1,
  31. outs: config.outs || "all",
  32. width: config.width || group.config.width || 6,
  33. height: config.height || 1,
  34. className: config.className || '',
  35. },
  36. beforeSend: function (msg) {
  37. var t = RED.util.evaluateNodeProperty(config.topic,config.topicType || "str",node,msg) || node.topi;
  38. if (t) { msg.topic = t; }
  39. if (node.pt) {
  40. node.status({shape:"dot",fill:"grey",text:msg.payload});
  41. }
  42. else {
  43. node.state[1] = msg.payload;
  44. node.status({shape:"dot",fill:"grey",text:node.state[1] + " | " + node.state[1]});
  45. }
  46. },
  47. convert: ui.toFloat.bind(this, config)
  48. });
  49. if (!node.pt) {
  50. node.on("input", function(msg) {
  51. node.state[0] = msg.payload;
  52. node.status({shape:"dot",fill:"grey",text:node.state[0] + " | " + node.state[1]});
  53. });
  54. }
  55. else if (node._wireCount === 0) {
  56. node.on("input", function(msg) {
  57. node.status({shape:"dot",fill:"grey",text:msg.payload});
  58. });
  59. }
  60. node.on("close", done);
  61. }
  62. RED.nodes.registerType("ui_slider", SliderNode);
  63. };