TopBottomAction.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. 2018, 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', 'underscore', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../api/SlotActionsProviderAPI', '../../../../apiHelpers/SlotAPIHelper', './TopBottomActionAPI'], function (stringResources, _, APIFactory, SlotActionsProviderAPI, SlotAPIHelper, TopBottomActionAPI) {
  10. return function () {
  11. function TopBottomAction(options) {
  12. _classCallCheck(this, TopBottomAction);
  13. this.content = options.content;
  14. this.dashboardApi = options.dashboardAPI;
  15. this.icons = options.features && options.features['Dashboard.Icons'];
  16. this.content.getFeature('SlotActions').registerProvider('topBottomAction', this.getAPI());
  17. }
  18. TopBottomAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex) {
  19. var dataSlot = this.getVisualization().getSlots().getSlot(dataSlotId);
  20. if (dataSlot && this._supportAction(dataSlot, itemIndex)) {
  21. this.slot = dataSlot;
  22. var slotId = dataSlot.getDefinition().getId();
  23. this.dataItemIndex = itemIndex ? parseInt(itemIndex) : 0;
  24. this.dataItem = this.slot.getDataItemList()[this.dataItemIndex];
  25. var viewOptions = this.getViewState();
  26. viewOptions.getTopBottomState = this.dataItem.getTopBottom.bind(this);
  27. viewOptions.contextColumns = this._isAttribute() && this._getFactColumns();
  28. viewOptions.allowPercentOperations = this._isAttribute();
  29. viewOptions.allowRankColumn = this.getVisualization().getDefinition().getId() === 'JQGrid';
  30. viewOptions.onSearch = this._onSearch.bind(this);
  31. var topbottomIcon = this.icons.getIcon('dashboard-topbottom');
  32. return [{
  33. name: 'topBottomAction',
  34. label: stringResources.get('toolbarActionTopBottom'),
  35. icon: topbottomIcon.id,
  36. type: 'NextView',
  37. view: {
  38. module: 'dashboard-analytics/lib/@waca/dashboard-common/dist/ui/dialogs/TopBottomDialog',
  39. state: viewOptions
  40. },
  41. actions: {
  42. apply: this.applyTopBottomValues.bind(this, slotId, itemIndex),
  43. reset: this.reset.bind(this, slotId, itemIndex)
  44. }
  45. }];
  46. }
  47. return [];
  48. };
  49. TopBottomAction.prototype._supportAction = function _supportAction(dataSlot, itemIndex) {
  50. if (this._isMultiMeasureDataSlot(dataSlot, itemIndex)) {
  51. return false;
  52. }
  53. itemIndex = itemIndex || 0;
  54. if (Array.isArray(itemIndex) && itemIndex.length != 1) {
  55. return false;
  56. }
  57. var dataItem = dataSlot.getDataItemList()[itemIndex];
  58. if (!dataItem) {
  59. return false; // when right click on an empty summary widget
  60. }
  61. var column = dataItem.getMetadataColumn();
  62. if (column === null) {
  63. return false;
  64. }
  65. var columnType = column.getType();
  66. var visDefinitionApi = this.getVisualization().getDefinition();
  67. var dataItemType = dataItem.getType();
  68. if (columnType === 'fact' || dataItemType === 'fact') {
  69. if (!visDefinitionApi.getProperty('supportsNonContextualTopBottomAction')) {
  70. return false;
  71. }
  72. } else {
  73. if (!visDefinitionApi.getProperty('supportsContextualTopBottomAction')) {
  74. return false;
  75. }
  76. }
  77. return !dataItem.getBinning() && column.getSourceCategory() !== 'property';
  78. };
  79. TopBottomAction.prototype._getFactColumns = function _getFactColumns() {
  80. return _.unique(this.getVisualization().getDataSource().findMetadataColumns('', 'fact'));
  81. };
  82. TopBottomAction.prototype._onSearch = function _onSearch(searchTerm) {
  83. return _.unique(this.getVisualization().getDataSource().findMetadataColumns(searchTerm, 'fact'));
  84. };
  85. //DEFECT 253869
  86. //Verify if mapIndex is defined to differentiate when we're selecting specific data item that is a multi measure or multiple data items (get actions for y axis)
  87. TopBottomAction.prototype._isMultiMeasureDataSlot = function _isMultiMeasureDataSlot(dataSlot, itemIndex) {
  88. return dataSlot && itemIndex == undefined ? SlotAPIHelper.isMultiMeasuresSeriesSlot(dataSlot) || SlotAPIHelper.isMultiMeasuresValueSlot(dataSlot) : false;
  89. };
  90. TopBottomAction.prototype.getViewState = function getViewState() {
  91. if (this.slot) {
  92. var options = {
  93. height: 280,
  94. width: 400 // those are hints only; for the placement of the toolbar.
  95. };
  96. return options;
  97. }
  98. return null;
  99. };
  100. TopBottomAction.prototype._isAttribute = function _isAttribute() {
  101. return this.dataItem.getType() === 'attribute' && this.dataItem.getMetadataColumn() && this.dataItem.getMetadataColumn().getType() === 'attribute';
  102. };
  103. TopBottomAction.prototype._addAggregateToContext = function _addAggregateToContext(state) {
  104. var contextColumnId = state.context && state.context.itemId;
  105. if (!contextColumnId) {
  106. // Do not add aggregation to context if without context
  107. return;
  108. }
  109. var dataItemList = this.getVisualization().getSlots().getDataItemList();
  110. if (dataItemList && dataItemList.length > 0) {
  111. var dataItem = dataItemList.find(function (item) {
  112. return item.getColumnId() === contextColumnId;
  113. });
  114. var contextItemAggregate = void 0;
  115. if (dataItem) {
  116. contextItemAggregate = dataItem.getAggregation();
  117. } else {
  118. // Assign context item default aggregation type if is not projected but with context column
  119. var contextColumn = this.getVisualization().getDataSource().getMetadataColumn(contextColumnId);
  120. contextItemAggregate = contextColumn && contextColumn.getDefaultAggregation();
  121. }
  122. if (contextItemAggregate) {
  123. state.context.aggregate = contextItemAggregate;
  124. }
  125. }
  126. };
  127. TopBottomAction.prototype.applyTopBottomValues = function applyTopBottomValues(dataSlotId, itemIndex, state) {
  128. itemIndex = itemIndex || 0;
  129. this.slot = this.getVisualization().getSlots().getSlot(dataSlotId);
  130. this.dataItem = this.slot.getDataItemList()[itemIndex];
  131. if (state) {
  132. this._addAggregateToContext(state);
  133. this.dataItem.setTopBottom(state);
  134. } else {
  135. this.dataItem.setTopBottom();
  136. }
  137. };
  138. TopBottomAction.prototype.reset = function reset(dataSlotId, itemIndex) {
  139. this.slot = this.getVisualization().getSlots().getSlot(dataSlotId);
  140. this.dataItem = this.slot.getDataItemList()[itemIndex];
  141. this.applyTopBottomValues(dataSlotId, itemIndex);
  142. };
  143. TopBottomAction.prototype.getVisualization = function getVisualization() {
  144. if (!this.visualization) {
  145. this.visualization = this.content.getFeature('Visualization');
  146. }
  147. return this.visualization;
  148. };
  149. TopBottomAction.prototype.getAPI = function getAPI() {
  150. if (!this._api) {
  151. this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI, TopBottomActionAPI]);
  152. }
  153. return this._api;
  154. };
  155. return TopBottomAction;
  156. }();
  157. });
  158. //# sourceMappingURL=TopBottomAction.js.map