123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- '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. 2019
- * 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', '../../../filters/FilterQuerySpec'], function (_, APIFactory, QueryModifierAPI, DataQueryUtils, FilterQuerySpec) {
- var QueryModifier = function () {
- function QueryModifier(_ref) {
- var content = _ref.content,
- dashboardAPI = _ref.dashboardAPI;
- _classCallCheck(this, QueryModifier);
- this.content = content;
- this.dashboard = dashboardAPI;
- this.eventGroups = this.dashboard.getFeature('EventGroups');
- this.globalFilters = this.dashboard.getFeature('GlobalFilters');
- this.content.getFeature('DataQueryExecution').registerQueryModifier(this.getAPI());
- }
- QueryModifier.prototype.getAPI = function getAPI() {
- if (!this.api) {
- this.api = APIFactory.createAPI(this, [QueryModifierAPI]);
- }
- return this.api;
- };
- QueryModifier.prototype.getType = function getType() {
- return 'main';
- };
- QueryModifier.prototype.modifyQuerySpecListForQueryHint = function modifyQuerySpecListForQueryHint(querySpecList) {
- var _this = this;
- //add more queryHints
- querySpecList.forEach(function (querySpec) {
- if (querySpec.type === _this.getType()) {
- //we only add to main query
- _this._addQueryHintToSpec(querySpec.spec);
- }
- });
- return querySpecList;
- };
- QueryModifier.prototype.modifyQuerySpecList = function modifyQuerySpecList(querySpecList) {
- querySpecList = this.modifyQuerySpecListForFilters(querySpecList);
- querySpecList = this.modifyQuerySpecListForQueryHint(querySpecList);
- return querySpecList;
- };
- QueryModifier.prototype.modifyQuerySpecListForFilters = function modifyQuerySpecListForFilters(querySpecList) {
- var _this2 = this;
- var visualization = this.content.getFeature('Visualization');
- var filterSpecList = DataQueryUtils.getFilterSpecListByVisualization(this.content, this.dashboard);
- var updatedFilterSpecList = DataQueryUtils.convertExcludeEmptyValuesFilters(filterSpecList, visualization.getDataSource());
- var filterQuerySpecList = this._getFilterQuerySpecList(updatedFilterSpecList, visualization);
- // apply the global filter to each query spec
- if (filterQuerySpecList && filterQuerySpecList.length) {
- _.each(querySpecList, function (querySpec) {
- if (querySpec.type === _this2.getType()) {
- var _querySpec$spec$filte;
- if (!querySpec.spec.filters) {
- querySpec.spec.filters = [];
- }
- (_querySpec$spec$filte = querySpec.spec.filters).push.apply(_querySpec$spec$filte, filterQuerySpecList);
- }
- });
- }
- return querySpecList;
- };
- /**
- * @private
- * Get the list of global filter query specifications
- */
- QueryModifier.prototype._getFilterQuerySpecList = function _getFilterQuerySpecList(filterList, visualization) {
- var filterSpec = new FilterQuerySpec(visualization);
- filterSpec.addFiltersToSpec(filterList);
- return filterSpec.hasFilterSpec() ? filterSpec.getFilterSpec() : [];
- };
- QueryModifier.prototype._addValueToQueryHints = function _addValueToQueryHints(spec, queryHintKey, queryHintValue) {
- if (!spec.queryHints) {
- spec.queryHints = {};
- }
- spec.queryHints[queryHintKey] = queryHintValue;
- };
- QueryModifier.prototype._addQueryHintToSpec = function _addQueryHintToSpec(spec) {
- var preferredModelItems = DataQueryUtils.getRelatedModelItemsForQueryHint(this.content, this.dashboard);
- if (preferredModelItems.length) {
- this._addValueToQueryHints(spec, 'preferredModelItems', preferredModelItems);
- }
- var refreshProperty = this.content.getPropertyValue('queryRefresh');
- if (!(refreshProperty && refreshProperty.autoRefresh)) {
- var localCache = this.dashboard.getCanvas().getPropertyValue('dataCache');
- if (localCache === 'yes') {
- this._addValueToQueryHints(spec, 'dataCacheExpiry', '3600');
- } else if (localCache === 'no') {
- this._addValueToQueryHints(spec, 'dataCacheExpiry', '0');
- }
- }
- };
- return QueryModifier;
- }();
- return QueryModifier;
- });
- //# sourceMappingURL=QueryModifier.js.map
|