123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- '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
|