'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * 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', '../../../util/JumpToActionHelper', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../content/slotActions/api/SlotActionsProviderAPI', '../../content/dataPointActions/api/DataPointActionsProviderAPI', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../widgets/livewidget/nls/StringResources'], function (_, JumpToActionHelper, APIFactory, SlotActionsProviderAPI, DataPointActionsProviderAPI, ContentActionsProviderAPI, StringResources) { return function () { function JumpToAction(options) { _classCallCheck(this, JumpToAction); this._dashboard = options.features && options.features.API || options.dashboardAPI; this._icons = options.features.Icons || options.features['Dashboard.Icons']; if (options.content) { this._content = options.content; this._content.getFeature('SlotActions').registerProvider('jumpToAction', this.getAPI()); this._content.getFeature('DataPointActions').registerProvider('jumpToAction', this.getAPI()); } else { options.features && options.features.ContentActions.registerProvider('jumpToAction', this.getAPI()); } } JumpToAction.prototype.destroy = function destroy() { this._dashboard = null; this._content = null; }; JumpToAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; // Valid values will be any number or an array of 1 number if (Array.isArray(itemIndex) && itemIndex.length !== 1) { return []; } if (options.area === 'cell_edge_row' || options.area === 'cell_edge_column') { return []; } return this._getContribution(); }; JumpToAction.prototype.getDataPointActionList = function getDataPointActionList(selections, actionOptions) { return this._supportDataPointAction(actionOptions) ? this._getContribution(selections, actionOptions) : []; }; JumpToAction.prototype._supportDataPointAction = function _supportDataPointAction(actionOptions) { return !actionOptions.noDrillthrough; }; JumpToAction.prototype._supportAction = function _supportAction(idList) { if (idList.length !== 1 || this._dashboard.getMode() === this._dashboard.MODES.EDIT_GROUP) { return false; } this._content = this._dashboard.getCanvas().getContent(idList[0]); return this._content && this._content.getType() === 'widget.live'; }; JumpToAction.prototype.getContentActionList = function getContentActionList(idList) { if (this._supportAction(idList)) { this._content = this._dashboard.getCanvas().getContent(idList[0]); return this._getDrillThroughToolbarContribution(); } return []; }; JumpToAction.prototype._getTargetInfo = function _getTargetInfo(content, dataSourceId, selections) { //@todo also take into account net page context (next thing to do) var drillThroughModel = this._dashboard.getFeature('DrillThroughService').getDrillThroughModelApiSync(); var entries = drillThroughModel.getDrillDefinitionEntries(content); return JumpToActionHelper.getJumpToTargets({ content: content, drillDefinitions: entries, selections: selections, dashboardApi: this._dashboard, sourceId: dataSourceId }); }; JumpToAction.prototype._getContribution = function _getContribution(selections) { var jumpToTargets = []; var toolbarContribution = []; var visualizationAPI = this._content.getFeature('Visualization'); var dataSource = visualizationAPI.getDataSource(); var dataSourceId = dataSource.getId(); jumpToTargets = this._getTargetInfo(this._content, dataSourceId, selections); if (jumpToTargets.targets.length > 0) { var contribution = this._getContributionAction({ oTargetsInfo: jumpToTargets, isDataPointSelection: true, sourceId: dataSourceId, selections: selections }); toolbarContribution = [contribution]; } return toolbarContribution; }; JumpToAction.prototype._isAutoGrouped = function _isAutoGrouped(visualizationAPI) { var dataItems = visualizationAPI.getSlots().getDataItemList(); var bAutoGroup = false; dataItems.forEach(function (dataItem) { if (dataItem.getBinning()) { bAutoGroup = true; } }); return bAutoGroup; }; JumpToAction.prototype._getDrillThroughToolbarContribution = function _getDrillThroughToolbarContribution() { var visualizationAPI = this._content.getFeature('Visualization'); // Do not show drillthrough if autoGroup is enabled var visDefinitionType = visualizationAPI && visualizationAPI.getDefinition() && visualizationAPI.getDefinition().getType(); if (visDefinitionType && !this._isAutoGrouped(visualizationAPI)) { var dataSource = visualizationAPI.getDataSource(); if (!dataSource || !this._isInteractionEnabled('drillThrough')) { return []; } var dataSourceId = dataSource.getId(); var oTargetsInfo = this._getTargetInfo(this._content, dataSourceId); var noTargets = oTargetsInfo.targets && !oTargetsInfo.targets.length; var _dashboard$getFeature = this._dashboard.getFeature('DashboardState').getUiState(), authoring = _dashboard$getFeature.authoring; if (!authoring && noTargets) { return []; } return [this._getContributionAction({ sourceId: dataSourceId, oTargetsInfo: oTargetsInfo, isAuthoringMode: authoring })]; } return []; }; JumpToAction.prototype._getContributionAction = function _getContributionAction() { var _this = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var oTargetsInfo = options.oTargetsInfo; var isAuthoringMode = !!options.isAuthoringMode; var isDataPointSelection = !!options.isDataPointSelection; var drillThroughIcon = this._icons.getIcon('visualizations-drillthrough_16'); var oneTarget = void 0; if (isDataPointSelection) { oneTarget = oTargetsInfo.targets && oTargetsInfo.targets.length === 1; } else { oneTarget = isAuthoringMode ? false : oTargetsInfo.targets && oTargetsInfo.targets.length === 1; } var contribution = { name: 'jumpTo', label: StringResources.get('drillthrough_jumpToLabel'), icon: drillThroughIcon.id, viewOptions: { content: this._content, sourceId: options.sourceId, jumpToTargets: function jumpToTargets(content, dataSourceId, selections) { return _this._getTargetInfo(content, dataSourceId, selections); }, isDataPointSelection: isDataPointSelection, dashboardApi: this._dashboard, selections: options.selections } }; if (oneTarget) { contribution = _.extend(contribution, { type: 'Button', actions: { apply: this._performDirectJumpTo.bind(this, oTargetsInfo) } }); } else { contribution = _.extend(contribution, { type: 'NextView', viewModule: 'dashboard-analytics/drill-through/jumpTo/JumpToView' }); } return contribution; }; JumpToAction.prototype._performDirectJumpTo = function _performDirectJumpTo(targetsInfo) { if (targetsInfo && _.isArray(targetsInfo.targets) && !!targetsInfo.targets.length) { var id = targetsInfo.targets[0].getId(); var target = targetsInfo.targetsMap[id]; if (target) { target.jumpTo(); } } }; JumpToAction.prototype._isInteractionEnabled = function _isInteractionEnabled(name) { var config = this._dashboard.getAppConfig('interactions') || {}; if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) { return false; } return true; }; JumpToAction.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI, ContentActionsProviderAPI, DataPointActionsProviderAPI]); } return this._api; }; return JumpToAction; }(); }); //# sourceMappingURL=JumpToAction.js.map