SlotAPIHelper.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict';
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * Licensed Materials - Property of IBM
  6. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define([], function () {
  10. var valueSlotIds = ['values', 'x', 'y'];
  11. var validateSlotAPI = function validateSlotAPI(slotAPI) {
  12. if (!slotAPI) {
  13. throw new Error('Invalid SlotAPI');
  14. }
  15. };
  16. var SlotAPIUtil = function () {
  17. function SlotAPIUtil() {
  18. _classCallCheck(this, SlotAPIUtil);
  19. }
  20. SlotAPIUtil.isValuesSlot = function isValuesSlot(slotAPI) {
  21. validateSlotAPI(slotAPI);
  22. return valueSlotIds.indexOf(slotAPI.getId()) !== -1;
  23. };
  24. SlotAPIUtil.isMultiMeasureSeriesDataItem = function isMultiMeasureSeriesDataItem(slotAPI, index) {
  25. return slotAPI.getDataItemList()[index].getColumnId() === SlotAPIUtil.MULTI_MEASURES_SERIES;
  26. };
  27. SlotAPIUtil.isMultiMeasuresSeriesSlot = function isMultiMeasuresSeriesSlot(slotAPI) {
  28. validateSlotAPI(slotAPI);
  29. var dataItemList = slotAPI.getDataItemList();
  30. return dataItemList.find(function (dataItem) {
  31. return dataItem.getColumnId() == SlotAPIUtil.MULTI_MEASURES_SERIES;
  32. }) ? true : false;
  33. };
  34. SlotAPIUtil.isMultiMeasuresValueSlot = function isMultiMeasuresValueSlot(slotAPI) {
  35. return slotAPI.getDefinition().isMultiMeasureSupported() && slotAPI.getDataItemList().length > 1;
  36. };
  37. SlotAPIUtil.isMultiMeasuresSeriesOrValue = function isMultiMeasuresSeriesOrValue(slot, dataItemIdx) {
  38. var dataItemList = slot.getDataItemList();
  39. var dataItem = dataItemList.length >= dataItemIdx && dataItemList[dataItemIdx];
  40. return SlotAPIUtil.isMultiMeasuresSeriesOrValueDataItem(dataItem);
  41. };
  42. SlotAPIUtil.isMultiMeasuresSeriesOrValueDataItem = function isMultiMeasuresSeriesOrValueDataItem(dataItem) {
  43. return dataItem && [SlotAPIUtil.MULTI_MEASURES_SERIES, SlotAPIUtil.MULTI_MEASURES_VALUE].indexOf(dataItem.getColumnId()) !== -1;
  44. };
  45. SlotAPIUtil.getMappedSlotListByDataset = function getMappedSlotListByDataset(visualization, dataset) {
  46. return visualization.getSlots().getMappedSlotList().filter(function (slot) {
  47. return slot.getDefinition().getDatasetIdList().indexOf(dataset) !== -1;
  48. });
  49. };
  50. SlotAPIUtil.getDataSlotById = function getDataSlotById(visualization, id) {
  51. var slots = visualization.getSlots();
  52. return slots ? slots.getSlot(id) : null;
  53. };
  54. SlotAPIUtil.getMetadataColumnForDataSlotHasOneMappedDataItem = function getMetadataColumnForDataSlotHasOneMappedDataItem(dataSource, dataSlot, itemIndices) {
  55. var dataItemList = dataSlot.getDataItemList();
  56. //itemIndices can be [underfined | null | number | array ]
  57. var index = itemIndices || 0;
  58. if (Array.isArray(index)) {
  59. if (index.length === 1) {
  60. index = index[0];
  61. } else {
  62. return null;
  63. }
  64. }
  65. return index < dataItemList.length ? dataSource.getMetadataColumn(dataItemList[index].getColumnId()) : null;
  66. };
  67. /**
  68. *
  69. * @param {*} slot slot api
  70. * @return return all the data items in the slot except multiMeasure series
  71. */
  72. SlotAPIUtil.getValidDataItems = function getValidDataItems(slot) {
  73. return slot.getDataItemList().filter(function (dataItem) {
  74. return dataItem.getColumnId() !== SlotAPIUtil.MULTI_MEASURES_SERIES;
  75. });
  76. };
  77. SlotAPIUtil.isSlotSortable = function isSlotSortable(slot, index, visualization) {
  78. index = index === undefined ? 0 : index;
  79. var def = slot.getDefinition();
  80. if (def && def.getProperty('sortable') !== undefined) {
  81. return def.getProperty('sortable');
  82. }
  83. if (slot.getDataItemList()[index].getType() === 'fact' && def && typeof def.getProperty('supportSortActionForMeasures') !== 'undefined') {
  84. return def.getProperty('supportSortActionForMeasures');
  85. }
  86. var slots = visualization.getDefinition().getProperty('dataSlots');
  87. for (var i = 0; i < slots.length; i++) {
  88. if (slots[i].subtype === 'location') {
  89. return false;
  90. }
  91. }
  92. if (def.getProperty('type') === 'category' || def.getProperty('type') === 'any') {
  93. return true;
  94. }
  95. var mappedSlots = visualization.getSlots().getMappedSlotList();
  96. if (mappedSlots.length === 2) {
  97. var hasType = function hasType(mappedSlots, sType) {
  98. return mappedSlots[0].getDefinition().getType() === sType || mappedSlots[1].getDefinition().getType() === sType;
  99. };
  100. return hasType(mappedSlots, 'category') && hasType(mappedSlots, 'ordinal');
  101. }
  102. return false;
  103. };
  104. SlotAPIUtil.getMultiMeasureSeriesSlot = function getMultiMeasureSeriesSlot(visualization, dataset) {
  105. var slots = visualization.getSlots();
  106. return slots.getSlotList().find(function (slot) {
  107. var definition = slot.getDefinition();
  108. var tags = definition && definition.getProperty('tags');
  109. return tags && tags.indexOf('ca.dashboard.repeatHere=true') > -1 && dataset === definition.getDatasetIdList()[0];
  110. });
  111. };
  112. SlotAPIUtil.doesDataItemSupportBinning = function doesDataItemSupportBinning(slot, dataItem) {
  113. return slot.getDefinition().getType() !== 'ordinal' && dataItem.getMetadataColumn().getType() === 'fact';
  114. };
  115. _createClass(SlotAPIUtil, null, [{
  116. key: 'MULTI_MEASURES_SERIES',
  117. get: function get() {
  118. return '_multiMeasuresSeries';
  119. }
  120. }, {
  121. key: 'MULTI_MEASURES_VALUE',
  122. get: function get() {
  123. return '_multiMeasuresValue';
  124. }
  125. }]);
  126. return SlotAPIUtil;
  127. }();
  128. return SlotAPIUtil;
  129. });
  130. //# sourceMappingURL=SlotAPIHelper.js.map