'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: 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(['../../../../widgets/livewidget/nls/StringResources', 'underscore', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../api/SlotActionsProviderAPI', '../../../../apiHelpers/SlotAPIHelper', './TopBottomActionAPI'], function (stringResources, _, APIFactory, SlotActionsProviderAPI, SlotAPIHelper, TopBottomActionAPI) { return function () { function TopBottomAction(options) { _classCallCheck(this, TopBottomAction); this.content = options.content; this.dashboardApi = options.dashboardAPI; this.icons = options.features && options.features['Dashboard.Icons']; this.content.getFeature('SlotActions').registerProvider('topBottomAction', this.getAPI()); } TopBottomAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex) { var dataSlot = this.getVisualization().getSlots().getSlot(dataSlotId); if (dataSlot && this._supportAction(dataSlot, itemIndex)) { this.slot = dataSlot; var slotId = dataSlot.getDefinition().getId(); this.dataItemIndex = itemIndex ? parseInt(itemIndex) : 0; this.dataItem = this.slot.getDataItemList()[this.dataItemIndex]; var viewOptions = this.getViewState(); viewOptions.getTopBottomState = this.dataItem.getTopBottom.bind(this); viewOptions.contextColumns = this._isAttribute() && this._getFactColumns(); viewOptions.allowPercentOperations = this._isAttribute(); viewOptions.allowRankColumn = this.getVisualization().getDefinition().getId() === 'JQGrid'; viewOptions.onSearch = this._onSearch.bind(this); var topbottomIcon = this.icons.getIcon('dashboard-topbottom'); return [{ name: 'topBottomAction', label: stringResources.get('toolbarActionTopBottom'), icon: topbottomIcon.id, type: 'NextView', view: { module: 'dashboard-analytics/lib/@waca/dashboard-common/dist/ui/dialogs/TopBottomDialog', state: viewOptions }, actions: { apply: this.applyTopBottomValues.bind(this, slotId, itemIndex), reset: this.reset.bind(this, slotId, itemIndex) } }]; } return []; }; TopBottomAction.prototype._supportAction = function _supportAction(dataSlot, itemIndex) { if (this._isMultiMeasureDataSlot(dataSlot, itemIndex)) { return false; } itemIndex = itemIndex || 0; if (Array.isArray(itemIndex) && itemIndex.length != 1) { return false; } var dataItem = dataSlot.getDataItemList()[itemIndex]; if (!dataItem) { return false; // when right click on an empty summary widget } var column = dataItem.getMetadataColumn(); if (column === null) { return false; } var columnType = column.getType(); var visDefinitionApi = this.getVisualization().getDefinition(); var dataItemType = dataItem.getType(); if (columnType === 'fact' || dataItemType === 'fact') { if (!visDefinitionApi.getProperty('supportsNonContextualTopBottomAction')) { return false; } } else { if (!visDefinitionApi.getProperty('supportsContextualTopBottomAction')) { return false; } } return !dataItem.getBinning() && column.getSourceCategory() !== 'property'; }; TopBottomAction.prototype._getFactColumns = function _getFactColumns() { return _.unique(this.getVisualization().getDataSource().findMetadataColumns('', 'fact')); }; TopBottomAction.prototype._onSearch = function _onSearch(searchTerm) { return _.unique(this.getVisualization().getDataSource().findMetadataColumns(searchTerm, 'fact')); }; //DEFECT 253869 //Verify if mapIndex is defined to differentiate when we're selecting specific data item that is a multi measure or multiple data items (get actions for y axis) TopBottomAction.prototype._isMultiMeasureDataSlot = function _isMultiMeasureDataSlot(dataSlot, itemIndex) { return dataSlot && itemIndex == undefined ? SlotAPIHelper.isMultiMeasuresSeriesSlot(dataSlot) || SlotAPIHelper.isMultiMeasuresValueSlot(dataSlot) : false; }; TopBottomAction.prototype.getViewState = function getViewState() { if (this.slot) { var options = { height: 280, width: 400 // those are hints only; for the placement of the toolbar. }; return options; } return null; }; TopBottomAction.prototype._isAttribute = function _isAttribute() { return this.dataItem.getType() === 'attribute' && this.dataItem.getMetadataColumn() && this.dataItem.getMetadataColumn().getType() === 'attribute'; }; TopBottomAction.prototype._addAggregateToContext = function _addAggregateToContext(state) { var contextColumnId = state.context && state.context.itemId; if (!contextColumnId) { // Do not add aggregation to context if without context return; } var dataItemList = this.getVisualization().getSlots().getDataItemList(); if (dataItemList && dataItemList.length > 0) { var dataItem = dataItemList.find(function (item) { return item.getColumnId() === contextColumnId; }); var contextItemAggregate = void 0; if (dataItem) { contextItemAggregate = dataItem.getAggregation(); } else { // Assign context item default aggregation type if is not projected but with context column var contextColumn = this.getVisualization().getDataSource().getMetadataColumn(contextColumnId); contextItemAggregate = contextColumn && contextColumn.getDefaultAggregation(); } if (contextItemAggregate) { state.context.aggregate = contextItemAggregate; } } }; TopBottomAction.prototype.applyTopBottomValues = function applyTopBottomValues(dataSlotId, itemIndex, state) { itemIndex = itemIndex || 0; this.slot = this.getVisualization().getSlots().getSlot(dataSlotId); this.dataItem = this.slot.getDataItemList()[itemIndex]; if (state) { this._addAggregateToContext(state); this.dataItem.setTopBottom(state); } else { this.dataItem.setTopBottom(); } }; TopBottomAction.prototype.reset = function reset(dataSlotId, itemIndex) { this.slot = this.getVisualization().getSlots().getSlot(dataSlotId); this.dataItem = this.slot.getDataItemList()[itemIndex]; this.applyTopBottomValues(dataSlotId, itemIndex); }; TopBottomAction.prototype.getVisualization = function getVisualization() { if (!this.visualization) { this.visualization = this.content.getFeature('Visualization'); } return this.visualization; }; TopBottomAction.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI, TopBottomActionAPI]); } return this._api; }; return TopBottomAction; }(); }); //# sourceMappingURL=TopBottomAction.js.map