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_text.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. function TextNode(config) {
  4. RED.nodes.createNode(this, config);
  5. var node = this;
  6. var group = RED.nodes.getNode(config.group);
  7. if (!group) { return; }
  8. var tab = RED.nodes.getNode(group.config.tab);
  9. if (!tab) { return; }
  10. var layout = config.layout||"row-spread";
  11. var angLayout = "row";
  12. var angLayoutAlign = "space-between center";
  13. if (layout === "row-spread") { angLayout = 'row'; angLayoutAlign = 'space-between center'}
  14. else if (layout === "row-left") { angLayout = 'row'; angLayoutAlign = 'start center'}
  15. else if (layout === "row-center") { angLayout = 'row'; angLayoutAlign = 'center center'}
  16. else if (layout === "row-right") { angLayout = 'row'; angLayoutAlign = 'end center'}
  17. else if (layout === "col-center") { angLayout = 'column'; angLayoutAlign = 'center center'}
  18. var done = ui.add({
  19. emitOnlyNewValues: false,
  20. node: node,
  21. tab: tab,
  22. group: group,
  23. control: {
  24. type: 'text',
  25. label: config.label,
  26. order: config.order,
  27. format: config.format,
  28. width: config.width || group.config.width || 6,
  29. height: config.height || 1,
  30. layout: angLayout,
  31. layoutAlign: angLayoutAlign,
  32. className: config.className || '',
  33. },
  34. convert: function(value,oldValue,msg) {
  35. if (value !== undefined && value !== null) {
  36. if (Buffer.isBuffer(value)) {
  37. value = value.toString('binary');
  38. }
  39. else {
  40. value = value.toString();
  41. }
  42. }
  43. else {
  44. msg.payload = oldValue;
  45. }
  46. return value;
  47. }
  48. });
  49. node.on("close", done);
  50. }
  51. RED.nodes.registerType("ui_text", TextNode);
  52. };