"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _ModuleSystem2 = _interopRequireDefault(require("./ModuleSystem.js")); var _reactFontawesome = require("@fortawesome/react-fontawesome"); var _Logger = _interopRequireDefault(require("./Logger")); var _reactMaterialize = require("react-materialize"); var _Systems = _interopRequireDefault(require("./Systems")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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); } 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; } 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 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); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } var ServiceSystem = /*#__PURE__*/ function (_ModuleSystem) { _inherits(ServiceSystem, _ModuleSystem); function ServiceSystem(id) { var _this; _classCallCheck(this, ServiceSystem); _this = _possibleConstructorReturn(this, _getPrototypeOf(ServiceSystem).call(this, id)); //this.systemID = systemID; // it' s in super!! _this.availableModules = _Systems.default.getServices(); return _this; } _createClass(ServiceSystem, [{ key: "loadService", value: function loadService(mod) { var rootMod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var ctor = mod.ctor, category = mod.category, namespace = mod.namespace, id = mod.id, inputs = mod.inputs, outputs = mod.outputs, shadow = mod.shadow; if (_Systems.default.getService(ctor, category, namespace) === undefined) { _Logger.default.warning("Service " + ctor + "->" + category + "->" + namespace + " is not bundled! You either forgot to add it to ServiceSystem or it doesn't exist!"); return; } var inrefs = []; for (var i in _Systems.default.getService(ctor, category, namespace).Inputs) { var v = _Systems.default.getService(ctor, category, namespace).Inputs[i].defaultValue; if (inputs[i]) v = inputs[i].value || v; inputs[i] = { name: i, value: v, pid: id, type: _Systems.default.getService(ctor, category, namespace).Inputs[i].type }; inrefs[i] = this.LinkManager.addInputRef(inputs[i]); } var outrefs = []; for (var i in _Systems.default.getService(ctor, category, namespace).Outputs) { outputs[i] = { name: i, pid: id, type: _Systems.default.getService(ctor, category, namespace).Outputs[i].type }; outrefs[i] = this.LinkManager.addOutputRef(outputs[i]); } this.__addToScene(_objectSpread({}, mod, { inrefs: inrefs, outrefs: outrefs, key: '' + id + id, children: [] })); } }, { key: "__Factory", value: function __Factory(item) { var children = []; var ctor = _Systems.default.getService(item.ctor, item.category, item.namespace); var props = item; props.System = this; // I have systemID but this is parametric for Module/Service props.systemID = this.systemID; return new ctor(props); } }, { key: "_shuffleAllKeys", value: function _shuffleAllKeys() { return; } }, { key: "__resolveItem", value: function __resolveItem(item) { if (this.LinkManager.isReady(item)) { this.resolved[item.id] = item; var mod = this.__Factory(item); item.reactElement = mod; delete this.modules[item.id]; this.modules[item.id] = mod; delete this.noresolve[item.id]; this.dirty = true; } } }, { key: "render", value: function render() { var arr = []; for (var i in this.modules) { arr.push(this.modules[i]); } return _react.default.createElement(ServiceUI, { modules: arr }); } }, { key: "change", value: function change(id, name, value) { this.resolved[id].inputs[name].value = value; this.resolved[id].inrefs[name].value = value; this.noresolve = _objectSpread({}, this.resolved); this.modules = {}; } }, { key: "addChild", value: function addChild(id, childid) { return; } }, { key: "remove", value: function remove(id) { delete this.modules[id]; delete this.resolved[id]; delete this.metamodules[id]; this.LinkManager.breakLinks(id); } }, { key: "export", value: function _export() { var _this2 = this; return Object.keys(this.resolved).map(function (key) { var item = _this2.resolved[key]; return { ctor: item.ctor, category: item.category, namespace: item.namespace, id: item.id, inputs: item.inputs, outputs: item.outputs, key: item.key }; }); } }]); return ServiceSystem; }(_ModuleSystem2.default); var ServiceUI = /*#__PURE__*/ function (_React$Component) { _inherits(ServiceUI, _React$Component); function ServiceUI(props) { var _this3; _classCallCheck(this, ServiceUI); _this3 = _possibleConstructorReturn(this, _getPrototypeOf(ServiceUI).call(this, props)); _this3.state = { vision: false, activeMod: localStorage.getItem('ServiceDisplay') || -1 //this.t = setInterval(() => this.forceUpdate(), 1000); }; return _this3; } _createClass(ServiceUI, [{ key: "toggle", value: function toggle() { this.setState({ vision: !this.state.vision }); } }, { key: "go", value: function go(m) { localStorage.setItem('ServiceDisplay', m); this.setState({ activeMod: m }); } }, { key: "render", value: function render() { var _this4 = this; var modules = Object.keys(this.props.modules).map(function (id, indx) { return _react.default.createElement(_this4.props.modules[id].constructor, _this4.props.modules[id].props); }); var ids = Object.keys(this.props.modules).map(function (id, indx) { return ('' + _this4.props.modules[id].getId()).toUpperCase() || _this4.props.modules[id].constructor.name; }); var activeModule = ids.indexOf(this.state.activeMod); var tabs = [_react.default.createElement("div", { className: "ServiceBar", key: 'SB' + Math.random() }, _react.default.createElement(_reactMaterialize.Tabs, { onChange: function onChange(a, e) { _this4.go(e.target.innerText); } }, _react.default.createElement(_reactMaterialize.Tab, { active: this.state.activeMod === 'X', title: 'X' }), ids.map(function (id, inx) { return _react.default.createElement(_reactMaterialize.Tab, { key: inx, title: id, active: _this4.state.activeMod === id }); })))]; if (activeModule > -1) tabs.push(_react.default.createElement(_reactMaterialize.Card, { key: 'SDisplay', className: "ServiceDisplay blue lighten-3", header: _react.default.createElement("h5", null, ids[activeModule]) }, modules[activeModule])); return tabs; } }]); return ServiceUI; }(_react.default.Component); var _default = ServiceSystem; exports.default = _default;