'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['jquery', '../common/NonVIPREventTarget', 'underscore'], function ($, NonVIPREventTarget, _) { var EVENTTYPE = { CUSTOMDATA: 'customdata', DATAPOINT: 'datapoint', ITEMCLASS: 'itemclass', ITEM: 'item', SUMMARY: 'summary', EXPANDED: 'expanded' }; var CELL_TYPE = { ROW: 'row', COLUMN: 'column' }; var AREA_TYPE = { ROW: 'cell_edge_row', COLUMN: 'cell_edge_column', CELL: 'cell', MEASURE: 'values', SUMMARY: 'summary' }; var SLOTID = { COLUMN: 'column_level1', ROW: 'row_level1', VALUES: 'values', HEAT: 'heat' }; var CrosstabEventTarget = function (_NonVIPREventTarget) { _inherits(CrosstabEventTarget, _NonVIPREventTarget); function CrosstabEventTarget() { _classCallCheck(this, CrosstabEventTarget); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, _NonVIPREventTarget.call.apply(_NonVIPREventTarget, [this].concat(args))); var options = args[0] || {}; _this.ownerWidget = options.ownerWidget; _this.view = options.view; return _this; } /** * Get the array of event targets based on the event. * Event target represents a data point object that corresponds to the event. * * @param event Event object */ CrosstabEventTarget.prototype.getEventTargets = function getEventTargets(event) { var _this2 = this; if (!this._isValidEvent(event)) { return []; } var targets = []; var items = this._getEventTargetItem(event); _.each(items, function (item) { if (item) { var area = $(item.source[0]).attr('area'); // determine if current selection is a valid selected area var isAreaSelected = _this2._isValidSelectedArea(item); // title Action/Slot action requirs the info as part of selectionContext if (isAreaSelected) { item.selectionContext = _this2._updateSelectionContext(item.selectionContext); } targets.push({ key: item.key, type: item.infoType, source: item.source, values: item.values, selectionContext: item.selectionContext, area: area, isAreaSelected: isAreaSelected }); } }); return targets; }; CrosstabEventTarget.prototype._isValidSelectedArea = function _isValidSelectedArea(item) { var $itemSource = item.source && item.source[0] && $(item.source[0]); if ($itemSource.hasClass('dashboard-grid-cell-selected')) { return $itemSource.attr('area') !== AREA_TYPE.SUMMARY; } }; CrosstabEventTarget.prototype._updateSelectionContext = function _updateSelectionContext(selectionContext) { selectionContext = selectionContext || {}; _.extend(selectionContext, { actions: { actionOptions: { TextAction: { isAreaSelected: true } } } }); return selectionContext; }; CrosstabEventTarget.prototype.decorateTarget = function decorateTarget(items, name, value, isMultiSelect) { var decorated = false; //crosstab does support style 'hightlight', it only decorate for style 'implied_selection' because this style supports muti-select cells if (name === 'highlight') { return true; } else if (name === 'implied_selection') { var visControl = this.view.visControl; if (items && items.length > 0) { var oSourceNode = items[0].source; //There will be only one items for crosstab if (oSourceNode) { var area = oSourceNode.attr('area'); var isMeasureHeader = area === AREA_TYPE.MEASURE; var isSummary = area === AREA_TYPE.SUMMARY; if (isMeasureHeader) { if (value) { if (isMultiSelect) { visControl.decorateMeasureHeader(oSourceNode[0]); } else { // Measures header decorating this._clearSelectionController().then(function () { visControl.clearSelection({ clearSelectionCaches: true }); visControl.decorateMeasureHeader(oSourceNode[0]); }); } } else { // Clearing measure header decorations (items is undefined on hover) visControl.resetMeasureHeaderDecorations(); } decorated = true; } if (isSummary) { if (value) { // Highlight summary cells this._clearSelectionController().then(function () { visControl.clearSelection({ clearSelectionCaches: true }); visControl.highlightSummary(oSourceNode[0]); }); } else { // Clearing summary cells highlighting visControl.resetSummaryHighlight(); } decorated = true; } } } else if (!items) { // Clearing measure header decorations (items is undefined on hover) visControl.resetMeasureHeaderDecorations(); visControl.resetSummaryHighlight(); decorated = true; } } return decorated; }; CrosstabEventTarget.prototype._clearSelectionController = function _clearSelectionController() { var visualization = this.content.getFeature('Visualization'); var mappedSlotList = visualization.getSlots().getMappedSlotList(); var itemIds = []; _.each(mappedSlotList, function (slot) { var dataItemList = slot.getDataItemList(); if (dataItemList[0].getType() === 'category') { _.each(dataItemList, function (dataitem) { itemIds.push(dataitem.getColumnId()); }); } }); var visController = this.content.getFeature('InteractivityController.deprecated'); return visController.select({ itemIds: itemIds, tuple: [], command: 'update', slotsToClear: mappedSlotList }); }; CrosstabEventTarget.prototype.remove = function remove() { this.ownerWidget = null; this.view = null; _NonVIPREventTarget.prototype.remove.call(this); }; CrosstabEventTarget.prototype._getEventTargetItem = function _getEventTargetItem(event) { var target = this._getTargetNode(event); if (target && target.textContent) { var $eventTarget = $(target); var bIsCell = $eventTarget.attr('tuple'); if (this.view.visControl.isCrosstaMeasureNodeSelected(target) || $eventTarget.attr('measure') === 'true') { return [this._getMeasureItemClassTarget(event)]; } else if ($eventTarget.attr('area') === AREA_TYPE.SUMMARY) { return [this._getSummaryItemTarget(event, bIsCell)]; } else { return bIsCell ? [this._getDatapointTarget(event)] : [this._getItemTarget(event)]; } } }; CrosstabEventTarget.prototype._getDatapointTarget = function _getDatapointTarget(event) { var oSelections = this.view.visControl.dataPointNodeToSlotsSelections(event); if (!oSelections) { return null; } var attributeSelections = oSelections.attributeSelections; var factSelections = []; if (oSelections.selectionContext) { // The selectionContext in a datapoint oSelection is the mapIndex of the data item that the datapoint corresponds to factSelections[oSelections.selectionContext] = oSelections.factSelections && oSelections.factSelections[0] ? oSelections.factSelections[0].value : []; } else { factSelections = oSelections.factSelections && oSelections.factSelections[0] ? [oSelections.factSelections[0].value] : []; } var aColumnValues = _.pluck(_.filter(attributeSelections, function (entry) { return entry.edgeType === CELL_TYPE.COLUMN; }), 'value'); var aRowValues = _.pluck(_.filter(attributeSelections, function (entry) { return entry.edgeType === CELL_TYPE.ROW; }), 'value'); var heatSelections = oSelections.factSelections && oSelections.factSelections[1] ? [oSelections.factSelections[1].value] : []; var oItem = this._createItem(EVENTTYPE.DATAPOINT, event); this._addItemValues(oItem.values, aColumnValues, aRowValues, factSelections, heatSelections); // Disable selection actions for events containing expanded items // This is due to limitations for brushing/slicing on expanded items for expand/collapse feature if (this._includesExpanded(aColumnValues, aRowValues)) { oItem.infoType = EVENTTYPE.EXPANDED; oItem.values = []; $(event.currentTarget).addClass('hoverExpanded'); } else { $(event.currentTarget).removeClass('hoverExpanded'); } return oItem; }; CrosstabEventTarget.prototype._getItemTarget = function _getItemTarget(event) { var oSelections = this.view.visControl.nodeToSelection(event); if (!oSelections) { return null; } var aColumnValues = oSelections.column_level1 ? oSelections.column_level1.value : []; var aRowValues = oSelections.row_level1 ? oSelections.row_level1.value : []; var aFactValues = oSelections.datapoint ? [oSelections.datapoint] : []; var aItemClassValues = oSelections.itemClassValues ? oSelections.itemClassValues : []; var sType = oSelections.isInnerEdge === true ? EVENTTYPE.DATAPOINT : EVENTTYPE.ITEM; var oItem = this._createItem(sType, event); // If itemClass target, obtain the item values first. The items are then used to create // the selection context in _getMeasureSelectionContext if (aItemClassValues.length > 0) { oItem.values = aItemClassValues; oItem.selectionContext = this._getMeasureSelectionContext(oItem.values); } else { var oSelectionContext = this._getSelectionContext(oSelections.selectionContext); if (oSelectionContext) { oItem.selectionContext = oSelectionContext; oItem.selectionContext.actions.actionOptions = { deleteAction: { excludeAction: true }, jumpToAction: { area: event.target.getAttribute('area') } }; } this._addItemValues(oItem.values, aColumnValues, aRowValues, aFactValues); } // Disable selection actions for events containing expanded items // This is due to limitations for brushing/slicing on expanded items for expand/collapse feature if (this._includesExpanded(aColumnValues, aRowValues)) { oItem.infoType = EVENTTYPE.EXPANDED; oItem.values = []; $(event.currentTarget).addClass('hoverExpanded'); } else { $(event.currentTarget).removeClass('hoverExpanded'); } return oItem; }; CrosstabEventTarget.prototype._getMeasureSelectionContext = function _getMeasureSelectionContext(oItemValues) { var selectionContext = { actions: { actionsToKeep: [], actionOptions: {} } }; selectionContext.slots = [this.visualization.getSlots().getSlot(SLOTID.VALUES)]; selectionContext.mapIndex = []; _.each(oItemValues, function (slot) { _.each(slot, function (dataItem) { selectionContext.mapIndex.push(dataItem.mapIndex); }); }); return selectionContext; }; CrosstabEventTarget.prototype._getSelectionContext = function _getSelectionContext(selectionContext) { if (selectionContext.level === undefined) { return null; } var oSlot = this.visualization.getSlots().getSlot(selectionContext.slotID); var aColumnItemAPIs = oSlot && oSlot.getDataItemList(); if (aColumnItemAPIs && aColumnItemAPIs.length > 0 && selectionContext.level < aColumnItemAPIs.length) { return { 'mapIndex': selectionContext.level, 'slots': [oSlot], 'actions': { actionsToKeep: [], actionOptions: {} } }; } }; CrosstabEventTarget.prototype._createItem = function _createItem(itemType, event) { var oItem = {}; oItem.infoType = itemType; var $target = $(this._getTargetNode(event)); oItem.key = $target.attr('row') + ':' + $target.attr('col'); oItem.source = $target; oItem.values = []; return oItem; }; CrosstabEventTarget.prototype._addItemValues = function _addItemValues(itemValues, colValues, rowValues, factValues, heatValues) { var aSlots = this.visualization.getSlots().getMappedSlotList(); //Mapped Slots only _.each(aSlots, function (entry) { var id = entry.getId(); if (id === SLOTID.COLUMN) { itemValues.push(colValues); } else if (id === SLOTID.ROW) { itemValues.push(rowValues); //Required Slot } else if (id === SLOTID.VALUES) { itemValues.push(factValues); //Required Slot } else if (id === SLOTID.HEAT) { itemValues.push(heatValues); } }); }; CrosstabEventTarget.prototype._getMeasureItemClassTarget = function _getMeasureItemClassTarget(event) { var itemTarget = this._getItemTarget(event); itemTarget.infoType = EVENTTYPE.ITEMCLASS; return itemTarget; }; CrosstabEventTarget.prototype._getSummaryItemTarget = function _getSummaryItemTarget(event, isCell) { var itemTarget = isCell ? null : this._getItemTarget(event); if (itemTarget) { itemTarget.infoType = EVENTTYPE.SUMMARY; itemTarget.selectionContext = { actions: { actionsToKeep: ['text'], actionOptions: { TextAction: { area: AREA_TYPE.SUMMARY } } } }; } return itemTarget; }; CrosstabEventTarget.prototype._getUnionValues = function _getUnionValues() { var dataItems = this.view.content.getFeature('Visualization').getSlots().getDataItemList(); var drillDownValue = void 0; var unionItems = []; var drillDownValues = []; // Get first level union item list and slot drill down values _.forEach(dataItems, function (dataItem) { drillDownValue = dataItem.getDrillDownValue(); if (drillDownValue) { drillDownValues.push(drillDownValue); } if (dataItem.getUnion) { unionItems.push.apply(unionItems, dataItem.getUnion().getDataItemList()); } }); var item = void 0; var values = []; // DFS on union model while (!_.isEmpty(unionItems)) { item = unionItems.pop(); drillDownValue = item.getDrillDownValue(); if (drillDownValue && !(_.indexOf(drillDownValues, drillDownValue) !== -1)) { values.push(drillDownValue); } if (item.getUnion) { unionItems.push.apply(unionItems, item.getUnion().getDataItemList()); } } return values; }; CrosstabEventTarget.prototype._includesExpanded = function _includesExpanded(aColumnValues, aRowValues) { var eventValues = []; // value.pu is for level based hiearchy; value.p.u is for member based hierachy eventValues.push.apply(eventValues, aColumnValues.reduce(function (arr, value) { if (value.pu) { arr.push(value.pu); } else if (value.p && value.p.u) { arr.push(value.p.u); } return arr; }, [])); eventValues.push.apply(eventValues, aRowValues.reduce(function (arr, value) { if (value.pu) { arr.push(value.pu); } else if (value.p && value.p.u) { arr.push(value.p.u); } return arr; }, [])); var unionValues = this._getUnionValues(); return !_.isEmpty(_.intersection(eventValues, unionValues)); }; CrosstabEventTarget.prototype._isValidEvent = function _isValidEvent(event) { var _this3 = this; var _isTargetValidGridCell = function _isTargetValidGridCell(eventTarget) { return eventTarget.localName === 'div' && ($(eventTarget).hasClass('bottom-right-grid-cell') || $(eventTarget).hasClass('top-right-grid-cell') || $(eventTarget).hasClass('bottom-left-grid-cell') || $(eventTarget).hasClass('top-left-grid-cell')); }; var _fnClickTapCheck = function _fnClickTapCheck(eventTarget) { return _isTargetValidGridCell(eventTarget); }; var _fnContextMenuCheck = function _fnContextMenuCheck(eventTarget) { return _isTargetValidGridCell(eventTarget); }; var _fnMouseMoveCheck = function _fnMouseMoveCheck(eventTarget) { return _isTargetValidGridCell(eventTarget); }; var _fnMouseLeaveCheck = function _fnMouseLeaveCheck(eventTarget) { return _this3.mouseWithinBoundCheck(event) && _isTargetValidGridCell(eventTarget); }; var _fnKeydownCheck = function _fnKeydownCheck(eventTarget) { if (_isTargetValidGridCell(eventTarget)) { return true; } return false; }; var oValidEvents = { click: _fnClickTapCheck, clicktap: _fnClickTapCheck, mousedown: _fnClickTapCheck, tap: _fnClickTapCheck, contextmenu: _fnContextMenuCheck, hold: _fnContextMenuCheck, mousemove: _fnMouseMoveCheck, mouseleave: _fnMouseLeaveCheck.bind(this), keydown: _fnKeydownCheck }; var fnCheck = oValidEvents[event.type]; var target = this._getTargetNode(event); return fnCheck && fnCheck(target) === true; }; return CrosstabEventTarget; }(NonVIPREventTarget); return CrosstabEventTarget; }); //# sourceMappingURL=CrosstabEventTarget.js.map