HideRowColumnAction.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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(['underscore', '../../../../widgets/livewidget/nls/StringResources', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../api/DataPointActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../util/ContentUtil'], function (_, stringResources, APIFactory, DataPointActionsProviderAPI, ContentActionsProviderAPI, ContentUtil) {
  9. var PROPERTYNAME = 'hiddenRowsAndColumns';
  10. var LOCALVIS = ['crosstab'];
  11. var HideRowColumnAction = function () {
  12. function HideRowColumnAction(_ref) {
  13. var dashboardAPI = _ref.dashboardAPI,
  14. content = _ref.content,
  15. features = _ref.features;
  16. _classCallCheck(this, HideRowColumnAction);
  17. this.dashboard = dashboardAPI || features && features.API;
  18. this.icons = features['Icons'] || features['Dashboard.Icons'];
  19. if (content) {
  20. // dataPointAction will pass in the content api
  21. this.content = content;
  22. if (features) {
  23. features.DataPointActions.registerProvider('HideRowColumnAction', this.getAPI());
  24. }
  25. } else {
  26. features && features.ContentActions.registerProvider('HideRowColumnAction', this.getAPI());
  27. }
  28. }
  29. HideRowColumnAction.prototype.getDataPointActionList = function getDataPointActionList(selections, options) {
  30. if (this._isLocalVis() && this._supportDataPointAction() && options.isAreaSelected) {
  31. this.selectedArea = ContentUtil.getContextFromSelection(this.content, this.dashboard);
  32. // if the selection is not valid, disable the action
  33. if (!this.selectedArea.length) {
  34. return [];
  35. }
  36. this.isAreaSelected = true;
  37. var iconHide = this.icons.getIcon('iconHide');
  38. return this._getContribution('Datapoint', stringResources.get('hideRowColumn'), iconHide, false);
  39. }
  40. return [];
  41. };
  42. HideRowColumnAction.prototype._supportDataPointAction = function _supportDataPointAction() {
  43. if (this.content.getFeature('state').getError() || this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
  44. return false;
  45. }
  46. return true;
  47. };
  48. /**
  49. * widgetAction interface
  50. * @param {*} idList
  51. */
  52. HideRowColumnAction.prototype.getContentActionList = function getContentActionList(idList) {
  53. var contentId = idList[0];
  54. this.content = this.dashboard.getCanvas().getContent(contentId);
  55. if (this._isLocalVis() && this._supportContentAction(idList)) {
  56. var iconView = this.icons.getIcon('iconView');
  57. return this._getContribution('Content', stringResources.get('showAllRowColumn'), iconView, this._isHidden());
  58. }
  59. return [];
  60. };
  61. HideRowColumnAction.prototype._getContribution = function _getContribution(actionOrigin, actionName, icon, isDisabled) {
  62. return [{
  63. name: 'hideRowColumnAction' + actionOrigin,
  64. label: actionName,
  65. icon: icon.id,
  66. type: 'Button',
  67. closeOnActionApplied: true,
  68. disabled: isDisabled,
  69. actions: {
  70. apply: this.onStateChange.bind(this)
  71. }
  72. }];
  73. };
  74. HideRowColumnAction.prototype._supportContentAction = function _supportContentAction(idList) {
  75. if (idList && idList.length > 1 || this.content.getFeature('state').getError() || this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
  76. return false;
  77. }
  78. return true;
  79. };
  80. HideRowColumnAction.prototype._isLocalVis = function _isLocalVis() {
  81. var visFeature = this.content.getFeature('Visualization');
  82. var visId = visFeature && visFeature.getDefinition().getId();
  83. return !!visId && _.contains(LOCALVIS, visId);
  84. };
  85. HideRowColumnAction.prototype.onStateChange = function onStateChange() {
  86. var propertyList = [];
  87. propertyList = this._buildPropertyList(propertyList);
  88. var transactionToken = this.dashboard.getFeature('Transaction').startTransaction();
  89. this.setProperties(propertyList, transactionToken);
  90. this._removeFilters(transactionToken);
  91. this.dashboard.getFeature('Transaction').endTransaction(transactionToken);
  92. };
  93. HideRowColumnAction.prototype._isHidden = function _isHidden() {
  94. return _.isEmpty(this.content.getPropertyValue(PROPERTYNAME) || []);
  95. };
  96. HideRowColumnAction.prototype._buildPropertyList = function _buildPropertyList(propertyList) {
  97. var newPropertyVal = [];
  98. if (this.isAreaSelected) {
  99. var currentPropertyValue = this.content.getPropertyValue(PROPERTYNAME) || [];
  100. newPropertyVal = _.union(this.selectedArea, currentPropertyValue);
  101. }
  102. propertyList.push({ 'id': PROPERTYNAME, 'value': newPropertyVal });
  103. return propertyList;
  104. };
  105. /**
  106. * This method sets the vis properties to the value given
  107. * @param propertyList - the propertyList that trigerred the state change
  108. */
  109. HideRowColumnAction.prototype.setProperties = function setProperties(propertyList, transactionToken) {
  110. var _this = this;
  111. propertyList.forEach(function (prop) {
  112. _this.content.setPropertyValue(prop.id, prop.value, transactionToken);
  113. });
  114. };
  115. HideRowColumnAction.prototype._removeFilters = function _removeFilters(transactionToken) {
  116. this.dashboard.getFeature('GlobalFilters').removeFilters(ContentUtil.getSelectors(this.content, this.dashboard), transactionToken);
  117. };
  118. HideRowColumnAction.prototype.getAPI = function getAPI() {
  119. if (!this._api) {
  120. return APIFactory.createAPI(this, [DataPointActionsProviderAPI, ContentActionsProviderAPI]);
  121. }
  122. return this._api;
  123. };
  124. return HideRowColumnAction;
  125. }();
  126. return HideRowColumnAction;
  127. });
  128. //# sourceMappingURL=HideRowColumnAction.js.map