123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- 'use strict';
- 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: BI Cloud (C) Copyright IBM Corp. 2017, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- define(['./postProcess/LocalAggregateSortInfo', '../../dashboard/queryService/QuerySelectionBuilder', 'underscore'], function (LocalAggregateSortInfo, QuerySelectionBuilder, _) {
- var VisQuerySelectionBuilder = function (_QuerySelectionBuilde) {
- _inherits(VisQuerySelectionBuilder, _QuerySelectionBuilde);
- function VisQuerySelectionBuilder(_ref) {
- var internalVisualization = _ref.internalVisualization,
- layerToQuerySlotsMap = _ref.layerToQuerySlotsMap,
- applyServerSort = _ref.applyServerSort;
- _classCallCheck(this, VisQuerySelectionBuilder);
- var _this = _possibleConstructorReturn(this, _QuerySelectionBuilde.call(this));
- _this.internalVisualization = internalVisualization;
- _this._querySlotSortPriority = 0;
- _this._serverSort = applyServerSort;
- _this._localAggregateSortInfo = new LocalAggregateSortInfo(internalVisualization);
- _this._querySlotSortPriority = _this._getDataItemsHighestSortPriority(layerToQuerySlotsMap) + 1;
- return _this;
- }
- VisQuerySelectionBuilder.prototype._forEachQuerySlotDataItem = function _forEachQuerySlotDataItem(layerToQuerySlotsMap, callback) {
- layerToQuerySlotsMap.forEach(function (querySlots) {
- querySlots.forEach(function (slot) {
- var dataItems = slot.getDataItemList();
- dataItems.forEach(function (item) {
- callback(item, slot);
- });
- });
- });
- };
- /**
- * override the super build.
- */
- VisQuerySelectionBuilder.prototype.build = function build(dataItem, slot, outputEdgeFilterExceptions) {
- var finalSelections = [];
- if (!dataItem.getBinning()) {
- //By default, return selections in the order agreed to by PM.
- finalSelections.push.apply(finalSelections, this._buildSelectionsFromDrillStateForHierarchyOrSet(dataItem));
- finalSelections.push.apply(finalSelections, this._buildSelectionsFromLocalFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions));
- finalSelections.push.apply(finalSelections, this._buildSelectionsFromSearchFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions));
- finalSelections.push.apply(finalSelections, this._buildSelectionsForTopBottom(dataItem));
- finalSelections.push.apply(finalSelections, this._buildSelectionsForSort(dataItem, slot));
- } else {
- finalSelections.push.apply(finalSelections, this._buildSelectionsFromLocalFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions));
- finalSelections.push.apply(finalSelections, this._buildSelectionsFromSearchFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions));
- finalSelections.push.apply(finalSelections, this._buildSelectionsForSort(dataItem, slot));
- }
- return finalSelections;
- };
- //For hierarchies or OLAP set, build one of root members, children of single root or children of current drill member.
- VisQuerySelectionBuilder.prototype._buildSelectionsFromDrillStateForHierarchyOrSet = function _buildSelectionsFromDrillStateForHierarchyOrSet(dataItem) {
- var localFilters = this.internalVisualization.getLocalFilters();
- var filterList = localFilters && localFilters.getFilterList() || [];
- return _QuerySelectionBuilde.prototype._buildSelectionsFromDrillStateForHierarchyOrSet.call(this, dataItem, filterList);
- };
- VisQuerySelectionBuilder.prototype._buildSelectionsFromSearchFiltersForOLAPDataItems = function _buildSelectionsFromSearchFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions) {
- var searchFilterList = this.internalVisualization.getSearchFilterList();
- return _QuerySelectionBuilde.prototype._buildSelectionsFromFiltersForOLAPDataItems.call(this, dataItem, searchFilterList, outputEdgeFilterExceptions);
- };
- VisQuerySelectionBuilder.prototype._buildSelectionsFromLocalFiltersForOLAPDataItems = function _buildSelectionsFromLocalFiltersForOLAPDataItems(dataItem, outputEdgeFilterExceptions) {
- var localFilters = this.internalVisualization.getLocalFilters();
- var localFilterList = localFilters.getFilterList();
- return _QuerySelectionBuilde.prototype._buildSelectionsFromFiltersForOLAPDataItems.call(this, dataItem, localFilterList, outputEdgeFilterExceptions);
- };
- /*
- * Sort application priority:
- * Apply user defined sort if there is one,
- * Apply model defined sort if there is one and user defined sort doesn't exit,
- * Apply default sort
- */
- VisQuerySelectionBuilder.prototype._buildSelectionsForSort = function _buildSelectionsForSort(dataItem, slot) {
- var bClientSortEnabled = this._serverSort ? false : this._isClientSideSortEnabledForDataItem(dataItem);
- var selections = [];
- if (!bClientSortEnabled) {
- var dataItemOrModelSort = dataItem.getSort();
- var sort = !dataItem.hasDefaultSort() && dataItemOrModelSort;
- sort = sort || dataItem.hasModelSort() && dataItemOrModelSort;
- var sortObj = sort && sort.type ? sort : null;
- var isIgnoreSlotSort = this._ignoreDefaultSlotSort(dataItem);
- // 3. Default sort: preserve the hierarchical order for Olap column.
- if (!sortObj && !isIgnoreSlotSort) {
- sortObj = this._getDefaultSort(slot, dataItem);
- if (sortObj) {
- sortObj.priority = this._querySlotSortPriority++;
- }
- }
- if (sortObj) {
- var sortSelectionSpec = {
- 'operation': 'order',
- 'sort': _.pick(sortObj, 'type', 'by', 'priority')
- };
- if (sortObj.context) {
- sortSelectionSpec.context = [{
- itemId: sortObj.context
- }];
- }
- selections = [sortSelectionSpec];
- }
- }
- return selections;
- };
- VisQuerySelectionBuilder.prototype._isClientSideSortEnabledForDataItem = function _isClientSideSortEnabledForDataItem(dataItem) {
- var localSortInfo = this._localAggregateSortInfo.getSortInfo();
- if (localSortInfo) {
- return localSortInfo.aggregateDataItemId === dataItem.getId();
- }
- return false;
- };
- /**
- *
- * @param {*} slot
- * @param {*} dataItem
- * todo: the original implementation at VisDataItemManager.getDefaultSort() need to be removed once useAPI.
- */
- VisQuerySelectionBuilder.prototype._getDefaultSort = function _getDefaultSort(slot, dataItem) {
- var sortObj = null;
- var sortType = void 0;
- var topBottomInfo = dataItem.getTopBottom();
- if (topBottomInfo) {
- var topBottomType = topBottomInfo.type;
- sortType = topBottomType === 'topcount' || topBottomType === 'toppercent' ? 'desc' : 'asc';
- sortObj = {
- type: sortType
- };
- if (topBottomInfo.context) {
- //Dataitem with top/bottom will always sort by 'value'.
- sortObj.by = 'value';
- sortObj.context = topBottomInfo.context.itemId;
- }
- } else {
- // 2. Sort from slot definition, but only if there is no topBottom set
- sortType = slot.getDefinition().getSort();
- // since after binning, dataItem type is attribute, if there is no sort on slot and measure add 'asc' sort
- if (!sortType && !!dataItem.getBinning()) {
- sortType = 'asc';
- }
- if (sortType) {
- sortObj = {
- type: sortType
- };
- }
- }
- return sortObj;
- };
- /**
- *
- * Default sort is ignored in the following cases:
- * - data source is OLAP or NamedSet and no topBottom is defined or no rank is defined for the dataItem
- * - data source is not OLAP and is not NamedSet and no topBottom is defined up to the passed one and one topBottom is defined after it
- * @param {Object} dataItem - current dataItem; see {@link DataItemAPI}
- * @returns {boolean} true if the default sort is to be ignored, false otherwise
- *
- * todo: the original implementation at VisDataSlotsManager.ignoreDefaultSlotSort() need to be removed once useAPI.
- */
- VisQuerySelectionBuilder.prototype._ignoreDefaultSlotSort = function _ignoreDefaultSlotSort(dataItem) {
- var ignore = false;
- var dataItemMappingInfoList = this.internalVisualization.getSlots().getMappingInfoList();
- var indexInMappingInfoList = -1;
- _.find(dataItemMappingInfoList, function (dataItemMappingObj, ind) {
- if (dataItemMappingObj.dataItem.getId() === dataItem.getId()) {
- indexInMappingInfoList = ind;
- return true;
- }
- return false;
- });
- var dataitemTopBottom = dataItem.getTopBottom();
- if (dataItem.getMetadataColumn().isOlapColumn() || dataItem.getMetadataColumn().isNamedSet()) {
- ignore = !dataitemTopBottom || !dataitemTopBottom.rank;
- } else {
- ignore = !this._hasPreviousTopBottom(dataItemMappingInfoList, indexInMappingInfoList) && !dataitemTopBottom && this._hasFollowedTopBottom(dataItemMappingInfoList, indexInMappingInfoList);
- }
- return ignore;
- };
- /**
- * check if there is any topBottom definition previous to the passed index
- * @param {Object} dataItemMappingInfoList - arrays of mappingInfo
- * @param {number} index - index of the current dataItem
- * @returns true if there is a topBottom definition defined before the passed index, false otherwise
- */
- VisQuerySelectionBuilder.prototype._hasPreviousTopBottom = function _hasPreviousTopBottom(dataItemMappingInfoList, index) {
- var hasPrevious = false;
- for (var i = 0; i < index; i++) {
- if (dataItemMappingInfoList[i].dataItem.getTopBottom()) {
- hasPrevious = true;
- break;
- }
- }
- return hasPrevious;
- };
- /**
- * check if there is any topBottom definition after to the passed index
- * @param {Object} dataItemMappingInfoList - arrays of mappingInfo
- * @param {number} index - index of the current dataItem
- * @returns true if there is a topBottom definition defined after the passed index, false otherwise
- */
- VisQuerySelectionBuilder.prototype._hasFollowedTopBottom = function _hasFollowedTopBottom(dataItemMappingInfoList, index) {
- var hasFollowed = false;
- for (var i = index + 1; i < dataItemMappingInfoList.length; i++) {
- if (dataItemMappingInfoList[i].dataItem.getTopBottom()) {
- hasFollowed = true;
- break;
- }
- }
- return hasFollowed;
- };
- VisQuerySelectionBuilder.prototype._getDataItemsHighestSortPriority = function _getDataItemsHighestSortPriority(layerToQuerySlotsMap) {
- var maxPriority = 0;
- this._forEachQuerySlotDataItem(layerToQuerySlotsMap, function (dataItem) {
- var sortObj = dataItem.getSort();
- if (sortObj && maxPriority < sortObj.priority) {
- maxPriority = sortObj.priority;
- }
- });
- return maxPriority;
- };
- return VisQuerySelectionBuilder;
- }(QuerySelectionBuilder);
- return VisQuerySelectionBuilder;
- });
- //# sourceMappingURL=VisQuerySelectionBuilder.js.map
|