/** * ag-grid-community - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components * @version v21.2.2 * @link http://www.ag-grid.com/ * @license MIT */ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var componentAnnotations_1 = require("../../widgets/componentAnnotations"); var optionsFactory_1 = require("./optionsFactory"); var providedFilter_1 = require("./providedFilter"); var utils_1 = require("../../utils"); var ConditionPosition; (function (ConditionPosition) { ConditionPosition[ConditionPosition["One"] = 0] = "One"; ConditionPosition[ConditionPosition["Two"] = 1] = "Two"; })(ConditionPosition = exports.ConditionPosition || (exports.ConditionPosition = {})); var DEFAULT_TRANSLATIONS = { loadingOoo: 'Loading...', empty: 'Choose One', equals: 'Equals', notEqual: 'Not equal', lessThan: 'Less than', greaterThan: 'Greater than', inRange: 'In range', lessThanOrEqual: 'Less than or equals', greaterThanOrEqual: 'Greater than or equals', filterOoo: 'Filter...', contains: 'Contains', notContains: 'Not contains', startsWith: 'Starts with', endsWith: 'Ends with', searchOoo: 'Search...', selectAll: 'Select All', applyFilter: 'Apply Filter', clearFilter: 'Clear Filter', andCondition: 'AND', orCondition: 'OR' }; /** * Every filter with a dropdown where the user can specify a comparing type against the filter values */ var SimpleFilter = /** @class */ (function (_super) { __extends(SimpleFilter, _super); function SimpleFilter() { return _super !== null && _super.apply(this, arguments) || this; } // returns true if this type requires a 'from' field, eg any filter that requires at least one text value SimpleFilter.prototype.showValueFrom = function (type) { return !this.doesFilterHaveHiddenInput(type) && type !== SimpleFilter.EMPTY; }; // returns true if this type requires a 'to' field, currently only 'range' returns true SimpleFilter.prototype.showValueTo = function (type) { return type === SimpleFilter.IN_RANGE; }; // floating filter calls this when user applies filter from floating filter SimpleFilter.prototype.onFloatingFilterChanged = function (type, value) { this.setValueFromFloatingFilter(value); this.setTypeFromFloatingFilter(type); this.onUiChanged(true); }; SimpleFilter.prototype.setTypeFromFloatingFilter = function (type) { this.eType1.value = type; this.eType2.value = null; this.eJoinOperatorAnd.checked = true; }; SimpleFilter.prototype.getModelFromUi = function () { if (!this.isConditionUiComplete(ConditionPosition.One)) { return null; } if (this.isAllowTwoConditions() && this.isConditionUiComplete(ConditionPosition.Two)) { var res = { filterType: this.getFilterType(), operator: this.getJoinOperator(), condition1: this.createCondition(ConditionPosition.One), condition2: this.createCondition(ConditionPosition.Two) }; return res; } else { var res = this.createCondition(ConditionPosition.One); return res; } }; SimpleFilter.prototype.getCondition1Type = function () { return this.eType1.value; }; SimpleFilter.prototype.getCondition2Type = function () { return this.eType2.value; }; SimpleFilter.prototype.getJoinOperator = function () { return this.eJoinOperatorOr.checked ? 'OR' : 'AND'; }; SimpleFilter.prototype.areModelsEqual = function (a, b) { // both are missing if (!a && !b) { return true; } // one is missing, other present if ((!a && b) || (a && !b)) { return false; } // one is combined, the other is not var aIsSimple = !a.operator; var bIsSimple = !b.operator; var oneSimpleOneCombined = (!aIsSimple && bIsSimple) || (aIsSimple && !bIsSimple); if (oneSimpleOneCombined) { return false; } var res; // otherwise both present, so compare if (aIsSimple) { var aSimple = a; var bSimple = b; res = this.areSimpleModelsEqual(aSimple, bSimple); } else { var aCombined = a; var bCombined = b; res = aCombined.operator === bCombined.operator && this.areSimpleModelsEqual(aCombined.condition1, bCombined.condition1) && this.areSimpleModelsEqual(aCombined.condition2, bCombined.condition2); } return res; }; SimpleFilter.prototype.setModelIntoUi = function (model) { var isCombined = model.operator; if (isCombined) { var combinedModel = model; var orChecked = combinedModel.operator === 'OR'; this.eJoinOperatorAnd.checked = !orChecked; this.eJoinOperatorOr.checked = orChecked; this.eType1.value = combinedModel.condition1.type; this.eType2.value = combinedModel.condition2.type; this.setConditionIntoUi(combinedModel.condition1, ConditionPosition.One); this.setConditionIntoUi(combinedModel.condition2, ConditionPosition.Two); } else { var simpleModel = model; this.eJoinOperatorAnd.checked = true; this.eJoinOperatorOr.checked = false; this.eType1.value = simpleModel.type; this.eType2.value = this.optionsFactory.getDefaultOption(); this.setConditionIntoUi(simpleModel, ConditionPosition.One); this.setConditionIntoUi(null, ConditionPosition.Two); } }; SimpleFilter.prototype.doesFilterPass = function (params) { var model = this.getModel(); var isCombined = model.operator; if (isCombined) { var combinedModel = model; var firstResult = this.individualConditionPasses(params, combinedModel.condition1); var secondResult = this.individualConditionPasses(params, combinedModel.condition2); if (combinedModel.operator === 'AND') { return firstResult && secondResult; } else { return firstResult || secondResult; } } else { var simpleModel = model; var result = this.individualConditionPasses(params, simpleModel); return result; } }; SimpleFilter.prototype.setParams = function (params) { _super.prototype.setParams.call(this, params); this.simpleFilterParams = params; this.optionsFactory = new optionsFactory_1.OptionsFactory(); this.optionsFactory.init(params, this.getDefaultFilterOptions()); this.allowTwoConditions = !params.suppressAndOrCondition; this.putOptionsIntoDropdown(); this.addChangedListeners(); }; SimpleFilter.prototype.putOptionsIntoDropdown = function () { var _this = this; var filterOptions = this.optionsFactory.getFilterOptions(); filterOptions.forEach(function (option) { var createOption = function () { var key = (typeof option === 'string') ? option : option.displayKey; var localName = _this.translate(key); var eOption = document.createElement("option"); eOption.text = localName; eOption.value = key; return eOption; }; _this.eType1.add(createOption()); _this.eType2.add(createOption()); }); var readOnly = filterOptions.length <= 1; this.eType1.disabled = readOnly; this.eType2.disabled = readOnly; }; SimpleFilter.prototype.isAllowTwoConditions = function () { return this.allowTwoConditions; }; SimpleFilter.prototype.createBodyTemplate = function () { var optionsTemplate1 = ""; var valueTemplate1 = this.createValueTemplate(ConditionPosition.One); var optionsTemplate2 = ""; var valueTemplate2 = this.createValueTemplate(ConditionPosition.Two); var uniqueGroupId = 'ag-simple-filter-and-or-' + this.getCompId(); var translate = this.gridOptionsWrapper.getLocaleTextFunc(); var andOrTemplate = "