@deephaven/jsapi-utils 0.38.0 → 0.38.1-beta.11
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.d.ts +1 -1
- package/dist/ConnectionUtils.d.ts.map +1 -1
- package/dist/ConnectionUtils.js.map +1 -1
- package/dist/DateUtils.d.ts +4 -4
- package/dist/DateUtils.d.ts.map +1 -1
- package/dist/DateUtils.js +16 -17
- package/dist/DateUtils.js.map +1 -1
- package/dist/Formatter.d.ts +3 -1
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +8 -7
- package/dist/Formatter.js.map +1 -1
- package/dist/FormatterUtils.d.ts +1 -1
- package/dist/FormatterUtils.js.map +1 -1
- package/dist/SessionUtils.d.ts +3 -3
- package/dist/SessionUtils.d.ts.map +1 -1
- package/dist/SessionUtils.js +2 -2
- package/dist/SessionUtils.js.map +1 -1
- package/dist/TableUtils.d.ts +106 -46
- package/dist/TableUtils.d.ts.map +1 -1
- package/dist/TableUtils.js +444 -284
- package/dist/TableUtils.js.map +1 -1
- package/dist/ViewportDataUtils.d.ts +13 -5
- package/dist/ViewportDataUtils.d.ts.map +1 -1
- package/dist/ViewportDataUtils.js +20 -9
- package/dist/ViewportDataUtils.js.map +1 -1
- package/dist/formatters/DateTimeColumnFormatter.d.ts +5 -3
- package/dist/formatters/DateTimeColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/DateTimeColumnFormatter.js +8 -5
- package/dist/formatters/DateTimeColumnFormatter.js.map +1 -1
- package/dist/formatters/DecimalColumnFormatter.d.ts +5 -2
- package/dist/formatters/DecimalColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/DecimalColumnFormatter.js +8 -5
- package/dist/formatters/DecimalColumnFormatter.js.map +1 -1
- package/dist/formatters/IntegerColumnFormatter.d.ts +5 -2
- package/dist/formatters/IntegerColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/IntegerColumnFormatter.js +8 -5
- package/dist/formatters/IntegerColumnFormatter.js.map +1 -1
- package/dist/formatters/TableColumnFormatter.d.ts +3 -1
- package/dist/formatters/TableColumnFormatter.d.ts.map +1 -1
- package/dist/formatters/TableColumnFormatter.js +2 -1
- package/dist/formatters/TableColumnFormatter.js.map +1 -1
- package/package.json +8 -8
package/dist/TableUtils.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
6
|
import { Type as FilterType, Operator as FilterOperator } from '@deephaven/filters';
|
|
5
7
|
import Log from '@deephaven/log';
|
|
6
|
-
import dh from '@deephaven/jsapi-shim';
|
|
7
8
|
import { PromiseUtils, TextUtils, TimeoutError } from '@deephaven/utils';
|
|
8
9
|
import DateUtils from "./DateUtils.js";
|
|
9
10
|
var log = Log.module('TableUtils');
|
|
@@ -11,6 +12,19 @@ var log = Log.module('TableUtils');
|
|
|
11
12
|
export class TableUtils {
|
|
12
13
|
// Regex looking for a negative or positive integer or decimal number
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Executes a callback on a given table and returns a Promise that will resolve
|
|
17
|
+
* the next time a particular event type fires on the table.
|
|
18
|
+
* @param exec Callback function to execute.
|
|
19
|
+
* @param table Table that gets passed to the `exec` function and that is
|
|
20
|
+
* subscribed to for a given `eventType`.
|
|
21
|
+
* @param eventType The event type to listen for.
|
|
22
|
+
* @param timeout If the event doesn't fire within the timeout, the returned
|
|
23
|
+
* Promise will be rejected.
|
|
24
|
+
* @returns a Promise to the original table that resolves on next `eventType`
|
|
25
|
+
* event
|
|
26
|
+
*/
|
|
27
|
+
|
|
14
28
|
static getSortIndex(sort, columnName) {
|
|
15
29
|
for (var i = 0; i < sort.length; i += 1) {
|
|
16
30
|
var _s$column;
|
|
@@ -301,6 +315,207 @@ export class TableUtils {
|
|
|
301
315
|
return TableUtils.getNormalizedType(type1) === TableUtils.getNormalizedType(type2);
|
|
302
316
|
}
|
|
303
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Adds quotes to a value if they're not already added
|
|
320
|
+
* @param value Value to add quotes around
|
|
321
|
+
*/
|
|
322
|
+
static quoteValue(value) {
|
|
323
|
+
if (value.length >= 2 && (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' || value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
return "\"".concat(value, "\"");
|
|
327
|
+
}
|
|
328
|
+
static isRangeOperation(operation) {
|
|
329
|
+
switch (operation) {
|
|
330
|
+
case '<':
|
|
331
|
+
case '<=':
|
|
332
|
+
case '=<':
|
|
333
|
+
case '>':
|
|
334
|
+
case '>=':
|
|
335
|
+
case '=>':
|
|
336
|
+
return true;
|
|
337
|
+
default:
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @param filter The column filter to apply the range operation to
|
|
344
|
+
* @param operation The range operation to run
|
|
345
|
+
* @param value The value to use for the operation
|
|
346
|
+
* @returns The condition with the specified operation
|
|
347
|
+
*/
|
|
348
|
+
static makeRangeFilterWithOperation(filter, operation, value) {
|
|
349
|
+
switch (operation) {
|
|
350
|
+
case '=':
|
|
351
|
+
return filter.eq(value);
|
|
352
|
+
case '<':
|
|
353
|
+
return filter.lessThan(value);
|
|
354
|
+
case '<=':
|
|
355
|
+
case '=<':
|
|
356
|
+
return filter.lessThanOrEqualTo(value);
|
|
357
|
+
case '>':
|
|
358
|
+
return filter.greaterThan(value);
|
|
359
|
+
case '>=':
|
|
360
|
+
case '=>':
|
|
361
|
+
return filter.greaterThanOrEqualTo(value);
|
|
362
|
+
case '!=':
|
|
363
|
+
case '!':
|
|
364
|
+
return filter.notEq(value);
|
|
365
|
+
default:
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled.
|
|
372
|
+
* Use in a component that loads a table, and call cancel when unmounting.
|
|
373
|
+
* @param table The table promise to wrap
|
|
374
|
+
*/
|
|
375
|
+
static makeCancelableTablePromise(table) {
|
|
376
|
+
return PromiseUtils.makeCancelable(table, resolved => {
|
|
377
|
+
resolved.close();
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Make a cancelable promise for a one-shot table event with a timeout.
|
|
383
|
+
* @param table Table to listen for events on
|
|
384
|
+
* @param eventName Event to listen for
|
|
385
|
+
* @param timeout Event timeout in milliseconds, defaults to 0
|
|
386
|
+
* @param matcher Optional function to determine if the promise can be resolved or stays pending
|
|
387
|
+
* @returns Resolves with the event data
|
|
388
|
+
*/
|
|
389
|
+
static makeCancelableTableEventPromise(table, eventName) {
|
|
390
|
+
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
391
|
+
var matcher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
392
|
+
var eventCleanup;
|
|
393
|
+
var timeoutId;
|
|
394
|
+
var isPending = true;
|
|
395
|
+
var wrappedPromise = new Promise((resolve, reject) => {
|
|
396
|
+
timeoutId = setTimeout(() => {
|
|
397
|
+
eventCleanup();
|
|
398
|
+
isPending = false;
|
|
399
|
+
reject(new TimeoutError("Event \"".concat(eventName, "\" timed out.")));
|
|
400
|
+
}, timeout);
|
|
401
|
+
eventCleanup = table.addEventListener(eventName, event => {
|
|
402
|
+
if (matcher != null && !matcher(event)) {
|
|
403
|
+
log.debug2('Event triggered, but matcher returned false.');
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
log.debug2('Event triggered, resolving.');
|
|
407
|
+
eventCleanup();
|
|
408
|
+
clearTimeout(timeoutId);
|
|
409
|
+
isPending = false;
|
|
410
|
+
resolve(event);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
wrappedPromise.cancel = () => {
|
|
414
|
+
if (isPending) {
|
|
415
|
+
log.debug2('Pending promise cleanup.');
|
|
416
|
+
eventCleanup();
|
|
417
|
+
clearTimeout(timeoutId);
|
|
418
|
+
isPending = false;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
log.debug2('Ignoring non-pending promise cancel.');
|
|
422
|
+
};
|
|
423
|
+
return wrappedPromise;
|
|
424
|
+
}
|
|
425
|
+
static removeCommas(value) {
|
|
426
|
+
return value.replace(/[\s|,]/g, '');
|
|
427
|
+
}
|
|
428
|
+
static makeBooleanValue(text) {
|
|
429
|
+
var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
430
|
+
if (text === '' && allowEmpty) {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
switch (text === null || text === void 0 ? void 0 : text.toLowerCase()) {
|
|
434
|
+
case 'null':
|
|
435
|
+
return null;
|
|
436
|
+
case '0':
|
|
437
|
+
case 'f':
|
|
438
|
+
case 'fa':
|
|
439
|
+
case 'fal':
|
|
440
|
+
case 'fals':
|
|
441
|
+
case 'false':
|
|
442
|
+
case 'n':
|
|
443
|
+
case 'no':
|
|
444
|
+
return false;
|
|
445
|
+
case '1':
|
|
446
|
+
case 't':
|
|
447
|
+
case 'tr':
|
|
448
|
+
case 'tru':
|
|
449
|
+
case 'true':
|
|
450
|
+
case 'y':
|
|
451
|
+
case 'ye':
|
|
452
|
+
case 'yes':
|
|
453
|
+
return true;
|
|
454
|
+
default:
|
|
455
|
+
throw new Error("Invalid boolean '".concat(text, "'"));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
static makeNumberValue(text) {
|
|
459
|
+
if (text === 'null' || text === '') {
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
var cleanText = text.toLowerCase().trim();
|
|
463
|
+
if (cleanText === '∞' || cleanText === 'infinity' || cleanText === 'inf') {
|
|
464
|
+
return Number.POSITIVE_INFINITY;
|
|
465
|
+
}
|
|
466
|
+
if (cleanText === '-∞' || cleanText === '-infinity' || cleanText === '-inf') {
|
|
467
|
+
return Number.NEGATIVE_INFINITY;
|
|
468
|
+
}
|
|
469
|
+
var numberText = TableUtils.removeCommas(cleanText);
|
|
470
|
+
if (TableUtils.NUMBER_REGEX.test(numberText)) {
|
|
471
|
+
return parseFloat(numberText);
|
|
472
|
+
}
|
|
473
|
+
throw new Error("Invalid number '".concat(text, "'"));
|
|
474
|
+
}
|
|
475
|
+
static getFilterOperatorString(operation) {
|
|
476
|
+
switch (operation) {
|
|
477
|
+
case FilterType.eq:
|
|
478
|
+
return '=';
|
|
479
|
+
case FilterType.notEq:
|
|
480
|
+
return '!=';
|
|
481
|
+
case FilterType.greaterThan:
|
|
482
|
+
return '>';
|
|
483
|
+
case FilterType.greaterThanOrEqualTo:
|
|
484
|
+
return '>=';
|
|
485
|
+
case FilterType.lessThan:
|
|
486
|
+
return '<';
|
|
487
|
+
case FilterType.lessThanOrEqualTo:
|
|
488
|
+
return '<=';
|
|
489
|
+
case FilterType.contains:
|
|
490
|
+
return '~';
|
|
491
|
+
case FilterType.notContains:
|
|
492
|
+
return '!~';
|
|
493
|
+
default:
|
|
494
|
+
throw new Error("Unexpected filter type ".concat(operation));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
static isTreeTable(table) {
|
|
498
|
+
return table != null && table.expand !== undefined && table.collapse !== undefined;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Copies the provided array, sorts by column name case insensitive, and returns the sorted array.
|
|
503
|
+
* @param columns The columns to sort
|
|
504
|
+
* @param isAscending Whether to sort ascending
|
|
505
|
+
*/
|
|
506
|
+
static sortColumns(columns) {
|
|
507
|
+
var isAscending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
508
|
+
return [...columns].sort((a, b) => {
|
|
509
|
+
var aName = a.name.toUpperCase();
|
|
510
|
+
var bName = b.name.toUpperCase();
|
|
511
|
+
return TextUtils.sort(aName, bName, isAscending);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
constructor(dh) {
|
|
515
|
+
_defineProperty(this, "dh", void 0);
|
|
516
|
+
this.dh = dh;
|
|
517
|
+
}
|
|
518
|
+
|
|
304
519
|
/**
|
|
305
520
|
* Create filter with the provided column and text. Handles multiple filters joined with && or ||
|
|
306
521
|
* @param column The column to set the filter on
|
|
@@ -308,7 +523,7 @@ export class TableUtils {
|
|
|
308
523
|
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
309
524
|
* @returns Returns the created filter, null if text could not be parsed
|
|
310
525
|
*/
|
|
311
|
-
|
|
526
|
+
makeQuickFilter(column, text, timeZone) {
|
|
312
527
|
var orComponents = text.split('||');
|
|
313
528
|
var orFilter = null;
|
|
314
529
|
for (var i = 0; i < orComponents.length; i += 1) {
|
|
@@ -318,7 +533,7 @@ export class TableUtils {
|
|
|
318
533
|
for (var j = 0; j < andComponents.length; j += 1) {
|
|
319
534
|
var andComponent = andComponents[j].trim();
|
|
320
535
|
if (andComponent.length > 0) {
|
|
321
|
-
var filter =
|
|
536
|
+
var filter = this.makeQuickFilterFromComponent(column, andComponent, timeZone);
|
|
322
537
|
if (filter) {
|
|
323
538
|
if (andFilter) {
|
|
324
539
|
andFilter = andFilter.and(filter);
|
|
@@ -346,7 +561,7 @@ export class TableUtils {
|
|
|
346
561
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
347
562
|
* @returns Returns the created filter, null if text could not be parsed
|
|
348
563
|
*/
|
|
349
|
-
|
|
564
|
+
makeQuickFilterFromComponent(column, text, timeZone) {
|
|
350
565
|
var {
|
|
351
566
|
type
|
|
352
567
|
} = column;
|
|
@@ -364,8 +579,11 @@ export class TableUtils {
|
|
|
364
579
|
}
|
|
365
580
|
return this.makeQuickTextFilter(column, text);
|
|
366
581
|
}
|
|
367
|
-
|
|
582
|
+
makeQuickNumberFilter(column, text) {
|
|
368
583
|
var columnFilter = column.filter();
|
|
584
|
+
var {
|
|
585
|
+
dh
|
|
586
|
+
} = this;
|
|
369
587
|
var filter = null;
|
|
370
588
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|=|!)?(\s*-\s*)?(\s*\d*(?:,\d{3})*(?:\.\d*)?\s*)?(null|nan|infinity|inf|\u221E)?(.*)/i;
|
|
371
589
|
var result = regex.exec(text);
|
|
@@ -435,7 +653,10 @@ export class TableUtils {
|
|
|
435
653
|
filter = column.filter();
|
|
436
654
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, value);
|
|
437
655
|
}
|
|
438
|
-
|
|
656
|
+
makeQuickTextFilter(column, text) {
|
|
657
|
+
var {
|
|
658
|
+
dh
|
|
659
|
+
} = this;
|
|
439
660
|
var cleanText = "".concat(text).trim();
|
|
440
661
|
var regex = /^(!~|!=|~|=|!)?(.*)/;
|
|
441
662
|
var result = regex.exec(cleanText);
|
|
@@ -509,7 +730,9 @@ export class TableUtils {
|
|
|
509
730
|
}
|
|
510
731
|
return null;
|
|
511
732
|
}
|
|
512
|
-
|
|
733
|
+
|
|
734
|
+
// eslint-disable-next-line class-methods-use-this
|
|
735
|
+
makeQuickBooleanFilter(column, text) {
|
|
513
736
|
var regex = /^(!=|=|!)?(.*)/;
|
|
514
737
|
var result = regex.exec("".concat(text).trim());
|
|
515
738
|
if (result === null) {
|
|
@@ -540,7 +763,7 @@ export class TableUtils {
|
|
|
540
763
|
* @param text The date string text to parse.
|
|
541
764
|
* @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York
|
|
542
765
|
*/
|
|
543
|
-
|
|
766
|
+
makeQuickDateFilter(column, text, timeZone) {
|
|
544
767
|
var cleanText = text.trim();
|
|
545
768
|
var regex = /\s*(>=|<=|=>|=<|>|<|!=|!|=)?(.*)/;
|
|
546
769
|
var result = regex.exec(cleanText);
|
|
@@ -576,7 +799,7 @@ export class TableUtils {
|
|
|
576
799
|
filterOperation = FilterType.eq;
|
|
577
800
|
break;
|
|
578
801
|
}
|
|
579
|
-
return
|
|
802
|
+
return this.makeQuickDateFilterWithOperation(column, dateText, filterOperation, timeZone);
|
|
580
803
|
}
|
|
581
804
|
|
|
582
805
|
/**
|
|
@@ -586,8 +809,11 @@ export class TableUtils {
|
|
|
586
809
|
* @param operation The filter operation to use.
|
|
587
810
|
* @param timeZone The time zone to make this filter with. E.g. America/New_York
|
|
588
811
|
*/
|
|
589
|
-
|
|
590
|
-
var
|
|
812
|
+
makeQuickDateFilterWithOperation(column, text, operation, timeZone) {
|
|
813
|
+
var {
|
|
814
|
+
dh
|
|
815
|
+
} = this;
|
|
816
|
+
var [startDate, endDate] = DateUtils.parseDateRange(dh, text, timeZone);
|
|
591
817
|
var startValue = startDate != null ? dh.FilterValue.ofNumber(startDate) : null;
|
|
592
818
|
var endValue = endDate != null ? dh.FilterValue.ofNumber(endDate) : null;
|
|
593
819
|
var filter = column.filter();
|
|
@@ -637,31 +863,10 @@ export class TableUtils {
|
|
|
637
863
|
throw new Error("Invalid operator: ".concat(operation));
|
|
638
864
|
}
|
|
639
865
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
*/
|
|
645
|
-
static quoteValue(value) {
|
|
646
|
-
if (value.length >= 2 && (value.charAt(0) === '"' && value.charAt(value.length - 1) === '"' || value.charAt(0) === "'" && value.charAt(value.length - 1) === "'")) {
|
|
647
|
-
return value;
|
|
648
|
-
}
|
|
649
|
-
return "\"".concat(value, "\"");
|
|
650
|
-
}
|
|
651
|
-
static isRangeOperation(operation) {
|
|
652
|
-
switch (operation) {
|
|
653
|
-
case '<':
|
|
654
|
-
case '<=':
|
|
655
|
-
case '=<':
|
|
656
|
-
case '>':
|
|
657
|
-
case '>=':
|
|
658
|
-
case '=>':
|
|
659
|
-
return true;
|
|
660
|
-
default:
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
static makeQuickCharFilter(column, text) {
|
|
866
|
+
makeQuickCharFilter(column, text) {
|
|
867
|
+
var {
|
|
868
|
+
dh
|
|
869
|
+
} = this;
|
|
665
870
|
var cleanText = "".concat(text).trim();
|
|
666
871
|
var regex = /^(>=|<=|=>|=<|>|<|!=|=|!)?(null|"."|'.'|.)?(.*)/;
|
|
667
872
|
var result = regex.exec(cleanText);
|
|
@@ -699,91 +904,7 @@ export class TableUtils {
|
|
|
699
904
|
var filterValue = dh.FilterValue.ofString(TableUtils.isRangeOperation(operation) ? TableUtils.quoteValue(value) : value);
|
|
700
905
|
return TableUtils.makeRangeFilterWithOperation(filter, operation, filterValue);
|
|
701
906
|
}
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* @param filter The column filter to apply the range operation to
|
|
705
|
-
* @param operation The range operation to run
|
|
706
|
-
* @param value The value to use for the operation
|
|
707
|
-
* @returns The condition with the specified operation
|
|
708
|
-
*/
|
|
709
|
-
static makeRangeFilterWithOperation(filter, operation, value) {
|
|
710
|
-
switch (operation) {
|
|
711
|
-
case '=':
|
|
712
|
-
return filter.eq(value);
|
|
713
|
-
case '<':
|
|
714
|
-
return filter.lessThan(value);
|
|
715
|
-
case '<=':
|
|
716
|
-
case '=<':
|
|
717
|
-
return filter.lessThanOrEqualTo(value);
|
|
718
|
-
case '>':
|
|
719
|
-
return filter.greaterThan(value);
|
|
720
|
-
case '>=':
|
|
721
|
-
case '=>':
|
|
722
|
-
return filter.greaterThanOrEqualTo(value);
|
|
723
|
-
case '!=':
|
|
724
|
-
case '!':
|
|
725
|
-
return filter.notEq(value);
|
|
726
|
-
default:
|
|
727
|
-
return null;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled.
|
|
733
|
-
* Use in a component that loads a table, and call cancel when unmounting.
|
|
734
|
-
* @param table The table promise to wrap
|
|
735
|
-
*/
|
|
736
|
-
static makeCancelableTablePromise(table) {
|
|
737
|
-
return PromiseUtils.makeCancelable(table, resolved => {
|
|
738
|
-
resolved.close();
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* Make a cancelable promise for a one-shot table event with a timeout.
|
|
744
|
-
* @param table Table to listen for events on
|
|
745
|
-
* @param eventName Event to listen for
|
|
746
|
-
* @param timeout Event timeout in milliseconds, defaults to 0
|
|
747
|
-
* @param matcher Optional function to determine if the promise can be resolved or stays pending
|
|
748
|
-
* @returns Resolves with the event data
|
|
749
|
-
*/
|
|
750
|
-
static makeCancelableTableEventPromise(table, eventName) {
|
|
751
|
-
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
752
|
-
var matcher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
753
|
-
var eventCleanup;
|
|
754
|
-
var timeoutId;
|
|
755
|
-
var isPending = true;
|
|
756
|
-
var wrappedPromise = new Promise((resolve, reject) => {
|
|
757
|
-
timeoutId = setTimeout(() => {
|
|
758
|
-
eventCleanup();
|
|
759
|
-
isPending = false;
|
|
760
|
-
reject(new TimeoutError("Event \"".concat(eventName, "\" timed out.")));
|
|
761
|
-
}, timeout);
|
|
762
|
-
eventCleanup = table.addEventListener(eventName, event => {
|
|
763
|
-
if (matcher != null && !matcher(event)) {
|
|
764
|
-
log.debug2('Event triggered, but matcher returned false.');
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
log.debug2('Event triggered, resolving.');
|
|
768
|
-
eventCleanup();
|
|
769
|
-
clearTimeout(timeoutId);
|
|
770
|
-
isPending = false;
|
|
771
|
-
resolve(event);
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
wrappedPromise.cancel = () => {
|
|
775
|
-
if (isPending) {
|
|
776
|
-
log.debug2('Pending promise cleanup.');
|
|
777
|
-
eventCleanup();
|
|
778
|
-
clearTimeout(timeoutId);
|
|
779
|
-
isPending = false;
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
log.debug2('Ignoring non-pending promise cancel.');
|
|
783
|
-
};
|
|
784
|
-
return wrappedPromise;
|
|
785
|
-
}
|
|
786
|
-
static makeAdvancedFilter(column, options, timeZone) {
|
|
907
|
+
makeAdvancedFilter(column, options, timeZone) {
|
|
787
908
|
var {
|
|
788
909
|
filterItems,
|
|
789
910
|
filterOperators,
|
|
@@ -799,7 +920,7 @@ export class TableUtils {
|
|
|
799
920
|
} = filterItem;
|
|
800
921
|
if (selectedType != null && selectedType.length > 0 && value != null && value.length > 0) {
|
|
801
922
|
try {
|
|
802
|
-
var newFilter =
|
|
923
|
+
var newFilter = this.makeAdvancedValueFilter(column, selectedType, value, timeZone);
|
|
803
924
|
if (newFilter != null) {
|
|
804
925
|
if (i === 0) {
|
|
805
926
|
filter = newFilter;
|
|
@@ -825,7 +946,7 @@ export class TableUtils {
|
|
|
825
946
|
}
|
|
826
947
|
}
|
|
827
948
|
}
|
|
828
|
-
var selectValueFilter =
|
|
949
|
+
var selectValueFilter = this.makeSelectValueFilter(column, selectedValues, invertSelection);
|
|
829
950
|
if (selectValueFilter != null) {
|
|
830
951
|
if (filter != null) {
|
|
831
952
|
filter = filter.and(selectValueFilter);
|
|
@@ -835,8 +956,167 @@ export class TableUtils {
|
|
|
835
956
|
}
|
|
836
957
|
return filter;
|
|
837
958
|
}
|
|
838
|
-
|
|
839
|
-
|
|
959
|
+
makeAdvancedValueFilter(column, operation, value, timeZone) {
|
|
960
|
+
var {
|
|
961
|
+
dh
|
|
962
|
+
} = this;
|
|
963
|
+
if (TableUtils.isDateType(column.type)) {
|
|
964
|
+
return this.makeQuickDateFilterWithOperation(column, value, operation, timeZone);
|
|
965
|
+
}
|
|
966
|
+
if (TableUtils.isNumberType(column.type) || TableUtils.isCharType(column.type)) {
|
|
967
|
+
return this.makeQuickFilter(column, "".concat(TableUtils.getFilterOperatorString(operation)).concat(value));
|
|
968
|
+
}
|
|
969
|
+
var filterValue = this.makeFilterValue(column.type, value);
|
|
970
|
+
var filter = column.filter();
|
|
971
|
+
switch (operation) {
|
|
972
|
+
case FilterType.eq:
|
|
973
|
+
return filter.eq(filterValue);
|
|
974
|
+
case FilterType.eqIgnoreCase:
|
|
975
|
+
return filter.eqIgnoreCase(filterValue);
|
|
976
|
+
case FilterType.notEq:
|
|
977
|
+
return filter.notEq(filterValue);
|
|
978
|
+
case FilterType.notEqIgnoreCase:
|
|
979
|
+
return filter.notEqIgnoreCase(filterValue);
|
|
980
|
+
case FilterType.greaterThan:
|
|
981
|
+
return filter.greaterThan(filterValue);
|
|
982
|
+
case FilterType.greaterThanOrEqualTo:
|
|
983
|
+
return filter.greaterThanOrEqualTo(filterValue);
|
|
984
|
+
case FilterType.lessThan:
|
|
985
|
+
return filter.lessThan(filterValue);
|
|
986
|
+
case FilterType.lessThanOrEqualTo:
|
|
987
|
+
return filter.lessThanOrEqualTo(filterValue);
|
|
988
|
+
case FilterType.isTrue:
|
|
989
|
+
return filter.isTrue();
|
|
990
|
+
case FilterType.isFalse:
|
|
991
|
+
return filter.isFalse();
|
|
992
|
+
case FilterType.isNull:
|
|
993
|
+
return filter.isNull();
|
|
994
|
+
case FilterType.contains:
|
|
995
|
+
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))));
|
|
996
|
+
case FilterType.notContains:
|
|
997
|
+
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))).not());
|
|
998
|
+
case FilterType.startsWith:
|
|
999
|
+
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i)^\\Q".concat(value, "\\E.*"))));
|
|
1000
|
+
case FilterType.endsWith:
|
|
1001
|
+
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E$"))));
|
|
1002
|
+
case FilterType.in:
|
|
1003
|
+
case FilterType.inIgnoreCase:
|
|
1004
|
+
case FilterType.notIn:
|
|
1005
|
+
case FilterType.notInIgnoreCase:
|
|
1006
|
+
case FilterType.invoke:
|
|
1007
|
+
default:
|
|
1008
|
+
throw new Error("Unexpected filter operation: ".concat(operation));
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Apply a filter to a table that won't match anything.
|
|
1014
|
+
* @table The table to apply the filter to
|
|
1015
|
+
* @columnName The name of the column to apploy the filter to
|
|
1016
|
+
* @param timeout Timeout before cancelling the promise that waits for the next
|
|
1017
|
+
* dh.Table.EVENT_FILTERCHANGED event
|
|
1018
|
+
* @returns a Promise to the Table that resolves after the next
|
|
1019
|
+
* dh.Table.EVENT_FILTERCHANGED event
|
|
1020
|
+
*/
|
|
1021
|
+
applyNeverFilter(table, columnName) {
|
|
1022
|
+
var _arguments = arguments,
|
|
1023
|
+
_this = this;
|
|
1024
|
+
return _asyncToGenerator(function* () {
|
|
1025
|
+
var timeout = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : TableUtils.APPLY_TABLE_CHANGE_TIMEOUT_MS;
|
|
1026
|
+
if (table == null) {
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
var column = table.findColumn(columnName);
|
|
1030
|
+
var filters = [_this.makeNeverFilter(column)];
|
|
1031
|
+
yield _this.applyFilter(table, filters, timeout);
|
|
1032
|
+
return table;
|
|
1033
|
+
})();
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Apply custom columns to a given table. Return a Promise that resolves with
|
|
1038
|
+
* the table once the dh.Table.EVENT_CUSTOMCOLUMNSCHANGED event has fired.
|
|
1039
|
+
* @param table The table to apply custom columns to.
|
|
1040
|
+
* @param columns The list of column expressions or definitions to apply.
|
|
1041
|
+
* @returns A Promise that will be resolved with the given table after the
|
|
1042
|
+
* columns are applied.
|
|
1043
|
+
*/
|
|
1044
|
+
applyCustomColumns(table, columns) {
|
|
1045
|
+
var _arguments2 = arguments,
|
|
1046
|
+
_this2 = this;
|
|
1047
|
+
return _asyncToGenerator(function* () {
|
|
1048
|
+
var timeout = _arguments2.length > 2 && _arguments2[2] !== undefined ? _arguments2[2] : TableUtils.APPLY_TABLE_CHANGE_TIMEOUT_MS;
|
|
1049
|
+
var {
|
|
1050
|
+
dh
|
|
1051
|
+
} = _this2;
|
|
1052
|
+
return TableUtils.executeAndWaitForEvent(t => t === null || t === void 0 ? void 0 : t.applyCustomColumns(columns), table, dh.Table.EVENT_CUSTOMCOLUMNSCHANGED, timeout);
|
|
1053
|
+
})();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Apply filters to a given table.
|
|
1058
|
+
* @param table Table to apply filters to
|
|
1059
|
+
* @param filters Filters to apply
|
|
1060
|
+
* @param timeout Timeout before cancelling the promise that waits for the next
|
|
1061
|
+
* dh.Table.EVENT_FILTERCHANGED event
|
|
1062
|
+
* @returns a Promise to the Table that resolves after the next
|
|
1063
|
+
* dh.Table.EVENT_FILTERCHANGED event
|
|
1064
|
+
*/
|
|
1065
|
+
applyFilter(table, filters) {
|
|
1066
|
+
var _arguments3 = arguments,
|
|
1067
|
+
_this3 = this;
|
|
1068
|
+
return _asyncToGenerator(function* () {
|
|
1069
|
+
var timeout = _arguments3.length > 2 && _arguments3[2] !== undefined ? _arguments3[2] : TableUtils.APPLY_TABLE_CHANGE_TIMEOUT_MS;
|
|
1070
|
+
var {
|
|
1071
|
+
dh
|
|
1072
|
+
} = _this3;
|
|
1073
|
+
return TableUtils.executeAndWaitForEvent(t => t === null || t === void 0 ? void 0 : t.applyFilter(filters), table, dh.Table.EVENT_FILTERCHANGED, timeout);
|
|
1074
|
+
})();
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Apply sorts to a given Table.
|
|
1079
|
+
* @param table The table to apply sorts to
|
|
1080
|
+
* @param sorts The sorts to apply
|
|
1081
|
+
* @param timeout Timeout before cancelling the promise that waits for the next
|
|
1082
|
+
* dh.Table.EVENT_SORTCHANGED event
|
|
1083
|
+
* @returns a Promise to the Table that resolves after the next
|
|
1084
|
+
* dh.Table.EVENT_SORTCHANGED event
|
|
1085
|
+
*/
|
|
1086
|
+
applySort(table, sorts) {
|
|
1087
|
+
var _arguments4 = arguments,
|
|
1088
|
+
_this4 = this;
|
|
1089
|
+
return _asyncToGenerator(function* () {
|
|
1090
|
+
var timeout = _arguments4.length > 2 && _arguments4[2] !== undefined ? _arguments4[2] : TableUtils.APPLY_TABLE_CHANGE_TIMEOUT_MS;
|
|
1091
|
+
var {
|
|
1092
|
+
dh
|
|
1093
|
+
} = _this4;
|
|
1094
|
+
return TableUtils.executeAndWaitForEvent(t => t === null || t === void 0 ? void 0 : t.applySort(sorts), table, dh.Table.EVENT_SORTCHANGED, timeout);
|
|
1095
|
+
})();
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Create a filter condition that results in zero results for a given column
|
|
1100
|
+
* @param column
|
|
1101
|
+
*/
|
|
1102
|
+
makeNeverFilter(column) {
|
|
1103
|
+
var {
|
|
1104
|
+
dh
|
|
1105
|
+
} = this;
|
|
1106
|
+
var value = null;
|
|
1107
|
+
if (TableUtils.isTextType(column.type)) {
|
|
1108
|
+
// Use 'a' so that it can work for String or Character types
|
|
1109
|
+
value = dh.FilterValue.ofString('a');
|
|
1110
|
+
} else if (TableUtils.isBooleanType(column.type)) {
|
|
1111
|
+
value = dh.FilterValue.ofBoolean(true);
|
|
1112
|
+
} else if (TableUtils.isDateType(column.type)) {
|
|
1113
|
+
value = dh.FilterValue.ofNumber(dh.DateWrapper.ofJsDate(new Date()));
|
|
1114
|
+
} else {
|
|
1115
|
+
value = dh.FilterValue.ofNumber(0);
|
|
1116
|
+
}
|
|
1117
|
+
var eqFilter = column.filter().eq(value);
|
|
1118
|
+
var notEqFilter = column.filter().notEq(value);
|
|
1119
|
+
return eqFilter.and(notEqFilter);
|
|
840
1120
|
}
|
|
841
1121
|
|
|
842
1122
|
/**
|
|
@@ -844,7 +1124,10 @@ export class TableUtils {
|
|
|
844
1124
|
* @param value The value to make the filter value from.
|
|
845
1125
|
* @returns The FilterValue item for this column/value combination
|
|
846
1126
|
*/
|
|
847
|
-
|
|
1127
|
+
makeFilterValue(columnType, value) {
|
|
1128
|
+
var {
|
|
1129
|
+
dh
|
|
1130
|
+
} = this;
|
|
848
1131
|
var type = TableUtils.getBaseType(columnType);
|
|
849
1132
|
if (TableUtils.isTextType(type)) {
|
|
850
1133
|
return dh.FilterValue.ofString(value);
|
|
@@ -862,7 +1145,10 @@ export class TableUtils {
|
|
|
862
1145
|
* @param value The value to actually set
|
|
863
1146
|
* @returns The FilterValue item for this column/value combination
|
|
864
1147
|
*/
|
|
865
|
-
|
|
1148
|
+
makeFilterRawValue(columnType, rawValue) {
|
|
1149
|
+
var {
|
|
1150
|
+
dh
|
|
1151
|
+
} = this;
|
|
866
1152
|
if (TableUtils.isTextType(columnType)) {
|
|
867
1153
|
return dh.FilterValue.ofString(rawValue);
|
|
868
1154
|
}
|
|
@@ -878,7 +1164,10 @@ export class TableUtils {
|
|
|
878
1164
|
* @param text The string value to make a type for
|
|
879
1165
|
* @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York
|
|
880
1166
|
*/
|
|
881
|
-
|
|
1167
|
+
makeValue(columnType, text, timeZone) {
|
|
1168
|
+
var {
|
|
1169
|
+
dh
|
|
1170
|
+
} = this;
|
|
882
1171
|
if (text === 'null') {
|
|
883
1172
|
return null;
|
|
884
1173
|
}
|
|
@@ -892,7 +1181,7 @@ export class TableUtils {
|
|
|
892
1181
|
return TableUtils.makeBooleanValue(text, true);
|
|
893
1182
|
}
|
|
894
1183
|
if (TableUtils.isDateType(columnType)) {
|
|
895
|
-
var [date] = DateUtils.parseDateRange(text, timeZone);
|
|
1184
|
+
var [date] = DateUtils.parseDateRange(dh, text, timeZone);
|
|
896
1185
|
return date;
|
|
897
1186
|
}
|
|
898
1187
|
if (TableUtils.isNumberType(columnType)) {
|
|
@@ -901,124 +1190,6 @@ export class TableUtils {
|
|
|
901
1190
|
log.error('Unexpected column type', columnType);
|
|
902
1191
|
return null;
|
|
903
1192
|
}
|
|
904
|
-
static makeBooleanValue(text) {
|
|
905
|
-
var allowEmpty = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
906
|
-
if (text === '' && allowEmpty) {
|
|
907
|
-
return null;
|
|
908
|
-
}
|
|
909
|
-
switch (text === null || text === void 0 ? void 0 : text.toLowerCase()) {
|
|
910
|
-
case 'null':
|
|
911
|
-
return null;
|
|
912
|
-
case '0':
|
|
913
|
-
case 'f':
|
|
914
|
-
case 'fa':
|
|
915
|
-
case 'fal':
|
|
916
|
-
case 'fals':
|
|
917
|
-
case 'false':
|
|
918
|
-
case 'n':
|
|
919
|
-
case 'no':
|
|
920
|
-
return false;
|
|
921
|
-
case '1':
|
|
922
|
-
case 't':
|
|
923
|
-
case 'tr':
|
|
924
|
-
case 'tru':
|
|
925
|
-
case 'true':
|
|
926
|
-
case 'y':
|
|
927
|
-
case 'ye':
|
|
928
|
-
case 'yes':
|
|
929
|
-
return true;
|
|
930
|
-
default:
|
|
931
|
-
throw new Error("Invalid boolean '".concat(text, "'"));
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
static makeNumberValue(text) {
|
|
935
|
-
if (text === 'null' || text === '') {
|
|
936
|
-
return null;
|
|
937
|
-
}
|
|
938
|
-
var cleanText = text.toLowerCase().trim();
|
|
939
|
-
if (cleanText === '∞' || cleanText === 'infinity' || cleanText === 'inf') {
|
|
940
|
-
return Number.POSITIVE_INFINITY;
|
|
941
|
-
}
|
|
942
|
-
if (cleanText === '-∞' || cleanText === '-infinity' || cleanText === '-inf') {
|
|
943
|
-
return Number.NEGATIVE_INFINITY;
|
|
944
|
-
}
|
|
945
|
-
var numberText = TableUtils.removeCommas(cleanText);
|
|
946
|
-
if (TableUtils.NUMBER_REGEX.test(numberText)) {
|
|
947
|
-
return parseFloat(numberText);
|
|
948
|
-
}
|
|
949
|
-
throw new Error("Invalid number '".concat(text, "'"));
|
|
950
|
-
}
|
|
951
|
-
static getFilterOperatorString(operation) {
|
|
952
|
-
switch (operation) {
|
|
953
|
-
case FilterType.eq:
|
|
954
|
-
return '=';
|
|
955
|
-
case FilterType.notEq:
|
|
956
|
-
return '!=';
|
|
957
|
-
case FilterType.greaterThan:
|
|
958
|
-
return '>';
|
|
959
|
-
case FilterType.greaterThanOrEqualTo:
|
|
960
|
-
return '>=';
|
|
961
|
-
case FilterType.lessThan:
|
|
962
|
-
return '<';
|
|
963
|
-
case FilterType.lessThanOrEqualTo:
|
|
964
|
-
return '<=';
|
|
965
|
-
case FilterType.contains:
|
|
966
|
-
return '~';
|
|
967
|
-
case FilterType.notContains:
|
|
968
|
-
return '!~';
|
|
969
|
-
default:
|
|
970
|
-
throw new Error("Unexpected filter type ".concat(operation));
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
static makeAdvancedValueFilter(column, operation, value, timeZone) {
|
|
974
|
-
if (TableUtils.isDateType(column.type)) {
|
|
975
|
-
return TableUtils.makeQuickDateFilterWithOperation(column, value, operation, timeZone);
|
|
976
|
-
}
|
|
977
|
-
if (TableUtils.isNumberType(column.type) || TableUtils.isCharType(column.type)) {
|
|
978
|
-
return TableUtils.makeQuickFilter(column, "".concat(TableUtils.getFilterOperatorString(operation)).concat(value));
|
|
979
|
-
}
|
|
980
|
-
var filterValue = TableUtils.makeFilterValue(column.type, value);
|
|
981
|
-
var filter = column.filter();
|
|
982
|
-
switch (operation) {
|
|
983
|
-
case FilterType.eq:
|
|
984
|
-
return filter.eq(filterValue);
|
|
985
|
-
case FilterType.eqIgnoreCase:
|
|
986
|
-
return filter.eqIgnoreCase(filterValue);
|
|
987
|
-
case FilterType.notEq:
|
|
988
|
-
return filter.notEq(filterValue);
|
|
989
|
-
case FilterType.notEqIgnoreCase:
|
|
990
|
-
return filter.notEqIgnoreCase(filterValue);
|
|
991
|
-
case FilterType.greaterThan:
|
|
992
|
-
return filter.greaterThan(filterValue);
|
|
993
|
-
case FilterType.greaterThanOrEqualTo:
|
|
994
|
-
return filter.greaterThanOrEqualTo(filterValue);
|
|
995
|
-
case FilterType.lessThan:
|
|
996
|
-
return filter.lessThan(filterValue);
|
|
997
|
-
case FilterType.lessThanOrEqualTo:
|
|
998
|
-
return filter.lessThanOrEqualTo(filterValue);
|
|
999
|
-
case FilterType.isTrue:
|
|
1000
|
-
return filter.isTrue();
|
|
1001
|
-
case FilterType.isFalse:
|
|
1002
|
-
return filter.isFalse();
|
|
1003
|
-
case FilterType.isNull:
|
|
1004
|
-
return filter.isNull();
|
|
1005
|
-
case FilterType.contains:
|
|
1006
|
-
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))));
|
|
1007
|
-
case FilterType.notContains:
|
|
1008
|
-
return filter.isNull().or(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E.*"))).not());
|
|
1009
|
-
case FilterType.startsWith:
|
|
1010
|
-
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i)^\\Q".concat(value, "\\E.*"))));
|
|
1011
|
-
case FilterType.endsWith:
|
|
1012
|
-
return filter.isNull().not().and(filter.invoke('matches', dh.FilterValue.ofString("(?s)(?i).*\\Q".concat(value, "\\E$"))));
|
|
1013
|
-
case FilterType.in:
|
|
1014
|
-
case FilterType.inIgnoreCase:
|
|
1015
|
-
case FilterType.notIn:
|
|
1016
|
-
case FilterType.notInIgnoreCase:
|
|
1017
|
-
case FilterType.invoke:
|
|
1018
|
-
default:
|
|
1019
|
-
throw new Error("Unexpected filter operation: ".concat(operation));
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
1193
|
|
|
1023
1194
|
/**
|
|
1024
1195
|
* Create a filter using the selected items
|
|
@@ -1029,7 +1200,10 @@ export class TableUtils {
|
|
|
1029
1200
|
* @param invertSelection Invert the selection (eg. All items are selected, then you deselect items)
|
|
1030
1201
|
* @returns Returns a `in` or `notIn` FilterCondition as necessary, or null if no filtering should be applied (everything selected)
|
|
1031
1202
|
*/
|
|
1032
|
-
|
|
1203
|
+
makeSelectValueFilter(column, selectedValues, invertSelection) {
|
|
1204
|
+
var {
|
|
1205
|
+
dh
|
|
1206
|
+
} = this;
|
|
1033
1207
|
if (selectedValues.length === 0) {
|
|
1034
1208
|
if (invertSelection) {
|
|
1035
1209
|
// No filter means select everything
|
|
@@ -1039,33 +1213,20 @@ export class TableUtils {
|
|
|
1039
1213
|
// KLUDGE: Return a conflicting filter to show no results.
|
|
1040
1214
|
// Could recognize this situation at a higher or lower level and pause updates on the
|
|
1041
1215
|
// table, but this situation should be rare and that wouldn't be much gains for some added complexity
|
|
1042
|
-
|
|
1043
|
-
if (TableUtils.isTextType(column.type)) {
|
|
1044
|
-
// Use 'a' so that it can work for String or Character types
|
|
1045
|
-
value = dh.FilterValue.ofString('a');
|
|
1046
|
-
} else if (TableUtils.isBooleanType(column.type)) {
|
|
1047
|
-
value = dh.FilterValue.ofBoolean(true);
|
|
1048
|
-
} else if (TableUtils.isDateType(column.type)) {
|
|
1049
|
-
value = dh.FilterValue.ofNumber(dh.DateWrapper.ofJsDate(new Date()));
|
|
1050
|
-
} else {
|
|
1051
|
-
value = dh.FilterValue.ofNumber(0);
|
|
1052
|
-
}
|
|
1053
|
-
var eqFilter = column.filter().eq(value);
|
|
1054
|
-
var notEqFilter = column.filter().notEq(value);
|
|
1055
|
-
return eqFilter.and(notEqFilter);
|
|
1216
|
+
return this.makeNeverFilter(column);
|
|
1056
1217
|
}
|
|
1057
1218
|
var values = [];
|
|
1058
1219
|
var isNullSelected = false;
|
|
1059
1220
|
for (var i = 0; i < selectedValues.length; i += 1) {
|
|
1060
|
-
var
|
|
1061
|
-
if (
|
|
1221
|
+
var value = selectedValues[i];
|
|
1222
|
+
if (value == null) {
|
|
1062
1223
|
isNullSelected = true;
|
|
1063
1224
|
} else if (TableUtils.isTextType(column.type)) {
|
|
1064
|
-
values.push(dh.FilterValue.ofString(typeof
|
|
1225
|
+
values.push(dh.FilterValue.ofString(typeof value === 'number' ? String.fromCharCode(value) : value));
|
|
1065
1226
|
} else if (TableUtils.isBooleanType(column.type)) {
|
|
1066
|
-
values.push(dh.FilterValue.ofBoolean(Boolean(
|
|
1227
|
+
values.push(dh.FilterValue.ofBoolean(Boolean(value)));
|
|
1067
1228
|
} else {
|
|
1068
|
-
values.push(dh.FilterValue.ofNumber(
|
|
1229
|
+
values.push(dh.FilterValue.ofNumber(value));
|
|
1069
1230
|
}
|
|
1070
1231
|
}
|
|
1071
1232
|
if (isNullSelected) {
|
|
@@ -1085,23 +1246,6 @@ export class TableUtils {
|
|
|
1085
1246
|
}
|
|
1086
1247
|
return column.filter().in(values);
|
|
1087
1248
|
}
|
|
1088
|
-
static isTreeTable(table) {
|
|
1089
|
-
return table != null && table.expand !== undefined && table.collapse !== undefined;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Copies the provided array, sorts by column name case insensitive, and returns the sorted array.
|
|
1094
|
-
* @param columns The columns to sort
|
|
1095
|
-
* @param isAscending Whether to sort ascending
|
|
1096
|
-
*/
|
|
1097
|
-
static sortColumns(columns) {
|
|
1098
|
-
var isAscending = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1099
|
-
return [...columns].sort((a, b) => {
|
|
1100
|
-
var aName = a.name.toUpperCase();
|
|
1101
|
-
var bName = b.name.toUpperCase();
|
|
1102
|
-
return TextUtils.sort(aName, bName, isAscending);
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
1249
|
}
|
|
1106
1250
|
_defineProperty(TableUtils, "dataType", {
|
|
1107
1251
|
BOOLEAN: 'boolean',
|
|
@@ -1118,11 +1262,27 @@ _defineProperty(TableUtils, "sortDirection", {
|
|
|
1118
1262
|
reverse: 'REVERSE',
|
|
1119
1263
|
none: null
|
|
1120
1264
|
});
|
|
1265
|
+
_defineProperty(TableUtils, "APPLY_TABLE_CHANGE_TIMEOUT_MS", 30000);
|
|
1121
1266
|
_defineProperty(TableUtils, "REVERSE_TYPE", Object.freeze({
|
|
1122
1267
|
NONE: 'none',
|
|
1123
1268
|
PRE_SORT: 'pre-sort',
|
|
1124
1269
|
POST_SORT: 'post-sort'
|
|
1125
1270
|
}));
|
|
1126
1271
|
_defineProperty(TableUtils, "NUMBER_REGEX", /^-?\d+(\.\d+)?$/);
|
|
1272
|
+
_defineProperty(TableUtils, "executeAndWaitForEvent", /*#__PURE__*/function () {
|
|
1273
|
+
var _ref2 = _asyncToGenerator(function* (exec, table, eventType) {
|
|
1274
|
+
var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : TableUtils.APPLY_TABLE_CHANGE_TIMEOUT_MS;
|
|
1275
|
+
if (table == null) {
|
|
1276
|
+
return null;
|
|
1277
|
+
}
|
|
1278
|
+
var eventPromise = TableUtils.makeCancelableTableEventPromise(table, eventType, timeout);
|
|
1279
|
+
exec(table);
|
|
1280
|
+
yield eventPromise;
|
|
1281
|
+
return table;
|
|
1282
|
+
});
|
|
1283
|
+
return function (_x, _x2, _x3) {
|
|
1284
|
+
return _ref2.apply(this, arguments);
|
|
1285
|
+
};
|
|
1286
|
+
}());
|
|
1127
1287
|
export default TableUtils;
|
|
1128
1288
|
//# sourceMappingURL=TableUtils.js.map
|