TopKeyDriversAction.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define([
  11. // '../renderer/topbottom/TopBottomLabel',
  12. '../../../../visualizations/renderer/topbottom/TopBottomLabel', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../api/SlotActionsProviderAPI', '../../../../apiHelpers/SlotAPIHelper', '../../../../widgets/livewidget/nls/StringResources'], function (TopBottomLabel, APIFactory, SlotActionsProviderAPI, SlotAPIHelper, stringResources) {
  13. 'use strict';
  14. var TOP_OP = 'top';
  15. var TOP_TYPE = 'topcount';
  16. var ACTION_ID = 'topKeyDriversAction';
  17. var ACTION_ICON = 'dashboard-topbottom';
  18. var ACTION_ITEMS = {
  19. TOP_5: 'top5',
  20. TOP_10: 'top10',
  21. ALL: 'all'
  22. };
  23. return function (_TopBottomLabel) {
  24. _inherits(TopKeyDriversAction, _TopBottomLabel);
  25. function TopKeyDriversAction(_ref) {
  26. var content = _ref.content,
  27. dashboardAPI = _ref.dashboardAPI,
  28. features = _ref.features;
  29. _classCallCheck(this, TopKeyDriversAction);
  30. var _this = _possibleConstructorReturn(this, _TopBottomLabel.call(this));
  31. _this.content = content;
  32. _this.dashboard = dashboardAPI;
  33. _this.icons = features && features['Dashboard.Icons'];
  34. features.SlotActions.registerProvider('topKeyDriversAction', _this.getAPI());
  35. return _this;
  36. }
  37. TopKeyDriversAction.prototype.getAPI = function getAPI() {
  38. if (!this._api) {
  39. this._api = APIFactory.createAPI(this, [SlotActionsProviderAPI]);
  40. }
  41. return this._api;
  42. };
  43. TopKeyDriversAction.prototype._isActionSupported = function _isActionSupported(dataSlot, mapIndex) {
  44. if (!this._isFocusModeEnabled()) {
  45. return false;
  46. }
  47. var actions = dataSlot.getDefinition().getProperty('actions');
  48. if (!actions) {
  49. return false;
  50. }
  51. if (actions.indexOf('TopKeyDriversAction') === -1) {
  52. return false;
  53. }
  54. return !this._isMultiMeasureDataSlot(dataSlot, mapIndex);
  55. };
  56. TopKeyDriversAction.prototype._isFocusModeEnabled = function _isFocusModeEnabled() {
  57. return !this.dashboard.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'FocusMode', 'disabled');
  58. };
  59. TopKeyDriversAction.prototype.getViewState = function getViewState(dataSlotId, itemIndex) {
  60. var dataSlot = this._getVisualization().getSlots().getSlot(dataSlotId);
  61. if (dataSlot) {
  62. return {
  63. height: 140,
  64. width: 140,
  65. getCurrentSelectedItem: this._getCurrentSelectedItem.bind(this, dataSlot, itemIndex),
  66. possibleItems: this._getPossibleItems(dataSlot, itemIndex),
  67. eventHandler: this
  68. };
  69. }
  70. return null;
  71. };
  72. /**
  73. * Initialize the set of TopKeyDriversAction settings the selected state
  74. */
  75. TopKeyDriversAction.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex) {
  76. this.dataSlot = this._getVisualization().getSlots().getSlot(dataSlotId);
  77. this.itemIndex = itemIndex;
  78. if (this.dataSlot && this._isActionSupported(this.dataSlot, itemIndex)) {
  79. var actionIcon = this.icons.getIcon(ACTION_ICON);
  80. return [{
  81. name: 'show',
  82. id: 'TopKeyDriversAction',
  83. text: stringResources.get('toolbarActionTopKeyDrivers'),
  84. label: stringResources.get('toolbarActionTopKeyDrivers'),
  85. icon: actionIcon.id,
  86. type: 'NextView',
  87. group: ACTION_ID,
  88. view: {
  89. module: 'dashboard-analytics/lib/@waca/dashboard-common/dist/ui/dialogs/CommonSelectItemsDialog',
  90. state: this.getViewState(dataSlotId, itemIndex)
  91. },
  92. actions: {
  93. apply: this.handleSelection.bind(this)
  94. }
  95. }];
  96. }
  97. return [];
  98. };
  99. TopKeyDriversAction.prototype._getCurrentSelectedItem = function _getCurrentSelectedItem(dataSlot, itemIndex) {
  100. var dataItem = dataSlot.getDataItemList()[itemIndex];
  101. var state = dataItem.getTopBottom();
  102. if (state && state.type === TOP_TYPE) {
  103. return state.value === 5 ? ACTION_ITEMS.TOP_5 : ACTION_ITEMS.TOP_10;
  104. }
  105. return ACTION_ITEMS.ALL;
  106. };
  107. /**
  108. * Get the array of possible items to be displayed on the dialog
  109. * @return array of items to display on dialog
  110. */
  111. TopKeyDriversAction.prototype._getPossibleItems = function _getPossibleItems() {
  112. return [{
  113. id: ACTION_ITEMS.ALL,
  114. localizedString: stringResources.get('allKeyDriversLabel')
  115. }, {
  116. id: ACTION_ITEMS.TOP_5,
  117. localizedString: this.getTopBottomLabel({
  118. limit: {
  119. op: TOP_OP,
  120. val: 5
  121. }
  122. })
  123. }, {
  124. id: ACTION_ITEMS.TOP_10,
  125. localizedString: this.getTopBottomLabel({
  126. limit: {
  127. op: TOP_OP,
  128. val: 10
  129. }
  130. })
  131. }];
  132. };
  133. TopKeyDriversAction.prototype._isMultiMeasureDataSlot = function _isMultiMeasureDataSlot(dataSlot, itemIndex) {
  134. if (itemIndex === undefined && dataSlot) {
  135. return SlotAPIHelper.isMultiMeasuresSeriesSlot(dataSlot) || SlotAPIHelper.isMultiMeasuresValueSlot(dataSlot);
  136. }
  137. return SlotAPIHelper.isMultiMeasuresSeriesOrValue(dataSlot, itemIndex);
  138. };
  139. TopKeyDriversAction.prototype._getVisualization = function _getVisualization() {
  140. if (!this.visualization) {
  141. this.visualization = this.content.getFeature('Visualization');
  142. }
  143. return this.visualization;
  144. };
  145. /**
  146. * Handler to the item selection.
  147. * @param {string} selectedItem - identifier of the item selected
  148. * @see {@link ACTION_ITEMS}
  149. */
  150. TopKeyDriversAction.prototype.handleSelection = function handleSelection(selectedItem) {
  151. var dataItem = this.dataSlot.getDataItemList()[this.itemIndex];
  152. switch (selectedItem) {
  153. case ACTION_ITEMS.ALL:
  154. dataItem.setTopBottom();
  155. break;
  156. case ACTION_ITEMS.TOP_5:
  157. case ACTION_ITEMS.TOP_10:
  158. dataItem.setTopBottom({
  159. type: TOP_TYPE,
  160. value: selectedItem === ACTION_ITEMS.TOP_5 ? 5 : 10
  161. });
  162. break;
  163. default:
  164. break;
  165. }
  166. };
  167. return TopKeyDriversAction;
  168. }(TopBottomLabel);
  169. });
  170. //# sourceMappingURL=TopKeyDriversAction.js.map