SlotActions.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './api/SlotActionsAPI', 'underscore'], function (APIFactory, SlotActionsAPI, _) {
  9. var SlotActions = function () {
  10. function SlotActions() {
  11. _classCallCheck(this, SlotActions);
  12. this.api = APIFactory.createAPI(this, [SlotActionsAPI]);
  13. this.providers = [];
  14. }
  15. SlotActions.prototype.registerProvider = function registerProvider(name, provider) {
  16. this.providers[name] = provider;
  17. };
  18. SlotActions.prototype.getSlotActionList = function getSlotActionList(dataSlotId, itemIndex, options) {
  19. var actionOptions = options && options.actionOptions || {};
  20. var actionsToKeep = options && options.actionsToKeep || [];
  21. var actions = [];
  22. for (var actionName in this.providers) {
  23. var feature = this.providers[actionName];
  24. if (feature.getSlotActionList) {
  25. var slotAction = null;
  26. try {
  27. slotAction = feature.getSlotActionList(dataSlotId, itemIndex, actionOptions[actionName]);
  28. } catch (e) {
  29. console.log(e);
  30. }
  31. if (!_.isEmpty(slotAction)) {
  32. var _actions;
  33. (_actions = actions).push.apply(_actions, slotAction);
  34. }
  35. }
  36. }
  37. // Filter actions if needed
  38. if (actionsToKeep.length) {
  39. actions = actions.filter(function (action) {
  40. // TODO We need to check all three of them for now because of some inconsistencies we have in our code.
  41. // New API's should use *name* to identify an action.
  42. return _.contains(actionsToKeep, action.id || action.group || action.name) || action.name === 'delete';
  43. });
  44. }
  45. return actions;
  46. };
  47. SlotActions.prototype.getAPI = function getAPI() {
  48. return this.api;
  49. };
  50. return SlotActions;
  51. }();
  52. return SlotActions;
  53. });
  54. //# sourceMappingURL=SlotActions.js.map