'use strict'; 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; }; }(); 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. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define([], function () { var valueSlotIds = ['values', 'x', 'y']; var validateSlotAPI = function validateSlotAPI(slotAPI) { if (!slotAPI) { throw new Error('Invalid SlotAPI'); } }; var SlotAPIUtil = function () { function SlotAPIUtil() { _classCallCheck(this, SlotAPIUtil); } SlotAPIUtil.isValuesSlot = function isValuesSlot(slotAPI) { validateSlotAPI(slotAPI); return valueSlotIds.indexOf(slotAPI.getId()) !== -1; }; SlotAPIUtil.isMultiMeasureSeriesDataItem = function isMultiMeasureSeriesDataItem(slotAPI, index) { return slotAPI.getDataItemList()[index].getColumnId() === SlotAPIUtil.MULTI_MEASURES_SERIES; }; SlotAPIUtil.isMultiMeasuresSeriesSlot = function isMultiMeasuresSeriesSlot(slotAPI) { validateSlotAPI(slotAPI); var dataItemList = slotAPI.getDataItemList(); return dataItemList.find(function (dataItem) { return dataItem.getColumnId() == SlotAPIUtil.MULTI_MEASURES_SERIES; }) ? true : false; }; SlotAPIUtil.isMultiMeasuresValueSlot = function isMultiMeasuresValueSlot(slotAPI) { return slotAPI.getDefinition().isMultiMeasureSupported() && slotAPI.getDataItemList().length > 1; }; SlotAPIUtil.isMultiMeasuresSeriesOrValue = function isMultiMeasuresSeriesOrValue(slot, dataItemIdx) { var dataItemList = slot.getDataItemList(); var dataItem = dataItemList.length >= dataItemIdx && dataItemList[dataItemIdx]; return SlotAPIUtil.isMultiMeasuresSeriesOrValueDataItem(dataItem); }; SlotAPIUtil.isMultiMeasuresSeriesOrValueDataItem = function isMultiMeasuresSeriesOrValueDataItem(dataItem) { return dataItem && [SlotAPIUtil.MULTI_MEASURES_SERIES, SlotAPIUtil.MULTI_MEASURES_VALUE].indexOf(dataItem.getColumnId()) !== -1; }; SlotAPIUtil.getMappedSlotListByDataset = function getMappedSlotListByDataset(visualization, dataset) { return visualization.getSlots().getMappedSlotList().filter(function (slot) { return slot.getDefinition().getDatasetIdList().indexOf(dataset) !== -1; }); }; SlotAPIUtil.getDataSlotById = function getDataSlotById(visualization, id) { var slots = visualization.getSlots(); return slots ? slots.getSlot(id) : null; }; SlotAPIUtil.getMetadataColumnForDataSlotHasOneMappedDataItem = function getMetadataColumnForDataSlotHasOneMappedDataItem(dataSource, dataSlot, itemIndices) { var dataItemList = dataSlot.getDataItemList(); //itemIndices can be [underfined | null | number | array ] var index = itemIndices || 0; if (Array.isArray(index)) { if (index.length === 1) { index = index[0]; } else { return null; } } return index < dataItemList.length ? dataSource.getMetadataColumn(dataItemList[index].getColumnId()) : null; }; /** * * @param {*} slot slot api * @return return all the data items in the slot except multiMeasure series */ SlotAPIUtil.getValidDataItems = function getValidDataItems(slot) { return slot.getDataItemList().filter(function (dataItem) { return dataItem.getColumnId() !== SlotAPIUtil.MULTI_MEASURES_SERIES; }); }; SlotAPIUtil.isSlotSortable = function isSlotSortable(slot, index, visualization) { index = index === undefined ? 0 : index; var def = slot.getDefinition(); if (def && def.getProperty('sortable') !== undefined) { return def.getProperty('sortable'); } if (slot.getDataItemList()[index].getType() === 'fact' && def && typeof def.getProperty('supportSortActionForMeasures') !== 'undefined') { return def.getProperty('supportSortActionForMeasures'); } var slots = visualization.getDefinition().getProperty('dataSlots'); for (var i = 0; i < slots.length; i++) { if (slots[i].subtype === 'location') { return false; } } if (def.getProperty('type') === 'category' || def.getProperty('type') === 'any') { return true; } var mappedSlots = visualization.getSlots().getMappedSlotList(); if (mappedSlots.length === 2) { var hasType = function hasType(mappedSlots, sType) { return mappedSlots[0].getDefinition().getType() === sType || mappedSlots[1].getDefinition().getType() === sType; }; return hasType(mappedSlots, 'category') && hasType(mappedSlots, 'ordinal'); } return false; }; SlotAPIUtil.getMultiMeasureSeriesSlot = function getMultiMeasureSeriesSlot(visualization, dataset) { var slots = visualization.getSlots(); return slots.getSlotList().find(function (slot) { var definition = slot.getDefinition(); var tags = definition && definition.getProperty('tags'); return tags && tags.indexOf('ca.dashboard.repeatHere=true') > -1 && dataset === definition.getDatasetIdList()[0]; }); }; SlotAPIUtil.doesDataItemSupportBinning = function doesDataItemSupportBinning(slot, dataItem) { return slot.getDefinition().getType() !== 'ordinal' && dataItem.getMetadataColumn().getType() === 'fact'; }; _createClass(SlotAPIUtil, null, [{ key: 'MULTI_MEASURES_SERIES', get: function get() { return '_multiMeasuresSeries'; } }, { key: 'MULTI_MEASURES_VALUE', get: function get() { return '_multiMeasuresValue'; } }]); return SlotAPIUtil; }(); return SlotAPIUtil; }); //# sourceMappingURL=SlotAPIHelper.js.map