'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', 'underscore'], function (APIFactory, ContentActionsProviderAPI, _) { var EventGroupActions = function () { function EventGroupActions(_ref) { var features = _ref.features; _classCallCheck(this, EventGroupActions); if (features) { this.dashboard = features.API; this.eventGroups = features.EventGroups; } } EventGroupActions.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]); } return this._api; }; EventGroupActions.prototype._isAvailable = function _isAvailable(idList) { return idList.length && this.dashboard.getMode() === this.dashboard.MODES.EDIT_GROUP && !this._isStaticWidget(idList); }; /** * check if a given selection is a static widget - Static widgets don't have a group * @param {String[]} idList - ids of selected widgets */ EventGroupActions.prototype._isStaticWidget = function _isStaticWidget(idList) { for (var index = 0; index < idList.length; index++) { if (!this.eventGroups.getGroupId(idList[index])) { return true; } } return false; }; /** * Get a count of distinct group indices in the selected nodes * @param {String[]} idList - ids of selected widgets * @return {String[]} distinct group ids in selection */ EventGroupActions.prototype._getDistinctGroupIdsInSelection = function _getDistinctGroupIdsInSelection(idList) { var _this = this; var distinctGroupIndexesInSelection = _.map(idList, function (id) { return _this.eventGroups.getGroupId(id); }); distinctGroupIndexesInSelection = _.uniq(distinctGroupIndexesInSelection); return distinctGroupIndexesInSelection; }; /** * Get the page id of a widget * @param {String[]} idList list of widget ids */ EventGroupActions.prototype._getPageId = function _getPageId(idList) { if (idList.length > 0) { var content = this.dashboard.getCanvas().getContent(idList[0]); while (content && content.getType() !== 'page') { content = content.getContainer(); } if (content) { return content.getId(); } } return false; }; /** * Count groups that will be affected by an action in the current list of selected nodes * @return {Number} count */ EventGroupActions.prototype._getCountGroupsAffected = function _getCountGroupsAffected(idList) { var _this2 = this; var count = 0; var groups = this.eventGroups.getGroupIdsOnPage(this._getPageId(idList)); if (groups.length > 0 && idList.length > 0) { count = _.filter(groups, function (groupId) { var groupWidgetIds = _this2.eventGroups.getContentIdList(groupId); return groupWidgetIds.length === _.intersection(groupWidgetIds, idList).length; }).length; } return count; }; /** * Get the number of groups * @return Returns the number of groups or 0 if its a static widget */ EventGroupActions.prototype.getNumberOfGroups = function getNumberOfGroups(idList) { var pageId = this._getPageId(idList); if (!pageId) { return 0; } return this.eventGroups.getGroupIdsOnPage(pageId).length; }; return EventGroupActions; }(); return EventGroupActions; }); //# sourceMappingURL=EventGroupActions.js.map