EventGroupActions.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 2018, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', 'underscore'], function (APIFactory, ContentActionsProviderAPI, _) {
  9. var EventGroupActions = function () {
  10. function EventGroupActions(_ref) {
  11. var features = _ref.features;
  12. _classCallCheck(this, EventGroupActions);
  13. if (features) {
  14. this.dashboard = features.API;
  15. this.eventGroups = features.EventGroups;
  16. }
  17. }
  18. EventGroupActions.prototype.getAPI = function getAPI() {
  19. if (!this._api) {
  20. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  21. }
  22. return this._api;
  23. };
  24. EventGroupActions.prototype._isAvailable = function _isAvailable(idList) {
  25. return idList.length && this.dashboard.getMode() === this.dashboard.MODES.EDIT_GROUP && !this._isStaticWidget(idList);
  26. };
  27. /**
  28. * check if a given selection is a static widget - Static widgets don't have a group
  29. * @param {String[]} idList - ids of selected widgets
  30. */
  31. EventGroupActions.prototype._isStaticWidget = function _isStaticWidget(idList) {
  32. for (var index = 0; index < idList.length; index++) {
  33. if (!this.eventGroups.getGroupId(idList[index])) {
  34. return true;
  35. }
  36. }
  37. return false;
  38. };
  39. /**
  40. * Get a count of distinct group indices in the selected nodes
  41. * @param {String[]} idList - ids of selected widgets
  42. * @return {String[]} distinct group ids in selection
  43. */
  44. EventGroupActions.prototype._getDistinctGroupIdsInSelection = function _getDistinctGroupIdsInSelection(idList) {
  45. var _this = this;
  46. var distinctGroupIndexesInSelection = _.map(idList, function (id) {
  47. return _this.eventGroups.getGroupId(id);
  48. });
  49. distinctGroupIndexesInSelection = _.uniq(distinctGroupIndexesInSelection);
  50. return distinctGroupIndexesInSelection;
  51. };
  52. /**
  53. * Get the page id of a widget
  54. * @param {String[]} idList list of widget ids
  55. */
  56. EventGroupActions.prototype._getPageId = function _getPageId(idList) {
  57. if (idList.length > 0) {
  58. var content = this.dashboard.getCanvas().getContent(idList[0]);
  59. while (content && content.getType() !== 'page') {
  60. content = content.getContainer();
  61. }
  62. if (content) {
  63. return content.getId();
  64. }
  65. }
  66. return false;
  67. };
  68. /**
  69. * Count groups that will be affected by an action in the current list of selected nodes
  70. * @return {Number} count
  71. */
  72. EventGroupActions.prototype._getCountGroupsAffected = function _getCountGroupsAffected(idList) {
  73. var _this2 = this;
  74. var count = 0;
  75. var groups = this.eventGroups.getGroupIdsOnPage(this._getPageId(idList));
  76. if (groups.length > 0 && idList.length > 0) {
  77. count = _.filter(groups, function (groupId) {
  78. var groupWidgetIds = _this2.eventGroups.getContentIdList(groupId);
  79. return groupWidgetIds.length === _.intersection(groupWidgetIds, idList).length;
  80. }).length;
  81. }
  82. return count;
  83. };
  84. /**
  85. * Get the number of groups
  86. * @return Returns the number of groups or 0 if its a static widget
  87. */
  88. EventGroupActions.prototype.getNumberOfGroups = function getNumberOfGroups(idList) {
  89. var pageId = this._getPageId(idList);
  90. if (!pageId) {
  91. return 0;
  92. }
  93. return this.eventGroups.getGroupIdsOnPage(pageId).length;
  94. };
  95. return EventGroupActions;
  96. }();
  97. return EventGroupActions;
  98. });
  99. //# sourceMappingURL=EventGroupActions.js.map