Import.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. var _reactMaterialize = require("react-materialize");
  9. var _reactExcelRenderer = require("react-excel-renderer");
  10. var _CrudService = _interopRequireDefault(require("../Services/CrudService"));
  11. var _DictionaryService = _interopRequireDefault(require("../Services/DictionaryService"));
  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 _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
  15. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  16. function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  17. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  18. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19. 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); } }
  20. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  22. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  23. 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); }
  24. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  25. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  26. 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); }
  27. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  28. var Module = _modularityFront.default.Module;
  29. var ImportModule =
  30. /*#__PURE__*/
  31. function (_Modularity$Module) {
  32. _inherits(ImportModule, _Modularity$Module);
  33. function ImportModule(props) {
  34. var _this;
  35. _classCallCheck(this, ImportModule);
  36. _this = _possibleConstructorReturn(this, _getPrototypeOf(ImportModule).call(this, props));
  37. _this.state = {
  38. rows: [],
  39. cols: [] // add token
  40. };
  41. var propertiesService = {
  42. Table: _this.Table.value,
  43. Token: _this.Token.value,
  44. Service: function Service(service) {
  45. return _this.updateService(service);
  46. }
  47. };
  48. _this.back_service = new _CrudService.default(propertiesService);
  49. return _this;
  50. }
  51. _createClass(ImportModule, [{
  52. key: "updateService",
  53. value: function updateService(s) {
  54. this.service = s;
  55. }
  56. }, {
  57. key: "sendData",
  58. value: function sendData() {
  59. var data = {
  60. rows: this.state.rows || [],
  61. cols: this.state.cols || []
  62. };
  63. this.service.import(data).then(function (v) {
  64. console.log(v);
  65. }).catch(function (e) {
  66. return console.log(e);
  67. });
  68. }
  69. }, {
  70. key: "fileHandler",
  71. value: function fileHandler(event) {
  72. var _this2 = this;
  73. var fileObj = event.target.files[0];
  74. if (!fileObj) return; //just pass the fileObj as parameter
  75. (0, _reactExcelRenderer.ExcelRenderer)(fileObj, function (err, resp) {
  76. if (err) {
  77. console.log(err);
  78. } else {
  79. var _resp$rows = _toArray(resp.rows),
  80. cols = _resp$rows[0],
  81. data = _resp$rows.slice(1);
  82. cols = cols.map(function (name, key) {
  83. return {
  84. name: name,
  85. key: key
  86. };
  87. });
  88. console.log(cols);
  89. console.log(data);
  90. _this2.setState({
  91. cols: cols,
  92. rows: data,
  93. results: true
  94. });
  95. }
  96. });
  97. }
  98. }, {
  99. key: "render",
  100. value: function render() {
  101. var _this3 = this;
  102. return _react.default.createElement("div", null, _react.default.createElement("input", {
  103. type: "file",
  104. onChange: this.fileHandler.bind(this),
  105. style: {
  106. "padding": "10px"
  107. }
  108. }), this.state.results === true ? _react.default.createElement("div", null, _react.default.createElement("button", {
  109. onClick: function onClick() {
  110. return _this3.sendData();
  111. }
  112. }, _DictionaryService.default.get("Import")), _react.default.createElement(_reactExcelRenderer.OutTable, {
  113. data: this.state.rows,
  114. columns: this.state.cols,
  115. tableClassName: "ExcelTable2007",
  116. tableHeaderRowClass: "heading"
  117. })) : null, _get(_getPrototypeOf(ImportModule.prototype), "render", this).call(this));
  118. }
  119. }]);
  120. return ImportModule;
  121. }(_modularityFront.default.Module);
  122. ImportModule.EditPosition = "center";
  123. ImportModule.Inputs = {
  124. Table: {
  125. type: _modularityFront.default.Module.Types.Text,
  126. defaultValue: "products"
  127. },
  128. Token: {
  129. type: Module.Types.Text,
  130. defaultValue: "123123"
  131. }
  132. };
  133. ImportModule.Outputs = {};
  134. ImportModule.Category = "Nikatlas";
  135. var _default = ImportModule;
  136. exports.default = _default;