ParameterControl.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _ExtendableContainer = _interopRequireDefault(require("../../base/ExtendableContainer"));
  8. var _InputField = _interopRequireDefault(require("../../base/InputField"));
  9. var _Logger = _interopRequireDefault(require("../../../systems/Logger"));
  10. var _Module3 = _interopRequireDefault(require("../../Module"));
  11. var _ModuleSystem = _interopRequireDefault(require("../../../systems/ModuleSystem"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  14. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  21. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  22. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  23. //import './ParameterControl.css';
  24. var ModuleCreation =
  25. /*#__PURE__*/
  26. function (_Module) {
  27. _inherits(ModuleCreation, _Module);
  28. function ModuleCreation(props) {
  29. var _this;
  30. _classCallCheck(this, ModuleCreation);
  31. _this = _possibleConstructorReturn(this, _getPrototypeOf(ModuleCreation).call(this, props));
  32. _this.state = {};
  33. _this.model = _this.createInputs(props.inputs);
  34. return _this;
  35. }
  36. _createClass(ModuleCreation, [{
  37. key: "render",
  38. value: function render() {
  39. return _react.default.createElement("div", null);
  40. }
  41. }]);
  42. return ModuleCreation;
  43. }(_Module3.default);
  44. var ParameterControl =
  45. /*#__PURE__*/
  46. function (_Module2) {
  47. _inherits(ParameterControl, _Module2);
  48. function ParameterControl(props) {
  49. var _this2;
  50. _classCallCheck(this, ParameterControl);
  51. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(ParameterControl).call(this, props));
  52. _this2.state = {};
  53. _this2.model = _this2.createInputs(_this2.props.module.Inputs);
  54. _this2.instance = _this2.createInstance();
  55. return _this2;
  56. }
  57. _createClass(ParameterControl, [{
  58. key: "componentWillReceiveProps",
  59. value: function componentWillReceiveProps() {
  60. this.instance = this.createInstance();
  61. this.forceUpdate();
  62. }
  63. }, {
  64. key: "createInputs",
  65. value: function createInputs(inputs) {
  66. var _this3 = this;
  67. var res = [];
  68. var _loop = function _loop(key) {
  69. var data = inputs[key];
  70. _this3.state[key] = data.defaultValue;
  71. res.push(_react.default.createElement(_InputField.default, {
  72. name: key,
  73. metadata: data,
  74. key: key,
  75. onChange: function onChange(v) {
  76. return _this3.setState(_defineProperty({}, key, v));
  77. }
  78. }));
  79. };
  80. for (var key in inputs) {
  81. _loop(key);
  82. }
  83. return res;
  84. }
  85. }, {
  86. key: "createInstance",
  87. value: function createInstance() {
  88. var inputs = {};
  89. for (var i in this.state) {
  90. inputs[i] = {
  91. name: i,
  92. value: this.state[i]
  93. };
  94. }
  95. var nprops = {
  96. ctor: this.props.module.name,
  97. category: this.props.module.Category,
  98. namespace: this.props.module.Namespace,
  99. children: [],
  100. id: '123',
  101. //random
  102. inputs: inputs,
  103. outputs: {} // console.log("INSTANCE : " , nprops);
  104. };
  105. var module = nprops;
  106. return module;
  107. }
  108. }, {
  109. key: "render",
  110. value: function render() {
  111. var OM = _Module3.default.OutputMarker;
  112. var header = _react.default.createElement(OM, {
  113. module: this.instance,
  114. text: this.props.module.name
  115. });
  116. return _react.default.createElement("div", {
  117. className: this.props.className + ' ParameterControl'
  118. }, header);
  119. }
  120. }]);
  121. return ParameterControl;
  122. }(_Module3.default);
  123. var _default = ParameterControl;
  124. exports.default = _default;