123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- '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(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../dataQueryExecution/api/QueryModifierAPI', './api/SummaryQueryModifierAPI', 'underscore'], function (APIFactory, QueryModifierAPI, SummaryQueryModifierAPI, _) {
- var SummaryQueryModifier = function () {
- function SummaryQueryModifier(options) {
- _classCallCheck(this, SummaryQueryModifier);
- var features = options && options.features;
- if (features) {
- this._mainModifier = features.QueryModifier;
- }
- var queryExecution = features && features.DataQueryExecution;
- if (queryExecution) {
- queryExecution.registerQueryModifier(this.getAPI());
- }
- this._dataItemLists = [];
- }
- SummaryQueryModifier.prototype.getAPI = function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [QueryModifierAPI, SummaryQueryModifierAPI]);
- }
- return this.api;
- };
- SummaryQueryModifier.prototype.getType = function getType() {
- return 'summary';
- };
- SummaryQueryModifier.prototype.resetDataItemIdList = function resetDataItemIdList() {
- this._dataItemLists = [];
- };
- SummaryQueryModifier.prototype.addDataItemIdList = function addDataItemIdList(dataItemList) {
- this._dataItemLists.push(dataItemList);
- };
- /**
- * Modify query spec based on the data item list added from SummaryTask in order.
- */
- SummaryQueryModifier.prototype.modifyQuerySpecList = function modifyQuerySpecList(specList) {
- var _this = this;
- specList = this._mainModifier && this._mainModifier.modifyQuerySpecList(specList);
- var extraFiltersRequired = [];
- var dataItemList = this._dataItemLists.shift();
- specList.forEach(function (specEntry) {
- specEntry.spec.dataItems = _.filter(specEntry.spec.dataItems, function (dataItem) {
- if (dataItemList.indexOf(dataItem.id) < 0) {
- // if the dataItem is not projected, but the dataItem affects the shape of the data result, e.g topbottom,
- // keep the dataItem in the list AND add a filter entry.
- var extraFilter = _this._getSummaryExtraFilter(dataItem);
- if (extraFilter) {
- extraFiltersRequired.push(extraFilter);
- return true;
- }
- // otherwise remove it from the summary query
- return false;
- }
- // keep it as part of the summary query
- return true;
- });
- specEntry.spec.projections = _.filter(specEntry.spec.projections, function (projection) {
- return dataItemList.indexOf(projection) > -1;
- });
- if (extraFiltersRequired.length) {
- var addExtraFilters = function addExtraFilters(specFilters, extraFilters) {
- specFilters.push.apply(specFilters, extraFilters);
- return specFilters;
- };
- specEntry.spec.filters = specEntry.spec.filters ? addExtraFilters(specEntry.spec.filters, extraFiltersRequired) : extraFiltersRequired;
- }
- });
- return specList;
- };
- /**
- * @private
- * Get the extra filter required for non-projected dataitems in a summary query
- * @param {object} dataItem - dataItem
- * @return {object} filter entry representing the non-projected data item context, null if an extra filter is not required
- */
- SummaryQueryModifier.prototype._getSummaryExtraFilter = function _getSummaryExtraFilter(dataItem) {
- var extraFilter = null;
- _.each(dataItem.selection, function (select) {
- if (select.operation !== 'order') {
- extraFilter = {
- type: 'pre',
- expression: {
- operator: 'in',
- itemId: dataItem.itemId,
- valueDataItem: dataItem.id
- }
- };
- }
- });
- return extraFilter;
- };
- return SummaryQueryModifier;
- }();
- return SummaryQueryModifier;
- });
- //# sourceMappingURL=SummaryQueryModifier.js.map
|