123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 'use strict';
- 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; }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2017, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['react', 'react-dom', 'ca-ui-toolkit', 'underscore', '../../../datatray/ExtensionBaseView', '../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/no-data_200', '../../../dataSources/nls/StringResources'], function (React, ReactDOM, toolkit, _, BaseView, noData200, StringResources) {
- var ContextualGrid = function (_BaseView) {
- _inherits(ContextualGrid, _BaseView);
- function ContextualGrid(options) {
- _classCallCheck(this, ContextualGrid);
- var _this = _possibleConstructorReturn(this, _BaseView.call(this, options));
- _this.dashboard = options.dashboard;
- _this.logger = _this.dashboard.getGlassCoreSvc('.Logger');
- return _this;
- }
- ContextualGrid.prototype.render = function render(content, container) {
- var _this2 = this;
- if (this.content !== content || this.containerNode !== container) {
- this.setViewContext(content, container);
- }
- BaseView.clearContainer(this.containerNode);
- // class name is needed for using style from ba-ui-toolkit
- this.containerNode.classList.add('ba-theme-waca');
- // get the view option from vis grid model in widget model
- var doAggregate = content.getPropertyValue('datagrid.viewOption') === 'projectedAggregated';
- this._setLoading();
- return this.content.getFeature('DataBehindTheVis').getData(doAggregate).then(function (results) {
- _this2._removeLoading();
- if (_this2._isResultValid(results)) {
- _this2._renderReactGrid(results);
- } else {
- _this2._noData();
- }
- }).catch(function (error) {
- var knownErrors = ['dwErrorStaleRequest'];
- var errorMessage = error && (error.message || error.msg) || 'dwErrorRenderingContextualGrid';
- if (knownErrors.indexOf(errorMessage) === -1) {
- //TODO: we could introduce a bad state view here
- _this2._removeLoading();
- _this2.logger.error(error);
- } else {
- _this2.logger.warn(error);
- }
- });
- };
- ContextualGrid.prototype.setViewContext = function setViewContext(content, container) {
- this._deregisterEvents();
- this.content = content;
- this.containerNode = container;
- this._registerEvents();
- };
- ContextualGrid.prototype._noData = function _noData() {
- var svg = React.createElement('svg', { viewBox: noData200.default.viewBox, focusable: 'false', className: 'noDataSvg' }, React.createElement('use', { class: 'ba-graphics-themable', xlinkHref: '#' + noData200.default.id, fill: '#00baa1' }));
- var text = React.createElement('p', {}, StringResources.get('DATA_TRAY_no_data_text'));
- var content = React.createElement('div', { className: 'noDataContent' }, svg, text);
- ReactDOM.render(content, this.containerNode);
- };
- ContextualGrid.prototype.remove = function remove() {
- ContextualGrid.inherited('remove', this, arguments);
- this._deregisterEvents();
- this._unmountReactComponents();
- };
- ContextualGrid.prototype._unmountReactComponents = function _unmountReactComponents() {
- if (this.containerNode) {
- ReactDOM.unmountComponentAtNode(this.containerNode);
- }
- };
- ContextualGrid.prototype._registerEvents = function _registerEvents() {
- if (this.content) {
- this._renderHandler = this.render.bind(this, this.content, this.containerNode);
- this.content.on('change:property:datagrid.viewOption', this._renderHandler, this);
- }
- };
- ContextualGrid.prototype._deregisterEvents = function _deregisterEvents() {
- if (this.content) {
- this.content.off('change:property:datagrid.viewOption', this._renderHandler, this);
- }
- };
- ContextualGrid.prototype._renderReactGrid = function _renderReactGrid(results) {
- var _this3 = this;
- var props = {
- numColumns: results.headers.length,
- numRows: results.cells.length,
- fixedRows: 1,
- useRowOptionsColumn: true,
- rowOptionsColumnText: StringResources.get('contextualGridMenuLabel'),
- dataCellRenderer: this._cellRenderer.bind(this, results),
- fixedRowCellRenderer: function fixedRowCellRenderer(_, colIndex, gridCellProps) {
- var headerData = results.headers[colIndex];
- var reactEle = React.createElement(toolkit.GridHeaderCell, gridCellProps, React.createElement('div', {
- style: BaseView.CELL.style.left
- }, headerData));
- reactEle.displayName = 'RowCell';
- return reactEle;
- },
- onFixedCornerCellMenu: function onFixedCornerCellMenu(clientX, clientY) {
- _this3.dashboard.showContextMenu({
- position: {
- pageX: clientX,
- pageY: clientY
- },
- menuId: 'com.ibm.bi.dashboard.contextualGridMenu',
- activeObject: {
- content: _this3.content,
- export: _this3._export.bind(_this3, results)
- }
- });
- }
- };
- var contextualGrid = React.createElement(toolkit.Grid, props);
- ReactDOM.render(contextualGrid, this.containerNode);
- };
- ContextualGrid.prototype._export = function _export(results) {
- this.dashboard.getFeature('CsvExport').export(results.title, [results.headers], results.cells);
- };
- ContextualGrid.prototype._cellRenderer = function _cellRenderer(results, rowIndex, colIndex, gridCellProps) {
- var dataCellObj = results.cells[rowIndex][colIndex];
- var style = BaseView.CELL.style.left;
- if (this._isCellValueMeasure(dataCellObj)) {
- style = BaseView.CELL.style.right;
- }
- return this._getCellComponent(dataCellObj, gridCellProps, style);
- };
- ContextualGrid.prototype._isCellValueMeasure = function _isCellValueMeasure(dataCell) {
- return dataCell && _.isUndefined(dataCell.label);
- };
- ContextualGrid.prototype._getCellComponent = function _getCellComponent(dataCell, gridCellProps, style) {
- if (style) {
- style['white-space'] = 'nowrap'; /*Deal with very long column value*/
- }
- var dataCellValue = dataCell.toString();
- var reactEle = React.createElement(toolkit.GridCell, gridCellProps, React.createElement('div', {
- style: style,
- title: dataCellValue
- }, dataCellValue));
- reactEle.displayName = 'Cell';
- return reactEle;
- };
- ContextualGrid.prototype._isResultValid = function _isResultValid(result) {
- return result.cells.length && result.headers.length;
- };
- return ContextualGrid;
- }(BaseView);
- return ContextualGrid;
- });
- //# sourceMappingURL=DataBehindTheVisView.js.map
|