ContextualGridAction.js 5.6 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. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../widgets/livewidget/nls/StringResources', '../../dataPointActions/api/DataPointActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (APIFactory, StringResources, DataPointActionsProviderAPI, ContentActionsProviderAPI) {
  9. var ContextualGridAction = function () {
  10. function ContextualGridAction(_ref) {
  11. var dashboardAPI = _ref.dashboardAPI,
  12. content = _ref.content,
  13. features = _ref.features;
  14. _classCallCheck(this, ContextualGridAction);
  15. this.dashboard = dashboardAPI || features && features.API;
  16. this.icons = features.Icons || features['Dashboard.Icons'];
  17. if (content) {
  18. // dataPointAction will pass in the content api
  19. this.content = content;
  20. if (features) {
  21. features.DataPointActions.registerProvider('contextualGridAction', this.getAPI());
  22. }
  23. } else {
  24. features && features.ContentActions.registerProvider('contextualGridAction', this.getAPI());
  25. }
  26. }
  27. /**
  28. * dataPoint actions
  29. * @param {*} selections
  30. * @param {*} options
  31. */
  32. ContextualGridAction.prototype.getDataPointActionList = function getDataPointActionList(selections, options) {
  33. var content = this.content;
  34. var bShowAllOptions = !options.noFilters;
  35. if (bShowAllOptions && this.dashboard.getMode() === this.dashboard.MODES.EDIT) {
  36. return this._getContributionList(content, true);
  37. }
  38. return [];
  39. };
  40. ContextualGridAction.prototype._supportAction = function _supportAction(idList, content) {
  41. var enableShowDataOfViz = this._isInteractionEnabled('showData') && this.dashboard.getMode() === this.dashboard.MODES.EDIT;
  42. if (idList && idList.length > 1 || !enableShowDataOfViz) {
  43. //contexualGrid does not support multi-widget Selections
  44. return false;
  45. } else {
  46. var state = content.getFeature('state');
  47. if (state.getError()) {
  48. //don't show data when widget is in error state
  49. return false;
  50. }
  51. }
  52. return true;
  53. };
  54. /**
  55. * widgetAction interface
  56. * @param {*} idList
  57. */
  58. ContextualGridAction.prototype.getContentActionList = function getContentActionList(idList) {
  59. var contentId = idList[0];
  60. var content = this.dashboard.getCanvas().getContent(contentId);
  61. if (this._supportAction(idList, content)) {
  62. return this._getContributionList(content, false);
  63. } else {
  64. return [];
  65. }
  66. };
  67. ContextualGridAction.prototype._isSupportedFromVisDefinition = function _isSupportedFromVisDefinition(content) {
  68. var visualization = content.getFeature('Visualization');
  69. if (!visualization) {
  70. //todo: the dashboard-feature loader should support to wait content-Visualization feature is ready.
  71. return false;
  72. }
  73. var definition = visualization.getDefinition();
  74. var supportsDataBehindTheViz = false;
  75. if (definition.getProperty('isMultilayersWidget') || definition.getProperty('noDataQuery') || this.dashboard.getApplicationName() === 'dashboardTemplate') {
  76. supportsDataBehindTheViz = false;
  77. } else {
  78. supportsDataBehindTheViz = true;
  79. }
  80. return supportsDataBehindTheViz;
  81. };
  82. /**
  83. * pop up data trays if the data tray is not open. If it is open, keep it open
  84. * @return Promise
  85. */
  86. ContextualGridAction.prototype._popUpDataTray = function _popUpDataTray() {
  87. var canvasExtensions = this.dashboard.getDashboardCoreSvc('.CanvasExtensions');
  88. if (canvasExtensions) {
  89. var splitter = canvasExtensions.splitPaneView.getSplitter();
  90. var handleIndex = this.dashboard.getApplicationName() === 'story' ? 1 : 0;
  91. return splitter.toggleItem(handleIndex, true /* always show */, { sender: 'showDataBehindVisAction' });
  92. } else {
  93. return Promise.resolve();
  94. }
  95. };
  96. ContextualGridAction.prototype._getContributionList = function _getContributionList(content, shouldCloseOnActionApplied) {
  97. if (this._isSupportedFromVisDefinition(content)) {
  98. var tooltipId = 'showDataBehindVizLabel';
  99. var commonQuerySubject = this.icons.getIcon('common-querySubject');
  100. return [{
  101. name: 'contextualGridAction',
  102. label: StringResources.get(tooltipId),
  103. icon: commonQuerySubject.id,
  104. type: 'Button',
  105. group: 'ShowDataBehindVizAction',
  106. closeOnActionApplied: shouldCloseOnActionApplied,
  107. actions: {
  108. apply: this._popUpDataTray.bind(this)
  109. }
  110. }];
  111. }
  112. return [];
  113. };
  114. /**
  115. * Check whether a particular interaction is enabled.
  116. * Perspective drives this config.
  117. *
  118. * @param {string} name - interaction name
  119. *
  120. * @return {boolean} TRUE if interaction is enabled and FALSE if not
  121. */
  122. ContextualGridAction.prototype._isInteractionEnabled = function _isInteractionEnabled(name) {
  123. var config = this.dashboard.getAppConfig('interactions') || {};
  124. if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) {
  125. return false;
  126. }
  127. return true;
  128. };
  129. ContextualGridAction.prototype.getAPI = function getAPI() {
  130. //todo: we need to implement WidgetAciontsProvider as well once it is ready
  131. return APIFactory.createAPI(this, [DataPointActionsProviderAPI, ContentActionsProviderAPI]);
  132. };
  133. return ContextualGridAction;
  134. }();
  135. return ContextualGridAction;
  136. });
  137. //# sourceMappingURL=ContextualGridAction.js.map