PendingSelections.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. /**
  10. * @class PendingSelections
  11. * @hideconstructor
  12. */
  13. define(['underscore', '../../../../apiHelpers/SlotAPIHelper'], function (_, SlotAPIHelper) {
  14. var PendingSelections = function () {
  15. function PendingSelections() {
  16. _classCallCheck(this, PendingSelections);
  17. this._pendingSelections = [];
  18. }
  19. PendingSelections.prototype.select = function select(selections) {
  20. var _this = this;
  21. _.each(selections, function (selection) {
  22. var isPending = _.find(_this._pendingSelections, function (p) {
  23. return _.isEqual(p, selection);
  24. });
  25. if (!isPending) {
  26. _this._pendingSelections.push(selection);
  27. }
  28. });
  29. };
  30. PendingSelections.prototype.deselect = function deselect(selections) {
  31. var _this2 = this;
  32. _.each(selections, function (selection) {
  33. var index = _.findIndex(_this2._pendingSelections, function (p) {
  34. return _.isEqual(p, selection);
  35. });
  36. if (index > -1) {
  37. _this2._pendingSelections.splice(index, 1);
  38. }
  39. });
  40. };
  41. PendingSelections.prototype.clearAll = function clearAll() {
  42. this._pendingSelections.length = 0;
  43. };
  44. PendingSelections.prototype.getSelections = function getSelections() {
  45. var selectedDataItemList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  46. var catDataItemList = _.filter(selectedDataItemList, function (dataItem) {
  47. return dataItem.getType() === 'attribute' && SlotAPIHelper.MULTI_MEASURES_SERIES !== dataItem.getColumnId();
  48. });
  49. var selectDataItemIds = _.map(catDataItemList, function (dataItem) {
  50. return dataItem.getId();
  51. });
  52. return _.filter(this._pendingSelections, function (selection) {
  53. return _.every(selectDataItemIds, function (dataItemId) {
  54. return _.find(selection.categories, function (cat) {
  55. return cat.dataItemId === dataItemId;
  56. });
  57. });
  58. });
  59. };
  60. PendingSelections.prototype.isSelected = function isSelected(selections) {
  61. var _this3 = this;
  62. return !!_.every(selections, function (selection) {
  63. return !!_.find(_this3._pendingSelections, function (p) {
  64. return _.isEqual(p, selection);
  65. });
  66. });
  67. };
  68. return PendingSelections;
  69. }();
  70. return PendingSelections;
  71. });
  72. //# sourceMappingURL=PendingSelections.js.map