123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- '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 Business Analytics (C) Copyright IBM Corp. 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class VisDnDSlotToSlotProvider
- * @hideconstructor
- *
- * @classdesc Handles drag and drop of metadata from slot to slot.
- */
- define(['underscore', 'dashboard-analytics/apiHelpers/SlotAPIHelper'], function (_, SlotAPIHelper) {
- return function () {
- function VisDnDSlotToSlotProvider() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- _classCallCheck(this, VisDnDSlotToSlotProvider);
- this.visDnDUtils = options.visDnDUtils;
- this.dashboardAPI = options.dashboardAPI;
- this.content = options.content;
- this.visualization = options.visualization;
- }
- VisDnDSlotToSlotProvider.prototype.destroy = function destroy() {
- this.visDnDUtils = null;
- this.dashboardAPI = null;
- this.content = null;
- };
- /**
- * @param {Object} source - the DndSource defined by whichever source starts the drag
- * @param {Object} target - the DnDTarget defined by the drop target which includes target specific information.
- * @param {String} target.el - the drop node.
- * @param {String} target.type - the type of the target (eg. slot.item)
- * @param {String} target.info - a target-specific function which includes information about that target.
- * @return {boolean} true if this provider supports the dndSource and target.
- */
- VisDnDSlotToSlotProvider.prototype.supports = function supports(source, target) {
- //Normally slots can accept the content of other slots. VisOverLay slots explicitly wire this off.
- return source.type === 'SLOT_ITEM' && source.data.source && !target.info.isVisOverlay;
- };
- VisDnDSlotToSlotProvider.prototype.accepts = function accepts(source, target) {
- if (!this.supports(source, target)) {
- return false;
- }
- return this._acceptsSlotItem(source, target);
- };
- VisDnDSlotToSlotProvider.prototype.onDrop = function onDrop(source, target) {
- //TODO: use a more generic onDrop callback rather than the full slotDataItemHandler.
- // and use slotAPI's/mappedDataItemAPI's instead.
- // same for SlotToSlotProvider
- if (!this.supports(source, target)) {
- return false;
- }
- target.info.onDrop(source, target);
- };
- //Can this slotDataItem accept a dataItem from this slot or another slot?
- VisDnDSlotToSlotProvider.prototype._acceptsSlotItem = function _acceptsSlotItem(source, target) {
- var sourceSlot = source.data.source.slot;
- var sourceIndexInSlot = source.data.source.indexInSlot;
- var targetSlotId = target.info.slot.getId();
- //You CAN'T add nothing
- if (!sourceSlot) {
- return false;
- }
- //You CAN'T add an item on itself or after the item before it within the same slot
- //(it is legitimate to swap an item with the item before it though)
- if (targetSlotId === sourceSlot.getId() && (sourceIndexInSlot === target.info.indexInSlot || (target.info.addAfter && sourceIndexInSlot - target.info.indexInSlot) === 1)) {
- return false;
- }
- //You CAN'T drop metadatacolumns that have certain taxonomy characteristics
- var sourceDataItem = sourceSlot.getDataItemList()[sourceIndexInSlot];
- var sourceMetadataColumn = sourceDataItem.getMetadataColumn();
- if (!this.isMeasureGroupItem(sourceSlot, sourceIndexInSlot) && !this._itemsSupported([sourceMetadataColumn], target.info.slot)) {
- return false;
- }
- //You CAN'T drop on top of the placeholder dataItem 'Measure Group (n)' from another item (you can drop after it)
- //EXCEPTION: You CAN drop on top if the source item is in the same slot.
- if (!target.info.addAfter && this.isMeasureGroupItem(target.info.slot, target.info.indexInSlot) && targetSlotId !== sourceSlot.getId()) {
- return false;
- }
- //You CAN'T drop 'Measure Group (n)' on any ordinal slot
- //TODO: follow rule from old slot editor which only checked ordinal slots (not any slots with finalSlotType=ordinal). Should it?
- if (target.info.slot.getDefinition().getType() === 'ordinal' && this.isMeasureGroupItem(sourceSlot, sourceIndexInSlot)) {
- return false;
- }
- // Can't swap a measure group if the dataset doesn't match
- var sourceDatasetIdList = sourceSlot.getDefinition().getDatasetIdList();
- var targetDatasetIdList = target.info.slot.getDefinition().getDatasetIdList();
- if (this.isMeasureGroupItem(sourceSlot, sourceIndexInSlot) && !_.isEqual(sourceDatasetIdList, targetDatasetIdList)) {
- return false;
- }
- return this._acceptsCommon(source, target, /*countOfItems*/1, target.info.addAfter);
- };
- VisDnDSlotToSlotProvider.prototype.isMeasureGroupItem = function isMeasureGroupItem(slot, indexInSlot) {
- if (SlotAPIHelper.isMultiMeasuresSeriesSlot(slot)) {
- var thisDataItem = slot.getDataItemList()[indexInSlot];
- return thisDataItem && thisDataItem.getColumnId() === '_multiMeasuresSeries';
- }
- return false;
- };
- VisDnDSlotToSlotProvider.prototype._itemsSupported = function _itemsSupported(metadataColumns, slot) {
- //convert to new metadataColumn api
- var sourceId = metadataColumns[0].getSourceId();
- var dataSource = sourceId && this.dashboardAPI.getFeature('DataSources').getDataSource(sourceId);
- if (dataSource) {
- var newMetadataColumnAPIs = metadataColumns.map(function (metadataColumn) {
- return dataSource.getMetadataColumn(metadataColumn.getId());
- });
- return slot.supportsColumns(newMetadataColumnAPIs);
- }
- return false;
- };
- VisDnDSlotToSlotProvider.prototype._acceptsCommon = function _acceptsCommon(source, target, countOfItemsToDrop, addAfter) {
- var sourceSlot = source.data.source.slot;
- var sourceIndexInSlot = source.data.source.indexInSlot;
- var targetSlotId = target.info.slot.getId();
- //IF this definition contains (or could contain) a multiMeasuresSeries item,
- //You CAN drop on or after in a values slot (even though values has maxItems of 1 => multi-items go where 'Measure Group (n)' is)
- if (target.info.slot.getId() === 'values' && SlotAPIHelper.isMultiMeasuresSeriesSlot(target.info.slot) || target.info.slot.getDefinition().isMultiMeasureSupported()) {
- return true;
- }
- //{ targetSlotId, sourceSlotId, indexInSourceSlot, sourceColumns, indexInTargetSlot, isReplace }
- var params = {
- targetSlotId: targetSlotId,
- sourceSlotId: sourceSlot.getId(),
- indexInSourceSlot: sourceIndexInSlot,
- sourceColumns: undefined,
- indexInTargetSlot: target.info.addAfter ? target.info.indexInSlot + 1 : target.info.indexInSlot,
- isReplace: !target.info.addAfter
- };
- var expandCollapseFeatureFlag = !this.dashboardAPI.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'expandCollapse', 'disabled');
- if (expandCollapseFeatureFlag && this.visualization.getType() === 'Crosstab') {
- if (!this.visDnDUtils.acceptsOlapV2(params)) {
- return false;
- }
- }
- //You CAN'T drop more items than the slot can allow.
- //(BUT you'll never exceed the slot limit if you're just re-arranging items in a single slot)
- return sourceSlot.getId() === targetSlotId || !this.visDnDUtils.exceedsItemsLimit(countOfItemsToDrop, target.info.indexInSlot, addAfter, target.info.slot);
- };
- return VisDnDSlotToSlotProvider;
- }();
- });
- //# sourceMappingURL=VisDnDSlotToSlotProvider.js.map
|