123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _react = _interopRequireDefault(require("react"));
- var _modularityFront = _interopRequireDefault(require("modularity-front"));
- var _reactMaterialize = require("react-materialize");
- var _reactMoment = _interopRequireDefault(require("react-moment"));
- require("./Table.css");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
- 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 _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 _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); }
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
- 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 Module = _modularityFront.default.Module;
- var TableModule =
- /*#__PURE__*/
- function (_Modularity$Module) {
- _inherits(TableModule, _Modularity$Module);
- function TableModule(props) {
- var _this;
- _classCallCheck(this, TableModule);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(TableModule).call(this, props));
- _this.state = {};
- _this.EditedTable.set(_this.TableData.value);
- _this.TableData.onUpdate(function (e) {
- return _this.forceUpdate();
- });
- return _this;
- }
- _createClass(TableModule, [{
- key: "change",
- value: function change(data, row_id) {
- console.log("event fid with", row_id);
- this.EditedRow.set(data);
- var updated_data = this.TableData.value;
- updated_data[row_id] = data;
- this.EditedTable.set(updated_data);
- this.forceUpdate();
- }
- }, {
- key: "row_edited",
- value: function row_edited(data, row_id) {
- this.onEdit.set(data);
- }
- }, {
- key: "row_deleted",
- value: function row_deleted(data, row_id) {
- this.onDelete.set(data);
- }
- }, {
- key: "resolve",
- value: function resolve(value, header) {
- if (header && _typeof(header) === "object") {
- switch (header.type) {
- case 'date':
- return _react.default.createElement(_reactMoment.default, {
- format: "HH:mm DD/MM/YYYY"
- }, value);
- default:
- return value;
- }
- }
- return value;
- }
- }, {
- key: "render",
- value: function render() {
- var _this2 = this;
- var headers;
- var data;
- headers = Object.keys(this.TableHeaders.value || this.TableData.value && this.TableData.value.length > 0 && this.TableData.value[0] || {}).map(function (key, index) {
- return _react.default.createElement("th", {
- key: index
- }, key);
- });
- data = (this.TableData.value || []).map(function (item, ind) {
- return _react.default.createElement("tr", {
- key: '' + item.id + item.price + item.quantity
- }, Object.keys(_this2.TableHeaders.value || {}).map(function (header, index) {
- var input = _this2.TableHeaders.value[header];
- if (header === 'image') {
- return _react.default.createElement("td", {
- key: header
- }, _react.default.createElement("img", {
- src: item[input.field || input]
- }));
- } else if (input === '-index-' && item.id) {
- return _react.default.createElement("td", {
- key: item.id + 'index'
- }, ind + 1);
- } else {
- var field = input.field || input;
- var value = _this2.resolve(item[field], input);
- if (value && _typeof(value) === "object") {
- value = value.name || value[0] || value;
- } else if (value) {
- if (input.precision && !isNaN(value)) {
- value = value.toFixed(input.precision);
- }
- if (input.suffix) {
- value = value + input.suffix;
- }
- if (input.prefix) {
- value = input.prefix + value;
- }
- }
- return _react.default.createElement("td", {
- key: header
- }, _react.default.createElement(Editable, {
- row_id: ind,
- value: value,
- header_key: input.field || input,
- onChange: function onChange(e, i) {
- return _this2.change(e, i);
- },
- row: item,
- edit: _this2.LiveEdit.value
- }));
- }
- }), _this2.props.onEdit ? _react.default.createElement(EditButton, {
- row_id: ind,
- row: item,
- row_edited: function row_edited(e) {
- return _this2.row_edited(e);
- }
- }) : null, _this2.props.onDelete ? _react.default.createElement(DeleteButton, {
- row_id: ind,
- row: item,
- row_deleted: function row_deleted(e) {
- return _this2.row_deleted(e);
- }
- }) : null, _this2.props.onView ? _react.default.createElement(ViewButton, {
- row_id: ind,
- row: item,
- view_row: function view_row(e) {
- return _this2.props.onView(e);
- }
- }) : null);
- });
- return _react.default.createElement("div", null, _get(_getPrototypeOf(TableModule.prototype), "render", this).call(this), data.length ? _react.default.createElement("table", {
- className: this.TableClass.value + ""
- }, _react.default.createElement("thead", null, _react.default.createElement("tr", null, headers)), _react.default.createElement("tbody", null, data)) : _react.default.createElement("div", {
- className: "NothingHere"
- }, " Nothing Here! "));
- }
- }]);
- return TableModule;
- }(_modularityFront.default.Module);
- TableModule.Inputs = {
- LiveEdit: {
- type: Module.Types.Boolean,
- defaultValue: false
- },
- TableHeaders: {
- type: Module.Types.Object,
- defaultValue: {
- "Name": "key1",
- "Age": "key2",
- "Value": "key3"
- }
- },
- TableData: {
- type: Module.Types.Array,
- defaultValue: [{
- "key1": "Natalie",
- "key2": "20",
- "key3": "120"
- }, {
- "key1": "Somer",
- "key2": "10 y",
- "key3": "1000"
- }, {
- "key1": "Panos",
- "key2": "3y",
- "key3": "500"
- }],
- arrType: Module.Types.Object
- },
- TableClass: {
- type: Module.Types.Text,
- defaultValue: "striped centered"
- }
- };
- var Editable =
- /*#__PURE__*/
- function (_React$Component) {
- _inherits(Editable, _React$Component);
- function Editable(props) {
- var _this3;
- _classCallCheck(this, Editable);
- _this3 = _possibleConstructorReturn(this, _getPrototypeOf(Editable).call(this, props));
- _this3.state = {
- value: _this3.props.value,
- LiveEdit: false
- };
- return _this3;
- }
- _createClass(Editable, [{
- key: "edit",
- value: function edit(e) {
- e.preventDefault();
- this.setState({
- LiveEdit: true
- });
- }
- }, {
- key: "handleSubmit",
- value: function handleSubmit(e) {
- e.preventDefault();
- var key = this.props.header_key;
- var output = this.props.row;
- output[key] = e.target.value;
- this.props.onChange(output, this.props.row_id);
- }
- }, {
- key: "_handleKeyPress",
- value: function _handleKeyPress(e) {
- if (e.key === 'Enter') {
- this.handleSubmit(e);
- this.setState({
- LiveEdit: false
- });
- }
- }
- }, {
- key: "blur",
- value: function blur(e) {
- this.handleSubmit(e);
- this.setState({
- LiveEdit: false
- });
- }
- }, {
- key: "render",
- value: function render() {
- var _this4 = this;
- var _this$props = this.props,
- onBlur = _this$props.onBlur,
- onChange = _this$props.onChange,
- value = _this$props.value,
- props = _objectWithoutProperties(_this$props, ["onBlur", "onChange", "value"]);
- return this.state.LiveEdit ? _react.default.createElement("input", {
- style: {
- width: "auto"
- },
- value: this.state.value,
- onChange: function onChange(e) {
- return _this4.setState({
- value: e.target.value
- });
- },
- onBlur: function onBlur(e) {
- return _this4.blur(e);
- },
- onKeyPress: function onKeyPress(e) {
- return _this4._handleKeyPress(e);
- }
- }) : _react.default.createElement("div", {
- onClick: function onClick(e) {
- return _this4.props.edit && _this4.edit(e);
- }
- }, this.state.value);
- }
- }]);
- return Editable;
- }(_react.default.Component);
- var EditButton =
- /*#__PURE__*/
- function (_React$Component2) {
- _inherits(EditButton, _React$Component2);
- function EditButton(props) {
- _classCallCheck(this, EditButton);
- return _possibleConstructorReturn(this, _getPrototypeOf(EditButton).call(this, props));
- }
- _createClass(EditButton, [{
- key: "_editRow",
- value: function _editRow(e) {
- e.preventDefault();
- this.props.row_edited(this.props.row, this.props.row_id);
- }
- }, {
- key: "render",
- value: function render() {
- var _this5 = this;
- return _react.default.createElement("td", {
- style: {
- width: "60px"
- }
- }, _react.default.createElement(_reactMaterialize.Button, {
- onClick: function onClick(e) {
- return _this5._editRow(e);
- },
- className: "btn-floating"
- }, _react.default.createElement(_reactMaterialize.Icon, {
- tiny: true
- }, "edit")));
- }
- }]);
- return EditButton;
- }(_react.default.Component);
- var DeleteButton =
- /*#__PURE__*/
- function (_React$Component3) {
- _inherits(DeleteButton, _React$Component3);
- function DeleteButton(props) {
- _classCallCheck(this, DeleteButton);
- return _possibleConstructorReturn(this, _getPrototypeOf(DeleteButton).call(this, props));
- }
- _createClass(DeleteButton, [{
- key: "_DeleteRow",
- value: function _DeleteRow(e) {
- e.preventDefault();
- this.props.row_deleted(this.props.row, this.props.row_id);
- }
- }, {
- key: "render",
- value: function render() {
- var _this6 = this;
- return _react.default.createElement("td", {
- style: {
- width: "60px"
- }
- }, _react.default.createElement(_reactMaterialize.Button, {
- onClick: function onClick(e) {
- return _this6._DeleteRow(e);
- },
- className: "btn-floating"
- }, _react.default.createElement(_reactMaterialize.Icon, {
- tiny: true
- }, "delete")));
- }
- }]);
- return DeleteButton;
- }(_react.default.Component);
- var ViewButton =
- /*#__PURE__*/
- function (_React$Component4) {
- _inherits(ViewButton, _React$Component4);
- function ViewButton(props) {
- _classCallCheck(this, ViewButton);
- return _possibleConstructorReturn(this, _getPrototypeOf(ViewButton).call(this, props));
- }
- _createClass(ViewButton, [{
- key: "render",
- value: function render() {
- var _this7 = this;
- return _react.default.createElement("td", {
- style: {
- width: "60px"
- }
- }, _react.default.createElement(_reactMaterialize.Button, {
- onClick: function onClick(e) {
- return _this7.props.view_row(_this7.props.row);
- },
- className: "btn-floating"
- }, _react.default.createElement(_reactMaterialize.Icon, {
- tiny: true
- }, "remove_red_eye")));
- }
- }]);
- return ViewButton;
- }(_react.default.Component);
- TableModule.Outputs = {
- EditedTable: {
- type: Module.Types.Array,
- arrType: Module.Types.Object
- },
- EditedRow: {
- type: Module.Types.Object
- },
- onEdit: {
- type: Module.Types.Object
- },
- onDelete: {
- type: Module.Types.Object
- }
- };
- TableModule.Category = "sxoinas";
- TableModule.EditPosition = "center";
- var _default = TableModule;
- exports.default = _default;
|