ModulesList.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 _ParameterControl = _interopRequireDefault(require("./ParameterControl"));
  8. var _ExtendableContainer = _interopRequireDefault(require("../../base/ExtendableContainer"));
  9. var _Logger = _interopRequireDefault(require("../../../systems/Logger"));
  10. var _Module2 = _interopRequireDefault(require("../../Module"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. 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); }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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); } }
  15. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18. 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); }
  19. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  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. Object.defineProperty(Object.prototype, "makeArray", {
  24. enumerable: false,
  25. value: function value(obj) {
  26. var array = [];
  27. for (var key in obj) {
  28. array.push(obj[key]);
  29. }
  30. return array;
  31. }
  32. }); //import './ModulesList.css';
  33. var ModulesList =
  34. /*#__PURE__*/
  35. function (_Module) {
  36. _inherits(ModulesList, _Module);
  37. function ModulesList(props) {
  38. var _this;
  39. _classCallCheck(this, ModulesList);
  40. _this = _possibleConstructorReturn(this, _getPrototypeOf(ModulesList).call(this, props));
  41. _this.state = {
  42. modules: []
  43. }; //console.log(props.list);
  44. return _this;
  45. }
  46. _createClass(ModulesList, [{
  47. key: "componentWillReceiveProps",
  48. value: function componentWillReceiveProps() {
  49. this.refresh();
  50. }
  51. }, {
  52. key: "componentDidMount",
  53. value: function componentDidMount() {
  54. _get(_getPrototypeOf(ModulesList.prototype), "componentDidMount", this).call(this);
  55. this.refresh();
  56. }
  57. }, {
  58. key: "parseModules",
  59. value: function parseModules(modules) {
  60. var mods = modules.map(function (m) {
  61. return [m.Namespace || "General", m.Category || 'Uncategorized', m.name];
  62. });
  63. var result = {
  64. 'Unordered': []
  65. };
  66. mods.forEach(function (names, index) {
  67. var temp = result;
  68. for (var i = 0; i < names.length - 1; i++) {
  69. if (!temp[names[i]]) temp[names[i]] = {};
  70. temp = temp[names[i]];
  71. }
  72. if (!temp.items) temp.items = [];
  73. temp.items.push(names[names.length - 1]);
  74. }); // console.log("ModuleStructure: " , result);
  75. return result;
  76. }
  77. }, {
  78. key: "makeFolder",
  79. value: function makeFolder(dictionary) {
  80. var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
  81. var res = [];
  82. for (var key in dictionary) {
  83. if (key === 'items') {
  84. for (var i in dictionary[key]) {
  85. // console.log(dictionary[key][i])
  86. res.push(_react.default.createElement(_ParameterControl.default, {
  87. className: this.props.controlClassName,
  88. module: this.props.list[path + dictionary[key][i]],
  89. name: i,
  90. key: i
  91. }));
  92. }
  93. continue;
  94. }
  95. res.push(_react.default.createElement(_ExtendableContainer.default, {
  96. header: key,
  97. key: key,
  98. className: this.props.className
  99. }, this.makeFolder(dictionary[key], path + key)));
  100. }
  101. return res;
  102. }
  103. }, {
  104. key: "refresh",
  105. value: function refresh() {
  106. var modules = Object.makeArray(this.props.list) || [];
  107. var array = [];
  108. var dictionary = this.parseModules(modules); // console.log("dictionary");
  109. // console.log(dictionary);
  110. var mods = this.makeFolder(dictionary); // let folders = Object.keys(modules).reduce((a,b) => {
  111. // a[modules[b].Category] = [...(a[modules[b].Category] || []), modules[b]];
  112. // return a;
  113. // }, {});
  114. this.setState({
  115. modules: mods,
  116. folders: []
  117. });
  118. }
  119. }, {
  120. key: "render",
  121. value: function render() {
  122. return this.state.modules || 'NO MODS';
  123. }
  124. }]);
  125. return ModulesList;
  126. }(_Module2.default);
  127. var _default = ModulesList;
  128. exports.default = _default;