1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __extends = (this && this.__extends) || (function () {
|
9 | var extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return function (d, b) {
|
13 | extendStatics(d, b);
|
14 | function __() { this.constructor = d; }
|
15 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
16 | };
|
17 | })();
|
18 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
19 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
20 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
21 | 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;
|
22 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
23 | };
|
24 | var __metadata = (this && this.__metadata) || function (k, v) {
|
25 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | var utils_1 = require("../utils");
|
29 | var baseFilter_1 = require("./baseFilter");
|
30 | var componentAnnotations_1 = require("../widgets/componentAnnotations");
|
31 | var TextFilter = (function (_super) {
|
32 | __extends(TextFilter, _super);
|
33 | function TextFilter() {
|
34 | return _super !== null && _super.apply(this, arguments) || this;
|
35 | }
|
36 | TextFilter.prototype.getDefaultType = function () {
|
37 | return baseFilter_1.BaseFilter.CONTAINS;
|
38 | };
|
39 | TextFilter.prototype.customInit = function () {
|
40 | this.comparator = this.filterParams.textCustomComparator ? this.filterParams.textCustomComparator : TextFilter.DEFAULT_COMPARATOR;
|
41 | this.formatter =
|
42 | this.filterParams.textFormatter ? this.filterParams.textFormatter :
|
43 | this.filterParams.caseSensitive == true ? TextFilter.DEFAULT_FORMATTER :
|
44 | TextFilter.DEFAULT_LOWERCASE_FORMATTER;
|
45 | _super.prototype.customInit.call(this);
|
46 | };
|
47 | TextFilter.prototype.modelFromFloatingFilter = function (from) {
|
48 | return {
|
49 | type: this.filter,
|
50 | filter: from,
|
51 | filterType: 'text'
|
52 | };
|
53 | };
|
54 | TextFilter.prototype.getApplicableFilterTypes = function () {
|
55 | return [baseFilter_1.BaseFilter.EQUALS, baseFilter_1.BaseFilter.NOT_EQUAL, baseFilter_1.BaseFilter.STARTS_WITH, baseFilter_1.BaseFilter.ENDS_WITH,
|
56 | baseFilter_1.BaseFilter.CONTAINS, baseFilter_1.BaseFilter.NOT_CONTAINS];
|
57 | };
|
58 | TextFilter.prototype.bodyTemplate = function (type) {
|
59 | var translate = this.translate.bind(this);
|
60 | var fieldId = type == baseFilter_1.FilterConditionType.MAIN ? "filterText" : "filterConditionText";
|
61 | return "<div class=\"ag-filter-body\">\n <input class=\"ag-filter-filter\" id=" + fieldId + " type=\"text\" placeholder=\"" + translate('filterOoo', 'Filter...') + "\"/>\n </div>";
|
62 | };
|
63 | TextFilter.prototype.initialiseFilterBodyUi = function (type) {
|
64 | _super.prototype.initialiseFilterBodyUi.call(this, type);
|
65 | this.addFilterChangedListener(type);
|
66 | this.setFilter(this.filterConditionText, baseFilter_1.FilterConditionType.CONDITION);
|
67 | this.setFilterType(this.filterCondition, baseFilter_1.FilterConditionType.CONDITION);
|
68 | };
|
69 | TextFilter.prototype.addFilterChangedListener = function (type) {
|
70 | var _this = this;
|
71 | var eElement = type === baseFilter_1.FilterConditionType.MAIN ? this.eFilterTextField : this.eFilterConditionTextField;
|
72 | var debounceMs = this.getDebounceMs(this.filterParams);
|
73 | var toDebounce = utils_1.Utils.debounce(function () { return _this.onFilterTextFieldChanged(type); }, debounceMs);
|
74 | this.addDestroyableEventListener(eElement, 'input', toDebounce);
|
75 | };
|
76 | TextFilter.prototype.refreshFilterBodyUi = function (type) {
|
77 | if (this.eFilterConditionTextField) {
|
78 | this.addFilterChangedListener(baseFilter_1.FilterConditionType.CONDITION);
|
79 | }
|
80 | };
|
81 | TextFilter.prototype.afterGuiAttached = function () {
|
82 | this.eFilterTextField.focus();
|
83 | };
|
84 | TextFilter.prototype.filterValues = function (type) {
|
85 | return type === baseFilter_1.FilterConditionType.MAIN ? this.filterText : this.filterConditionText;
|
86 | };
|
87 | TextFilter.prototype.individualFilterPasses = function (params, type) {
|
88 | var filterText = type == baseFilter_1.FilterConditionType.MAIN ? this.filterText : this.filterConditionText;
|
89 | var filter = type == baseFilter_1.FilterConditionType.MAIN ? this.filter : this.filterCondition;
|
90 | if (!filterText) {
|
91 | return type === baseFilter_1.FilterConditionType.MAIN ? true : this.conditionValue === 'AND';
|
92 | }
|
93 | else {
|
94 | return this.checkIndividualFilter(params, filter, filterText);
|
95 | }
|
96 | };
|
97 | TextFilter.prototype.checkIndividualFilter = function (params, filterType, filterText) {
|
98 | var value = this.filterParams.valueGetter(params.node);
|
99 | if (value == null || value === undefined) {
|
100 | return filterType === baseFilter_1.BaseFilter.NOT_EQUAL || filterType === baseFilter_1.BaseFilter.NOT_CONTAINS;
|
101 | }
|
102 | var valueFormatted = this.formatter(value);
|
103 | return this.comparator(filterType, valueFormatted, filterText);
|
104 | };
|
105 | TextFilter.prototype.onFilterTextFieldChanged = function (type) {
|
106 | var value = type === baseFilter_1.FilterConditionType.MAIN ? this.eFilterTextField.value : this.eFilterConditionTextField.value;
|
107 | var current = type === baseFilter_1.FilterConditionType.MAIN ? this.filterText : this.filterConditionText;
|
108 | var filterText = utils_1.Utils.makeNull(value);
|
109 | if (filterText && filterText.trim() === '') {
|
110 | filterText = null;
|
111 | }
|
112 | if (current !== filterText) {
|
113 | var newLowerCase = filterText && this.filterParams.caseSensitive != true ? filterText.toLowerCase() :
|
114 | filterText;
|
115 | var previousLowerCase = current && this.filterParams.caseSensitive != true ? current.toLowerCase() :
|
116 | current;
|
117 | if (type === baseFilter_1.FilterConditionType.MAIN) {
|
118 | this.filterText = this.formatter(filterText);
|
119 | }
|
120 | else {
|
121 | this.filterConditionText = this.formatter(filterText);
|
122 | }
|
123 | if (previousLowerCase !== newLowerCase) {
|
124 | this.onFilterChanged();
|
125 | }
|
126 | }
|
127 | };
|
128 | TextFilter.prototype.setFilter = function (filter, type) {
|
129 | filter = utils_1.Utils.makeNull(filter);
|
130 | if (type === baseFilter_1.FilterConditionType.MAIN) {
|
131 | if (filter) {
|
132 | this.filterText = this.formatter(filter);
|
133 | if (!this.eFilterTextField)
|
134 | return;
|
135 | this.eFilterTextField.value = filter;
|
136 | }
|
137 | else {
|
138 | this.filterText = null;
|
139 | if (!this.eFilterTextField)
|
140 | return;
|
141 | this.eFilterTextField.value = null;
|
142 | }
|
143 | }
|
144 | else {
|
145 | if (filter) {
|
146 | this.filterConditionText = this.formatter(filter);
|
147 | if (!this.eFilterConditionTextField)
|
148 | return;
|
149 | this.eFilterConditionTextField.value = filter;
|
150 | }
|
151 | else {
|
152 | this.filterConditionText = null;
|
153 | if (!this.eFilterConditionTextField)
|
154 | return;
|
155 | this.eFilterConditionTextField.value = null;
|
156 | }
|
157 | }
|
158 | };
|
159 | TextFilter.prototype.getFilter = function () {
|
160 | return this.filterText;
|
161 | };
|
162 | TextFilter.prototype.resetState = function () {
|
163 | this.setFilter(null, baseFilter_1.FilterConditionType.MAIN);
|
164 | this.setFilterType(this.defaultFilter, baseFilter_1.FilterConditionType.MAIN);
|
165 | this.setFilter(null, baseFilter_1.FilterConditionType.CONDITION);
|
166 | this.setFilterType(this.defaultFilter, baseFilter_1.FilterConditionType.CONDITION);
|
167 | };
|
168 | TextFilter.prototype.serialize = function (type) {
|
169 | var filter = type === baseFilter_1.FilterConditionType.MAIN ? this.filter : this.filterCondition;
|
170 | var filterText = type === baseFilter_1.FilterConditionType.MAIN ? this.filterText : this.filterConditionText;
|
171 | return {
|
172 | type: filter ? filter : this.defaultFilter,
|
173 | filter: filterText,
|
174 | filterType: 'text'
|
175 | };
|
176 | };
|
177 | TextFilter.prototype.parse = function (model, type) {
|
178 | this.setFilterType(model.type, type);
|
179 | this.setFilter(model.filter, type);
|
180 | };
|
181 | TextFilter.prototype.setType = function (filterType, type) {
|
182 | this.setFilterType(filterType, type);
|
183 | };
|
184 | TextFilter.DEFAULT_FORMATTER = function (from) {
|
185 | return from;
|
186 | };
|
187 | TextFilter.DEFAULT_LOWERCASE_FORMATTER = function (from) {
|
188 | if (from == null) {
|
189 | return null;
|
190 | }
|
191 | return from.toString().toLowerCase();
|
192 | };
|
193 | TextFilter.DEFAULT_COMPARATOR = function (filter, value, filterText) {
|
194 | switch (filter) {
|
195 | case TextFilter.CONTAINS:
|
196 | return value.indexOf(filterText) >= 0;
|
197 | case TextFilter.NOT_CONTAINS:
|
198 | return value.indexOf(filterText) === -1;
|
199 | case TextFilter.EQUALS:
|
200 | return value === filterText;
|
201 | case TextFilter.NOT_EQUAL:
|
202 | return value != filterText;
|
203 | case TextFilter.STARTS_WITH:
|
204 | return value.indexOf(filterText) === 0;
|
205 | case TextFilter.ENDS_WITH:
|
206 | var index = value.lastIndexOf(filterText);
|
207 | return index >= 0 && index === (value.length - filterText.length);
|
208 | default:
|
209 |
|
210 | console.warn('invalid filter type ' + filter);
|
211 | return false;
|
212 | }
|
213 | };
|
214 | __decorate([
|
215 | componentAnnotations_1.QuerySelector('#filterText'),
|
216 | __metadata("design:type", HTMLInputElement)
|
217 | ], TextFilter.prototype, "eFilterTextField", void 0);
|
218 | __decorate([
|
219 | componentAnnotations_1.QuerySelector('#filterConditionText'),
|
220 | __metadata("design:type", HTMLInputElement)
|
221 | ], TextFilter.prototype, "eFilterConditionTextField", void 0);
|
222 | return TextFilter;
|
223 | }(baseFilter_1.ComparableBaseFilter));
|
224 | exports.TextFilter = TextFilter;
|