'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof 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; } /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard * (C) Copyright IBM Corp. 2018, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', '../../util/AjaxHelper', '../../lib/@waca/dashboard-common/dist/utils/ContentUtil', '../../cmHelper/CMHelper', '../../widgets/livewidget/nls/StringResources', '../../features/content/common/DataPointActionBase'], function (_, AjaxHelper, ContentUtil, CMHelper, StringResources, DataPointActionBase) { /** * * Handle 'Jump to' target, i.e, open target perspective **/ var JumpToTarget = function (_DataPointActionBase) { _inherits(JumpToTarget, _DataPointActionBase); function JumpToTarget(options) { _classCallCheck(this, JumpToTarget); var _this = _possibleConstructorReturn(this, _DataPointActionBase.call(this, options)); _this.drillDefinitionEntry = options.drillDefinitionEntry; _this.selections = options.selections; //undefined at selected widget level, has valid data for selected data point _this.rangeValueTypes = { boundRange: 'boundRange', unboundedRange: 'unboundedRange', unboundedStartRange: 'unboundedStartRange', unboundedEndRange: 'unboundedEndRange' }; _this.negativeFilterOps = ['notin', 'notbetween']; _this.rangeFilterOps = ['gt', 'gte', 'lt', 'lte', 'between']; return _this; } JumpToTarget.prototype.getId = function getId() { return this.drillDefinitionEntry.getId(); }; JumpToTarget.prototype.getName = function getName() { return this.drillDefinitionEntry.getName(); }; JumpToTarget.prototype.jumpTo = function jumpTo() { var _this2 = this; return this._buildDrillTargetSpec().then(function (spec) { spec = spec || {}; spec.content = spec.content || {}; spec.content.cmProperties = spec.content.cmProperties || {}; var unsaveMessage = StringResources.get('drillthrough_unsaveMsg', { name: decodeURIComponent(spec.content.pathRef) }); var openPerspective = void 0, closePerspective = void 0; openPerspective = closePerspective = _this2.drillDefinitionEntry.getPerspective(); if (openPerspective === 'authoring') { // CADBLW-5575 - For reporting, we must not set the perspective in the // openApplication call because it prevents it from switching to ClassicViewer // in the case that the target report has interactivity turned off. openPerspective = undefined; } return _this2.dashboard.closeApplication(closePerspective, spec.content.cmProperties.id, { unsaveMessage: unsaveMessage }).then(_this2.dashboard.openApplication.bind(_this2.dashboard, openPerspective, spec)); }).catch(function (error) { var jqXHR = error.jqXHR || error || {}; if (error.code === 404) { jqXHR.responseText = StringResources.get('drillthrough_jumpToTarget_notFound', { name: _this2.drillDefinitionEntry.getName() }); } else { jqXHR.responseText = jqXHR.responseText ? jqXHR.responseText : jqXHR.statusText; } if (jqXHR.responseText) { AjaxHelper.showAjaxServiceErrorMessage(_this2.dashboard, jqXHR); //Eat the rejection and return as success return Promise.resolve(); } // Unexpected case return _this2.dashboard.getGlassSvc('.Content').then(function (contentService) { return CMHelper.getReportName(contentService, _this2.drillDefinitionEntry.getAssetId()).then(function (targetName) { jqXHR.responseText = StringResources.get('errorDrillToTarget', { targetName: targetName }); AjaxHelper.showAjaxServiceErrorMessage(_this2.dashboard, jqXHR); return Promise.resolve(); }); }); }); }; JumpToTarget.prototype._buildDrillTargetSpec = function _buildDrillTargetSpec() { var _this3 = this; var options = {}; this.dashboard.prepareGlassOptions(options); var currentAssetId = this.drillDefinitionEntry.getAssetId(); var currentSearchPath = this.drillDefinitionEntry.getAssetSearchPath(); return CMHelper.getPathRefInfo(options, { storeId: currentAssetId, searchPath: currentSearchPath, fields: ['searchPath'] }).then(function (pathRefInfo) { if (!pathRefInfo) { return {}; } var newAssetId = pathRefInfo.objRef; if (!_.isEmpty(newAssetId) && newAssetId !== currentAssetId) { _this3.drillDefinitionEntry.setAssetId(newAssetId); } var newAssetSearchPath = pathRefInfo.searchPath; if (!_.isEmpty(newAssetSearchPath) && newAssetSearchPath !== currentSearchPath) { _this3.drillDefinitionEntry.setAssetSearchPath(newAssetSearchPath); } var spec = { content: { cmProperties: { id: newAssetId }, isViewer: true, altDrillFlag: true, //@todo Reporting add this new flag to route to new implementation that supports JSON parameter values prompt: false, //@todo what is this? format: 'HTML', // Default to HTML until we support more format. editSpecification: '', //dashboard drill through to target does not need this property pathRef: pathRefInfo.pathRef } }; // exploration is the CM type for dashboard/story/explore if (_this3.drillDefinitionEntry.getType() === 'exploration') { spec.content.filters = JSON.stringify(_this3._getDashboardParameterValues()); } else { spec.content.parameterValuesJSON = JSON.stringify(_this3._getReportParameterValues()); } return spec; }); }; JumpToTarget.prototype._getDashboardParameterValues = function _getDashboardParameterValues() { if (this.dashboardParameterValues && _.size(this.dashboardParameterValues) > 0) { return this.dashboardParameterValues; } this.dashboardParameterValues = { assetID: this._getVisualization().getDataSource().getAssetId(), filters: [] }; var mergedConvertedFilter = this._getMergedConvertedFilter(); this.dashboardParameterValues.filters.push(mergedConvertedFilter); return this.dashboardParameterValues; }; JumpToTarget.prototype._getMergedConvertedFilter = function _getMergedConvertedFilter() { var _getFilterInfo2 = this._getFilterInfo(), globalFilters = _getFilterInfo2.globalFilters, localFilters = _getFilterInfo2.localFilters, selectionFilters = _getFilterInfo2.selectionFilters, dataPointFilter = _getFilterInfo2.dataPointFilter; var mergedFilters = {}; // the order has to be globalFilters -> localFilters -> dataPointFilter -> selectionFilters this._getSimpleFilterContext(globalFilters, mergedFilters); this._getSimpleFilterContext(localFilters, mergedFilters); this._getSimpleFilterContext(dataPointFilter, mergedFilters); this._getSimpleFilterContext(selectionFilters, mergedFilters); return mergedFilters; }; /** * If the filter entry in filter list is simple expression, just add to mergedFilters. * In case of compound filter express, walk each simple filter expression to collect the context. * @extends Please check unit test {@link testJumpToDashboardWithComplicatedFilterExpression} */ JumpToTarget.prototype._getSimpleFilterContext = function _getSimpleFilterContext() { var filterList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var _this4 = this; var mergedFilters = arguments[1]; var append = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (filterList.length === 0) { return; } filterList.forEach(function (filter) { if (filter.columnId) { if (append && mergedFilters[filter.columnId] && mergedFilters[filter.columnId].values && filter.values) { var _mergedFilters$filter; // Filter column already exists in merged, just append the filter values. (_mergedFilters$filter = mergedFilters[filter.columnId].values).push.apply(_mergedFilters$filter, filter.values); } else { mergedFilters[filter.columnId] = filter; } } else { // In case of compound filter, need to add the simple filter context or append the filter values if column id already exists _this4._getSimpleFilterContext(filter.values, mergedFilters, true); } }); }; JumpToTarget.prototype._getFilterInfo = function _getFilterInfo() { var visualization = this._getVisualization(); var datasource = visualization.getDataSource(); var localFilters = visualization.getLocalFilters(); var type = this.dashboard.getAppConfig('pageContainerType'); var filterInfo = { localFilters: localFilters.getFilterList(), globalFilters: this.globalFilters.getFilterList({ origin: 'filter', sourceId: datasource.getId(), scope: ContentUtil.getPageContent(this.content, type).getId(), eventGroupId: this.eventGroups.getGroupId(this.content.getId()) }), selectionFilters: this.globalFilters.getFilterList({ origin: 'visualization', sourceId: datasource.getId(), scope: ContentUtil.getPageContent(this.content, type).getId(), eventGroupId: this.eventGroups.getGroupId(this.content.getId()) }), dataPointFilter: this._getDataPointFilter() }; return filterInfo; }; JumpToTarget.prototype._getDataPointFilter = function _getDataPointFilter() { var datapointFilters = []; if (this.selections && this.selections.dataPoints) { this.selections.dataPoints.forEach(function (dataPoint) { if (dataPoint.categories) { dataPoint.categories.forEach(function (category) { var filterEntry = _.findWhere(datapointFilters, { columnId: category.columnId }); if (!filterEntry) { filterEntry = { columnId: category.columnId, operator: 'in', values: [] }; datapointFilters.push(filterEntry); } filterEntry.values.push({ u: category.value, d: category.label }); }); } }); } return datapointFilters; }; JumpToTarget.prototype._getReportParameterValues = function _getReportParameterValues() { var _this5 = this; var reportParameterValues = {}; var mappings = this.drillDefinitionEntry.getMappings(); _.each(mappings, function (mapping) { var values = _this5._getParamterValues(mapping); if (!values) { return; } if (_this5._isRangeParameter(mapping.capabilities)) { // Complex parameter values. var complexValues = _this5._buildRangeValues(values, mapping.type); reportParameterValues[mapping.name] = complexValues; } else { if (values.startValue || values.endValue) { // Dashboard has range values, and convert to simple array values var arrayValues = []; if (values.startValue) { arrayValues.push(values.startValue); } if (values.endValue) { arrayValues.push(values.endValue); } values = arrayValues; } if (values.length > 0) { // Simple parameter values built from simple array values. reportParameterValues[mapping.name] = []; values.forEach(function (value) { reportParameterValues[mapping.name].push({ use: _this5._getUseValueFromValue(value, mapping.type), display: _this5._getDisplayValueFromValue(value) }); }); } } }); return reportParameterValues; }; JumpToTarget.prototype._getParamterValues = function _getParamterValues(mapping) { var values = void 0; if (mapping && mapping.mapTo) { // Get values from selections values = this._getValuesFromSelections(mapping.mapTo); // No values from selections, search local filters if (!values || !values.length) { values = this._getValuesFromFilters(mapping.mapTo, this._getLocalFilters().getFilterList()); } // No values from projections and local filters, search global filters // in_range prompt expecting start and end values respectively so values is object type. if (!values || Array.isArray(values) && !values.length || (typeof values === 'undefined' ? 'undefined' : _typeof(values)) === 'object' && _.isEmpty(values)) { var globalFilterList = [].concat(this.globalFilters.getFilterList(this._getNetPageContextSelectors('filter'))); globalFilterList.push.apply(globalFilterList, this.globalFilters.getFilterList(this._getNetPageContextSelectors('visualization'))); values = this._getValuesFromFilters(mapping.mapTo, globalFilterList); } } return values; }; JumpToTarget.prototype._getValuesFromSelections = function _getValuesFromSelections(mapTo) { var values = null; // When selection has numeric values, map it to the target first since numeric selections are not included in pending filter or brushing var dataPoints = this.selections && this.selections.dataPoints || []; if (!dataPoints.length) { // Content contribution is built before selection happens so need to collect selections here. dataPoints = this.content.getFeature('DataPointSelections').getSelections(); } var facts = _.pluck(dataPoints, 'facts'); facts.forEach(function (items) { items && items.forEach(function (item) { if (item.columnId === mapTo) { values = item.value !== null && item.value !== undefined ? [item.value] : null; } }); }); if (values) { // Found source column and return; return values; } var groupedSelections = this._groupSelections(dataPoints); values = this._getValues(groupedSelections, mapTo); return values; }; JumpToTarget.prototype._getValues = function _getValues(groupedSelections, mapTo) { var _this6 = this; if (groupedSelections) { var _ret = function () { var values = []; for (var groupKey in groupedSelections) { var columnIds = groupKey.split(','); if (columnIds.indexOf(mapTo) !== -1) { groupedSelections[groupKey].forEach(function (groupSelection) { groupSelection.forEach(function (selection) { selection.columnId === mapTo && values.push(selection); }); }); } } return { v: _this6._uniqueValues(values) }; }(); if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; } }; JumpToTarget.prototype._uniqueValues = function _uniqueValues() { var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var uniqueValues = []; var valuesMap = {}; values.forEach(function (value) { if (!valuesMap[value.u]) { valuesMap[value.u] = 1; uniqueValues.push(value); } }); return uniqueValues; }; JumpToTarget.prototype._getFilterSpec = function _getFilterSpec(mapTo, filterList) { var resultSpec = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; /** * filterList could have multiple filters based on different pre or post aggregations or aggregation types * But we will only pass the values of the first entry to target */ for (var i = 0; i < filterList.length; i++) { if (filterList[i].columnId === mapTo) { if (resultSpec) { var _resultSpec$values; (_resultSpec$values = resultSpec.values).push.apply(_resultSpec$values, filterList[i].values); } else { resultSpec = filterList[i]; } break; } else if (filterList[i].values && filterList[i].values.length) { resultSpec = this._getFilterSpec(mapTo, filterList[i].values, resultSpec); } } return resultSpec; }; JumpToTarget.prototype._getValuesFromFilters = function _getValuesFromFilters(mapTo, filterList) { var filterSpec = filterList && this._getFilterSpec(mapTo, filterList); // Return filter values if exist, and the operator is not negative operations // Fact filter ids are generated from itemId and aggregation type, e.g. [Sales (query)].[Sales].[Revenue]_sum, // so get(mapTo) won't return fact filters. var values = void 0; if (filterSpec && !this._isNegativeOperation(filterSpec) && filterSpec.values) { values = filterSpec.values; if (this._isRangeFilter(filterSpec)) { var startValue = void 0; var endValue = void 0; switch (filterSpec.operator) { case 'between': startValue = values[0]; endValue = values[1]; break; case 'gt': case 'gte': startValue = values[0]; break; case 'lt': case 'lte': endValue = values[0]; break; default: break; } // complex value structure values = { startValue: startValue, endValue: endValue }; } } return values; }; JumpToTarget.prototype._getNetPageContextSelectors = function _getNetPageContextSelectors(origin) { var page = ContentUtil.getPageContent(this.content); return { scope: page && page.getId(), sourceId: this._getVisualization().getDataSource().getId(), origin: origin }; }; JumpToTarget.prototype._isNegativeOperation = function _isNegativeOperation(localFilter) { return this.negativeFilterOps.indexOf(localFilter.operator) !== -1; }; JumpToTarget.prototype._isRangeFilter = function _isRangeFilter(localFilter) { return this.rangeFilterOps.indexOf(localFilter.operator) !== -1; }; JumpToTarget.prototype.remove = function remove() { this.drillDefinitionEntry = null; this.selections = null; }; JumpToTarget.prototype._isRangeParameter = function _isRangeParameter(capabilities) { return capabilities && (capabilities.indexOf(this.rangeValueTypes.unboundedRange) !== -1 || capabilities.indexOf(this.rangeValueTypes.boundRange) !== -1); }; /** * Range parameter value is a complex expression with the * form of "boundRange" with a "start" and "end", "unboundedEndRange" with a "start" and "unboundedStartRange" with an "end", * and the values are from selections or a range filters. The first value will be used for both tart and end in case of multi selected values. * @example * { * 'Parameter1': [ * { * 'boundRange': { * 'start': { * 'use': '2010-01-01T00:00:00', * 'display': '2010-01-01T00:00:00' * }, * 'end': { * 'use': '2010-01-31T00:00:00', * 'display': '2010-01-31T00:00:00' * } * } * } * ] * } * @example * { * 'Parameter1': [ * { * 'unboundedEndRange': { * 'start': { * 'use': '2013-07-01T00:00:00', * 'display': '2013-07-01T00:00:00' * } * } * } * ] * } * @param {object} values - either an array of values or an object with start and end values. * @param {string} mappingType - the parameter type. */ JumpToTarget.prototype._buildRangeValues = function _buildRangeValues(values, mappingType) { var startValue = void 0; var endValue = void 0; if (values) { // For non-range selected values, set start and end values to the first selected value. if (_.isArray(values) && values.length >= 1) { startValue = values[0]; endValue = values[0]; } else { startValue = values.startValue; endValue = values.endValue; } } var valueExpr = {}; if (startValue && endValue) { valueExpr[this.rangeValueTypes.boundRange] = { start: { use: this._getUseValueFromValue(startValue, mappingType), display: this._getDisplayValueFromValue(startValue) }, end: { use: this._getUseValueFromValue(endValue, mappingType), display: this._getDisplayValueFromValue(endValue) } }; } else if (startValue) { valueExpr[this.rangeValueTypes.unboundedEndRange] = { start: { use: this._getUseValueFromValue(startValue, mappingType), display: this._getDisplayValueFromValue(startValue) } }; } else if (endValue) { valueExpr[this.rangeValueTypes.unboundedStartRange] = { end: { use: this._getUseValueFromValue(endValue, mappingType), display: this._getDisplayValueFromValue(endValue) } }; } // When a range has no startValue and endValue return null. return _.isEmpty(valueExpr) ? null : [valueExpr]; }; JumpToTarget.prototype._getUseValueFromValue = function _getUseValueFromValue(value, mappingType) { var resultValue = null; if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { if (mappingType === 'memberUniqueName') { resultValue = value.value === undefined ? value.u : value.value; } else { resultValue = value.label === undefined ? value.d : value.label; } } else { resultValue = value; } return resultValue; }; JumpToTarget.prototype._getDisplayValueFromValue = function _getDisplayValueFromValue(value) { return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' ? value.label === undefined ? value.d : value.label : value; }; return JumpToTarget; }(DataPointActionBase); return JumpToTarget; }); //# sourceMappingURL=JumpToTarget.js.map