ForecastDetailsView.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: Dashboard
  8. * (C) Copyright IBM Corp. 2019
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['react', 'react-dom', 'ca-ui-toolkit', 'jquery', 'underscore', '../ExtensionBaseView'], function (React, ReactDOM, toolkit, $, _, BaseView) {
  12. var Grid = toolkit.Grid,
  13. GridCell = toolkit.GridCell;
  14. var ForecastDetailsView = function (_BaseView) {
  15. _inherits(ForecastDetailsView, _BaseView);
  16. function ForecastDetailsView(options) {
  17. _classCallCheck(this, ForecastDetailsView);
  18. return _possibleConstructorReturn(this, _BaseView.call(this, options));
  19. }
  20. ForecastDetailsView.prototype.render = function render(container, resultTable) {
  21. this.table = resultTable;
  22. this.containerNode = container;
  23. BaseView.clearContainer(this.containerNode);
  24. // class name is needed for using style from ba-ui-toolkit
  25. this.containerNode.classList.add('ba-theme-waca');
  26. return this._renderReactGrid();
  27. };
  28. ForecastDetailsView.prototype._renderReactGrid = function _renderReactGrid() {
  29. var _this2 = this;
  30. return new Promise(function (resolve) {
  31. var props = {
  32. numColumns: _this2.table.getNumColumns(),
  33. numRows: _this2.table.getNumRows(),
  34. fixedRows: _this2.table.getNumHeaderRows(),
  35. fixedColumns: _this2.table.getNumFixedColumns(),
  36. autoMeasureColumnWidth: true,
  37. autoMeasureRowHeight: true,
  38. dataCellRenderer: _this2._cellRenderer.bind(_this2, _this2.table.getCell.bind(_this2.table)),
  39. fixedRowCellRenderer: _this2._cellRenderer.bind(_this2, _this2.table.getHeader.bind(_this2.table)),
  40. fixedColumnCellRenderer: _this2._cellRenderer.bind(_this2, _this2.table.getFixedColumn.bind(_this2.table))
  41. };
  42. ReactDOM.render(React.createElement(Grid, props), _this2.containerNode, function () {
  43. return resolve(props);
  44. });
  45. });
  46. };
  47. ForecastDetailsView.prototype._cellRenderer = function _cellRenderer(getDataFn, rowIndex, colIndex, gridCellProps) {
  48. var data = getDataFn(rowIndex, colIndex);
  49. gridCellProps.style = _.extend({}, gridCellProps.style, data.style.gridCell || {});
  50. return this._getCellComponent(data.value, gridCellProps, data.style.cellValue.alignment);
  51. };
  52. ForecastDetailsView.prototype._getCellComponent = function _getCellComponent(value, gridCellProps, alignment) {
  53. return React.createElement(
  54. GridCell,
  55. gridCellProps,
  56. React.createElement(
  57. 'div',
  58. { style: BaseView.CELL.style[alignment || 'left'] },
  59. value || ''
  60. )
  61. );
  62. };
  63. return ForecastDetailsView;
  64. }(BaseView);
  65. return ForecastDetailsView;
  66. });
  67. //# sourceMappingURL=ForecastDetailsView.js.map