LassoSelectAction.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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(['../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (StringResources, APIFactory, ContentActionsProviderAPI) {
  10. var LassoSelectAction = function () {
  11. function LassoSelectAction(_ref) {
  12. var features = _ref.features;
  13. _classCallCheck(this, LassoSelectAction);
  14. if (features) {
  15. this.dashboard = features.API;
  16. this.icons = features.Icons;
  17. this._actions = [{
  18. id: 'lw-lasso-select',
  19. name: 'lasso',
  20. icon: 'visualizations-marquee_16',
  21. label: StringResources.get('toolbarActionLassoSelect')
  22. }];
  23. features.ContentActions.registerProvider('lasso', this.getAPI());
  24. }
  25. }
  26. LassoSelectAction.prototype.initialize = function initialize() {
  27. var _this = this;
  28. return this.dashboard.getCollectionExtension('com.ibm.bi.dashboard.live-lassoAction').then(function (actions) {
  29. actions.forEach(function (action) {
  30. var id = action.id,
  31. name = action.name,
  32. icon = action.icon,
  33. label = action.label;
  34. _this._actions.push({ id: id, name: name, icon: icon, label: label });
  35. });
  36. });
  37. };
  38. LassoSelectAction.prototype.getAPI = function getAPI() {
  39. if (!this._api) {
  40. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  41. }
  42. return this._api;
  43. };
  44. LassoSelectAction.prototype.destroy = function destroy() {
  45. this.dashboard = null;
  46. };
  47. LassoSelectAction.prototype.getContentActionList = function getContentActionList(idList) {
  48. var _this2 = this;
  49. if (this._supportAction(idList) && this.content) {
  50. var visualizationGesture = this.content.getFeature('VisualizationGesture');
  51. return this._actions.map(function (action) {
  52. return {
  53. id: action.id,
  54. name: action.name,
  55. label: action.label,
  56. icon: _this2.icons.getIcon(action.icon) && _this2.icons.getIcon(action.icon).id,
  57. type: 'Button',
  58. selected: visualizationGesture ? visualizationGesture.getLassoSelectState() && visualizationGesture.getLassoViewId() === action.id : false,
  59. order: 50,
  60. actions: {
  61. apply: _this2._toggleLassoSelect.bind(_this2, action.id)
  62. }
  63. };
  64. });
  65. }
  66. return [];
  67. };
  68. LassoSelectAction.prototype._supportAction = function _supportAction(idList) {
  69. if (!this._isInteractionEnabled('lassoSelect')) {
  70. return false;
  71. }
  72. if (idList.length !== 1) {
  73. return false;
  74. }
  75. if (this.dashboard.getMode() === this.dashboard.MODES.EDIT_GROUP) {
  76. return false;
  77. }
  78. this.content = this.dashboard.getCanvas().getContent(idList[0]);
  79. if (!this.content) {
  80. return false;
  81. }
  82. var visualization = this.content.getFeature('Visualization');
  83. if (!visualization || visualization.getDefinition().getState().getError() || !visualization.getSlots().isMappingComplete()) {
  84. return false;
  85. }
  86. var state = this.content.getFeature('state');
  87. var hasError = Boolean(state && !!state.getError());
  88. if (hasError) {
  89. return false;
  90. }
  91. return this.content.getType() === 'widget.live' && this._isSupportedVisualizationType(visualization.getType()) && !visualization.getDefinition().getProperty('isSchematic') && !visualization.getDefinition().getProperty('isCustomVis');
  92. };
  93. LassoSelectAction.prototype._isSupportedVisualizationType = function _isSupportedVisualizationType(type) {
  94. var visDefsNoLassoSelect = ['Singleton', 'DataPlayer', 'Crosstab', 'List', 'Hierarchy', 'KPI', 'Pie', 'Wordle', 'Area', 'Dial', 'Bullet', 'DecisionTree', 'Sunburst', 'Spiral', 'DriverAnalysis', 'visualizationPreview', 'snippetList'];
  95. return !(visDefsNoLassoSelect.indexOf(type) !== -1);
  96. };
  97. /**
  98. * Check whether a particular interaction is enabled.
  99. * Perspective drives this config.
  100. *
  101. * @param {string} name - interaction name
  102. *
  103. * @return {boolean} TRUE if interaction is enabled and FALSE if not
  104. */
  105. LassoSelectAction.prototype._isInteractionEnabled = function _isInteractionEnabled(name) {
  106. var config = this._getInteractionConfig();
  107. if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) {
  108. return false;
  109. }
  110. return true;
  111. };
  112. LassoSelectAction.prototype._getInteractionConfig = function _getInteractionConfig() {
  113. return this.dashboard.getAppConfig('interactions') || {};
  114. };
  115. /**
  116. * Action invoked to toggle laaso selection on a viz
  117. */
  118. LassoSelectAction.prototype._toggleLassoSelect = function _toggleLassoSelect(viewId, event) {
  119. var visualizationGesture = this.content.getFeature('VisualizationGesture');
  120. if (visualizationGesture) {
  121. var lassoState = visualizationGesture.getLassoSelectState();
  122. visualizationGesture.setLassoSelectState(!lassoState, viewId);
  123. var toolbar = this.content.getFeature('Toolbar.internal');
  124. if (toolbar) {
  125. toolbar.refresh();
  126. } else {
  127. //Ideally, toolbar should exist for content, but explore doesn't use this feature and have their toolbar ¯\_(ツ)_/¯
  128. //Manually select the button
  129. //Future realses will have a better impelemtation.
  130. var $toolBarItem = event && event.currentTarget;
  131. if ($toolBarItem) {
  132. if (lassoState) {
  133. $toolBarItem.classList.remove('selected');
  134. } else {
  135. $toolBarItem.classList.add('selected');
  136. }
  137. }
  138. }
  139. }
  140. };
  141. return LassoSelectAction;
  142. }();
  143. return LassoSelectAction;
  144. });
  145. //# sourceMappingURL=LassoSelectAction.js.map