DummyService.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 _Module2 = _interopRequireDefault(require("../Module"));
  8. var _ExtendableContainer = _interopRequireDefault(require("../base/ExtendableContainer"));
  9. var _ModuleUtilities = require("../ModuleUtilities");
  10. var _reactFontawesome = require("@fortawesome/react-fontawesome");
  11. var _reactMaterialize = require("react-materialize");
  12. var _reactJsonView = _interopRequireDefault(require("react-json-view"));
  13. require("./DummyService.css");
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. 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); }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. 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); } }
  18. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  20. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  21. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  22. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  23. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  24. 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); }
  25. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  26. var DummyService =
  27. /*#__PURE__*/
  28. function (_Module) {
  29. _inherits(DummyService, _Module);
  30. function DummyService(props) {
  31. var _this;
  32. _classCallCheck(this, DummyService);
  33. _this = _possibleConstructorReturn(this, _getPrototypeOf(DummyService).call(this, props));
  34. var dummy = JSON.parse(localStorage.getItem("dummyData") || "{}");
  35. _this.state = {
  36. text: _this.input.value || {},
  37. object: dummy.object || {},
  38. string: dummy.string || ''
  39. };
  40. _this.input.onUpdate(function (v) {
  41. var text = _this.input.value;
  42. _this.setState({
  43. text: text
  44. });
  45. });
  46. _this.string.set(_this.state.string);
  47. _this.object.set(_this.state.object);
  48. return _this;
  49. }
  50. _createClass(DummyService, [{
  51. key: "send",
  52. value: function send(e) {
  53. if (e.key === "Enter") {
  54. var v = e.target.value;
  55. this.string.set(v);
  56. this.save();
  57. }
  58. }
  59. }, {
  60. key: "save",
  61. value: function save() {
  62. var dummy = {
  63. string: this.string.value,
  64. object: this.object.value
  65. };
  66. localStorage.setItem("dummyData", JSON.stringify(dummy));
  67. }
  68. }, {
  69. key: "sendJSON",
  70. value: function sendJSON(e) {
  71. if (e.key === "Enter") {
  72. var v = e.target.value;
  73. try {
  74. var obj = JSON.parse(v);
  75. this.object.set(obj);
  76. this.save();
  77. } catch (e) {
  78. console.log("Not JSON", e);
  79. return;
  80. }
  81. }
  82. }
  83. }, {
  84. key: "render",
  85. value: function render() {
  86. var _this2 = this;
  87. // console.log(this.object);
  88. return _react.default.createElement("div", {
  89. className: '',
  90. key: 'DummyService' + Math.random()
  91. }, _react.default.createElement("div", {
  92. className: "row"
  93. }, this.__renderID()), _react.default.createElement("div", {
  94. className: "row"
  95. }, _react.default.createElement(_reactMaterialize.Col, {
  96. s: 12,
  97. className: "JSONViewer"
  98. }, "Input", _react.default.createElement(_reactJsonView.default, {
  99. src: this.state.text,
  100. theme: "apathy",
  101. displayDataTypes: false,
  102. collapsed: false,
  103. collapseStringsAfterLength: 7
  104. })), _react.default.createElement(_reactMaterialize.Col, {
  105. s: 12,
  106. className: "JSONViewer"
  107. }, "Object", _react.default.createElement(_reactJsonView.default, {
  108. src: this.state.object,
  109. onAdd: function onAdd(add) {
  110. _this2.object.set(add.new_value);
  111. _this2.save();
  112. _this2.setState({
  113. object: add.new_value
  114. });
  115. },
  116. theme: "apathy",
  117. onEdit: function onEdit(add) {
  118. _this2.object.set(add.updated_src);
  119. _this2.save();
  120. _this2.setState({
  121. object: add.updated_src
  122. });
  123. },
  124. onDelete: function onDelete(add) {
  125. _this2.object.set(add.updated_src);
  126. _this2.save();
  127. _this2.setState({
  128. object: add.updated_src
  129. });
  130. },
  131. displayDataTypes: false,
  132. enableClipboard: false,
  133. collapsed: true,
  134. collapseStringsAfterLength: 7
  135. })), _react.default.createElement(_reactMaterialize.Col, {
  136. s: 12,
  137. className: "input-field"
  138. }, "String", _react.default.createElement("textarea", {
  139. type: "textarea",
  140. className: "white materialize-textarea",
  141. onKeyPress: function onKeyPress(e) {
  142. return _this2.send(e);
  143. },
  144. defaultValue: this.state.string
  145. }))), _react.default.createElement("div", {
  146. className: "row"
  147. }, _react.default.createElement("div", {
  148. className: "col s12"
  149. }, "Connections"), _react.default.createElement("div", {
  150. className: "col s12"
  151. }, _react.default.createElement(_ModuleUtilities.OutputLink, {
  152. output: this.object
  153. })), _react.default.createElement("div", {
  154. className: "col s12"
  155. }, _react.default.createElement(_ModuleUtilities.OutputLink, {
  156. output: this.string
  157. })), _react.default.createElement("div", {
  158. className: "col s12"
  159. }, _react.default.createElement(_ModuleUtilities.InputLink, {
  160. input: this.input
  161. }))), _react.default.createElement("div", {
  162. className: "row"
  163. }), _get(_getPrototypeOf(DummyService.prototype), "render", this).call(this));
  164. }
  165. }]);
  166. return DummyService;
  167. }(_Module2.default);
  168. DummyService.Outputs = {
  169. object: {},
  170. string: {}
  171. };
  172. DummyService.Inputs = {
  173. input: {
  174. type: _Module2.default.Types.Link
  175. }
  176. };
  177. DummyService.Category = "Services";
  178. var _default = DummyService;
  179. exports.default = _default;