UNPKG

@syncfusion/ej2-pivotview

Version:

The pivot grid, or pivot table, is used to visualize large sets of relational data in a cross-tabular format, similar to an Excel pivot table.

133 lines (132 loc) 7.75 kB
import { isNullOrUndefined, closest } from '@syncfusion/ej2-base'; import * as cls from '../base/css-constant'; /** * `DialogAction` module is used to handle field list dialog related behaviour. * */ /** @hidden */ var NodeStateModified = /** @class */ (function () { /** * Constructor for the dialog action. * * @param {PivotCommon} parent - It represent the parent data. * @hidden */ function NodeStateModified(parent) { this.parent = parent; } /** * Updates the dataSource by drag and drop the selected field from either field list or axis table with dropped target position. * * @param {DragAndDropEventArgs} args - Contains both pivot button and field list drag and drop information. * @param {string} fieldName - Defines dropped field name to update dataSource. * @returns {boolean} true if the node is successfully dropped, otherwise false. * @hidden */ NodeStateModified.prototype.onStateModified = function (args, fieldName) { var droppedClass = ''; var nodeDropped = true; var target = closest(args.target, '.' + cls.DROPPABLE_CLASS); var droppedPosition = -1; this.parent.dataSourceUpdate.btnElement = args.element ? args.element.parentElement : undefined; if (target) { droppedClass = target.classList[1] === cls.ROW_AXIS_CLASS ? 'rows' : target.classList[1] === cls.COLUMN_AXIS_CLASS ? 'columns' : target.classList[1] === cls.VALUE_AXIS_CLASS ? 'values' : target.classList[1] === cls.FILTER_AXIS_CLASS ? 'filters' : ''; } if (this.parent.dataType === 'olap' || this.parent.dataType === 'pivot') { var actualFieldName = (this.parent.dataType === 'olap' && this.parent.engineModule.fieldList[fieldName] && this.parent.engineModule.fieldList[fieldName].isCalculatedField ? this.parent.engineModule.fieldList[fieldName].tag : fieldName); if (args.cancel && droppedClass === '') { nodeDropped = false; return nodeDropped; } else if ((this.parent.dataSourceUpdate.btnElement && (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'true' && (droppedClass === 'filters' || droppedClass === 'values'))) || (this.parent.dataSourceUpdate.btnElement && (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' && actualFieldName.toLowerCase().indexOf('[measures].') > -1 && this.parent.dataType === 'olap' && (droppedClass === 'filters' || droppedClass === 'rows' || droppedClass === 'columns'))) || (this.parent.dataSourceUpdate.btnElement && (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' && this.parent.dataType === 'olap' && actualFieldName.toLowerCase().indexOf('[measures].') === -1 && this.parent.engineModule.fieldList[fieldName] && this.parent.engineModule.fieldList[fieldName].isNamedSets && (droppedClass === 'filters' || droppedClass === 'values'))) || (this.parent.dataSourceUpdate.btnElement && (this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'false' && this.parent.dataType === 'olap' && actualFieldName.toLowerCase().indexOf('[measures].') === -1 && droppedClass === 'values'))) { var title = this.parent.localeObj.getConstant('warning'); var description = this.parent.localeObj.getConstant('fieldDropErrorAction'); this.parent.errorDialog.createErrorDialog(title, description); nodeDropped = false; return nodeDropped; } } else { if ((args.cancel && droppedClass === '') || (this.parent.dataSourceUpdate.btnElement && this.parent.dataSourceUpdate.btnElement.getAttribute('isValue') === 'true' && ((droppedClass === 'filters' || droppedClass === 'values') || droppedClass.indexOf(this.parent.dataSourceSettings.valueAxis) > -1))) { nodeDropped = false; return nodeDropped; } } if (droppedClass !== '') { if (this.parent.dataType === 'olap' || this.parent.dataType === 'pivot') { var actualFieldName = (this.parent.dataType === 'olap' && this.parent.engineModule.fieldList[fieldName] && this.parent.engineModule.fieldList[fieldName].isCalculatedField ? this.parent.engineModule.fieldList[fieldName].tag : fieldName); if ((actualFieldName.toLowerCase().indexOf('[measures].') > -1 && this.parent.dataType === 'olap' && (droppedClass === 'filters' || droppedClass === 'rows' || droppedClass === 'columns')) || (this.parent.engineModule.fieldList[fieldName] && this.parent.engineModule.fieldList[fieldName].isNamedSets && droppedClass === 'filters') || (this.parent.dataType === 'olap' && droppedClass === 'values' && actualFieldName.toLowerCase().indexOf('[measures].') === -1)) { var title = this.parent.localeObj.getConstant('warning'); var description = this.parent.localeObj.getConstant('fieldDropErrorAction'); this.parent.errorDialog.createErrorDialog(title, description); nodeDropped = false; return nodeDropped; } } if (this.parent.dataType === 'pivot' && this.parent.engineModule.fieldList[fieldName] && this.parent.engineModule.fieldList[fieldName].aggregateType === 'CalculatedField' && droppedClass !== 'values') { var title = this.parent.localeObj.getConstant('warning'); var description = this.parent.localeObj.getConstant('dropAction'); this.parent.errorDialog.createErrorDialog(title, description); nodeDropped = false; return nodeDropped; } droppedPosition = this.getButtonPosition(args.target, droppedClass); } else if (this.parent.engineModule.fieldList[fieldName]) { this.parent.engineModule.fieldList[fieldName].isSelected = false; if (this.parent.dataType === 'olap') { this.parent.engineModule.updateFieldlistData(fieldName); } } nodeDropped = this.parent.dataSourceUpdate.updateDataSource(fieldName, droppedClass, droppedPosition); return nodeDropped; }; NodeStateModified.prototype.getButtonPosition = function (target, droppedClass) { var droppedPosition = -1; var targetBtn = closest(target, '.' + cls.PIVOT_BUTTON_WRAPPER_CLASS); if (!isNullOrUndefined(targetBtn)) { targetBtn = targetBtn.querySelector('.' + cls.PIVOT_BUTTON_CLASS); var axisPanel = this.parent.element.querySelector('.e-' + droppedClass); var pivotButtons = [].slice.call(axisPanel.querySelectorAll('.' + cls.PIVOT_BUTTON_CLASS)); for (var i = 0, n = pivotButtons.length; i < n; i++) { if (pivotButtons[i].id === targetBtn.id) { droppedPosition = i; break; } } } return droppedPosition; }; return NodeStateModified; }()); export { NodeStateModified };