123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- '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: BI Cloud (C) Copyright IBM Corp. 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/QueryModifierAPI', './DataQueryUtils'], function (_, APIFactory, QueryModifierAPI) {
- var SharedSlotVisQueryModifier = function () {
- function SharedSlotVisQueryModifier(_ref) {
- var content = _ref.content,
- features = _ref.features;
- _classCallCheck(this, SharedSlotVisQueryModifier);
- this.content = content;
- features.DataQueryExecution.registerQueryModifier(this.getAPI());
- }
- SharedSlotVisQueryModifier.prototype.getAPI = function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [QueryModifierAPI]);
- }
- return this.api;
- };
- SharedSlotVisQueryModifier.prototype.getType = function getType() {
- return 'main';
- };
- SharedSlotVisQueryModifier.prototype.modifyQuerySpecList = function modifyQuerySpecList(querySpecList) {
- var visualization = this.content.getFeature('Visualization');
- var mappedSlots = visualization.getSlots().getMappedSlotList();
- if (this._hasSharedSlot(mappedSlots)) {
- this._addExtraDataItems(querySpecList, mappedSlots);
- }
- return querySpecList;
- };
- SharedSlotVisQueryModifier.prototype._hasSharedSlot = function _hasSharedSlot(mappedSlots) {
- var sharedSlots = mappedSlots.filter(function (slot) {
- return slot.getDefinition().getDatasetIdList().length > 1;
- });
- return sharedSlots.length > 0;
- };
- SharedSlotVisQueryModifier.prototype._getDataItemMap = function _getDataItemMap(querySpecList) {
- var result = {};
- querySpecList.forEach(function (querySpec) {
- querySpec.spec.dataItems.forEach(function (dataItem) {
- if (!result[dataItem.id]) {
- result[dataItem.id] = dataItem;
- }
- });
- });
- return result;
- };
- SharedSlotVisQueryModifier.prototype._getNestIdList = function _getNestIdList(querySpec) {
- var result = [];
- querySpec.dataItems.forEach(function (dataItem) {
- if (dataItem.nest) {
- result.push.apply(result, dataItem.nest);
- }
- });
- return result;
- };
- /**
- * Get the extra data items from other datasets
- * We only need to copy data items with type fact
- *
- * @param {*} mappedSlots
- * @param {*} datasetId
- * @returns
- * @memberof SharedSlotVisQueryModifier
- */
- SharedSlotVisQueryModifier.prototype._getExtraDataItemIdList = function _getExtraDataItemIdList(querySpec, mappedSlots) {
- var extraDataItemIdList = [];
- var projections = querySpec.spec.projections;
- var nestIdList = this._getNestIdList(querySpec.spec);
- var excludedIdList = [].concat(projections, nestIdList);
- mappedSlots.forEach(function (slot) {
- slot.getDataItemList().forEach(function (dataItem) {
- var id = dataItem.getId();
- if (dataItem.getType() === 'fact' && !(excludedIdList.indexOf(id) !== -1)) {
- extraDataItemIdList.push(id);
- }
- });
- });
- return extraDataItemIdList;
- };
- SharedSlotVisQueryModifier.prototype._addExtraDataItems = function _addExtraDataItems(querySpecList, mappedSlots) {
- var _this = this;
- var dataItemMap = this._getDataItemMap(querySpecList);
- querySpecList.forEach(function (querySpec) {
- var extraDataItems = [];
- var extraDataItemIdList = _this._getExtraDataItemIdList(querySpec, mappedSlots);
- extraDataItemIdList.forEach(function (id) {
- var dataItem = dataItemMap[id];
- if (_this._isValidDataItem(dataItem)) {
- /*
- When sorting by a fact in one of the Bar/line queries, we need to introduce that
- fact item and sort spec into the other query as a context item.
- The query layer will use that item to produce a sorted result.
- */
- extraDataItems.push(dataItem);
- }
- });
- if (extraDataItems.length) {
- var _querySpec$spec$dataI;
- (_querySpec$spec$dataI = querySpec.spec.dataItems).push.apply(_querySpec$spec$dataI, extraDataItems);
- }
- _this._modifyMultiEdgeSort(querySpec);
- });
- };
- /**
- *
- * Return true is the data item has sorting spec in selection
- * @memberof SharedSlotVisQueryModifier
- */
- SharedSlotVisQueryModifier.prototype._isValidDataItem = function _isValidDataItem(dataItem) {
- if (!dataItem.selection) {
- return false;
- }
- var sortingSpec = dataItem.selection.filter(function (value) {
- return Object.keys(value).indexOf('sort') !== -1;
- });
- return sortingSpec.length > 0;
- };
- /**
- *
- * Turn off the multiEdgeSort(There is only one edge which is the shared slot)
- * @param {*} querySpec query spec object
- * @memberof SharedSlotVisQueryModifier
- */
- SharedSlotVisQueryModifier.prototype._modifyMultiEdgeSort = function _modifyMultiEdgeSort(querySpec) {
- if (querySpec.spec.queryHints) {
- querySpec.spec.queryHints.multiEdgeSort = false;
- }
- };
- return SharedSlotVisQueryModifier;
- }();
- return SharedSlotVisQueryModifier;
- });
- //# sourceMappingURL=SharedSlotVisQueryModifier.js.map
|