SwapRowColumnAction.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(['../../../../widgets/livewidget/nls/StringResources', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (stringResources, ContentActionsProviderAPI, APIFactory) {
  9. var SwapRowColumnAction = function () {
  10. function SwapRowColumnAction(dashboard, dashboardState, icons) {
  11. _classCallCheck(this, SwapRowColumnAction);
  12. this._dashboard = dashboard;
  13. this._dashboardState = dashboardState;
  14. this._icons = icons;
  15. }
  16. SwapRowColumnAction.prototype.getContentActionList = function getContentActionList(idList) {
  17. var contribution = [];
  18. if (this._getSelectedContent(idList)) {
  19. var contentId = idList[0];
  20. var content = this._dashboard.getCanvas().getContent(contentId);
  21. var visualization = content.getFeature('Visualization');
  22. var swapIcon = this._icons.getIcon('dashboard-swap');
  23. if (this._supportAction(content)) {
  24. contribution = [{
  25. name: 'swapRowsAndColumns',
  26. label: stringResources.get('swapRowsAndColumns'),
  27. icon: swapIcon.id,
  28. actions: {
  29. apply: this.swapRowsAndColumns.bind(this, visualization)
  30. },
  31. type: 'Button'
  32. }];
  33. }
  34. }
  35. return contribution;
  36. };
  37. SwapRowColumnAction.prototype.swapRowsAndColumns = function swapRowsAndColumns(visualization) {
  38. visualization.getSlots().swapSlots('column_level1', 'row_level1');
  39. };
  40. SwapRowColumnAction.prototype._supportAction = function _supportAction(content) {
  41. var isAllowed = false;
  42. var uiState = this._dashboardState.getUiState();
  43. var visualization = content.getFeature('Visualization');
  44. if (visualization && !uiState.eventGroups) {
  45. var visId = visualization.getDefinition().getId();
  46. var mappingComplete = visualization.getSlots().isMappingComplete();
  47. isAllowed = mappingComplete && visId === 'crosstab';
  48. }
  49. return isAllowed;
  50. };
  51. SwapRowColumnAction.prototype._getSelectedContent = function _getSelectedContent(idList) {
  52. return idList.length === 1;
  53. };
  54. SwapRowColumnAction.prototype.getAPI = function getAPI() {
  55. if (!this._api) {
  56. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  57. }
  58. return this._api;
  59. };
  60. return SwapRowColumnAction;
  61. }();
  62. return SwapRowColumnAction;
  63. });
  64. //# sourceMappingURL=SwapRowColumnAction.js.map