ServiceSystem.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 _ModuleSystem2 = _interopRequireDefault(require("./ModuleSystem.js"));
  8. var _reactFontawesome = require("@fortawesome/react-fontawesome");
  9. var _Logger = _interopRequireDefault(require("./Logger"));
  10. var _reactMaterialize = require("react-materialize");
  11. var _Systems = _interopRequireDefault(require("./Systems"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. 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); }
  14. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  15. 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; }
  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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  22. 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); }
  23. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  24. var ServiceSystem =
  25. /*#__PURE__*/
  26. function (_ModuleSystem) {
  27. _inherits(ServiceSystem, _ModuleSystem);
  28. function ServiceSystem(id) {
  29. var _this;
  30. _classCallCheck(this, ServiceSystem);
  31. _this = _possibleConstructorReturn(this, _getPrototypeOf(ServiceSystem).call(this, id)); //this.systemID = systemID; // it' s in super!!
  32. _this.availableModules = _Systems.default.getServices();
  33. return _this;
  34. }
  35. _createClass(ServiceSystem, [{
  36. key: "loadService",
  37. value: function loadService(mod) {
  38. var rootMod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  39. var ctor = mod.ctor,
  40. category = mod.category,
  41. namespace = mod.namespace,
  42. id = mod.id,
  43. inputs = mod.inputs,
  44. outputs = mod.outputs,
  45. shadow = mod.shadow;
  46. if (_Systems.default.getService(ctor, category, namespace) === undefined) {
  47. _Logger.default.warning("Service " + ctor + "->" + category + "->" + namespace + " is not bundled! You either forgot to add it to ServiceSystem or it doesn't exist!");
  48. return;
  49. }
  50. var inrefs = [];
  51. for (var i in _Systems.default.getService(ctor, category, namespace).Inputs) {
  52. var v = _Systems.default.getService(ctor, category, namespace).Inputs[i].defaultValue;
  53. if (inputs[i]) v = inputs[i].value || v;
  54. inputs[i] = {
  55. name: i,
  56. value: v,
  57. pid: id,
  58. type: _Systems.default.getService(ctor, category, namespace).Inputs[i].type
  59. };
  60. inrefs[i] = this.LinkManager.addInputRef(inputs[i]);
  61. }
  62. var outrefs = [];
  63. for (var i in _Systems.default.getService(ctor, category, namespace).Outputs) {
  64. outputs[i] = {
  65. name: i,
  66. pid: id,
  67. type: _Systems.default.getService(ctor, category, namespace).Outputs[i].type
  68. };
  69. outrefs[i] = this.LinkManager.addOutputRef(outputs[i]);
  70. }
  71. this.__addToScene(_objectSpread({}, mod, {
  72. inrefs: inrefs,
  73. outrefs: outrefs,
  74. key: '' + id + id,
  75. children: []
  76. }));
  77. }
  78. }, {
  79. key: "__Factory",
  80. value: function __Factory(item) {
  81. var children = [];
  82. var ctor = _Systems.default.getService(item.ctor, item.category, item.namespace);
  83. var props = item;
  84. props.System = this; // I have systemID but this is parametric for Module/Service
  85. props.systemID = this.systemID;
  86. return new ctor(props);
  87. }
  88. }, {
  89. key: "_shuffleAllKeys",
  90. value: function _shuffleAllKeys() {
  91. return;
  92. }
  93. }, {
  94. key: "__resolveItem",
  95. value: function __resolveItem(item) {
  96. if (this.LinkManager.isReady(item)) {
  97. this.resolved[item.id] = item;
  98. var mod = this.__Factory(item);
  99. item.reactElement = mod;
  100. delete this.modules[item.id];
  101. this.modules[item.id] = mod;
  102. delete this.noresolve[item.id];
  103. this.dirty = true;
  104. }
  105. }
  106. }, {
  107. key: "render",
  108. value: function render() {
  109. var arr = [];
  110. for (var i in this.modules) {
  111. arr.push(this.modules[i]);
  112. }
  113. return _react.default.createElement(ServiceUI, {
  114. modules: arr
  115. });
  116. }
  117. }, {
  118. key: "change",
  119. value: function change(id, name, value) {
  120. this.resolved[id].inputs[name].value = value;
  121. this.resolved[id].inrefs[name].value = value;
  122. this.noresolve = _objectSpread({}, this.resolved);
  123. this.modules = {};
  124. }
  125. }, {
  126. key: "addChild",
  127. value: function addChild(id, childid) {
  128. return;
  129. }
  130. }, {
  131. key: "remove",
  132. value: function remove(id) {
  133. delete this.modules[id];
  134. delete this.resolved[id];
  135. delete this.metamodules[id];
  136. this.LinkManager.breakLinks(id);
  137. }
  138. }, {
  139. key: "export",
  140. value: function _export() {
  141. var _this2 = this;
  142. return Object.keys(this.resolved).map(function (key) {
  143. var item = _this2.resolved[key];
  144. return {
  145. ctor: item.ctor,
  146. category: item.category,
  147. namespace: item.namespace,
  148. id: item.id,
  149. inputs: item.inputs,
  150. outputs: item.outputs,
  151. key: item.key
  152. };
  153. });
  154. }
  155. }]);
  156. return ServiceSystem;
  157. }(_ModuleSystem2.default);
  158. var ServiceUI =
  159. /*#__PURE__*/
  160. function (_React$Component) {
  161. _inherits(ServiceUI, _React$Component);
  162. function ServiceUI(props) {
  163. var _this3;
  164. _classCallCheck(this, ServiceUI);
  165. _this3 = _possibleConstructorReturn(this, _getPrototypeOf(ServiceUI).call(this, props));
  166. _this3.state = {
  167. vision: false,
  168. activeMod: localStorage.getItem('ServiceDisplay') || -1 //this.t = setInterval(() => this.forceUpdate(), 1000);
  169. };
  170. return _this3;
  171. }
  172. _createClass(ServiceUI, [{
  173. key: "toggle",
  174. value: function toggle() {
  175. this.setState({
  176. vision: !this.state.vision
  177. });
  178. }
  179. }, {
  180. key: "go",
  181. value: function go(m) {
  182. localStorage.setItem('ServiceDisplay', m);
  183. this.setState({
  184. activeMod: m
  185. });
  186. }
  187. }, {
  188. key: "render",
  189. value: function render() {
  190. var _this4 = this;
  191. var modules = Object.keys(this.props.modules).map(function (id, indx) {
  192. return _react.default.createElement(_this4.props.modules[id].constructor, _this4.props.modules[id].props);
  193. });
  194. var ids = Object.keys(this.props.modules).map(function (id, indx) {
  195. return ('' + _this4.props.modules[id].getId()).toUpperCase() || _this4.props.modules[id].constructor.name;
  196. });
  197. var activeModule = ids.indexOf(this.state.activeMod);
  198. var tabs = [_react.default.createElement("div", {
  199. className: "ServiceBar",
  200. key: 'SB' + Math.random()
  201. }, _react.default.createElement(_reactMaterialize.Tabs, {
  202. onChange: function onChange(a, e) {
  203. _this4.go(e.target.innerText);
  204. }
  205. }, _react.default.createElement(_reactMaterialize.Tab, {
  206. active: this.state.activeMod === 'X',
  207. title: 'X'
  208. }), ids.map(function (id, inx) {
  209. return _react.default.createElement(_reactMaterialize.Tab, {
  210. key: inx,
  211. title: id,
  212. active: _this4.state.activeMod === id
  213. });
  214. })))];
  215. if (activeModule > -1) tabs.push(_react.default.createElement(_reactMaterialize.Card, {
  216. key: 'SDisplay',
  217. className: "ServiceDisplay blue lighten-3",
  218. header: _react.default.createElement("h5", null, ids[activeModule])
  219. }, modules[activeModule]));
  220. return tabs;
  221. }
  222. }]);
  223. return ServiceUI;
  224. }(_react.default.Component);
  225. var _default = ServiceSystem;
  226. exports.default = _default;