@michalrakus/x-react-web-lib 1.28.0 → 1.30.0

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.XAggregateType = exports.ResultType = void 0;
3
+ exports.XAggregateFunction = exports.ResultType = void 0;
4
4
  // TODO - replaced with DataTableFilterMetaData
5
5
  // export interface FilterValue {
6
6
  // value : string;
@@ -22,10 +22,10 @@ var ResultType;
22
22
  ResultType[ResultType["RowCountAndPagedRows"] = 2] = "RowCountAndPagedRows";
23
23
  ResultType[ResultType["AllRows"] = 3] = "AllRows";
24
24
  })(ResultType = exports.ResultType || (exports.ResultType = {}));
25
- var XAggregateType;
26
- (function (XAggregateType) {
27
- XAggregateType["Min"] = "MIN";
28
- XAggregateType["Max"] = "MAX";
29
- XAggregateType["Sum"] = "SUM";
30
- XAggregateType["Avg"] = "AVG";
31
- })(XAggregateType = exports.XAggregateType || (exports.XAggregateType = {}));
25
+ var XAggregateFunction;
26
+ (function (XAggregateFunction) {
27
+ XAggregateFunction["Min"] = "MIN";
28
+ XAggregateFunction["Max"] = "MAX";
29
+ XAggregateFunction["Sum"] = "SUM";
30
+ XAggregateFunction["Avg"] = "AVG";
31
+ })(XAggregateFunction = exports.XAggregateFunction || (exports.XAggregateFunction = {}));
@@ -1,4 +1,6 @@
1
1
  import { XEntity, XField } from "./XEntityMetadata";
2
+ import { XCustomFilter, XCustomFilterItem } from "./FindParam";
3
+ import { DataTableSortMeta } from "primereact/datatable";
2
4
  export declare class XUtilsCommon {
3
5
  static newLine: string;
4
6
  static getValueByPath(object: any, path: string): any;
@@ -15,6 +17,33 @@ export declare class XUtilsCommon {
15
17
  static displayValueAsUI(prefix: string | null, value: any, xField: XField | undefined): string;
16
18
  static objectAsJSON(value: any): string;
17
19
  static arrayCreateMap<ID, T>(array: T[], idField: string): Map<ID, T>;
20
+ static arrayMoveElement(array: any[], position: number, offset: number): void;
21
+ static arraySort(array: any[], fieldOrValueFunction: string | ((item: any) => any)): any[];
22
+ /**
23
+ * returns true, if param item is member of the array
24
+ * remark: null/undefined items in array are ignored, item = null/undefined is ignored
25
+ *
26
+ * @param array
27
+ * @param item
28
+ * @param idField
29
+ */
30
+ static arrayIncludes<T>(array: T[], item: T, idField: string): boolean;
31
+ /**
32
+ * returns intersection of 2 row lists
33
+ * remark: null/undefined items in both array1 and array2 are ignored
34
+ *
35
+ * @param array1
36
+ * @param array2
37
+ * @param idField
38
+ */
39
+ static arrayIntersect<T>(array1: T[], array2: T[], idField: string): T[];
40
+ static createCustomFilter(filter: string | undefined | null): XCustomFilterItem | undefined;
41
+ static createCustomFilterItems(customFilter: XCustomFilter | undefined): XCustomFilterItem[] | undefined;
42
+ static createMultiSortMeta(sortField: string | DataTableSortMeta[] | undefined): DataTableSortMeta[] | undefined;
43
+ static filterAnd(...filters: (XCustomFilter | undefined)[]): XCustomFilterItem[] | undefined;
44
+ static filterIdIn(idField: string, idList: number[]): XCustomFilter;
45
+ static createPathFieldExp(pathFieldOrPathFieldExp: string): string;
46
+ static isPathField(pathFieldOrPathFieldExp: string): boolean;
18
47
  static getDayName(date: Date | null | undefined): string | undefined;
19
48
  static dateAddDays(date: Date | null, days: number): Date | null;
20
49
  static dateAddMonths(date: Date | null, months: number): Date | null;
@@ -292,6 +292,171 @@ var XUtilsCommon = /** @class */ (function () {
292
292
  }
293
293
  return idRowMap;
294
294
  };
295
+ XUtilsCommon.arrayMoveElement = function (array, position, offset) {
296
+ var element = array[position];
297
+ array.splice(position, 1);
298
+ var positionNew = position + offset;
299
+ if (positionNew > array.length) {
300
+ positionNew = positionNew - array.length - 1; // element goes to the begin
301
+ }
302
+ else if (positionNew < 0) {
303
+ positionNew = array.length + positionNew + 1; // element goes to the end
304
+ }
305
+ if (positionNew >= 0 && positionNew <= array.length) {
306
+ array.splice(positionNew, 0, element);
307
+ }
308
+ };
309
+ XUtilsCommon.arraySort = function (array, fieldOrValueFunction) {
310
+ var valueFunction;
311
+ if (typeof fieldOrValueFunction === 'string') {
312
+ valueFunction = function (item) { return item[fieldOrValueFunction]; };
313
+ }
314
+ else {
315
+ valueFunction = fieldOrValueFunction;
316
+ }
317
+ return array.sort(function (suggestion1, suggestion2) {
318
+ var value1 = valueFunction(suggestion1);
319
+ var value2 = valueFunction(suggestion2);
320
+ if (value1 > value2) {
321
+ return 1;
322
+ }
323
+ else if (value1 < value2) {
324
+ return -1;
325
+ }
326
+ else {
327
+ return 0;
328
+ }
329
+ });
330
+ };
331
+ /**
332
+ * returns true, if param item is member of the array
333
+ * remark: null/undefined items in array are ignored, item = null/undefined is ignored
334
+ *
335
+ * @param array
336
+ * @param item
337
+ * @param idField
338
+ */
339
+ XUtilsCommon.arrayIncludes = function (array, item, idField) {
340
+ return item && array.some(function (arrayItem) { return arrayItem && arrayItem[idField] === item[idField]; });
341
+ };
342
+ /**
343
+ * returns intersection of 2 row lists
344
+ * remark: null/undefined items in both array1 and array2 are ignored
345
+ *
346
+ * @param array1
347
+ * @param array2
348
+ * @param idField
349
+ */
350
+ XUtilsCommon.arrayIntersect = function (array1, array2, idField) {
351
+ var e_5, _a;
352
+ var array2IdSet = new Set();
353
+ try {
354
+ for (var array2_1 = __values(array2), array2_1_1 = array2_1.next(); !array2_1_1.done; array2_1_1 = array2_1.next()) {
355
+ var item = array2_1_1.value;
356
+ if (item) {
357
+ array2IdSet.add(item[idField]);
358
+ }
359
+ }
360
+ }
361
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
362
+ finally {
363
+ try {
364
+ if (array2_1_1 && !array2_1_1.done && (_a = array2_1.return)) _a.call(array2_1);
365
+ }
366
+ finally { if (e_5) throw e_5.error; }
367
+ }
368
+ return array1.filter(function (item) { return item && array2IdSet.has(item[idField]); });
369
+ };
370
+ // ************* XCustomFilter/XCustomFilterItem/DataTableSortMeta **************
371
+ // pomocna metodka - aby sme nemuseli v kode vypisovat {where: <filter>, params: {}}
372
+ XUtilsCommon.createCustomFilter = function (filter) {
373
+ var customFilterItem = undefined;
374
+ if (filter) {
375
+ customFilterItem = { where: filter, params: {} };
376
+ }
377
+ return customFilterItem;
378
+ };
379
+ // pomocna metodka - konvertuje XCustomFilter -> XCustomFilterItem[]
380
+ XUtilsCommon.createCustomFilterItems = function (customFilter) {
381
+ var customFilterItems = undefined;
382
+ if (customFilter) {
383
+ if (Array.isArray(customFilter)) {
384
+ customFilterItems = customFilter;
385
+ }
386
+ else {
387
+ customFilterItems = [customFilter];
388
+ }
389
+ }
390
+ return customFilterItems;
391
+ };
392
+ // pomocna metodka - konvertuje sortField -> DataTableSortMeta[]
393
+ XUtilsCommon.createMultiSortMeta = function (sortField) {
394
+ var multiSortMeta = undefined;
395
+ if (sortField) {
396
+ if (Array.isArray(sortField)) {
397
+ multiSortMeta = sortField;
398
+ }
399
+ else {
400
+ // default order is asc, supported is also value in form "<column name> desc"
401
+ var order = 1;
402
+ var fieldAndOrder = sortField.split(' ');
403
+ if (fieldAndOrder.length === 2) {
404
+ sortField = fieldAndOrder[0];
405
+ if (fieldAndOrder[1].toLowerCase() === "desc") {
406
+ order = -1;
407
+ }
408
+ }
409
+ multiSortMeta = [{ field: sortField, order: order }];
410
+ }
411
+ }
412
+ return multiSortMeta;
413
+ };
414
+ // pomocna metodka
415
+ XUtilsCommon.filterAnd = function () {
416
+ var e_6, _a;
417
+ var filters = [];
418
+ for (var _i = 0; _i < arguments.length; _i++) {
419
+ filters[_i] = arguments[_i];
420
+ }
421
+ var customFilterItemsResult = undefined;
422
+ if (filters.length > 0) {
423
+ customFilterItemsResult = [];
424
+ try {
425
+ for (var filters_1 = __values(filters), filters_1_1 = filters_1.next(); !filters_1_1.done; filters_1_1 = filters_1.next()) {
426
+ var filter = filters_1_1.value;
427
+ var customFilterItems = XUtilsCommon.createCustomFilterItems(filter);
428
+ if (customFilterItems) {
429
+ customFilterItemsResult.push.apply(customFilterItemsResult, __spreadArray([], __read(customFilterItems), false));
430
+ }
431
+ }
432
+ }
433
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
434
+ finally {
435
+ try {
436
+ if (filters_1_1 && !filters_1_1.done && (_a = filters_1.return)) _a.call(filters_1);
437
+ }
438
+ finally { if (e_6) throw e_6.error; }
439
+ }
440
+ }
441
+ return customFilterItemsResult;
442
+ };
443
+ // pomocna metodka
444
+ // ak je idList prazdny, vytvori podmienku id IN (0) a nevrati ziadne zaznamy
445
+ XUtilsCommon.filterIdIn = function (idField, idList) {
446
+ return { where: "[".concat(idField, "] IN (:...idList)"), params: { "idList": idList.length > 0 ? idList : [0] } };
447
+ };
448
+ // helper
449
+ XUtilsCommon.createPathFieldExp = function (pathFieldOrPathFieldExp) {
450
+ // if fieldOrPathFieldExp is only pathField (e.g. attrX or assocA.attrB) then make path field expression (enclose field into [])
451
+ if (XUtilsCommon.isPathField(pathFieldOrPathFieldExp)) {
452
+ pathFieldOrPathFieldExp = "[".concat(pathFieldOrPathFieldExp, "]");
453
+ }
454
+ return pathFieldOrPathFieldExp;
455
+ };
456
+ // helper
457
+ XUtilsCommon.isPathField = function (pathFieldOrPathFieldExp) {
458
+ return /^[a-zA-Z0-9_.]+$/.test(pathFieldOrPathFieldExp);
459
+ };
295
460
  XUtilsCommon.getDayName = function (date) {
296
461
  var days = ['nedeľa', 'pondelok', 'utorok', 'streda', 'štvrtok', 'piatok', 'sobota'];
297
462
  return date ? days[date.getDay()] : undefined;
@@ -471,6 +471,12 @@ function convertValueBase(fieldType, scale, value, fromModel, asUI) {
471
471
  value = booleanAsUIText(value);
472
472
  }
473
473
  }
474
+ else if (fieldType === "jsonb") {
475
+ // konverziu z modelu (json objekt-u) netreba
476
+ if (asUI) {
477
+ value = XUtilsCommon_1.XUtilsCommon.objectAsJSON(value);
478
+ }
479
+ }
474
480
  else {
475
481
  // vsetko ostatne
476
482
  if (asUI && asUI !== AsUIType.Excel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",