UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

133 lines (132 loc) 4.92 kB
import { ColumnType } from './enums'; // Тип фильтра по колонке export var FilterOperator; (function (FilterOperator) { FilterOperator["NONE"] = "NONE"; FilterOperator["BETWEEN"] = "BETWEEN"; FilterOperator["NOT_BETWEEN"] = "NOT_BETWEEN"; FilterOperator["CONTAINS"] = "CONTAINS"; FilterOperator["NOT_CONTAINS"] = "NOT_CONTAINS"; FilterOperator["EQUALS"] = "EQUALS"; FilterOperator["NOT_EQUALS"] = "NOT_EQUALS"; FilterOperator["EMPTY"] = "EMPTY"; FilterOperator["NOT_EMPTY"] = "NOT_EMPTY"; FilterOperator["SET"] = "SET"; })(FilterOperator || (FilterOperator = {})); // Фильтр по колонке var Filter = /** @class */ (function () { function Filter(fieldName, operator, value, value2, // For between items, // Selected items active, // Фильтр применен в текущий момент format, // Формат вывода caption, // Заголово колонки type) { if (items === void 0) { items = []; } if (active === void 0) { active = false; } if (format === void 0) { format = ''; } if (caption === void 0) { caption = ''; } if (type === void 0) { type = ColumnType.STRING; } this.fieldName = fieldName; this.operator = operator; this.value = value; this.value2 = value2; this.items = items; this.active = active; this.format = format; this.caption = caption; this.type = type; this.orFilter = null; } Object.defineProperty(Filter.prototype, "txtValue", { get: function () { if (!this.value) { return ''; } return this.value + ''; }, enumerable: true, configurable: true }); Filter.prototype.clearItems = function () { this.items.splice(0, this.items.length); }; // Клонируем фильтр. Редактор фильра будет привязан к копии, // чтобы не задеть текущие фильтры. Filter.prototype.clone = function (active) { var res = new Filter(this.fieldName, this.operator, this.value, this.value2, this.items.slice(), active, this.format, this.caption, this.type); return res; }; Filter.prototype.valueToString = function (value, intl, formatter) { if (value === true) { return intl.translate('True'); } if (value === false) { return intl.translate('False'); } var v = formatter.format(this.type, this.format, value); if (this.type === ColumnType.STRING) { return "'" + v + "'"; } return v; }; Filter.prototype.toString = function (intl, formatter) { var _this = this; var field = "[" + this.caption + "]"; var op = ''; var values = ''; var v1 = ''; var v2 = ''; var items = ''; if (this.value !== null) { v1 = this.valueToString(this.value, intl, formatter); } if (this.value2 !== null) { v2 = this.valueToString(this.value2, intl, formatter); } if (this.items.length > 0) { items = this.items.map(function (i) { return _this.valueToString(i, intl, formatter); }).join(', '); } switch (this.operator) { case FilterOperator.EQUALS: op = ' = '; values = v1; break; case FilterOperator.NOT_EQUALS: op = ' <> '; values = v1; break; case FilterOperator.CONTAINS: op = 'Contains'; values = v1; break; case FilterOperator.NOT_CONTAINS: op = 'Not contains'; values = v1; break; case FilterOperator.BETWEEN: op = 'Between'; values = v1 + " " + intl.translate('And').toUpperCase() + " " + v2; break; case FilterOperator.NOT_BETWEEN: op = 'Not between'; values = v1 + " " + intl.translate('And').toUpperCase() + " " + v2; break; case FilterOperator.EMPTY: op = 'Is empty'; break; case FilterOperator.NOT_EMPTY: op = 'Is not empty'; break; case FilterOperator.SET: op = 'In'; values = "(" + items + ")"; break; } op = intl.translate(op).toUpperCase(); return field + " " + op + " " + values; }; return Filter; }()); export { Filter };