Search.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 _index = _interopRequireDefault(require("../../Modules/index.js"));
  10. var _FilterModule = _interopRequireDefault(require("../../Modules/FilterModule.js"));
  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. var Table = _index.default.Table,
  24. Pagination = _index.default.Pagination,
  25. Form = _index.default.Form;
  26. var Module = _modularityFront.default.Module; // NOT USED ANYWHERE YET
  27. var Search =
  28. /*#__PURE__*/
  29. function (_Modularity$Module) {
  30. _inherits(Search, _Modularity$Module);
  31. function Search(props) {
  32. var _this;
  33. _classCallCheck(this, Search);
  34. _this = _possibleConstructorReturn(this, _getPrototypeOf(Search).call(this, props));
  35. _this.state = {
  36. page: 1,
  37. data: [],
  38. totalPages: 1,
  39. showForm: false,
  40. model: {},
  41. mode: 0,
  42. formButton: "Add"
  43. };
  44. _this.service.onUpdate(function () {
  45. return _this.serviceUpdate(_this.state.page);
  46. });
  47. _this.serviceUpdate(_this.state.page);
  48. return _this;
  49. }
  50. _createClass(Search, [{
  51. key: "_rowDeleted",
  52. value: function _rowDeleted(row) {
  53. var _this2 = this;
  54. if (!row) return;
  55. var Service = this.service.value;
  56. if (Service.delete && row.id) Service.delete(row.id).then(function () {
  57. return _this2.serviceUpdate(_this2.state.page);
  58. });
  59. }
  60. }, {
  61. key: "handleClick",
  62. value: function handleClick() {
  63. console.log("added");
  64. }
  65. }, {
  66. key: "prepareForm",
  67. value: function prepareForm(headers) {
  68. var row = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  69. var mod = {};
  70. console.log(headers);
  71. for (var i in headers) {
  72. if (!headers[i]) continue; //if(headers[i].fieldName === "id") continue;
  73. mod[headers[i].Name || headers[i].fieldName] = {
  74. type: "text",
  75. placeholder: i,
  76. columns: 6,
  77. value: row[i],
  78. filter: headers[i].filter
  79. };
  80. }
  81. return mod;
  82. }
  83. }, {
  84. key: "showAddForm",
  85. value: function showAddForm() {
  86. var headers = this.TableHeaders.value; // add Required !
  87. var mod = this.prepareForm(headers);
  88. this.setState({
  89. showForm: true,
  90. model: mod,
  91. mode: 0,
  92. formButton: 'Add'
  93. });
  94. }
  95. }, {
  96. key: "render",
  97. value: function render() {
  98. var _this3 = this;
  99. var page = this.state.page,
  100. totalPages = this.state.totalPages,
  101. data = this.state.data;
  102. var TableView = _react.default.createElement(_reactMaterialize.Row, {
  103. style: {
  104. display: 'flex'
  105. }
  106. }, _react.default.createElement(_reactMaterialize.Col, {
  107. s: 2,
  108. style: this.props.filterStyle,
  109. className: this.props.filterClassName
  110. }, _react.default.createElement(_FilterModule.default, {
  111. Inputs: this.FilterInput.value,
  112. Filters: function Filters(filters) {
  113. return _this3.setFilters(filters);
  114. }
  115. })), _react.default.createElement(_reactMaterialize.Col, {
  116. s: 10
  117. }, _react.default.createElement(Table, {
  118. TableHeaders: this.TableHeaders.value,
  119. TableData: data,
  120. TableClass: this.TableClass.value,
  121. LiveEdit: this.LiveEdit.value,
  122. EditedRow: function EditedRow(v) {
  123. return _this3.rowEdit(v);
  124. },
  125. onEdit: function onEdit(v) {
  126. return _this3._rowEdited(v);
  127. },
  128. onDelete: function onDelete(v) {
  129. return _this3._rowDeleted(v);
  130. }
  131. }), _react.default.createElement(_reactMaterialize.Row, null, _react.default.createElement(_reactMaterialize.Col, {
  132. offset: "s10"
  133. }, _react.default.createElement(_reactMaterialize.Button, {
  134. onClick: function onClick() {
  135. return _this3.showAddForm();
  136. }
  137. }, "Add"))), _react.default.createElement(Pagination, {
  138. selected: page,
  139. lastPage: totalPages,
  140. onPage: function onPage(v) {
  141. return _this3.pageChanged(v);
  142. }
  143. })));
  144. var FormView = _react.default.createElement(_reactMaterialize.Row, {
  145. key: Math.random()
  146. }, _react.default.createElement(_reactMaterialize.Col, {
  147. s: 12
  148. }, _react.default.createElement(Form, {
  149. FormInputs: this.state.model,
  150. button: this.state.formButton,
  151. formData: function formData(data) {
  152. return _this3.state.mode ? _this3.update(data) : _this3.add(data);
  153. }
  154. })));
  155. return [this.state.showForm ? FormView : TableView, _get(_getPrototypeOf(Search.prototype), "render", this).call(this)];
  156. }
  157. }]);
  158. return Search;
  159. }(_modularityFront.default.Module);
  160. Search.Inputs = {
  161. service: {
  162. type: Module.Types.Object,
  163. defaultValue: {}
  164. },
  165. perPage: {
  166. type: Module.Types.Number,
  167. defaultValue: 2
  168. },
  169. TableHeaders: {
  170. type: Module.Types.Object,
  171. defaultValue: {
  172. "Id": "id",
  173. "Name": "name",
  174. "Value": "price"
  175. }
  176. },
  177. TableClass: {
  178. type: Module.Types.Text,
  179. defaultValue: "striped centered"
  180. },
  181. LiveEdit: {
  182. type: Module.Types.Boolean,
  183. defaultValue: false
  184. },
  185. FilterInput: {
  186. type: Module.Types.Array,
  187. arrType: Module.Types.Object
  188. }
  189. };
  190. Search.Outputs = {
  191. onFilters: {}
  192. };
  193. Search.Category = "Nikatlas";
  194. Search.EditPosition = "top-right";
  195. var _default = Search;
  196. exports.default = _default;