'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. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', '../ExtensionBaseController', './DataSourcesView'], function (_, BaseController, DataSourcesView) { 'use strict'; var SOURCE_TYPE = { PACKAGE: 'package' }; var DataSourcesController = function (_BaseController) { _inherits(DataSourcesController, _BaseController); function DataSourcesController(dashboard, appSettings, eventRouter) { _classCallCheck(this, DataSourcesController); var _this = _possibleConstructorReturn(this, _BaseController.call(this, dashboard, appSettings, eventRouter)); _this.dataSourcesFeature = _this.dashboard.getFeature('DataSources'); _this.emptyDatasetRenderer = DataSourcesView.renderEmptyDataset; _this.MUIDataGridRender = DataSourcesView.renderMUIGrid; return _this; } /** * @see ExtensionBaseController */ DataSourcesController.prototype.getTabContrib = function getTabContrib(event, eventName, currentTabId) { var _this2 = this; return Promise.all([this._prepareDataSources(), this._getSelectedContent()]).then(function (deps) { var tabContribs = deps[0]; var content = deps[1]; if (!tabContribs.length) { return null; } var selectedTab = null; var activeSourceId = null; switch (eventName) { case 'dataSourcePanel:dataSourceSelected': if (event && event.sender) { selectedTab = _.findWhere(tabContribs, { id: event.sender }); selectedTab.isSelectedOnTrayRender = true; } else { selectedTab = _.findWhere(tabContribs, { id: currentTabId }); if (selectedTab) { selectedTab.isSelectedOnTrayRender = true; } } break; case 'shapingmodel:changed': activeSourceId = _this2.dashboard.getActiveDataSourceId(); if (!activeSourceId) { throw new Error('shapingmodel:changed triggered, but there is no active data source'); } selectedTab = _.findWhere(tabContribs, { id: activeSourceId }); if (currentTabId === activeSourceId) { selectedTab.select = _this2.select.bind(_this2, { id: activeSourceId, forceRender: true }); selectedTab.isSelectedOnTrayRender = true; } break; case 'widget:rerendered': selectedTab = _.findWhere(tabContribs, { id: currentTabId }); //Widget rerendered but a datasource view is the current tab. //The data source view should still be the active view if (selectedTab) { selectedTab.isSelectedOnTrayRender = true; } break; case 'splitterPanel:show': selectedTab = _.findWhere(tabContribs, { id: currentTabId }); if (selectedTab) { selectedTab.isSelectedOnTrayRender = true; selectedTab.select = _this2.select.bind(_this2, { id: currentTabId, forceRender: true }); } break; case 'remove': selectedTab = _.findWhere(tabContribs, { id: currentTabId }); if (selectedTab) { selectedTab.isSelectedOnTrayRender = true; selectedTab.select = _this2.select.bind(_this2, { id: currentTabId, forceRender: true }); } break; } if (!selectedTab && !content) { var _activeSourceId = _this2.dashboard.getActiveDataSourceId(); if (!_activeSourceId) { selectedTab = tabContribs[0]; } else { selectedTab = _.findWhere(tabContribs, { id: _activeSourceId }); } selectedTab.isSelectedOnTrayRender = true; } return tabContribs; }); }; /** * Given an array of source model object, returns and array of source objects that the tab control expects. * @return {Promise} promise that will resolve with an array of source object ready for the tab control */ DataSourcesController.prototype._prepareDataSources = function _prepareDataSources() { var _this3 = this; var whenNamesReady = []; var aPrepDataSources = []; var getName = function getName(source, item) { return source.getLocalizedName().then(function (name) { item.name = name; item.state = source.getState(); //State can be updated by the getLocalizedName() call, so set it after that call has finished. }).fail(function () { item.state = 'error'; }); }; var dataSources = this.dataSourcesFeature.getDataSourceList() || []; dataSources.forEach(function (dataSource) { var id = dataSource.getId(); var item = { type: dataSource.getType(), id: id, select: _this3.select.bind(_this3, { id: id }) }; aPrepDataSources.push(item); whenNamesReady.push(getName(dataSource, item)); }); return Promise.all(whenNamesReady).then(function () { return aPrepDataSources; }); }; /** * Renders the data source grid view. */ DataSourcesController.prototype.render = function render(context, container) { var _this4 = this; var source = this.dataSourcesFeature.getDataSource(context.id); if (source && source.getType() === SOURCE_TYPE.PACKAGE) { return this.emptyDatasetRenderer(container); } return source.getModule().then(function (module) { // enableDataQuality is a string var enableDataQuality = _this4.appSettings.options && _this4.appSettings.options.config ? _this4.appSettings.options.config.enableDataQuality == 'true' : true; return _this4.MUIDataGridRender(module, enableDataQuality, container, _this4.dashboard); }); }; /** * @see ExtensionBaseController */ DataSourcesController.prototype.select = function select(context, currentTabId, container) { if (currentTabId === context.id && !context.forceRender) { return Promise.resolve(false); } this.dashboard.getFeature('DataSources').setActiveDataSourceId(context.id); this.eventRouter.trigger('dataSourceGrid:dataSourceSelected', { 'sender': context.id }); return this.render(context, container); }; return DataSourcesController; }(BaseController); return DataSourcesController; }); //# sourceMappingURL=DataSourcesController.js.map