DrillAction.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: Content Explorer
  9. *| (C) Copyright IBM Corp. 2019
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['../../common/DataPointActionBase', '../api/DataPointActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../widgets/livewidget/nls/StringResources', 'underscore'], function (DataPointActionBase, DataPointActionsProviderAPI, APIFactory, stringResources, _) {
  16. var DrillAction = function (_DataPointActionBase) {
  17. _inherits(DrillAction, _DataPointActionBase);
  18. function DrillAction(options) {
  19. _classCallCheck(this, DrillAction);
  20. var _this = _possibleConstructorReturn(this, _DataPointActionBase.call(this, options));
  21. _this.content.getFeature('DataPointActions').registerProvider('DrillAction', _this.getAPI());
  22. _this.icons = options.features['Dashboard.Icons'];
  23. return _this;
  24. }
  25. DrillAction.prototype.getAPI = function getAPI() {
  26. if (!this._api) {
  27. this._api = APIFactory.createAPI(this, [DataPointActionsProviderAPI]);
  28. }
  29. return this._api;
  30. };
  31. DrillAction.prototype.getDataPointActionList = function getDataPointActionList(selections, actionOptions) {
  32. var actionList = [];
  33. var dashboardNavigationDrillup = this.icons.getIcon('dashboard-navigation-drillback');
  34. var dashboardNavigationDrilldown = this.icons.getIcon('dashboard-navigation-drilldown');
  35. if (this._supportAction(selections, actionOptions)) {
  36. var bDisableDrillDownOption = !this._canDrillDown(selections);
  37. var bDisableDrillUpOption = !this._canDrillUp(selections);
  38. actionList.push.apply(actionList, [{
  39. name: 'drillUp',
  40. label: stringResources.get('toolbarActionDrillUp'),
  41. text: stringResources.get('toolbarActionDrillUp'),
  42. icon: dashboardNavigationDrillup.id,
  43. type: 'Button',
  44. closeOnActionApplied: true,
  45. disabled: bDisableDrillUpOption,
  46. actions: {
  47. apply: this.drillUp.bind(this, selections)
  48. }
  49. }, {
  50. name: 'drillDown',
  51. label: stringResources.get('toolbarActionDrillDown'),
  52. text: stringResources.get('toolbarActionDrillDown'),
  53. icon: dashboardNavigationDrilldown.id,
  54. type: 'Button',
  55. closeOnActionApplied: true,
  56. disabled: bDisableDrillDownOption,
  57. actions: {
  58. apply: this.drillDown.bind(this, selections)
  59. }
  60. }]);
  61. }
  62. return actionList;
  63. };
  64. DrillAction.prototype._getVisualization = function _getVisualization() {
  65. if (!this.visualization) {
  66. this.visualization = this.content.getFeature('Visualization');
  67. }
  68. return this.visualization;
  69. };
  70. DrillAction.prototype._getSelectedCategories = function _getSelectedCategories(selections) {
  71. return _.compact(_.pluck(selections.dataPoints, 'categories'));
  72. };
  73. DrillAction.prototype._supportAction = function _supportAction() {
  74. var selections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  75. var actionOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  76. var support = !actionOptions.noFilters || actionOptions.drillOnly;
  77. if (!support) {
  78. return support;
  79. }
  80. // Support one member from one column.
  81. var categories = this._getSelectedCategories(selections);
  82. support = categories && categories.length === 1 && categories[0].length === 1;
  83. if (!support) {
  84. return support;
  85. }
  86. var columnId = categories[0][0].columnId;
  87. var dataSource = this._getVisualization().getDataSource();
  88. var metadataColumn = dataSource.getMetadataColumn(columnId);
  89. return metadataColumn && (metadataColumn.isHierarchy() || metadataColumn.isNamedSet());
  90. };
  91. DrillAction.prototype._getSelectionMappingInfo = function _getSelectionMappingInfo(selections) {
  92. var slots = this._getVisualization().getSlots();
  93. var selectedCategories = this._getSelectedCategories(selections);
  94. var dataItemId = selectedCategories[0][0].dataItemId;
  95. var dataItemMappingInfo = slots.getMappingInfo(dataItemId);
  96. return dataItemMappingInfo;
  97. };
  98. DrillAction.prototype._executeDrill = function _executeDrill(drillDataItem, drillFunction) {
  99. var transaction = this.dashboard.getFeature('Transaction');
  100. var localTransactionToken = transaction.startTransaction();
  101. var localFilters = this._getVisualization().getLocalFilters();
  102. localFilters.removeFilter({
  103. itemId: drillDataItem.getColumnId()
  104. }, localTransactionToken);
  105. return drillFunction(localTransactionToken).finally(function () {
  106. transaction.endTransaction(localTransactionToken);
  107. });
  108. };
  109. DrillAction.prototype.drillUp = function drillUp(selections) {
  110. var drillDataItem = this._getSelectionMappingInfo(selections).dataItem;
  111. var memberId = this._getSelectedCategories(selections)[0][0].parentId;
  112. this._executeDrill(drillDataItem, function (transactionToken) {
  113. return drillDataItem.drillUp(memberId, transactionToken);
  114. });
  115. };
  116. DrillAction.prototype.drillDown = function drillDown(selections) {
  117. var drillDataItem = this._getSelectionMappingInfo(selections).dataItem;
  118. var selectedCategories = this._getSelectedCategories(selections);
  119. var memberId = selectedCategories[0][0].value;
  120. var parentId = selectedCategories[0][0].parentId;
  121. this._executeDrill(drillDataItem, function (transactionToken) {
  122. return drillDataItem.drillDown(memberId, transactionToken, parentId);
  123. });
  124. };
  125. DrillAction.prototype._canDrillDown = function _canDrillDown(selections) {
  126. return this._getSelectionMappingInfo(selections).dataItem.canDrillDown();
  127. };
  128. DrillAction.prototype._canDrillUp = function _canDrillUp(selections) {
  129. var parentId = this._getSelectedCategories(selections)[0][0].parentId;
  130. return parentId !== undefined;
  131. };
  132. return DrillAction;
  133. }(DataPointActionBase);
  134. return DrillAction;
  135. });
  136. //# sourceMappingURL=DrillAction.js.map