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 context_1 = require("../context/context");
|
29 | var dateFilter_1 = require("./dateFilter");
|
30 | var componentAnnotations_1 = require("../widgets/componentAnnotations");
|
31 | var utils_1 = require("../utils");
|
32 | var componentRecipes_1 = require("../components/framework/componentRecipes");
|
33 | var component_1 = require("../widgets/component");
|
34 | var constants_1 = require("../constants");
|
35 | var InputTextFloatingFilterComp = (function (_super) {
|
36 | __extends(InputTextFloatingFilterComp, _super);
|
37 | function InputTextFloatingFilterComp() {
|
38 | var _this = _super.call(this, "<div><input ref=\"eColumnFloatingFilter\" class=\"ag-floating-filter-input\"></div>") || this;
|
39 | _this.lastKnownModel = null;
|
40 | return _this;
|
41 | }
|
42 | InputTextFloatingFilterComp.prototype.init = function (params) {
|
43 | this.onFloatingFilterChanged = params.onFloatingFilterChanged;
|
44 | this.currentParentModel = params.currentParentModel;
|
45 | var debounceMs = params.debounceMs != null ? params.debounceMs : 500;
|
46 | var toDebounce = utils_1._.debounce(this.syncUpWithParentFilter.bind(this), debounceMs);
|
47 | this.addDestroyableEventListener(this.eColumnFloatingFilter, 'input', toDebounce);
|
48 | this.addDestroyableEventListener(this.eColumnFloatingFilter, 'keypress', toDebounce);
|
49 | this.addDestroyableEventListener(this.eColumnFloatingFilter, 'keydown', toDebounce);
|
50 | var columnDef = params.column.getDefinition();
|
51 | if (columnDef.filterParams && columnDef.filterParams.filterOptions && columnDef.filterParams.filterOptions.length === 1 && columnDef.filterParams.filterOptions[0] === 'inRange') {
|
52 | this.eColumnFloatingFilter.disabled = true;
|
53 | }
|
54 | };
|
55 | InputTextFloatingFilterComp.prototype.onParentModelChanged = function (parentModel, combinedFilter) {
|
56 | if (combinedFilter != null) {
|
57 | this.eColumnFloatingFilter.value = this.parseAsText(combinedFilter.condition1) + " " + combinedFilter.operator + " " + this.parseAsText(combinedFilter.condition2);
|
58 | this.eColumnFloatingFilter.disabled = true;
|
59 | this.lastKnownModel = null;
|
60 | this.eColumnFloatingFilter.title = this.eColumnFloatingFilter.value;
|
61 | this.eColumnFloatingFilter.style.cursor = 'default';
|
62 | return;
|
63 | }
|
64 | else {
|
65 | this.eColumnFloatingFilter.disabled = false;
|
66 | }
|
67 | if (this.equalModels(this.lastKnownModel, parentModel)) {
|
68 |
|
69 | if (!this.lastKnownModel && !parentModel) {
|
70 | this.eColumnFloatingFilter.value = '';
|
71 | }
|
72 | return;
|
73 | }
|
74 | this.lastKnownModel = parentModel;
|
75 | var incomingTextValue = this.asFloatingFilterText(parentModel);
|
76 | if (incomingTextValue === this.eColumnFloatingFilter.value) {
|
77 | return;
|
78 | }
|
79 | this.eColumnFloatingFilter.value = incomingTextValue;
|
80 | this.eColumnFloatingFilter.title = '';
|
81 | };
|
82 | InputTextFloatingFilterComp.prototype.syncUpWithParentFilter = function (e) {
|
83 | var model = this.asParentModel();
|
84 | if (this.equalModels(this.lastKnownModel, model)) {
|
85 | return;
|
86 | }
|
87 | var modelUpdated = null;
|
88 | if (utils_1._.isKeyPressed(e, constants_1.Constants.KEY_ENTER)) {
|
89 | modelUpdated = this.onFloatingFilterChanged({
|
90 | model: model,
|
91 | apply: true
|
92 | });
|
93 | }
|
94 | else {
|
95 | modelUpdated = this.onFloatingFilterChanged({
|
96 | model: model,
|
97 | apply: false
|
98 | });
|
99 | }
|
100 | if (modelUpdated) {
|
101 | this.lastKnownModel = model;
|
102 | }
|
103 | };
|
104 | InputTextFloatingFilterComp.prototype.equalModels = function (left, right) {
|
105 | if (utils_1._.referenceCompare(left, right)) {
|
106 | return true;
|
107 | }
|
108 | if (!left || !right) {
|
109 | return false;
|
110 | }
|
111 | if (Array.isArray(left) || Array.isArray(right)) {
|
112 | return false;
|
113 | }
|
114 | return (utils_1._.referenceCompare(left.type, right.type) &&
|
115 | utils_1._.referenceCompare(left.filter, right.filter) &&
|
116 | utils_1._.referenceCompare(left.filterTo, right.filterTo) &&
|
117 | utils_1._.referenceCompare(left.filterType, right.filterType));
|
118 | };
|
119 | __decorate([
|
120 | componentAnnotations_1.RefSelector('eColumnFloatingFilter'),
|
121 | __metadata("design:type", HTMLInputElement)
|
122 | ], InputTextFloatingFilterComp.prototype, "eColumnFloatingFilter", void 0);
|
123 | return InputTextFloatingFilterComp;
|
124 | }(component_1.Component));
|
125 | exports.InputTextFloatingFilterComp = InputTextFloatingFilterComp;
|
126 | var TextFloatingFilterComp = (function (_super) {
|
127 | __extends(TextFloatingFilterComp, _super);
|
128 | function TextFloatingFilterComp() {
|
129 | return _super !== null && _super.apply(this, arguments) || this;
|
130 | }
|
131 | TextFloatingFilterComp.prototype.asFloatingFilterText = function (parentModel) {
|
132 | if (!parentModel) {
|
133 | return '';
|
134 | }
|
135 | return parentModel.filter;
|
136 | };
|
137 | TextFloatingFilterComp.prototype.asParentModel = function () {
|
138 | var currentParentModel = this.currentParentModel();
|
139 | return {
|
140 | type: currentParentModel.type,
|
141 | filter: this.eColumnFloatingFilter.value,
|
142 | filterType: 'text'
|
143 | };
|
144 | };
|
145 | TextFloatingFilterComp.prototype.parseAsText = function (model) {
|
146 | return this.asFloatingFilterText(model);
|
147 | };
|
148 | return TextFloatingFilterComp;
|
149 | }(InputTextFloatingFilterComp));
|
150 | exports.TextFloatingFilterComp = TextFloatingFilterComp;
|
151 | var DateFloatingFilterComp = (function (_super) {
|
152 | __extends(DateFloatingFilterComp, _super);
|
153 | function DateFloatingFilterComp() {
|
154 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
155 | _this.lastKnownModel = null;
|
156 | return _this;
|
157 | }
|
158 | DateFloatingFilterComp.prototype.init = function (params) {
|
159 | this.onFloatingFilterChanged = params.onFloatingFilterChanged;
|
160 | this.currentParentModel = params.currentParentModel;
|
161 | var debounceMs = params.debounceMs != null ? params.debounceMs : 500;
|
162 | var toDebounce = utils_1._.debounce(this.onDateChanged.bind(this), debounceMs);
|
163 | var dateComponentParams = {
|
164 | onDateChanged: toDebounce,
|
165 | filterParams: params.column.getColDef().filterParams
|
166 | };
|
167 | this.dateComponentPromise = this.componentRecipes.newDateComponent(dateComponentParams);
|
168 | var body = utils_1._.loadTemplate("<div></div>");
|
169 | this.dateComponentPromise.then(function (dateComponent) {
|
170 | body.appendChild(dateComponent.getGui());
|
171 | var columnDef = params.column.getDefinition();
|
172 | var isInRange = (columnDef.filterParams &&
|
173 | columnDef.filterParams.filterOptions &&
|
174 | columnDef.filterParams.filterOptions.length === 1 &&
|
175 | columnDef.filterParams.filterOptions[0] === 'inRange');
|
176 | if (dateComponent.eDateInput) {
|
177 | dateComponent.eDateInput.disabled = isInRange;
|
178 | }
|
179 | });
|
180 | this.setTemplateFromElement(body);
|
181 | };
|
182 | DateFloatingFilterComp.prototype.onDateChanged = function () {
|
183 | var parentModel = this.currentParentModel();
|
184 | var model = this.asParentModel();
|
185 | if (this.equalModels(parentModel, model)) {
|
186 | return;
|
187 | }
|
188 | this.onFloatingFilterChanged({
|
189 | model: model,
|
190 | apply: true
|
191 | });
|
192 | this.lastKnownModel = model;
|
193 | };
|
194 | DateFloatingFilterComp.prototype.equalModels = function (left, right) {
|
195 | if (utils_1._.referenceCompare(left, right)) {
|
196 | return true;
|
197 | }
|
198 | if (!left || !right) {
|
199 | return false;
|
200 | }
|
201 | if (Array.isArray(left) || Array.isArray(right)) {
|
202 | return false;
|
203 | }
|
204 | return (utils_1._.referenceCompare(left.type, right.type) &&
|
205 | utils_1._.referenceCompare(left.dateFrom, right.dateFrom) &&
|
206 | utils_1._.referenceCompare(left.dateTo, right.dateTo) &&
|
207 | utils_1._.referenceCompare(left.filterType, right.filterType));
|
208 | };
|
209 | DateFloatingFilterComp.prototype.asParentModel = function () {
|
210 | var currentParentModel = this.currentParentModel();
|
211 | var filterValueDate = this.dateComponentPromise.resolveNow(null, function (dateComponent) { return dateComponent.getDate(); });
|
212 | var filterValueText = utils_1._.serializeDateToYyyyMmDd(dateFilter_1.DateFilter.removeTimezone(filterValueDate), "-");
|
213 | return {
|
214 | type: currentParentModel.type,
|
215 | dateFrom: filterValueText,
|
216 | dateTo: currentParentModel ? currentParentModel.dateTo : null,
|
217 | filterType: 'date'
|
218 | };
|
219 | };
|
220 | DateFloatingFilterComp.prototype.onParentModelChanged = function (parentModel) {
|
221 | var _this = this;
|
222 | this.lastKnownModel = parentModel;
|
223 | this.dateComponentPromise.then(function (dateComponent) {
|
224 | if (!parentModel || !parentModel.dateFrom) {
|
225 | dateComponent.setDate(null);
|
226 | return;
|
227 | }
|
228 | _this.enrichDateInput(parentModel.type, parentModel.dateFrom, parentModel.dateTo, dateComponent);
|
229 | dateComponent.setDate(utils_1._.parseYyyyMmDdToDate(parentModel.dateFrom, '-'));
|
230 | });
|
231 | };
|
232 | DateFloatingFilterComp.prototype.enrichDateInput = function (type, dateFrom, dateTo, dateComponent) {
|
233 | if (dateComponent.eDateInput) {
|
234 | if (type === 'inRange') {
|
235 | dateComponent.eDateInput.title = dateFrom + " to " + dateTo;
|
236 | dateComponent.eDateInput.disabled = true;
|
237 | }
|
238 | else {
|
239 | dateComponent.eDateInput.title = '';
|
240 | dateComponent.eDateInput.disabled = true;
|
241 | }
|
242 | }
|
243 | };
|
244 | __decorate([
|
245 | context_1.Autowired('componentRecipes'),
|
246 | __metadata("design:type", componentRecipes_1.ComponentRecipes)
|
247 | ], DateFloatingFilterComp.prototype, "componentRecipes", void 0);
|
248 | return DateFloatingFilterComp;
|
249 | }(component_1.Component));
|
250 | exports.DateFloatingFilterComp = DateFloatingFilterComp;
|
251 | var NumberFloatingFilterComp = (function (_super) {
|
252 | __extends(NumberFloatingFilterComp, _super);
|
253 | function NumberFloatingFilterComp() {
|
254 | return _super !== null && _super.apply(this, arguments) || this;
|
255 | }
|
256 | NumberFloatingFilterComp.prototype.asFloatingFilterText = function (toParse) {
|
257 | var currentParentModel = this.currentParentModel();
|
258 | if (toParse == null && currentParentModel == null) {
|
259 | return '';
|
260 | }
|
261 | if (toParse == null && currentParentModel != null && currentParentModel.type !== 'inRange') {
|
262 | this.eColumnFloatingFilter.disabled = false;
|
263 | return '';
|
264 | }
|
265 | if (currentParentModel != null && currentParentModel.type === 'inRange') {
|
266 | this.eColumnFloatingFilter.disabled = true;
|
267 | return this.parseAsText(currentParentModel);
|
268 | }
|
269 | this.eColumnFloatingFilter.disabled = false;
|
270 | return this.parseAsText(toParse);
|
271 | };
|
272 | NumberFloatingFilterComp.prototype.parseAsText = function (model) {
|
273 | if (model.type && model.type === 'inRange') {
|
274 | var number_1 = this.asNumber(model.filter);
|
275 | var numberTo = this.asNumber(model.filterTo);
|
276 | return (number_1 ? number_1 + '' : '') +
|
277 | '-' +
|
278 | (numberTo ? numberTo + '' : '');
|
279 | }
|
280 | var number = this.asNumber(model.filter);
|
281 | return number != null ? number + '' : '';
|
282 | };
|
283 | NumberFloatingFilterComp.prototype.asParentModel = function () {
|
284 | var currentParentModel = this.currentParentModel();
|
285 | var filterValueNumber = this.asNumber(this.eColumnFloatingFilter.value);
|
286 | var filterValueText = this.eColumnFloatingFilter.value;
|
287 | var modelFilterValue = null;
|
288 | if (filterValueNumber == null && filterValueText === '') {
|
289 | modelFilterValue = null;
|
290 | }
|
291 | else if (filterValueNumber == null) {
|
292 | modelFilterValue = currentParentModel.filter;
|
293 | }
|
294 | else {
|
295 | modelFilterValue = filterValueNumber;
|
296 | }
|
297 | return {
|
298 | type: currentParentModel.type,
|
299 | filter: modelFilterValue,
|
300 | filterTo: !currentParentModel ? null : currentParentModel.filterTo,
|
301 | filterType: 'number'
|
302 | };
|
303 | };
|
304 | NumberFloatingFilterComp.prototype.asNumber = function (value) {
|
305 | if (value == null) {
|
306 | return null;
|
307 | }
|
308 | if (value === '') {
|
309 | return null;
|
310 | }
|
311 | var asNumber = Number(value);
|
312 | var invalidNumber = !utils_1._.isNumeric(asNumber);
|
313 | return invalidNumber ? null : asNumber;
|
314 | };
|
315 | return NumberFloatingFilterComp;
|
316 | }(InputTextFloatingFilterComp));
|
317 | exports.NumberFloatingFilterComp = NumberFloatingFilterComp;
|
318 | var SetFloatingFilterComp = (function (_super) {
|
319 | __extends(SetFloatingFilterComp, _super);
|
320 | function SetFloatingFilterComp() {
|
321 | return _super !== null && _super.apply(this, arguments) || this;
|
322 | }
|
323 | SetFloatingFilterComp.prototype.init = function (params) {
|
324 | _super.prototype.init.call(this, params);
|
325 | this.eColumnFloatingFilter.disabled = true;
|
326 | };
|
327 | SetFloatingFilterComp.prototype.asFloatingFilterText = function (parentModel) {
|
328 | this.eColumnFloatingFilter.disabled = true;
|
329 | if (!parentModel)
|
330 | return '';
|
331 |
|
332 | var values = (parentModel instanceof Array) ? parentModel : parentModel.values;
|
333 | if (values.length === 0) {
|
334 | return '';
|
335 | }
|
336 | var arrayToDisplay = values.length > 10 ? values.slice(0, 10).concat('...') : values;
|
337 | return "(" + values.length + ") " + arrayToDisplay.join(",");
|
338 | };
|
339 | SetFloatingFilterComp.prototype.parseAsText = function (model) {
|
340 | return this.asFloatingFilterText(model);
|
341 | };
|
342 | SetFloatingFilterComp.prototype.asParentModel = function () {
|
343 | if (this.eColumnFloatingFilter.value == null || this.eColumnFloatingFilter.value === '') {
|
344 | return {
|
345 | values: [],
|
346 | filterType: 'set'
|
347 | };
|
348 | }
|
349 | return {
|
350 | values: this.eColumnFloatingFilter.value.split(","),
|
351 | filterType: 'set'
|
352 | };
|
353 | };
|
354 | SetFloatingFilterComp.prototype.equalModels = function (left, right) {
|
355 | return false;
|
356 | };
|
357 | return SetFloatingFilterComp;
|
358 | }(InputTextFloatingFilterComp));
|
359 | exports.SetFloatingFilterComp = SetFloatingFilterComp;
|
360 | var ReadModelAsStringFloatingFilterComp = (function (_super) {
|
361 | __extends(ReadModelAsStringFloatingFilterComp, _super);
|
362 | function ReadModelAsStringFloatingFilterComp() {
|
363 | return _super !== null && _super.apply(this, arguments) || this;
|
364 | }
|
365 | ReadModelAsStringFloatingFilterComp.prototype.init = function (params) {
|
366 | _super.prototype.init.call(this, params);
|
367 | this.eColumnFloatingFilter.disabled = true;
|
368 | };
|
369 | ReadModelAsStringFloatingFilterComp.prototype.onParentModelChanged = function (parentModel) {
|
370 | this.eColumnFloatingFilter.value = this.asFloatingFilterText(this.currentParentModel());
|
371 | };
|
372 | ReadModelAsStringFloatingFilterComp.prototype.asFloatingFilterText = function (parentModel) {
|
373 | return parentModel;
|
374 | };
|
375 | ReadModelAsStringFloatingFilterComp.prototype.parseAsText = function (model) {
|
376 | return model;
|
377 | };
|
378 | ReadModelAsStringFloatingFilterComp.prototype.asParentModel = function () {
|
379 | return null;
|
380 | };
|
381 | return ReadModelAsStringFloatingFilterComp;
|
382 | }(InputTextFloatingFilterComp));
|
383 | exports.ReadModelAsStringFloatingFilterComp = ReadModelAsStringFloatingFilterComp;
|