UNPKG

a-chart

Version:

A-Chart is a ReactJS Library/Package to address all posibilities of Reporting Functionality

218 lines (168 loc) 7.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Chart = undefined; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _redux = require("redux"); var _reactRedux = require("react-redux"); var _grid = require("./components/dataGrid/grid"); var _grid2 = _interopRequireDefault(_grid); var _indexR = require("./reducer/indexR"); var _indexR2 = _interopRequireDefault(_indexR); var _userMethods = require("./util/userMethods"); var _userMethods2 = _interopRequireDefault(_userMethods); var _utilFns = require("./util/utilFns"); var Util = _interopRequireWildcard(_utilFns); var _reduxThunk = require("redux-thunk"); var _reduxThunk2 = _interopRequireDefault(_reduxThunk); require("font-awesome/css/font-awesome.min.css"); require("./styles.css"); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var HOCFN = function HOCFN(WrappedComponent) { var HOC = function (_React$Component) { _inherits(HOC, _React$Component); function HOC() { _classCallCheck(this, HOC); return _possibleConstructorReturn(this, (HOC.__proto__ || Object.getPrototypeOf(HOC)).apply(this, arguments)); } _createClass(HOC, [{ key: "render", value: function render() { return _react2.default.createElement(WrappedComponent, this.props); } }]); return HOC; }(_react2.default.Component); return HOC; }; var Achart = function (_UserClass) { _inherits(Achart, _UserClass); function Achart(props) { _classCallCheck(this, Achart); var _this2 = _possibleConstructorReturn(this, (Achart.__proto__ || Object.getPrototypeOf(Achart)).call(this, props)); var defConfig = { width: "666", header: true, // Default true headerConfig: {}, headers: [], // **optional formatters: {}, //**optional //Type:collection of ojects// property of dsiplay array //formatters are giving a option to apply your formatting logic(display format like amount and currency format) while rendering cells. //Also inside the function you will get hte complete scope of the cuurent row in "this" Object //Example: name is column property // formatters: { // name: function(val){ // return this.col2+"---"+val // } // } columnsToHide: "", //Comma seprated string, to hide specific columns from grid **optional columnsForSort: "", //Comma seprated string, to enable sorting for columns **optional analyticalColumns: "", //Comma seprated string, to show sum of numerical columns **optional rowFocus: false, // Default false **optional export: "", // export data to xls or csv (now will support only one type in single config) Default false **optional mode: "None", //Multi,Single,None Default none **optional fieldsToEdit: "", //Comma seprated string, these fields can edit from grid **optional search: false, // Search functionality **optional // Default false searchFields: "", // Comma seprated string, Search will happen only against these columns **optional searchScope: false // this will give an opption to choose fields to search in **optional // Default false }; defConfig._tableId = "achart-d-grid_" + Math.floor(Math.random() * 11111); _this2.state = { key: Math.random() }; _this2.config = Object.assign({}, defConfig, _this2.props.config); if (typeof _this2.props.items === "string") { _this2.items = _this2.props.items; } else { _this2.items = Object.assign([], _this2.props.items); } var that = _this2; _this2.Util = Util; _this2.Util._prepHeader = _this2.Util._prepHeader.bind(that); var headePrep = _this2.Util._prepHeader; // headePrep(this.items,this.config); var customMiddleWare = function customMiddleWare(store) { return function (next) { return function (action) { //console.log("bbbbbbbbbbbbb"); headePrep(action.items, action.config); next(action); }; }; }; customMiddleWare.bind(that); // var m=[thunk,customMiddleWare] var m = [_reduxThunk2.default, customMiddleWare]; //console.log(...m); var storeWithMiddleware = _redux.applyMiddleware.apply(undefined, m)(_redux.createStore); _this2.store = storeWithMiddleware(_indexR2.default); return _this2; } _createClass(Achart, [{ key: "componentDidMount", value: function componentDidMount() {} }, { key: "render", value: function render() { if (this.config && this.config.headers && this.items) { // this.Util._prepHeader(); } return _react2.default.createElement( _reactRedux.Provider, { store: this.store }, _react2.default.createElement( "div", { className: "aChart" }, this.items ? _react2.default.createElement(_grid2.default, { key: this.state.key, itemSource: this.items, config: this.config }) : _react2.default.createElement( "h3", null, " Please provide data source to plot, 'items' as Arrays " ) ) ); } }]); return Achart; }(_userMethods2.default); var Chart = exports.Chart = function (_Component) { _inherits(Chart, _Component); function Chart(props) { _classCallCheck(this, Chart); var _this3 = _possibleConstructorReturn(this, (Chart.__proto__ || Object.getPrototypeOf(Chart)).call(this, props)); _this3.items = [{ make: "Ashik" }, { make: "ap" }]; return _this3; } _createClass(Chart, [{ key: "render", value: function render() { return _react2.default.createElement( "div", null, _react2.default.createElement( "h3", null, "Charting " ), this.items.map(function (d, i) { return _react2.default.createElement( "div", { key: i }, d.make ); }) ); } }]); return Chart; }(_react.Component); module.exports = Achart; //export default Achart;