@deephaven/jsapi-utils 0.22.3-beta.15 → 0.22.3-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ConnectionUtils.js +3 -7
- package/dist/ConnectionUtils.js.map +1 -1
- package/dist/DateUtils.js +12 -58
- package/dist/DateUtils.js.map +1 -1
- package/dist/Formatter.d.ts +1 -1
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +10 -35
- package/dist/Formatter.js.map +1 -1
- package/dist/FormatterUtils.js +1 -2
- package/dist/FormatterUtils.js.map +1 -1
- package/dist/TableUtils.d.ts +4 -2
- package/dist/TableUtils.d.ts.map +1 -1
- package/dist/TableUtils.js +26 -291
- package/dist/TableUtils.js.map +1 -1
- package/dist/formatters/BooleanColumnFormatter.js +0 -6
- package/dist/formatters/BooleanColumnFormatter.js.map +1 -1
- package/dist/formatters/CharColumnFormatter.js +0 -4
- package/dist/formatters/CharColumnFormatter.js.map +1 -1
- package/dist/formatters/DateTimeColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/DateTimeColumnFormatter.js +4 -28
- package/dist/formatters/DateTimeColumnFormatter.js.map +1 -1
- package/dist/formatters/DecimalColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/DecimalColumnFormatter.js +8 -28
- package/dist/formatters/DecimalColumnFormatter.js.map +1 -1
- package/dist/formatters/DefaultColumnFormatter.js +0 -4
- package/dist/formatters/DefaultColumnFormatter.js.map +1 -1
- package/dist/formatters/IntegerColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/IntegerColumnFormatter.js +9 -25
- package/dist/formatters/IntegerColumnFormatter.js.map +1 -1
- package/dist/formatters/StringColumnFormatter.js +0 -2
- package/dist/formatters/StringColumnFormatter.js.map +1 -1
- package/dist/formatters/TableColumnFormatter.js +4 -13
- package/dist/formatters/TableColumnFormatter.js.map +1 -1
- package/dist/formatters/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/TableUtils.js
CHANGED
|
@@ -1,119 +1,94 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
2
|
import { Type as FilterType, Operator as FilterOperator } from '@deephaven/filters';
|
|
4
3
|
import Log from '@deephaven/log';
|
|
5
4
|
import dh from '@deephaven/jsapi-shim';
|
|
6
5
|
import { PromiseUtils, TextUtils, TimeoutError } from '@deephaven/utils';
|
|
7
6
|
import DateUtils from "./DateUtils.js";
|
|
8
7
|
var log = Log.module('TableUtils');
|
|
9
|
-
|
|
10
8
|
/** Utility class to provide some functions for working with tables */
|
|
11
9
|
export class TableUtils {
|
|
12
10
|
// Regex looking for a negative or positive integer or decimal number
|
|
11
|
+
|
|
13
12
|
static getSortIndex(sort, columnIndex) {
|
|
14
13
|
for (var i = 0; i < sort.length; i += 1) {
|
|
15
14
|
var _s$column;
|
|
16
|
-
|
|
17
15
|
var s = sort[i];
|
|
18
|
-
|
|
19
16
|
if (((_s$column = s.column) === null || _s$column === void 0 ? void 0 : _s$column.index) === columnIndex) {
|
|
20
17
|
return i;
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return null;
|
|
25
21
|
}
|
|
22
|
+
|
|
26
23
|
/**
|
|
27
24
|
* @param tableSort The sorts from the table to get the sort from
|
|
28
25
|
* @param columnIndex The index of the column to get the sort for
|
|
29
26
|
* @returns The sort for the column, or null if it's not sorted
|
|
30
27
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
28
|
static getSortForColumn(tableSort, columnIndex) {
|
|
34
29
|
var sortIndex = TableUtils.getSortIndex(tableSort, columnIndex);
|
|
35
|
-
|
|
36
30
|
if (sortIndex != null) {
|
|
37
31
|
return tableSort[sortIndex];
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return null;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
static getFilterText(filter) {
|
|
44
36
|
if (filter) {
|
|
45
37
|
return filter.toString();
|
|
46
38
|
}
|
|
47
|
-
|
|
48
39
|
return null;
|
|
49
40
|
}
|
|
50
|
-
/** Return the valid filter types for the column */
|
|
51
|
-
|
|
52
41
|
|
|
42
|
+
/** Return the valid filter types for the column */
|
|
53
43
|
static getFilterTypes(columnType) {
|
|
54
44
|
if (TableUtils.isBooleanType(columnType)) {
|
|
55
45
|
return [FilterType.isTrue, FilterType.isFalse, FilterType.isNull];
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
if (TableUtils.isCharType(columnType) || TableUtils.isNumberType(columnType) || TableUtils.isDateType(columnType)) {
|
|
59
48
|
return [FilterType.eq, FilterType.notEq, FilterType.greaterThan, FilterType.greaterThanOrEqualTo, FilterType.lessThan, FilterType.lessThanOrEqualTo];
|
|
60
49
|
}
|
|
61
|
-
|
|
62
50
|
if (TableUtils.isTextType(columnType)) {
|
|
63
51
|
return [FilterType.eq, FilterType.eqIgnoreCase, FilterType.notEq, FilterType.notEqIgnoreCase, FilterType.contains, FilterType.notContains, FilterType.startsWith, FilterType.endsWith];
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
return [];
|
|
67
54
|
}
|
|
68
|
-
|
|
69
55
|
static getNextSort(columns, sorts, columnIndex) {
|
|
70
56
|
if (columns == null || columnIndex < 0 || columnIndex >= columns.length) {
|
|
71
57
|
return null;
|
|
72
58
|
}
|
|
73
|
-
|
|
74
59
|
var sort = TableUtils.getSortForColumn(sorts, columnIndex);
|
|
75
|
-
|
|
76
60
|
if (sort === null) {
|
|
77
61
|
return columns[columnIndex].sort().asc();
|
|
78
62
|
}
|
|
79
|
-
|
|
80
63
|
if (sort.direction === TableUtils.sortDirection.ascending) {
|
|
81
64
|
return sort.desc();
|
|
82
65
|
}
|
|
83
|
-
|
|
84
66
|
return null;
|
|
85
67
|
}
|
|
86
|
-
|
|
87
68
|
static makeColumnSort(columns, columnIndex, direction, isAbs) {
|
|
88
69
|
if (columns == null || columnIndex < 0 || columnIndex >= columns.length) {
|
|
89
70
|
return null;
|
|
90
71
|
}
|
|
91
|
-
|
|
92
72
|
if (direction === TableUtils.sortDirection.none) {
|
|
93
73
|
return null;
|
|
94
74
|
}
|
|
95
|
-
|
|
96
75
|
var sort = columns[columnIndex].sort();
|
|
97
|
-
|
|
98
76
|
switch (direction) {
|
|
99
77
|
case TableUtils.sortDirection.ascending:
|
|
100
78
|
sort = sort.asc();
|
|
101
79
|
break;
|
|
102
|
-
|
|
103
80
|
case TableUtils.sortDirection.descending:
|
|
104
81
|
sort = sort.desc();
|
|
105
82
|
break;
|
|
106
|
-
|
|
107
83
|
default:
|
|
108
84
|
break;
|
|
109
85
|
}
|
|
110
|
-
|
|
111
86
|
if (isAbs) {
|
|
112
87
|
sort = sort.abs();
|
|
113
88
|
}
|
|
114
|
-
|
|
115
89
|
return sort;
|
|
116
90
|
}
|
|
91
|
+
|
|
117
92
|
/**
|
|
118
93
|
* Toggles the sort for the specified column
|
|
119
94
|
* @param sorts The current sorts from IrisGrid.state
|
|
@@ -121,27 +96,22 @@ export class TableUtils {
|
|
|
121
96
|
* @param columnIndex The column index to apply the sort to
|
|
122
97
|
* @param addToExisting Add this sort to the existing sort
|
|
123
98
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
99
|
static toggleSortForColumn(sorts, columns, columnIndex) {
|
|
127
100
|
var addToExisting = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
128
|
-
|
|
129
101
|
if (columnIndex < 0 || columnIndex >= columns.length) {
|
|
130
102
|
return [];
|
|
131
103
|
}
|
|
132
|
-
|
|
133
104
|
var newSort = TableUtils.getNextSort(columns, sorts, columnIndex);
|
|
134
105
|
return TableUtils.setSortForColumn(sorts, columnIndex, newSort, addToExisting);
|
|
135
106
|
}
|
|
136
|
-
|
|
137
107
|
static sortColumn(sorts, columns, modelColumn, direction, isAbs, addToExisting) {
|
|
138
108
|
if (sorts == null || modelColumn < 0 || modelColumn >= columns.length) {
|
|
139
109
|
return [];
|
|
140
110
|
}
|
|
141
|
-
|
|
142
111
|
var newSort = TableUtils.makeColumnSort(columns, modelColumn, direction, isAbs);
|
|
143
112
|
return TableUtils.setSortForColumn(sorts, modelColumn, newSort, addToExisting);
|
|
144
113
|
}
|
|
114
|
+
|
|
145
115
|
/**
|
|
146
116
|
* Sets the sort for the given column *and* removes any reverses
|
|
147
117
|
* @param tableSort The current sorts from IrisGrid.state
|
|
@@ -150,13 +120,10 @@ export class TableUtils {
|
|
|
150
120
|
* @param addToExisting Add this sort to the existing sort
|
|
151
121
|
* @returns Returns the modified array of sorts - removing reverses
|
|
152
122
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
123
|
static setSortForColumn(tableSort, columnIndex, sort) {
|
|
156
124
|
var addToExisting = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
157
125
|
var sortIndex = TableUtils.getSortIndex(tableSort, columnIndex);
|
|
158
126
|
var sorts = [];
|
|
159
|
-
|
|
160
127
|
if (addToExisting) {
|
|
161
128
|
sorts = sorts.concat(tableSort.filter(_ref => {
|
|
162
129
|
var {
|
|
@@ -164,41 +131,33 @@ export class TableUtils {
|
|
|
164
131
|
} = _ref;
|
|
165
132
|
return direction !== TableUtils.sortDirection.reverse;
|
|
166
133
|
}));
|
|
167
|
-
|
|
168
134
|
if (sortIndex !== null) {
|
|
169
135
|
sorts.splice(sortIndex, 1);
|
|
170
136
|
}
|
|
171
137
|
}
|
|
172
|
-
|
|
173
138
|
if (sort !== null) {
|
|
174
139
|
sorts.push(sort);
|
|
175
140
|
}
|
|
176
|
-
|
|
177
141
|
return sorts;
|
|
178
142
|
}
|
|
179
|
-
|
|
180
143
|
static getNormalizedType(columnType) {
|
|
181
144
|
switch (columnType) {
|
|
182
145
|
case 'boolean':
|
|
183
146
|
case 'java.lang.Boolean':
|
|
184
147
|
case TableUtils.dataType.BOOLEAN:
|
|
185
148
|
return TableUtils.dataType.BOOLEAN;
|
|
186
|
-
|
|
187
149
|
case 'char':
|
|
188
150
|
case 'java.lang.Character':
|
|
189
151
|
case TableUtils.dataType.CHAR:
|
|
190
152
|
return TableUtils.dataType.CHAR;
|
|
191
|
-
|
|
192
153
|
case 'java.lang.String':
|
|
193
154
|
case TableUtils.dataType.STRING:
|
|
194
155
|
return TableUtils.dataType.STRING;
|
|
195
|
-
|
|
196
156
|
case 'io.deephaven.db.tables.utils.DBDateTime':
|
|
197
157
|
case 'io.deephaven.time.DateTime':
|
|
198
158
|
case 'com.illumon.iris.db.tables.utils.DBDateTime':
|
|
199
159
|
case TableUtils.dataType.DATETIME:
|
|
200
160
|
return TableUtils.dataType.DATETIME;
|
|
201
|
-
|
|
202
161
|
case 'double':
|
|
203
162
|
case 'java.lang.Double':
|
|
204
163
|
case 'float':
|
|
@@ -206,7 +165,6 @@ export class TableUtils {
|
|
|
206
165
|
case 'java.math.BigDecimal':
|
|
207
166
|
case TableUtils.dataType.DECIMAL:
|
|
208
167
|
return TableUtils.dataType.DECIMAL;
|
|
209
|
-
|
|
210
168
|
case 'int':
|
|
211
169
|
case 'java.lang.Integer':
|
|
212
170
|
case 'long':
|
|
@@ -218,39 +176,32 @@ export class TableUtils {
|
|
|
218
176
|
case 'java.math.BigInteger':
|
|
219
177
|
case TableUtils.dataType.INT:
|
|
220
178
|
return TableUtils.dataType.INT;
|
|
221
|
-
|
|
222
179
|
default:
|
|
223
180
|
return TableUtils.dataType.UNKNOWN;
|
|
224
181
|
}
|
|
225
182
|
}
|
|
226
|
-
|
|
227
183
|
static isLongType(columnType) {
|
|
228
184
|
switch (columnType) {
|
|
229
185
|
case 'long':
|
|
230
186
|
case 'java.lang.Long':
|
|
231
187
|
return true;
|
|
232
|
-
|
|
233
188
|
default:
|
|
234
189
|
return false;
|
|
235
190
|
}
|
|
236
191
|
}
|
|
237
|
-
|
|
238
192
|
static isDateType(columnType) {
|
|
239
193
|
switch (columnType) {
|
|
240
194
|
case 'io.deephaven.db.tables.utils.DBDateTime':
|
|
241
195
|
case 'io.deephaven.time.DateTime':
|
|
242
196
|
case 'com.illumon.iris.db.tables.utils.DBDateTime':
|
|
243
197
|
return true;
|
|
244
|
-
|
|
245
198
|
default:
|
|
246
199
|
return false;
|
|
247
200
|
}
|
|
248
201
|
}
|
|
249
|
-
|
|
250
202
|
static isNumberType(columnType) {
|
|
251
203
|
return TableUtils.isIntegerType(columnType) || TableUtils.isDecimalType(columnType);
|
|
252
204
|
}
|
|
253
|
-
|
|
254
205
|
static isIntegerType(columnType) {
|
|
255
206
|
switch (columnType) {
|
|
256
207
|
case 'int':
|
|
@@ -263,12 +214,10 @@ export class TableUtils {
|
|
|
263
214
|
case 'byte':
|
|
264
215
|
case 'java.lang.Byte':
|
|
265
216
|
return true;
|
|
266
|
-
|
|
267
217
|
default:
|
|
268
218
|
return false;
|
|
269
219
|
}
|
|
270
220
|
}
|
|
271
|
-
|
|
272
221
|
static isDecimalType(columnType) {
|
|
273
222
|
switch (columnType) {
|
|
274
223
|
case 'double':
|
|
@@ -277,68 +226,59 @@ export class TableUtils {
|
|
|
277
226
|
case 'float':
|
|
278
227
|
case 'java.lang.Float':
|
|
279
228
|
return true;
|
|
280
|
-
|
|
281
229
|
default:
|
|
282
230
|
return false;
|
|
283
231
|
}
|
|
284
232
|
}
|
|
285
|
-
|
|
286
233
|
static isBooleanType(columnType) {
|
|
287
234
|
switch (columnType) {
|
|
288
235
|
case 'boolean':
|
|
289
236
|
case 'java.lang.Boolean':
|
|
290
237
|
return true;
|
|
291
|
-
|
|
292
238
|
default:
|
|
293
239
|
return false;
|
|
294
240
|
}
|
|
295
241
|
}
|
|
296
|
-
|
|
297
242
|
static isCharType(columnType) {
|
|
298
243
|
switch (columnType) {
|
|
299
244
|
case 'char':
|
|
300
245
|
case 'java.lang.Character':
|
|
301
246
|
return true;
|
|
302
|
-
|
|
303
247
|
default:
|
|
304
248
|
return false;
|
|
305
249
|
}
|
|
306
250
|
}
|
|
307
|
-
|
|
308
251
|
static isStringType(columnType) {
|
|
309
252
|
switch (columnType) {
|
|
310
253
|
case 'java.lang.String':
|
|
311
254
|
return true;
|
|
312
|
-
|
|
313
255
|
default:
|
|
314
256
|
return false;
|
|
315
257
|
}
|
|
316
258
|
}
|
|
317
|
-
|
|
318
259
|
static isTextType(columnType) {
|
|
319
260
|
return this.isStringType(columnType) || this.isCharType(columnType);
|
|
320
261
|
}
|
|
262
|
+
|
|
321
263
|
/**
|
|
322
264
|
* Get base column type
|
|
323
265
|
* @param columnType Column type
|
|
324
266
|
* @returns Element type for array columns, original type for non-array columns
|
|
325
267
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
268
|
static getBaseType(columnType) {
|
|
329
269
|
return columnType.split('[]')[0];
|
|
330
270
|
}
|
|
271
|
+
|
|
331
272
|
/**
|
|
332
273
|
* Check if the column types are compatible
|
|
333
274
|
* @param type1 Column type to check
|
|
334
275
|
* @param type2 Column type to check
|
|
335
276
|
* @returns True, if types are compatible
|
|
336
277
|
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
278
|
static isCompatibleType(type1, type2) {
|
|
340
279
|
return TableUtils.getNormalizedType(type1) === TableUtils.getNormalizedType(type2);
|
|
341
280
|
}
|
|
281
|
+
|
|
342
282
|
/**
|
|
343
283
|
* Create filter with the provided column and text. Handles multiple filters joined with && or ||
|
|
344
284
|
* @param column The column to set the filter on
|
|
@@ -346,23 +286,17 @@ export class TableUtils {
|
|
|
346
286
|
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
347
287
|
* @returns Returns the created filter, null if text could not be parsed
|
|
348
288
|
*/
|
|
349
|
-
|
|
350
|
-
|
|
351
289
|
static makeQuickFilter(column, text, timeZone) {
|
|
352
290
|
var orComponents = text.split('||');
|
|
353
291
|
var orFilter = null;
|
|
354
|
-
|
|
355
292
|
for (var i = 0; i < orComponents.length; i += 1) {
|
|
356
293
|
var orComponent = orComponents[i];
|
|
357
294
|
var andComponents = orComponent.split('&&');
|
|
358
295
|
var andFilter = null;
|
|
359
|
-
|
|
360
296
|
for (var j = 0; j < andComponents.length; j += 1) {
|
|
361
297
|
var andComponent = andComponents[j].trim();
|
|
362
|
-
|
|
363
298
|
if (andComponent.length > 0) {
|
|
364
299
|
var filter = TableUtils.makeQuickFilterFromComponent(column, andComponent, timeZone);
|
|
365
|
-
|
|
366
300
|
if (filter) {
|
|
367
301
|
if (andFilter) {
|
|
368
302
|
andFilter = andFilter.and(filter);
|
|
@@ -374,16 +308,15 @@ export class TableUtils {
|
|
|
374
308
|
}
|
|
375
309
|
}
|
|
376
310
|
}
|
|
377
|
-
|
|
378
311
|
if (orFilter && andFilter) {
|
|
379
312
|
orFilter = orFilter.or(andFilter);
|
|
380
313
|
} else {
|
|
381
314
|
orFilter = andFilter;
|
|
382
315
|
}
|
|
383
316
|
}
|
|
384
|
-
|
|
385
317
|
return orFilter;
|
|
386
318
|
}
|
|
319
|
+
|
|
387
320
|
/**
|
|
388
321
|
* Create filter with the provided column and text of one component (no multiple conditions)
|
|
389
322
|
* @param column The column to set the filter on
|
|
@@ -391,37 +324,28 @@ export class TableUtils {
|
|
|
391
324
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
392
325
|
* @returns Returns the created filter, null if text could not be parsed
|
|
393
326
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
327
|
static makeQuickFilterFromComponent(column, text, timeZone) {
|
|
397
328
|
var {
|
|
398
329
|
type
|
|
399
330
|
} = column;
|
|
400
|
-
|
|
401
331
|
if (TableUtils.isNumberType(type)) {
|
|
402
332
|
return this.makeQuickNumberFilter(column, text);
|
|
403
333
|
}
|
|
404
|
-
|
|
405
334
|
if (TableUtils.isBooleanType(type)) {
|
|
406
335
|
return this.makeQuickBooleanFilter(column, text);
|
|
407
336
|
}
|
|
408
|
-
|
|
409
337
|
if (timeZone != null && TableUtils.isDateType(type)) {
|
|
410
338
|
return this.makeQuickDateFilter(column, text, timeZone);
|
|
411
339
|
}
|
|
412
|
-
|
|
413
340
|
if (TableUtils.isCharType(type)) {
|
|
414
341
|
return this.makeQuickCharFilter(column, text);
|
|
415
342
|
}
|
|
416
|
-
|
|
417
343
|
return this.makeQuickTextFilter(column, text);
|
|
418
344
|
}
|
|
419
|
-
|
|
420
345
|
static makeQuickNumberFilter(column, text) {
|
|
421
346
|
if (text == null) {
|
|
422
347
|
return null;
|
|
423
348
|
}
|
|
424
|
-
|
|
425
349
|
var columnFilter = column.filter();
|
|
426
350
|
var filter = null;
|
|
427
351
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|=|!)?(\s*-\s*)?(\s*\d*(?:,\d{3})*(?:\.\d*)?\s*)?(null|nan|infinity|inf|\u221E)?(.*)/i;
|
|
@@ -430,39 +354,30 @@ export class TableUtils {
|
|
|
430
354
|
var negativeSign = null;
|
|
431
355
|
var value = null;
|
|
432
356
|
var abnormalValue = null; // includes nan, null and infinity(positive & negative)
|
|
433
|
-
|
|
434
357
|
var overflow = null;
|
|
435
|
-
|
|
436
358
|
if (result !== null && result.length > 3) {
|
|
437
359
|
[, operation, negativeSign, value, abnormalValue, overflow] = result;
|
|
438
360
|
}
|
|
439
|
-
|
|
440
361
|
if (overflow != null && overflow.trim().length > 0) {
|
|
441
362
|
// Some bad characters after the number, bail out!
|
|
442
363
|
return null;
|
|
443
364
|
}
|
|
444
|
-
|
|
445
365
|
if (operation == null) {
|
|
446
366
|
operation = '=';
|
|
447
367
|
}
|
|
448
|
-
|
|
449
368
|
if (abnormalValue != null) {
|
|
450
369
|
if (!(operation === '=' || operation === '!' || operation === '!=')) {
|
|
451
370
|
// only equal and not equal operations are supported for abnormal value filter
|
|
452
371
|
return null;
|
|
453
372
|
}
|
|
454
|
-
|
|
455
373
|
abnormalValue = abnormalValue.trim().toLowerCase();
|
|
456
|
-
|
|
457
374
|
switch (abnormalValue) {
|
|
458
375
|
case 'null':
|
|
459
376
|
filter = columnFilter.isNull();
|
|
460
377
|
break;
|
|
461
|
-
|
|
462
378
|
case 'nan':
|
|
463
379
|
filter = dh.FilterCondition.invoke('isNaN', columnFilter);
|
|
464
380
|
break;
|
|
465
|
-
|
|
466
381
|
case 'infinity':
|
|
467
382
|
case 'inf':
|
|
468
383
|
case '\u221E':
|
|
@@ -471,26 +386,19 @@ export class TableUtils {
|
|
|
471
386
|
} else {
|
|
472
387
|
filter = dh.FilterCondition.invoke('isInf', columnFilter).and(columnFilter.greaterThan(dh.FilterValue.ofNumber(0)));
|
|
473
388
|
}
|
|
474
|
-
|
|
475
389
|
break;
|
|
476
|
-
|
|
477
390
|
default:
|
|
478
391
|
break;
|
|
479
392
|
}
|
|
480
|
-
|
|
481
393
|
if (filter !== null && (operation === '!' || operation === '!=')) {
|
|
482
394
|
filter = filter.not();
|
|
483
395
|
}
|
|
484
|
-
|
|
485
396
|
return filter;
|
|
486
397
|
}
|
|
487
|
-
|
|
488
398
|
if (value == null) {
|
|
489
399
|
return null;
|
|
490
400
|
}
|
|
491
|
-
|
|
492
401
|
value = TableUtils.removeCommas(value);
|
|
493
|
-
|
|
494
402
|
if (TableUtils.isLongType(column.type)) {
|
|
495
403
|
try {
|
|
496
404
|
value = dh.FilterValue.ofNumber(dh.LongWrapper.ofString("".concat(negativeSign != null ? '-' : '').concat(value)));
|
|
@@ -500,65 +408,50 @@ export class TableUtils {
|
|
|
500
408
|
}
|
|
501
409
|
} else {
|
|
502
410
|
value = parseFloat(value);
|
|
503
|
-
|
|
504
411
|
if (value == null || Number.isNaN(value)) {
|
|
505
412
|
return null;
|
|
506
413
|
}
|
|
507
|
-
|
|
508
414
|
value = dh.FilterValue.ofNumber(negativeSign != null ? 0 - value : value);
|
|
509
415
|
}
|
|
510
|
-
|
|
511
416
|
filter = column.filter();
|
|
512
417
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, value);
|
|
513
418
|
}
|
|
514
|
-
|
|
515
419
|
static makeQuickTextFilter(column, text) {
|
|
516
420
|
if (text == null) {
|
|
517
421
|
return null;
|
|
518
422
|
}
|
|
519
|
-
|
|
520
423
|
var cleanText = "".concat(text).trim();
|
|
521
424
|
var regex = /^(!~|!=|~|=|!)?(.*)/;
|
|
522
425
|
var result = regex.exec(cleanText);
|
|
523
426
|
var operation = null;
|
|
524
427
|
var value = null;
|
|
525
|
-
|
|
526
428
|
if (result !== null && result.length > 2) {
|
|
527
429
|
[, operation, value] = result;
|
|
528
|
-
|
|
529
430
|
if (value != null) {
|
|
530
431
|
value = value.trim();
|
|
531
432
|
}
|
|
532
433
|
}
|
|
533
|
-
|
|
534
434
|
if (value == null || value.length === 0) {
|
|
535
435
|
return null;
|
|
536
436
|
}
|
|
537
|
-
|
|
538
437
|
if (operation == null) {
|
|
539
438
|
operation = '=';
|
|
540
439
|
}
|
|
541
|
-
|
|
542
440
|
var filter = column.filter();
|
|
543
|
-
|
|
544
441
|
if (value.toLowerCase() === 'null') {
|
|
545
442
|
// Null is a special case!
|
|
546
443
|
switch (operation) {
|
|
547
444
|
case '=':
|
|
548
445
|
return filter.isNull();
|
|
549
|
-
|
|
550
446
|
case '!=':
|
|
551
447
|
case '!':
|
|
552
448
|
return filter.isNull().not();
|
|
553
|
-
|
|
554
449
|
default:
|
|
555
450
|
return null;
|
|
556
451
|
}
|
|
557
452
|
}
|
|
558
|
-
|
|
559
453
|
var prefix = null;
|
|
560
454
|
var suffix = null;
|
|
561
|
-
|
|
562
455
|
if (value.startsWith('*')) {
|
|
563
456
|
prefix = '*';
|
|
564
457
|
value = value.substring(1);
|
|
@@ -566,71 +459,54 @@ export class TableUtils {
|
|
|
566
459
|
suffix = '*';
|
|
567
460
|
value = value.substring(0, value.length - 1);
|
|
568
461
|
}
|
|
569
|
-
|
|
570
462
|
value = value.replace('\\', '');
|
|
571
|
-
|
|
572
463
|
switch (operation) {
|
|
573
464
|
case '~':
|
|
574
465
|
{
|
|
575
466
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))));
|
|
576
467
|
}
|
|
577
|
-
|
|
578
468
|
case '!~':
|
|
579
469
|
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))).not());
|
|
580
|
-
|
|
581
470
|
case '!=':
|
|
582
471
|
if (prefix === '*') {
|
|
583
472
|
// Does not end with
|
|
584
473
|
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E$"))).not());
|
|
585
474
|
}
|
|
586
|
-
|
|
587
475
|
if (suffix === '*') {
|
|
588
476
|
// Does not start with
|
|
589
477
|
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i)^\\Q".concat(value, "\\E.*"))).not());
|
|
590
478
|
}
|
|
591
|
-
|
|
592
479
|
return filter.notEqIgnoreCase(dh.FilterValue.ofString(value.toLowerCase()));
|
|
593
|
-
|
|
594
480
|
case '=':
|
|
595
481
|
if (prefix === '*') {
|
|
596
482
|
// Ends with
|
|
597
483
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E$"))));
|
|
598
484
|
}
|
|
599
|
-
|
|
600
485
|
if (suffix === '*') {
|
|
601
486
|
// Starts with
|
|
602
487
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i)^\\Q".concat(value, "\\E.*"))));
|
|
603
488
|
}
|
|
604
|
-
|
|
605
489
|
return filter.eqIgnoreCase(dh.FilterValue.ofString(value.toLowerCase()));
|
|
606
|
-
|
|
607
490
|
default:
|
|
608
491
|
break;
|
|
609
492
|
}
|
|
610
|
-
|
|
611
493
|
return null;
|
|
612
494
|
}
|
|
613
|
-
|
|
614
495
|
static makeQuickBooleanFilter(column, text) {
|
|
615
496
|
if (text == null) {
|
|
616
497
|
return null;
|
|
617
498
|
}
|
|
618
|
-
|
|
619
499
|
var regex = /^(!=|=|!)?(.*)/;
|
|
620
500
|
var result = regex.exec("".concat(text).trim());
|
|
621
|
-
|
|
622
501
|
if (result === null) {
|
|
623
502
|
return null;
|
|
624
503
|
}
|
|
625
|
-
|
|
626
504
|
var [, operation, value] = result;
|
|
627
505
|
var notEqual = operation === '!' || operation === '!=';
|
|
628
506
|
var cleanValue = value.trim().toLowerCase();
|
|
629
507
|
var filter = column.filter();
|
|
630
|
-
|
|
631
508
|
try {
|
|
632
509
|
var boolValue = TableUtils.makeBooleanValue(cleanValue);
|
|
633
|
-
|
|
634
510
|
if (boolValue != null && boolValue) {
|
|
635
511
|
filter = filter.isTrue();
|
|
636
512
|
} else if (boolValue === null) {
|
|
@@ -638,67 +514,57 @@ export class TableUtils {
|
|
|
638
514
|
} else {
|
|
639
515
|
filter = filter.isFalse();
|
|
640
516
|
}
|
|
641
|
-
|
|
642
517
|
return notEqual ? filter.not() : filter;
|
|
643
518
|
} catch (e) {
|
|
644
519
|
return null;
|
|
645
520
|
}
|
|
646
521
|
}
|
|
522
|
+
|
|
647
523
|
/**
|
|
648
524
|
* Builds a date filter parsed from the text string which may or may not include an operator.
|
|
649
525
|
* @param column The column to build the filter from, with or without a leading operator.
|
|
650
526
|
* @param text The date string text to parse.
|
|
651
527
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
652
528
|
*/
|
|
653
|
-
|
|
654
|
-
|
|
655
529
|
static makeQuickDateFilter(column, text, timeZone) {
|
|
656
530
|
var cleanText = text.trim();
|
|
657
531
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|!|=)?(.*)/;
|
|
658
532
|
var result = regex.exec(cleanText);
|
|
659
|
-
|
|
660
533
|
if (result == null || result.length <= 2) {
|
|
661
534
|
throw new Error("Unable to parse date filter: ".concat(text));
|
|
662
535
|
}
|
|
663
|
-
|
|
664
536
|
var operation = null;
|
|
665
537
|
var dateText = null;
|
|
666
538
|
[, operation, dateText] = result;
|
|
667
539
|
var filterOperation = FilterType.eq;
|
|
668
|
-
|
|
669
540
|
switch (operation) {
|
|
670
541
|
case '<':
|
|
671
542
|
filterOperation = FilterType.lessThan;
|
|
672
543
|
break;
|
|
673
|
-
|
|
674
544
|
case '<=':
|
|
675
545
|
case '=<':
|
|
676
546
|
filterOperation = FilterType.lessThanOrEqualTo;
|
|
677
547
|
break;
|
|
678
|
-
|
|
679
548
|
case '>':
|
|
680
549
|
filterOperation = FilterType.greaterThan;
|
|
681
550
|
break;
|
|
682
|
-
|
|
683
551
|
case '>=':
|
|
684
552
|
case '=>':
|
|
685
553
|
filterOperation = FilterType.greaterThanOrEqualTo;
|
|
686
554
|
break;
|
|
687
|
-
|
|
688
555
|
case '!=':
|
|
689
556
|
case '!':
|
|
690
557
|
filterOperation = FilterType.notEq;
|
|
691
558
|
break;
|
|
692
|
-
|
|
693
559
|
case '=':
|
|
694
560
|
case '==':
|
|
695
561
|
default:
|
|
696
562
|
filterOperation = FilterType.eq;
|
|
697
563
|
break;
|
|
698
564
|
}
|
|
699
|
-
|
|
700
565
|
return TableUtils.makeQuickDateFilterWithOperation(column, dateText, filterOperation, timeZone);
|
|
701
566
|
}
|
|
567
|
+
|
|
702
568
|
/**
|
|
703
569
|
* Builds a date filter parsed from the text string with the provided filter.
|
|
704
570
|
* @param column The column to build the filter from.
|
|
@@ -706,25 +572,17 @@ export class TableUtils {
|
|
|
706
572
|
* @param operation The filter operation to use.
|
|
707
573
|
* @param timeZone The time zone to make this filter with. E.g. America/New_York
|
|
708
574
|
*/
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
static makeQuickDateFilterWithOperation(column, text) {
|
|
712
|
-
var operation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : FilterType.eq;
|
|
713
|
-
var timeZone = arguments.length > 3 ? arguments[3] : undefined;
|
|
714
|
-
|
|
575
|
+
static makeQuickDateFilterWithOperation(column, text, operation, timeZone) {
|
|
715
576
|
if (column == null) {
|
|
716
577
|
throw new Error('Column is null');
|
|
717
578
|
}
|
|
718
|
-
|
|
719
579
|
var [startDate, endDate] = DateUtils.parseDateRange(text, timeZone);
|
|
720
580
|
var startValue = startDate != null ? dh.FilterValue.ofNumber(startDate) : null;
|
|
721
581
|
var endValue = endDate != null ? dh.FilterValue.ofNumber(endDate) : null;
|
|
722
582
|
var filter = column.filter();
|
|
723
|
-
|
|
724
583
|
if (startValue == null) {
|
|
725
584
|
return operation === FilterType.notEq ? filter.isNull().not() : filter.isNull();
|
|
726
585
|
}
|
|
727
|
-
|
|
728
586
|
switch (operation) {
|
|
729
587
|
case FilterType.eq:
|
|
730
588
|
{
|
|
@@ -733,67 +591,52 @@ export class TableUtils {
|
|
|
733
591
|
var endFilter = filter.lessThan(endValue);
|
|
734
592
|
return startFilter.and(endFilter);
|
|
735
593
|
}
|
|
736
|
-
|
|
737
594
|
return filter.eq(startValue);
|
|
738
595
|
}
|
|
739
|
-
|
|
740
596
|
case FilterType.lessThan:
|
|
741
597
|
{
|
|
742
598
|
return filter.lessThan(startValue);
|
|
743
599
|
}
|
|
744
|
-
|
|
745
600
|
case FilterType.lessThanOrEqualTo:
|
|
746
601
|
{
|
|
747
602
|
if (endValue != null) {
|
|
748
603
|
return filter.lessThan(endValue);
|
|
749
604
|
}
|
|
750
|
-
|
|
751
605
|
return filter.lessThanOrEqualTo(startValue);
|
|
752
606
|
}
|
|
753
|
-
|
|
754
607
|
case FilterType.greaterThan:
|
|
755
608
|
{
|
|
756
609
|
if (endValue != null) {
|
|
757
610
|
return filter.greaterThanOrEqualTo(endValue);
|
|
758
611
|
}
|
|
759
|
-
|
|
760
612
|
return filter.greaterThan(startValue);
|
|
761
613
|
}
|
|
762
|
-
|
|
763
614
|
case FilterType.greaterThanOrEqualTo:
|
|
764
615
|
return filter.greaterThanOrEqualTo(startValue);
|
|
765
|
-
|
|
766
616
|
case FilterType.notEq:
|
|
767
617
|
{
|
|
768
618
|
if (endValue != null) {
|
|
769
619
|
var _startFilter = filter.lessThan(startValue);
|
|
770
|
-
|
|
771
620
|
var _endFilter = filter.greaterThanOrEqualTo(endValue);
|
|
772
|
-
|
|
773
621
|
return _startFilter.or(_endFilter);
|
|
774
622
|
}
|
|
775
|
-
|
|
776
623
|
return filter.notEq(startValue);
|
|
777
624
|
}
|
|
778
|
-
|
|
779
625
|
default:
|
|
780
626
|
throw new Error("Invalid operator: ".concat(operation));
|
|
781
627
|
}
|
|
782
628
|
}
|
|
629
|
+
|
|
783
630
|
/**
|
|
784
631
|
* Adds quotes to a value if they're not already added
|
|
785
632
|
* @param value Value to add quotes around
|
|
786
633
|
*/
|
|
787
|
-
|
|
788
|
-
|
|
789
634
|
static quoteValue(value) {
|
|
790
635
|
if (value.length >= 2 && (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' || value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
|
|
791
636
|
return value;
|
|
792
637
|
}
|
|
793
|
-
|
|
794
638
|
return "\"".concat(value, "\"");
|
|
795
639
|
}
|
|
796
|
-
|
|
797
640
|
static isRangeOperation(operation) {
|
|
798
641
|
switch (operation) {
|
|
799
642
|
case '<':
|
|
@@ -803,109 +646,91 @@ export class TableUtils {
|
|
|
803
646
|
case '>=':
|
|
804
647
|
case '=>':
|
|
805
648
|
return true;
|
|
806
|
-
|
|
807
649
|
default:
|
|
808
650
|
return false;
|
|
809
651
|
}
|
|
810
652
|
}
|
|
811
|
-
|
|
812
653
|
static makeQuickCharFilter(column, text) {
|
|
813
654
|
if (text == null) {
|
|
814
655
|
return null;
|
|
815
656
|
}
|
|
816
|
-
|
|
817
657
|
var cleanText = "".concat(text).trim();
|
|
818
658
|
var regex = /^(>=|<=|=>|=<|>|<|!=|=|!)?(null|"."|'.'|.)?(.*)/;
|
|
819
659
|
var result = regex.exec(cleanText);
|
|
820
660
|
var operation = null;
|
|
821
661
|
var value = null;
|
|
822
662
|
var overflow = null;
|
|
823
|
-
|
|
824
663
|
if (result !== null && result.length > 3) {
|
|
825
664
|
[, operation, value, overflow] = result;
|
|
826
665
|
}
|
|
827
|
-
|
|
828
666
|
if (overflow != null && overflow.trim().length > 0) {
|
|
829
667
|
// Some bad characters after the number, bail out!
|
|
830
668
|
return null;
|
|
831
669
|
}
|
|
832
|
-
|
|
833
670
|
if (value == null || value.length === 0) {
|
|
834
671
|
return null;
|
|
835
672
|
}
|
|
836
|
-
|
|
837
673
|
if (operation == null) {
|
|
838
674
|
operation = '=';
|
|
839
675
|
}
|
|
840
|
-
|
|
841
676
|
var filter = column.filter();
|
|
842
|
-
|
|
843
677
|
if (value.toLowerCase() === 'null') {
|
|
844
678
|
// Null is a special case!
|
|
845
679
|
switch (operation) {
|
|
846
680
|
case '=':
|
|
847
681
|
return filter.isNull();
|
|
848
|
-
|
|
849
682
|
case '!=':
|
|
850
683
|
case '!':
|
|
851
684
|
return filter.isNull().not();
|
|
852
|
-
|
|
853
685
|
default:
|
|
854
686
|
return null;
|
|
855
687
|
}
|
|
856
|
-
}
|
|
857
|
-
|
|
688
|
+
}
|
|
858
689
|
|
|
690
|
+
// We need to put quotes around range operations or else the API fails
|
|
859
691
|
var filterValue = dh.FilterValue.ofString(TableUtils.isRangeOperation(operation) ? TableUtils.quoteValue(value) : value);
|
|
860
692
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, filterValue);
|
|
861
693
|
}
|
|
694
|
+
|
|
862
695
|
/**
|
|
863
696
|
* @param filter The column filter to apply the range operation to
|
|
864
697
|
* @param operation The range operation to run
|
|
865
698
|
* @param value The value to use for the operation
|
|
866
699
|
* @returns The condition with the specified operation
|
|
867
700
|
*/
|
|
868
|
-
|
|
869
|
-
|
|
870
701
|
static makeRangeFilterWithOperation(filter, operation, value) {
|
|
871
702
|
switch (operation) {
|
|
872
703
|
case '=':
|
|
873
704
|
return filter.eq(value);
|
|
874
|
-
|
|
875
705
|
case '<':
|
|
876
706
|
return filter.lessThan(value);
|
|
877
|
-
|
|
878
707
|
case '<=':
|
|
879
708
|
case '=<':
|
|
880
709
|
return filter.lessThanOrEqualTo(value);
|
|
881
|
-
|
|
882
710
|
case '>':
|
|
883
711
|
return filter.greaterThan(value);
|
|
884
|
-
|
|
885
712
|
case '>=':
|
|
886
713
|
case '=>':
|
|
887
714
|
return filter.greaterThanOrEqualTo(value);
|
|
888
|
-
|
|
889
715
|
case '!=':
|
|
890
716
|
case '!':
|
|
891
717
|
return filter.notEq(value);
|
|
892
|
-
|
|
893
718
|
default:
|
|
894
719
|
return null;
|
|
895
720
|
}
|
|
896
721
|
}
|
|
722
|
+
|
|
897
723
|
/**
|
|
898
724
|
* Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled.
|
|
899
725
|
* Use in a component that loads a table, and call cancel when unmounting.
|
|
900
726
|
* @param table The table promise to wrap
|
|
901
727
|
*/
|
|
902
|
-
|
|
903
|
-
|
|
904
728
|
static makeCancelableTablePromise(table) {
|
|
905
729
|
return PromiseUtils.makeCancelable(table, resolved => {
|
|
906
730
|
resolved.close();
|
|
907
731
|
});
|
|
908
732
|
}
|
|
733
|
+
|
|
909
734
|
/**
|
|
910
735
|
* Make a cancelable promise for a one-shot table event with a timeout.
|
|
911
736
|
* @param table Table to listen for events on
|
|
@@ -914,8 +739,6 @@ export class TableUtils {
|
|
|
914
739
|
* @param matcher Optional function to determine if the promise can be resolved or stays pending
|
|
915
740
|
* @returns Resolves with the event data
|
|
916
741
|
*/
|
|
917
|
-
|
|
918
|
-
|
|
919
742
|
static makeCancelableTableEventPromise(table, eventName) {
|
|
920
743
|
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
921
744
|
var matcher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
@@ -933,7 +756,6 @@ export class TableUtils {
|
|
|
933
756
|
log.debug2('Event triggered, but matcher returned false.');
|
|
934
757
|
return;
|
|
935
758
|
}
|
|
936
|
-
|
|
937
759
|
log.debug2('Event triggered, resolving.');
|
|
938
760
|
eventCleanup();
|
|
939
761
|
clearTimeout(timeoutId);
|
|
@@ -941,7 +763,6 @@ export class TableUtils {
|
|
|
941
763
|
resolve(event);
|
|
942
764
|
});
|
|
943
765
|
});
|
|
944
|
-
|
|
945
766
|
wrappedPromise.cancel = () => {
|
|
946
767
|
if (isPending) {
|
|
947
768
|
log.debug2('Pending promise cleanup.');
|
|
@@ -950,13 +771,10 @@ export class TableUtils {
|
|
|
950
771
|
isPending = false;
|
|
951
772
|
return;
|
|
952
773
|
}
|
|
953
|
-
|
|
954
774
|
log.debug2('Ignoring non-pending promise cancel.');
|
|
955
775
|
};
|
|
956
|
-
|
|
957
776
|
return wrappedPromise;
|
|
958
777
|
}
|
|
959
|
-
|
|
960
778
|
static makeAdvancedFilter(column, options, timeZone) {
|
|
961
779
|
var {
|
|
962
780
|
filterItems,
|
|
@@ -965,24 +783,20 @@ export class TableUtils {
|
|
|
965
783
|
selectedValues
|
|
966
784
|
} = options;
|
|
967
785
|
var filter = null;
|
|
968
|
-
|
|
969
786
|
for (var i = 0; i < filterItems.length; i += 1) {
|
|
970
787
|
var filterItem = filterItems[i];
|
|
971
788
|
var {
|
|
972
789
|
selectedType,
|
|
973
790
|
value
|
|
974
791
|
} = filterItem;
|
|
975
|
-
|
|
976
792
|
if (selectedType != null && selectedType.length > 0 && value != null && value.length > 0) {
|
|
977
793
|
try {
|
|
978
794
|
var newFilter = TableUtils.makeAdvancedValueFilter(column, selectedType, value, timeZone);
|
|
979
|
-
|
|
980
795
|
if (newFilter != null) {
|
|
981
796
|
if (i === 0) {
|
|
982
797
|
filter = newFilter;
|
|
983
798
|
} else if (filter !== null && i - 1 < filterOperators.length) {
|
|
984
799
|
var filterOperator = filterOperators[i - 1];
|
|
985
|
-
|
|
986
800
|
if (filterOperator === FilterOperator.and) {
|
|
987
801
|
filter = filter.and(newFilter);
|
|
988
802
|
} else if (filterOperator === FilterOperator.or) {
|
|
@@ -1003,9 +817,7 @@ export class TableUtils {
|
|
|
1003
817
|
}
|
|
1004
818
|
}
|
|
1005
819
|
}
|
|
1006
|
-
|
|
1007
820
|
var selectValueFilter = TableUtils.makeSelectValueFilter(column, selectedValues, invertSelection);
|
|
1008
|
-
|
|
1009
821
|
if (selectValueFilter != null) {
|
|
1010
822
|
if (filter != null) {
|
|
1011
823
|
filter = filter.and(selectValueFilter);
|
|
@@ -1013,33 +825,28 @@ export class TableUtils {
|
|
|
1013
825
|
filter = selectValueFilter;
|
|
1014
826
|
}
|
|
1015
827
|
}
|
|
1016
|
-
|
|
1017
828
|
return filter;
|
|
1018
829
|
}
|
|
1019
|
-
|
|
1020
830
|
static removeCommas(value) {
|
|
1021
831
|
return value.replace(/[\s|,]/g, '');
|
|
1022
832
|
}
|
|
833
|
+
|
|
1023
834
|
/**
|
|
1024
835
|
* @param columnType The column type to make the filter value from.
|
|
1025
836
|
* @param value The value to make the filter value from.
|
|
1026
837
|
* @returns The FilterValue item for this column/value combination
|
|
1027
838
|
*/
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
839
|
static makeFilterValue(columnType, value) {
|
|
1031
840
|
var type = TableUtils.getBaseType(columnType);
|
|
1032
|
-
|
|
1033
841
|
if (TableUtils.isTextType(type)) {
|
|
1034
842
|
return dh.FilterValue.ofString(value);
|
|
1035
843
|
}
|
|
1036
|
-
|
|
1037
844
|
if (TableUtils.isLongType(type)) {
|
|
1038
845
|
return dh.FilterValue.ofNumber(dh.LongWrapper.ofString(TableUtils.removeCommas(value)));
|
|
1039
846
|
}
|
|
1040
|
-
|
|
1041
847
|
return dh.FilterValue.ofNumber(TableUtils.removeCommas(value));
|
|
1042
848
|
}
|
|
849
|
+
|
|
1043
850
|
/**
|
|
1044
851
|
* Takes a value and converts it to an `dh.FilterValue`
|
|
1045
852
|
*
|
|
@@ -1047,68 +854,53 @@ export class TableUtils {
|
|
|
1047
854
|
* @param value The value to actually set
|
|
1048
855
|
* @returns The FilterValue item for this column/value combination
|
|
1049
856
|
*/
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
857
|
static makeFilterRawValue(columnType, rawValue) {
|
|
1053
858
|
if (TableUtils.isTextType(columnType)) {
|
|
1054
859
|
return dh.FilterValue.ofString(rawValue);
|
|
1055
860
|
}
|
|
1056
|
-
|
|
1057
861
|
if (TableUtils.isBooleanType(columnType)) {
|
|
1058
862
|
return dh.FilterValue.ofBoolean(rawValue);
|
|
1059
863
|
}
|
|
1060
|
-
|
|
1061
864
|
return dh.FilterValue.ofNumber(rawValue);
|
|
1062
865
|
}
|
|
866
|
+
|
|
1063
867
|
/**
|
|
1064
868
|
* Converts a string value to a value appropriate for the column
|
|
1065
869
|
* @param columnType The column type to make the value for
|
|
1066
870
|
* @param text The string value to make a type for
|
|
1067
871
|
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
1068
872
|
*/
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
873
|
static makeValue(columnType, text, timeZone) {
|
|
1072
874
|
if (text == null || text === 'null') {
|
|
1073
875
|
return null;
|
|
1074
876
|
}
|
|
1075
|
-
|
|
1076
877
|
if (TableUtils.isTextType(columnType)) {
|
|
1077
878
|
return text;
|
|
1078
879
|
}
|
|
1079
|
-
|
|
1080
880
|
if (TableUtils.isLongType(columnType)) {
|
|
1081
881
|
return dh.LongWrapper.ofString(TableUtils.removeCommas(text));
|
|
1082
882
|
}
|
|
1083
|
-
|
|
1084
883
|
if (TableUtils.isBooleanType(columnType)) {
|
|
1085
884
|
return TableUtils.makeBooleanValue(text, true);
|
|
1086
885
|
}
|
|
1087
|
-
|
|
1088
886
|
if (TableUtils.isDateType(columnType)) {
|
|
1089
887
|
var [date] = DateUtils.parseDateRange(text, timeZone);
|
|
1090
888
|
return date;
|
|
1091
889
|
}
|
|
1092
|
-
|
|
1093
890
|
if (TableUtils.isNumberType(columnType)) {
|
|
1094
891
|
return TableUtils.makeNumberValue(text);
|
|
1095
892
|
}
|
|
1096
|
-
|
|
1097
893
|
log.error('Unexpected column type', columnType);
|
|
1098
894
|
return null;
|
|
1099
895
|
}
|
|
1100
|
-
|
|
1101
896
|
static makeBooleanValue(text) {
|
|
1102
897
|
var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1103
|
-
|
|
1104
898
|
if (text === '' && allowEmpty) {
|
|
1105
899
|
return null;
|
|
1106
900
|
}
|
|
1107
|
-
|
|
1108
901
|
switch (text === null || text === void 0 ? void 0 : text.toLowerCase()) {
|
|
1109
902
|
case 'null':
|
|
1110
903
|
return null;
|
|
1111
|
-
|
|
1112
904
|
case '0':
|
|
1113
905
|
case 'f':
|
|
1114
906
|
case 'fa':
|
|
@@ -1118,7 +910,6 @@ export class TableUtils {
|
|
|
1118
910
|
case 'n':
|
|
1119
911
|
case 'no':
|
|
1120
912
|
return false;
|
|
1121
|
-
|
|
1122
913
|
case '1':
|
|
1123
914
|
case 't':
|
|
1124
915
|
case 'tr':
|
|
@@ -1128,125 +919,89 @@ export class TableUtils {
|
|
|
1128
919
|
case 'ye':
|
|
1129
920
|
case 'yes':
|
|
1130
921
|
return true;
|
|
1131
|
-
|
|
1132
922
|
default:
|
|
1133
923
|
throw new Error("Invalid boolean '".concat(text, "'"));
|
|
1134
924
|
}
|
|
1135
925
|
}
|
|
1136
|
-
|
|
1137
926
|
static makeNumberValue(text) {
|
|
1138
927
|
if (text == null || text === 'null' || text === '') {
|
|
1139
928
|
return null;
|
|
1140
929
|
}
|
|
1141
|
-
|
|
1142
930
|
var cleanText = text.toLowerCase().trim();
|
|
1143
|
-
|
|
1144
931
|
if (cleanText === '∞' || cleanText === 'infinity' || cleanText === 'inf') {
|
|
1145
932
|
return Number.POSITIVE_INFINITY;
|
|
1146
933
|
}
|
|
1147
|
-
|
|
1148
934
|
if (cleanText === '-∞' || cleanText === '-infinity' || cleanText === '-inf') {
|
|
1149
935
|
return Number.NEGATIVE_INFINITY;
|
|
1150
936
|
}
|
|
1151
|
-
|
|
1152
937
|
var numberText = TableUtils.removeCommas(cleanText);
|
|
1153
|
-
|
|
1154
938
|
if (TableUtils.NUMBER_REGEX.test(numberText)) {
|
|
1155
939
|
return parseFloat(numberText);
|
|
1156
940
|
}
|
|
1157
|
-
|
|
1158
941
|
throw new Error("Invalid number '".concat(text, "'"));
|
|
1159
942
|
}
|
|
1160
|
-
|
|
1161
943
|
static getFilterOperatorString(operation) {
|
|
1162
944
|
switch (operation) {
|
|
1163
945
|
case FilterType.eq:
|
|
1164
946
|
return '=';
|
|
1165
|
-
|
|
1166
947
|
case FilterType.notEq:
|
|
1167
948
|
return '!=';
|
|
1168
|
-
|
|
1169
949
|
case FilterType.greaterThan:
|
|
1170
950
|
return '>';
|
|
1171
|
-
|
|
1172
951
|
case FilterType.greaterThanOrEqualTo:
|
|
1173
952
|
return '>=';
|
|
1174
|
-
|
|
1175
953
|
case FilterType.lessThan:
|
|
1176
954
|
return '<';
|
|
1177
|
-
|
|
1178
955
|
case FilterType.lessThanOrEqualTo:
|
|
1179
956
|
return '<=';
|
|
1180
|
-
|
|
1181
957
|
case FilterType.contains:
|
|
1182
958
|
return '~';
|
|
1183
|
-
|
|
1184
959
|
case FilterType.notContains:
|
|
1185
960
|
return '!~';
|
|
1186
|
-
|
|
1187
961
|
default:
|
|
1188
962
|
throw new Error("Unexpected filter type ".concat(operation));
|
|
1189
963
|
}
|
|
1190
964
|
}
|
|
1191
|
-
|
|
1192
965
|
static makeAdvancedValueFilter(column, operation, value, timeZone) {
|
|
1193
966
|
if (TableUtils.isDateType(column.type)) {
|
|
1194
967
|
return TableUtils.makeQuickDateFilterWithOperation(column, value, operation, timeZone);
|
|
1195
968
|
}
|
|
1196
|
-
|
|
1197
969
|
if (TableUtils.isNumberType(column.type) || TableUtils.isCharType(column.type)) {
|
|
1198
970
|
return TableUtils.makeQuickFilter(column, "".concat(TableUtils.getFilterOperatorString(operation)).concat(value));
|
|
1199
971
|
}
|
|
1200
|
-
|
|
1201
972
|
var filterValue = TableUtils.makeFilterValue(column.type, value);
|
|
1202
973
|
var filter = column.filter();
|
|
1203
|
-
|
|
1204
974
|
switch (operation) {
|
|
1205
975
|
case FilterType.eq:
|
|
1206
976
|
return filter.eq(filterValue);
|
|
1207
|
-
|
|
1208
977
|
case FilterType.eqIgnoreCase:
|
|
1209
978
|
return filter.eqIgnoreCase(filterValue);
|
|
1210
|
-
|
|
1211
979
|
case FilterType.notEq:
|
|
1212
980
|
return filter.notEq(filterValue);
|
|
1213
|
-
|
|
1214
981
|
case FilterType.notEqIgnoreCase:
|
|
1215
982
|
return filter.notEqIgnoreCase(filterValue);
|
|
1216
|
-
|
|
1217
983
|
case FilterType.greaterThan:
|
|
1218
984
|
return filter.greaterThan(filterValue);
|
|
1219
|
-
|
|
1220
985
|
case FilterType.greaterThanOrEqualTo:
|
|
1221
986
|
return filter.greaterThanOrEqualTo(filterValue);
|
|
1222
|
-
|
|
1223
987
|
case FilterType.lessThan:
|
|
1224
988
|
return filter.lessThan(filterValue);
|
|
1225
|
-
|
|
1226
989
|
case FilterType.lessThanOrEqualTo:
|
|
1227
990
|
return filter.lessThanOrEqualTo(filterValue);
|
|
1228
|
-
|
|
1229
991
|
case FilterType.isTrue:
|
|
1230
992
|
return filter.isTrue();
|
|
1231
|
-
|
|
1232
993
|
case FilterType.isFalse:
|
|
1233
994
|
return filter.isFalse();
|
|
1234
|
-
|
|
1235
995
|
case FilterType.isNull:
|
|
1236
996
|
return filter.isNull();
|
|
1237
|
-
|
|
1238
997
|
case FilterType.contains:
|
|
1239
998
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))));
|
|
1240
|
-
|
|
1241
999
|
case FilterType.notContains:
|
|
1242
1000
|
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))).not());
|
|
1243
|
-
|
|
1244
1001
|
case FilterType.startsWith:
|
|
1245
1002
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i)^\\Q".concat(value, "\\E.*"))));
|
|
1246
|
-
|
|
1247
1003
|
case FilterType.endsWith:
|
|
1248
1004
|
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E$"))));
|
|
1249
|
-
|
|
1250
1005
|
case FilterType.in:
|
|
1251
1006
|
case FilterType.inIgnoreCase:
|
|
1252
1007
|
case FilterType.notIn:
|
|
@@ -1256,6 +1011,7 @@ export class TableUtils {
|
|
|
1256
1011
|
throw new Error("Unexpected filter operation: ".concat(operation));
|
|
1257
1012
|
}
|
|
1258
1013
|
}
|
|
1014
|
+
|
|
1259
1015
|
/**
|
|
1260
1016
|
* Create a filter using the selected items
|
|
1261
1017
|
* Has a flag for invertSelection as we start from a "Select All" state and a user just deselects items.
|
|
@@ -1265,20 +1021,17 @@ export class TableUtils {
|
|
|
1265
1021
|
* @param invertSelection Invert the selection (eg. All items are selected, then you deselect items)
|
|
1266
1022
|
* @returns Returns a `in` or `notIn` FilterCondition as necessary, or null if no filtering should be applied (everything selected)
|
|
1267
1023
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
1024
|
static makeSelectValueFilter(column, selectedValues, invertSelection) {
|
|
1271
1025
|
if (selectedValues.length === 0) {
|
|
1272
1026
|
if (invertSelection) {
|
|
1273
1027
|
// No filter means select everything
|
|
1274
1028
|
return null;
|
|
1275
|
-
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// KLUDGE: Return a conflicting filter to show no results.
|
|
1276
1032
|
// Could recognize this situation at a higher or lower level and pause updates on the
|
|
1277
1033
|
// table, but this situation should be rare and that wouldn't be much gains for some added complexity
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
1034
|
var value = null;
|
|
1281
|
-
|
|
1282
1035
|
if (TableUtils.isTextType(column.type)) {
|
|
1283
1036
|
// Use 'a' so that it can work for String or Character types
|
|
1284
1037
|
value = dh.FilterValue.ofString('a');
|
|
@@ -1289,18 +1042,14 @@ export class TableUtils {
|
|
|
1289
1042
|
} else {
|
|
1290
1043
|
value = dh.FilterValue.ofNumber(0);
|
|
1291
1044
|
}
|
|
1292
|
-
|
|
1293
1045
|
var eqFilter = column.filter().eq(value);
|
|
1294
1046
|
var notEqFilter = column.filter().notEq(value);
|
|
1295
1047
|
return eqFilter.and(notEqFilter);
|
|
1296
1048
|
}
|
|
1297
|
-
|
|
1298
1049
|
var values = [];
|
|
1299
1050
|
var isNullSelected = false;
|
|
1300
|
-
|
|
1301
1051
|
for (var i = 0; i < selectedValues.length; i += 1) {
|
|
1302
1052
|
var _value = selectedValues[i];
|
|
1303
|
-
|
|
1304
1053
|
if (_value == null) {
|
|
1305
1054
|
isNullSelected = true;
|
|
1306
1055
|
} else if (TableUtils.isTextType(column.type)) {
|
|
@@ -1311,40 +1060,32 @@ export class TableUtils {
|
|
|
1311
1060
|
values.push(dh.FilterValue.ofNumber(_value));
|
|
1312
1061
|
}
|
|
1313
1062
|
}
|
|
1314
|
-
|
|
1315
1063
|
if (isNullSelected) {
|
|
1316
1064
|
if (values.length > 0) {
|
|
1317
1065
|
if (invertSelection) {
|
|
1318
1066
|
return column.filter().isNull().not().and(column.filter().notIn(values));
|
|
1319
1067
|
}
|
|
1320
|
-
|
|
1321
1068
|
return column.filter().isNull().or(column.filter().in(values));
|
|
1322
1069
|
}
|
|
1323
|
-
|
|
1324
1070
|
if (invertSelection) {
|
|
1325
1071
|
return column.filter().isNull().not();
|
|
1326
1072
|
}
|
|
1327
|
-
|
|
1328
1073
|
return column.filter().isNull();
|
|
1329
1074
|
}
|
|
1330
|
-
|
|
1331
1075
|
if (invertSelection) {
|
|
1332
1076
|
return column.filter().notIn(values);
|
|
1333
1077
|
}
|
|
1334
|
-
|
|
1335
1078
|
return column.filter().in(values);
|
|
1336
1079
|
}
|
|
1337
|
-
|
|
1338
1080
|
static isTreeTable(table) {
|
|
1339
1081
|
return table != null && table.expand !== undefined && table.collapse !== undefined;
|
|
1340
1082
|
}
|
|
1083
|
+
|
|
1341
1084
|
/**
|
|
1342
1085
|
* Copies the provided array, sorts by column name case insensitive, and returns the sorted array.
|
|
1343
1086
|
* @param columns The columns to sort
|
|
1344
1087
|
* @param isAscending Whether to sort ascending
|
|
1345
1088
|
*/
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
1089
|
static sortColumns(columns) {
|
|
1349
1090
|
var isAscending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1350
1091
|
return [...columns].sort((a, b) => {
|
|
@@ -1353,9 +1094,7 @@ export class TableUtils {
|
|
|
1353
1094
|
return TextUtils.sort(aName, bName, isAscending);
|
|
1354
1095
|
});
|
|
1355
1096
|
}
|
|
1356
|
-
|
|
1357
1097
|
}
|
|
1358
|
-
|
|
1359
1098
|
_defineProperty(TableUtils, "dataType", {
|
|
1360
1099
|
BOOLEAN: 'boolean',
|
|
1361
1100
|
CHAR: 'char',
|
|
@@ -1365,21 +1104,17 @@ _defineProperty(TableUtils, "dataType", {
|
|
|
1365
1104
|
STRING: 'string',
|
|
1366
1105
|
UNKNOWN: 'unknown'
|
|
1367
1106
|
});
|
|
1368
|
-
|
|
1369
1107
|
_defineProperty(TableUtils, "sortDirection", {
|
|
1370
1108
|
ascending: 'ASC',
|
|
1371
1109
|
descending: 'DESC',
|
|
1372
1110
|
reverse: 'REVERSE',
|
|
1373
1111
|
none: null
|
|
1374
1112
|
});
|
|
1375
|
-
|
|
1376
1113
|
_defineProperty(TableUtils, "REVERSE_TYPE", Object.freeze({
|
|
1377
1114
|
NONE: 'none',
|
|
1378
1115
|
PRE_SORT: 'pre-sort',
|
|
1379
1116
|
POST_SORT: 'post-sort'
|
|
1380
1117
|
}));
|
|
1381
|
-
|
|
1382
1118
|
_defineProperty(TableUtils, "NUMBER_REGEX", /^-?\d+(\.\d+)?$/);
|
|
1383
|
-
|
|
1384
1119
|
export default TableUtils;
|
|
1385
1120
|
//# sourceMappingURL=TableUtils.js.map
|