JumpToAction.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: Dashboard
  6. * (C) Copyright IBM Corp. 2019, 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', '../../../util/JumpToActionHelper', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../content/slotActions/api/SlotActionsProviderAPI', '../../content/dataPointActions/api/DataPointActionsProviderAPI', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../widgets/livewidget/nls/StringResources'], function (_, JumpToActionHelper, APIFactory, SlotActionsProviderAPI, DataPointActionsProviderAPI, ContentActionsProviderAPI, StringResources) {
  10. return function () {
  11. function JumpToAction(options) {
  12. _classCallCheck(this, JumpToAction);
  13. this._dashboard = options.features && options.features.API || options.dashboardAPI;
  14. this._icons = options.features.Icons || options.features['Dashboard.Icons'];
  15. if (options.content) {
  16. this._content = options.content;
  17. this._content.getFeature('SlotActions').registerProvider('jumpToAction', this.getAPI());
  18. this._content.getFeature('DataPointActions').registerProvider('jumpToAction', this.getAPI());
  19. } else {
  20. options.features && options.features.ContentActions.registerProvider('jumpToAction', this.getAPI());
  21. }
  22. }
  23. JumpToAction.prototype.destroy = function destroy() {
  24. this._dashboard = null;
  25. this._content = null;
  26. };
  27. JumpToAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex) {
  28. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  29. // Valid values will be any number or an array of 1 number
  30. if (Array.isArray(itemIndex) && itemIndex.length !== 1) {
  31. return [];
  32. }
  33. if (options.area === 'cell_edge_row' || options.area === 'cell_edge_column') {
  34. return [];
  35. }
  36. return this._getContribution();
  37. };
  38. JumpToAction.prototype.getDataPointActionList = function getDataPointActionList(selections, actionOptions) {
  39. return this._supportDataPointAction(actionOptions) ? this._getContribution(selections, actionOptions) : [];
  40. };
  41. JumpToAction.prototype._supportDataPointAction = function _supportDataPointAction(actionOptions) {
  42. return !actionOptions.noDrillthrough;
  43. };
  44. JumpToAction.prototype._supportAction = function _supportAction(idList) {
  45. if (idList.length !== 1 || this._dashboard.getMode() === this._dashboard.MODES.EDIT_GROUP) {
  46. return false;
  47. }
  48. this._content = this._dashboard.getCanvas().getContent(idList[0]);
  49. return this._content && this._content.getType() === 'widget.live';
  50. };
  51. JumpToAction.prototype.getContentActionList = function getContentActionList(idList) {
  52. if (this._supportAction(idList)) {
  53. this._content = this._dashboard.getCanvas().getContent(idList[0]);
  54. return this._getDrillThroughToolbarContribution();
  55. }
  56. return [];
  57. };
  58. JumpToAction.prototype._getTargetInfo = function _getTargetInfo(content, dataSourceId, selections) {
  59. //@todo also take into account net page context (next thing to do)
  60. var drillThroughModel = this._dashboard.getFeature('DrillThroughService').getDrillThroughModelApiSync();
  61. var entries = drillThroughModel.getDrillDefinitionEntries(content);
  62. return JumpToActionHelper.getJumpToTargets({
  63. content: content,
  64. drillDefinitions: entries,
  65. selections: selections,
  66. dashboardApi: this._dashboard,
  67. sourceId: dataSourceId
  68. });
  69. };
  70. JumpToAction.prototype._getContribution = function _getContribution(selections) {
  71. var jumpToTargets = [];
  72. var toolbarContribution = [];
  73. var visualizationAPI = this._content.getFeature('Visualization');
  74. var dataSource = visualizationAPI.getDataSource();
  75. var dataSourceId = dataSource.getId();
  76. jumpToTargets = this._getTargetInfo(this._content, dataSourceId, selections);
  77. if (jumpToTargets.targets.length > 0) {
  78. var contribution = this._getContributionAction({
  79. oTargetsInfo: jumpToTargets,
  80. isDataPointSelection: true,
  81. sourceId: dataSourceId,
  82. selections: selections
  83. });
  84. toolbarContribution = [contribution];
  85. }
  86. return toolbarContribution;
  87. };
  88. JumpToAction.prototype._isAutoGrouped = function _isAutoGrouped(visualizationAPI) {
  89. var dataItems = visualizationAPI.getSlots().getDataItemList();
  90. var bAutoGroup = false;
  91. dataItems.forEach(function (dataItem) {
  92. if (dataItem.getBinning()) {
  93. bAutoGroup = true;
  94. }
  95. });
  96. return bAutoGroup;
  97. };
  98. JumpToAction.prototype._getDrillThroughToolbarContribution = function _getDrillThroughToolbarContribution() {
  99. var visualizationAPI = this._content.getFeature('Visualization');
  100. // Do not show drillthrough if autoGroup is enabled
  101. var visDefinitionType = visualizationAPI && visualizationAPI.getDefinition() && visualizationAPI.getDefinition().getType();
  102. if (visDefinitionType && !this._isAutoGrouped(visualizationAPI)) {
  103. var dataSource = visualizationAPI.getDataSource();
  104. if (!dataSource || !this._isInteractionEnabled('drillThrough')) {
  105. return [];
  106. }
  107. var dataSourceId = dataSource.getId();
  108. var oTargetsInfo = this._getTargetInfo(this._content, dataSourceId);
  109. var noTargets = oTargetsInfo.targets && !oTargetsInfo.targets.length;
  110. var _dashboard$getFeature = this._dashboard.getFeature('DashboardState').getUiState(),
  111. authoring = _dashboard$getFeature.authoring;
  112. if (!authoring && noTargets) {
  113. return [];
  114. }
  115. return [this._getContributionAction({
  116. sourceId: dataSourceId,
  117. oTargetsInfo: oTargetsInfo,
  118. isAuthoringMode: authoring
  119. })];
  120. }
  121. return [];
  122. };
  123. JumpToAction.prototype._getContributionAction = function _getContributionAction() {
  124. var _this = this;
  125. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  126. var oTargetsInfo = options.oTargetsInfo;
  127. var isAuthoringMode = !!options.isAuthoringMode;
  128. var isDataPointSelection = !!options.isDataPointSelection;
  129. var drillThroughIcon = this._icons.getIcon('visualizations-drillthrough_16');
  130. var oneTarget = void 0;
  131. if (isDataPointSelection) {
  132. oneTarget = oTargetsInfo.targets && oTargetsInfo.targets.length === 1;
  133. } else {
  134. oneTarget = isAuthoringMode ? false : oTargetsInfo.targets && oTargetsInfo.targets.length === 1;
  135. }
  136. var contribution = {
  137. name: 'jumpTo',
  138. label: StringResources.get('drillthrough_jumpToLabel'),
  139. icon: drillThroughIcon.id,
  140. viewOptions: {
  141. content: this._content,
  142. sourceId: options.sourceId,
  143. jumpToTargets: function jumpToTargets(content, dataSourceId, selections) {
  144. return _this._getTargetInfo(content, dataSourceId, selections);
  145. },
  146. isDataPointSelection: isDataPointSelection,
  147. dashboardApi: this._dashboard,
  148. selections: options.selections
  149. }
  150. };
  151. if (oneTarget) {
  152. contribution = _.extend(contribution, {
  153. type: 'Button',
  154. actions: {
  155. apply: this._performDirectJumpTo.bind(this, oTargetsInfo)
  156. }
  157. });
  158. } else {
  159. contribution = _.extend(contribution, {
  160. type: 'NextView',
  161. viewModule: 'dashboard-analytics/drill-through/jumpTo/JumpToView'
  162. });
  163. }
  164. return contribution;
  165. };
  166. JumpToAction.prototype._performDirectJumpTo = function _performDirectJumpTo(targetsInfo) {
  167. if (targetsInfo && _.isArray(targetsInfo.targets) && !!targetsInfo.targets.length) {
  168. var id = targetsInfo.targets[0].getId();
  169. var target = targetsInfo.targetsMap[id];
  170. if (target) {
  171. target.jumpTo();
  172. }
  173. }
  174. };
  175. JumpToAction.prototype._isInteractionEnabled = function _isInteractionEnabled(name) {
  176. var config = this._dashboard.getAppConfig('interactions') || {};
  177. if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) {
  178. return false;
  179. }
  180. return true;
  181. };
  182. JumpToAction.prototype.getAPI = function getAPI() {
  183. if (!this._api) {
  184. this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI, ContentActionsProviderAPI, DataPointActionsProviderAPI]);
  185. }
  186. return this._api;
  187. };
  188. return JumpToAction;
  189. }();
  190. });
  191. //# sourceMappingURL=JumpToAction.js.map