123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- '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: Content Explorer
- *| (C) Copyright IBM Corp. 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../common/DataPointActionBase', '../api/DataPointActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../widgets/livewidget/nls/StringResources', 'underscore'], function (DataPointActionBase, DataPointActionsProviderAPI, APIFactory, stringResources, _) {
- var DrillAction = function (_DataPointActionBase) {
- _inherits(DrillAction, _DataPointActionBase);
- function DrillAction(options) {
- _classCallCheck(this, DrillAction);
- var _this = _possibleConstructorReturn(this, _DataPointActionBase.call(this, options));
- _this.content.getFeature('DataPointActions').registerProvider('DrillAction', _this.getAPI());
- _this.icons = options.features['Dashboard.Icons'];
- return _this;
- }
- DrillAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [DataPointActionsProviderAPI]);
- }
- return this._api;
- };
- DrillAction.prototype.getDataPointActionList = function getDataPointActionList(selections, actionOptions) {
- var actionList = [];
- var dashboardNavigationDrillup = this.icons.getIcon('dashboard-navigation-drillback');
- var dashboardNavigationDrilldown = this.icons.getIcon('dashboard-navigation-drilldown');
- if (this._supportAction(selections, actionOptions)) {
- var bDisableDrillDownOption = !this._canDrillDown(selections);
- var bDisableDrillUpOption = !this._canDrillUp(selections);
- actionList.push.apply(actionList, [{
- name: 'drillUp',
- label: stringResources.get('toolbarActionDrillUp'),
- text: stringResources.get('toolbarActionDrillUp'),
- icon: dashboardNavigationDrillup.id,
- type: 'Button',
- closeOnActionApplied: true,
- disabled: bDisableDrillUpOption,
- actions: {
- apply: this.drillUp.bind(this, selections)
- }
- }, {
- name: 'drillDown',
- label: stringResources.get('toolbarActionDrillDown'),
- text: stringResources.get('toolbarActionDrillDown'),
- icon: dashboardNavigationDrilldown.id,
- type: 'Button',
- closeOnActionApplied: true,
- disabled: bDisableDrillDownOption,
- actions: {
- apply: this.drillDown.bind(this, selections)
- }
- }]);
- }
- return actionList;
- };
- DrillAction.prototype._getVisualization = function _getVisualization() {
- if (!this.visualization) {
- this.visualization = this.content.getFeature('Visualization');
- }
- return this.visualization;
- };
- DrillAction.prototype._getSelectedCategories = function _getSelectedCategories(selections) {
- return _.compact(_.pluck(selections.dataPoints, 'categories'));
- };
- DrillAction.prototype._supportAction = function _supportAction() {
- var selections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var actionOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var support = !actionOptions.noFilters || actionOptions.drillOnly;
- if (!support) {
- return support;
- }
- // Support one member from one column.
- var categories = this._getSelectedCategories(selections);
- support = categories && categories.length === 1 && categories[0].length === 1;
- if (!support) {
- return support;
- }
- var columnId = categories[0][0].columnId;
- var dataSource = this._getVisualization().getDataSource();
- var metadataColumn = dataSource.getMetadataColumn(columnId);
- return metadataColumn && (metadataColumn.isHierarchy() || metadataColumn.isNamedSet());
- };
- DrillAction.prototype._getSelectionMappingInfo = function _getSelectionMappingInfo(selections) {
- var slots = this._getVisualization().getSlots();
- var selectedCategories = this._getSelectedCategories(selections);
- var dataItemId = selectedCategories[0][0].dataItemId;
- var dataItemMappingInfo = slots.getMappingInfo(dataItemId);
- return dataItemMappingInfo;
- };
- DrillAction.prototype._executeDrill = function _executeDrill(drillDataItem, drillFunction) {
- var transaction = this.dashboard.getFeature('Transaction');
- var localTransactionToken = transaction.startTransaction();
- var localFilters = this._getVisualization().getLocalFilters();
- localFilters.removeFilter({
- itemId: drillDataItem.getColumnId()
- }, localTransactionToken);
- return drillFunction(localTransactionToken).finally(function () {
- transaction.endTransaction(localTransactionToken);
- });
- };
- DrillAction.prototype.drillUp = function drillUp(selections) {
- var drillDataItem = this._getSelectionMappingInfo(selections).dataItem;
- var memberId = this._getSelectedCategories(selections)[0][0].parentId;
- this._executeDrill(drillDataItem, function (transactionToken) {
- return drillDataItem.drillUp(memberId, transactionToken);
- });
- };
- DrillAction.prototype.drillDown = function drillDown(selections) {
- var drillDataItem = this._getSelectionMappingInfo(selections).dataItem;
- var selectedCategories = this._getSelectedCategories(selections);
- var memberId = selectedCategories[0][0].value;
- var parentId = selectedCategories[0][0].parentId;
- this._executeDrill(drillDataItem, function (transactionToken) {
- return drillDataItem.drillDown(memberId, transactionToken, parentId);
- });
- };
- DrillAction.prototype._canDrillDown = function _canDrillDown(selections) {
- return this._getSelectionMappingInfo(selections).dataItem.canDrillDown();
- };
- DrillAction.prototype._canDrillUp = function _canDrillUp(selections) {
- var parentId = this._getSelectedCategories(selections)[0][0].parentId;
- return parentId !== undefined;
- };
- return DrillAction;
- }(DataPointActionBase);
- return DrillAction;
- });
- //# sourceMappingURL=DrillAction.js.map
|