@michalrakus/x-react-web-lib 1.2.0 → 1.4.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.
Files changed (39) hide show
  1. package/XCalendar.d.ts +3 -0
  2. package/XCalendar.js +5 -0
  3. package/XDropdownForEntity.d.ts +3 -0
  4. package/XDropdownForEntity.js +5 -0
  5. package/XInputDecimalBase.d.ts +3 -0
  6. package/XInputDecimalBase.js +5 -0
  7. package/gulpfile.js +4 -1
  8. package/lib/components/XAutoCompleteBase.d.ts +1 -0
  9. package/lib/components/XAutoCompleteBase.js +6 -4
  10. package/lib/components/XAutoCompleteDT.js +1 -2
  11. package/lib/components/XCalendar.d.ts +8 -0
  12. package/lib/components/XCalendar.js +27 -0
  13. package/lib/components/XDropdown.d.ts +2 -7
  14. package/lib/components/XDropdown.js +8 -88
  15. package/lib/components/XDropdownDTFilter.js +8 -7
  16. package/lib/components/XDropdownForEntity.d.ts +24 -0
  17. package/lib/components/XDropdownForEntity.js +148 -0
  18. package/lib/components/XExportRowsDialog.js +2 -2
  19. package/lib/components/XFieldSelector.js +4 -3
  20. package/lib/components/XFormBase.d.ts +2 -0
  21. package/lib/components/XFormBase.js +10 -0
  22. package/lib/components/XFormComponent.d.ts +5 -1
  23. package/lib/components/XFormComponent.js +31 -3
  24. package/lib/components/XFormComponentDT.js +28 -2
  25. package/lib/components/XFormDataTable2.d.ts +2 -1
  26. package/lib/components/XFormDataTable2.js +45 -12
  27. package/lib/components/XInputDate.d.ts +12 -8
  28. package/lib/components/XInputDate.js +49 -44
  29. package/lib/components/XInputDecimalBase.d.ts +12 -0
  30. package/lib/components/XInputDecimalBase.js +18 -0
  31. package/lib/components/XLazyDataTable.d.ts +10 -1
  32. package/lib/components/XLazyDataTable.js +136 -52
  33. package/lib/components/XUtilsMetadata.d.ts +6 -2
  34. package/lib/components/XUtilsMetadata.js +79 -18
  35. package/lib/serverApi/ExportImportParam.d.ts +2 -0
  36. package/lib/serverApi/XEntityMetadata.d.ts +3 -2
  37. package/lib/serverApi/XUtilsCommon.d.ts +1 -0
  38. package/lib/serverApi/XUtilsCommon.js +9 -0
  39. package/package.json +1 -1
@@ -112,6 +112,8 @@ var tristatecheckbox_1 = require("primereact/tristatecheckbox");
112
112
  var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
113
113
  var XExportRowsDialog_1 = require("./XExportRowsDialog");
114
114
  var api_1 = require("primereact/api");
115
+ var XCalendar_1 = require("./XCalendar");
116
+ var XInputDecimalBase_1 = require("./XInputDecimalBase");
115
117
  var XLazyDataTable = function (props) {
116
118
  // must be here, is used in createInitFilters()
117
119
  var xEntity = XUtilsMetadata_1.XUtilsMetadata.getXEntity(props.entity);
@@ -438,7 +440,7 @@ var XLazyDataTable = function (props) {
438
440
  if (csvParam && csvParam.useHeaderLine) {
439
441
  csvParam.headers = getHeaders();
440
442
  }
441
- exportParam = { exportType: exportType, filters: filtersAfterFiltering, multiSortMeta: multiSortMeta, entity: props.entity, fields: getFields(), csvParam: csvParam };
443
+ exportParam = { exportType: exportType, filters: filtersAfterFiltering, customFilter: customFilter, multiSortMeta: multiSortMeta, entity: props.entity, fields: getFields(), csvParam: csvParam };
442
444
  _a.label = 1;
443
445
  case 1:
444
446
  _a.trys.push([1, 3, , 4]);
@@ -476,58 +478,90 @@ var XLazyDataTable = function (props) {
476
478
  console.log("Nie je vyselectovany ziaden zaznam.");
477
479
  }
478
480
  };
479
- // ****** checkbox vo filtri ********
481
+ // ****** dropdown vo filtri ********
480
482
  // pouziva sa len pre simple filtrovanie (filterDisplay="row")
481
- var onCheckboxFilterChange = function (field, checkboxValue) {
482
- // TODO - treba vyklonovat?
483
+ var onDropdownFilterChange = function (field, displayValue) {
484
+ var filterValue = displayValue !== XUtils_1.XUtils.dropdownEmptyOptionValue ? displayValue : null;
485
+ setFilterValue(field, filterValue, api_1.FilterMatchMode.EQUALS);
486
+ };
487
+ var getDropdownFilterValue = function (field) {
488
+ var filterValue = getFilterValue(field);
489
+ return filterValue !== null ? filterValue : XUtils_1.XUtils.dropdownEmptyOptionValue;
490
+ };
491
+ // ****** vseobecne metodky pre set/get do/z filtra ********
492
+ // zatial funguje len pre simple filtrovanie (filterDisplay="row")
493
+ // vseobecna specialna metodka pouzvana pri custom filtri (XLazyColumn.filterElement)
494
+ var setFilterItem = function (field, filterItem) {
495
+ filters[field] = filterItem;
496
+ // neskusal som, ci treba aj toto klonovat ale pravdepodobne hej
483
497
  var filtersCloned = __assign({}, filters);
484
- if (checkboxValue !== null) {
485
- filtersCloned[field] = { value: checkboxValue ? "1" : "0", matchMode: api_1.FilterMatchMode.EQUALS };
486
- }
487
- else {
488
- // pouzivatel zrusil hodnotu vo filtri (vybral prazdny stav v checkboxe), zrusime polozku z filtra
489
- //delete filtersCloned[field];
490
- filtersCloned[field] = { value: null, matchMode: api_1.FilterMatchMode.EQUALS };
491
- }
492
498
  setFilters(filtersCloned);
493
499
  };
494
- var getCheckboxFilterValue = function (field) {
495
- var checkboxValue = null;
496
- var filterValue = filters[field];
497
- if (filterValue !== undefined && filterValue !== null) {
498
- if (filterValue.value === '1') {
499
- checkboxValue = true;
500
- }
501
- else if (filterValue.value === '0') {
502
- checkboxValue = false;
503
- }
500
+ // vseobecna metodka - nastavi hodnotu do filtra
501
+ // ak je matchMode === undefined, tak zachova povodnu hodnotu matchMode
502
+ var setFilterValue = function (field, value, matchMode) {
503
+ var filterValue = filters[field]; // funguje len pre filterDisplay="row"
504
+ filterValue.value = value;
505
+ if (matchMode !== undefined) {
506
+ filterValue.matchMode = matchMode;
507
+ }
508
+ // treba klonovat, inac react nezobrazi zmenenu hodnotu
509
+ var filtersCloned = __assign({}, filters);
510
+ setFilters(filtersCloned);
511
+ };
512
+ // vseobecna metodka - precita hodnotu z filtra (vrati napr. typ Date | null)
513
+ var getFilterValue = function (field) {
514
+ var filterValue = filters[field]; // funguje len pre filterDisplay="row"
515
+ return filterValue.value;
516
+ };
517
+ // ****** vseobecne metodky pre set/get do/z filtra - pre betweenFilter ********
518
+ // do DataTableFilterMetaData.value ulozime dvojprvkove pole [value1, value2]
519
+ // na backende spracujeme toto dvojprvkove pole
520
+ var setFilterValue1 = function (field, value) {
521
+ // na zaciatku (po inicializacii lazy table) je filterValue = null
522
+ var filterValue = getFilterValue(field);
523
+ if (filterValue !== null) {
524
+ filterValue[0] = value;
525
+ }
526
+ else {
527
+ filterValue = [value, null];
504
528
  }
505
- return checkboxValue;
529
+ setFilterValue(field, filterValue, api_1.FilterMatchMode.BETWEEN);
506
530
  };
507
- // ****** dropdown vo filtri ********
508
- // pouziva sa len pre simple filtrovanie (filterDisplay="row")
509
- var onDropdownFilterChange = function (field, displayValue) {
510
- // TODO - treba vyklonovat?
511
- var filtersCloned = __assign({}, filters);
512
- if (displayValue !== XUtils_1.XUtils.dropdownEmptyOptionValue) {
513
- filtersCloned[field] = { value: displayValue, matchMode: api_1.FilterMatchMode.EQUALS };
531
+ var setFilterValue2 = function (field, value) {
532
+ // na zaciatku (po inicializacii lazy table) je filterValue = null
533
+ var filterValue = getFilterValue(field);
534
+ if (filterValue !== null) {
535
+ filterValue[1] = value;
514
536
  }
515
537
  else {
516
- // pouzivatel zrusil hodnotu vo filtri (vybral prazdny riadok), zrusime polozku z filtra
517
- //delete filtersCloned[field];
518
- filtersCloned[field] = { value: null, matchMode: api_1.FilterMatchMode.EQUALS };
538
+ filterValue = [null, value];
519
539
  }
520
- setFilters(filtersCloned);
540
+ setFilterValue(field, filterValue, api_1.FilterMatchMode.BETWEEN);
521
541
  };
522
- var getDropdownFilterValue = function (field) {
523
- var dropdownValue = XUtils_1.XUtils.dropdownEmptyOptionValue;
524
- var filterValue = filters[field];
525
- if (filterValue !== undefined && filterValue !== null) {
526
- if (filterValue.value !== null) {
527
- dropdownValue = filterValue.value;
542
+ var getFilterValue1 = function (field) {
543
+ return getFilterValue1or2(field, 0);
544
+ };
545
+ var getFilterValue2 = function (field) {
546
+ return getFilterValue1or2(field, 1);
547
+ };
548
+ var getFilterValue1or2 = function (field, index) {
549
+ var filterValue = getFilterValue(field);
550
+ return filterValue !== null ? filterValue[index] : null;
551
+ };
552
+ var getBetweenFilter = function (columnBetweenFilter, tableBetweenFilter) {
553
+ var betweenFilter = undefined;
554
+ // columnBetweenFilter has higher prio than tableBetweenFilter
555
+ if (columnBetweenFilter !== undefined) {
556
+ if (columnBetweenFilter === "row" || columnBetweenFilter === "column") {
557
+ betweenFilter = columnBetweenFilter;
528
558
  }
559
+ // for "noBetween" stays betweenFilter = undefined (simple filter used)
560
+ }
561
+ else {
562
+ betweenFilter = tableBetweenFilter; // betweenFilter from XLazyDataTable property
529
563
  }
530
- return dropdownValue;
564
+ return betweenFilter;
531
565
  };
532
566
  var bodyTemplate = function (columnProps, rowData, xField) {
533
567
  var rowDataValue = XUtilsCommon_1.XUtilsCommon.getValueByPath(rowData, columnProps.field);
@@ -684,14 +718,61 @@ var XLazyDataTable = function (props) {
684
718
  header = headerLabel;
685
719
  }
686
720
  // *********** filterElement ***********
721
+ var betweenFilter = undefined;
687
722
  var filterElement;
688
- if (xField.type === "boolean") {
689
- var checkboxValue = getCheckboxFilterValue(childColumn.props.field);
690
- filterElement = react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, { value: checkboxValue, onChange: function (e) { return onCheckboxFilterChange(childColumn.props.field, e.value); } });
723
+ if (childColumn.props.filterElement !== undefined) {
724
+ filterElement = function (options) {
725
+ // compilator sa stazoval ze childColumn.props.filterElement muze byt undefined, preto som pridal "!"
726
+ return childColumn.props.filterElement(setFilterItem, options);
727
+ };
691
728
  }
692
- else if (childColumn.props.dropdownInFilter) {
693
- var dropdownValue = getDropdownFilterValue(childColumn.props.field);
694
- filterElement = react_1.default.createElement(XDropdownDTFilter_1.XDropdownDTFilter, { entity: props.entity, path: childColumn.props.field, value: dropdownValue, onValueChange: onDropdownFilterChange });
729
+ else {
730
+ if (xField.type === "boolean") {
731
+ var checkboxValue = getFilterValue(childColumn.props.field);
732
+ filterElement = react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, { value: checkboxValue, onChange: function (e) { return setFilterValue(childColumn.props.field, e.value, api_1.FilterMatchMode.EQUALS); } });
733
+ }
734
+ else if (childColumn.props.dropdownInFilter) {
735
+ var dropdownValue = getDropdownFilterValue(childColumn.props.field);
736
+ filterElement = react_1.default.createElement(XDropdownDTFilter_1.XDropdownDTFilter, { entity: props.entity, path: childColumn.props.field, value: dropdownValue, onValueChange: onDropdownFilterChange });
737
+ }
738
+ else if (xField.type === "date" || xField.type === "datetime") {
739
+ betweenFilter = getBetweenFilter(childColumn.props.betweenFilter, props.betweenFilter);
740
+ if (betweenFilter !== undefined) {
741
+ // display: 'flex' umiestni XCalendar elementy vedla seba
742
+ filterElement =
743
+ react_1.default.createElement("div", { style: betweenFilter === "row" ? { display: 'flex' } : undefined },
744
+ react_1.default.createElement(XCalendar_1.XCalendar, { value: getFilterValue1(childColumn.props.field), onChange: function (value) { return setFilterValue1(childColumn.props.field, value); }, datetime: xField.type === "datetime" }),
745
+ react_1.default.createElement(XCalendar_1.XCalendar, { value: getFilterValue2(childColumn.props.field), onChange: function (value) { return setFilterValue2(childColumn.props.field, value); }, datetime: xField.type === "datetime" }));
746
+ }
747
+ else {
748
+ var dateValue = getFilterValue(childColumn.props.field);
749
+ filterElement = react_1.default.createElement(XCalendar_1.XCalendar, { value: dateValue, onChange: function (value) { return setFilterValue(childColumn.props.field, value); }, datetime: xField.type === "datetime" });
750
+ }
751
+ }
752
+ else if (xField.type === "decimal" || xField.type === "number") {
753
+ var params = XUtilsMetadata_1.XUtilsMetadata.getParamsForInputNumber(xField);
754
+ betweenFilter = getBetweenFilter(childColumn.props.betweenFilter, props.betweenFilter);
755
+ if (betweenFilter !== undefined) {
756
+ // display: 'flex' umiestni input elementy pod seba (betweenFilter = "column") resp. vedla seba (betweenFilter = "row")
757
+ filterElement =
758
+ react_1.default.createElement("div", { style: { display: 'flex', flexDirection: betweenFilter } },
759
+ react_1.default.createElement(XInputDecimalBase_1.XInputDecimalBase, __assign({ value: getFilterValue1(childColumn.props.field), onChange: function (value) { return setFilterValue1(childColumn.props.field, value); } }, params)),
760
+ react_1.default.createElement(XInputDecimalBase_1.XInputDecimalBase, __assign({ value: getFilterValue2(childColumn.props.field), onChange: function (value) { return setFilterValue2(childColumn.props.field, value); } }, params)));
761
+ }
762
+ else {
763
+ var numberValue = getFilterValue(childColumn.props.field);
764
+ filterElement = react_1.default.createElement(XInputDecimalBase_1.XInputDecimalBase, __assign({ value: numberValue, onChange: function (value) { return setFilterValue(childColumn.props.field, value); } }, params));
765
+ }
766
+ }
767
+ }
768
+ // ************** dataType **************
769
+ // depending on the dataType of the column, suitable match modes are displayed in filter
770
+ var dataType = undefined;
771
+ if (xField.type === "decimal" || xField.type === "number") {
772
+ dataType = "numeric";
773
+ }
774
+ else if (xField.type === "date" || xField.type === "datetime") {
775
+ dataType = "date";
695
776
  }
696
777
  // *********** showFilterMenu ***********
697
778
  var showFilterMenu;
@@ -701,7 +782,7 @@ var XLazyDataTable = function (props) {
701
782
  else {
702
783
  showFilterMenu = true; // default
703
784
  if (props.filterDisplay === "row") {
704
- if (xField.type === "boolean" || childColumn.props.dropdownInFilter) {
785
+ if (xField.type === "boolean" || childColumn.props.dropdownInFilter || betweenFilter !== undefined) {
705
786
  showFilterMenu = false;
706
787
  }
707
788
  }
@@ -710,9 +791,12 @@ var XLazyDataTable = function (props) {
710
791
  // pre filterDisplay = "row" nechceme clear button, chceme setrit miesto
711
792
  var showClearButton = props.filterDisplay === "menu";
712
793
  // *********** body ***********
713
- // TODO - mozno by bolo dobre vytvarat body pre kazdy field, nech je to vsetko konzistentne
714
794
  var body;
715
- if (xField.type === "decimal" || xField.type === "date" || xField.type === "datetime" || xField.type === "boolean") {
795
+ if (childColumn.props.body !== undefined) {
796
+ body = childColumn.props.body;
797
+ }
798
+ // TODO - mozno by bolo dobre vytvarat body pre kazdy typ fieldu, nech je to vsetko konzistentne
799
+ else if (xField.type === "decimal" || xField.type === "date" || xField.type === "datetime" || xField.type === "boolean") {
716
800
  body = function (rowData) { return bodyTemplate(childColumn.props, rowData, xField); };
717
801
  }
718
802
  // *********** width/headerStyle ***********
@@ -721,7 +805,7 @@ var XLazyDataTable = function (props) {
721
805
  // TODO - if filter not used at all, then buttons flags should be false
722
806
  var filterMenuInFilterRow = props.filterDisplay === "row" && showFilterMenu;
723
807
  var filterButtonInHeader = props.filterDisplay === "menu";
724
- width = XUtilsMetadata_1.XUtilsMetadata.computeColumnWidth(xField, filterMenuInFilterRow, undefined, headerLabel, true, filterButtonInHeader);
808
+ width = XUtilsMetadata_1.XUtilsMetadata.computeColumnWidth(xField, betweenFilter, filterMenuInFilterRow, undefined, headerLabel, true, filterButtonInHeader);
725
809
  }
726
810
  var headerStyle = {};
727
811
  if (width !== undefined) {
@@ -741,7 +825,7 @@ var XLazyDataTable = function (props) {
741
825
  align = "center";
742
826
  }
743
827
  }
744
- return react_1.default.createElement(column_1.Column, { field: childColumn.props.field, header: header, filter: true, sortable: true, filterElement: filterElement, showFilterMenu: showFilterMenu, showClearButton: showClearButton, body: body, headerStyle: headerStyle, align: align });
828
+ return react_1.default.createElement(column_1.Column, { field: childColumn.props.field, header: header, filter: true, sortable: true, filterElement: filterElement, dataType: dataType, showFilterMenu: showFilterMenu, showClearButton: showClearButton, body: body, headerStyle: headerStyle, align: align });
745
829
  });
746
830
  return (react_1.default.createElement("div", null,
747
831
  react_1.default.createElement("div", { className: "flex justify-content-center" },
@@ -1,5 +1,6 @@
1
- import { XAssoc, XEntity, XField } from "../serverApi/XEntityMetadata";
1
+ import { XAssoc, XEntity, XField, XRelationType } from "../serverApi/XEntityMetadata";
2
2
  import { XBrowseMeta } from "../serverApi/XBrowseMetadata";
3
+ import { XBetweenFilterProp } from "./XLazyDataTable";
3
4
  export declare class XUtilsMetadata {
4
5
  private static xEntityMap;
5
6
  private static xBrowseMetaMap;
@@ -9,6 +10,8 @@ export declare class XUtilsMetadata {
9
10
  static getXField(xEntity: XEntity, field: string): XField;
10
11
  static getXFieldByPath(xEntity: XEntity, path: string): XField;
11
12
  static getXFieldByPathStr(entity: string, path: string): XField;
13
+ static getXAssocByPath(xEntity: XEntity, path: string): XAssoc;
14
+ static getLastXAssocByPath(xEntity: XEntity, path: string): XAssoc;
12
15
  static getXAssocToOne(xEntity: XEntity, assocField: string): XAssoc;
13
16
  static getXAssocToMany(xEntity: XEntity, assocField: string): XAssoc;
14
17
  static getXAssocToOneByAssocEntity(xEntity: XEntity, assocEntityName: string): XAssoc;
@@ -16,6 +19,7 @@ export declare class XUtilsMetadata {
16
19
  static getXEntityForAssocToOne(xEntity: XEntity, assocField: string): XEntity;
17
20
  static getXEntityForAssocToMany(xEntity: XEntity, assocField: string): XEntity;
18
21
  static getXFieldList(xEntity: XEntity): XField[];
22
+ static getXAssocList(xEntity: XEntity, relationTypeList?: XRelationType[]): XAssoc[];
19
23
  static getParamsForInputNumber(xField: XField): {
20
24
  useGrouping: boolean;
21
25
  fractionDigits?: number;
@@ -24,7 +28,7 @@ export declare class XUtilsMetadata {
24
28
  size?: number;
25
29
  };
26
30
  static CHAR_SIZE: number;
27
- static computeColumnWidth(xField: XField, filterMenuInFilterRow: boolean, formColumnType: string | undefined, header: string | undefined, sortableButtonInHeader: boolean, filterButtonInHeader: boolean): string | undefined;
31
+ static computeColumnWidth(xField: XField, betweenFilter: XBetweenFilterProp, filterMenuInFilterRow: boolean, formColumnType: string | undefined, header: string | undefined, sortableButtonInHeader: boolean, filterButtonInHeader: boolean): string | undefined;
28
32
  static computeColumnWidthBase(charSize?: number, paddingAndOther?: number): number | undefined;
29
33
  static getXBrowseMeta(entity: string, browseId?: string): XBrowseMeta;
30
34
  static setXBrowseMeta(entity: string, browseId: string | undefined, xBrowseMeta: XBrowseMeta): void;
@@ -127,7 +127,7 @@ var XUtilsMetadata = /** @class */ (function () {
127
127
  return XUtilsMetadata.getXField(xEntity, field);
128
128
  }
129
129
  else {
130
- var xAssoc = XUtilsMetadata.getXAssocToOne(xEntity, field);
130
+ var xAssoc = XUtilsMetadata.getXAssoc(xEntity, field);
131
131
  var xAssocEntity = XUtilsMetadata.getXEntity(xAssoc.entityName);
132
132
  return XUtilsMetadata.getXFieldByPath(xAssocEntity, restPath);
133
133
  }
@@ -135,17 +135,33 @@ var XUtilsMetadata = /** @class */ (function () {
135
135
  XUtilsMetadata.getXFieldByPathStr = function (entity, path) {
136
136
  return XUtilsMetadata.getXFieldByPath(XUtilsMetadata.getXEntity(entity), path);
137
137
  };
138
+ XUtilsMetadata.getXAssocByPath = function (xEntity, path) {
139
+ var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
140
+ if (restPath === null) {
141
+ return XUtilsMetadata.getXAssoc(xEntity, field);
142
+ }
143
+ else {
144
+ var xAssoc = XUtilsMetadata.getXAssoc(xEntity, field);
145
+ var xAssocEntity = XUtilsMetadata.getXEntity(xAssoc.entityName);
146
+ return XUtilsMetadata.getXAssocByPath(xAssocEntity, restPath);
147
+ }
148
+ };
149
+ // for path assoc1.assoc2.field returns assoc2 (last assoc before field)
150
+ XUtilsMetadata.getLastXAssocByPath = function (xEntity, path) {
151
+ var pathToAssoc = XUtilsCommon_1.XUtilsCommon.getPathToAssoc(path);
152
+ return XUtilsMetadata.getXAssocByPath(xEntity, pathToAssoc);
153
+ };
138
154
  XUtilsMetadata.getXAssocToOne = function (xEntity, assocField) {
139
- return XUtilsMetadata.getXAssoc(xEntity, xEntity.assocToOneMap, assocField);
155
+ return XUtilsMetadata.getXAssoc(xEntity, assocField, ["many-to-one", "one-to-one"]);
140
156
  };
141
157
  XUtilsMetadata.getXAssocToMany = function (xEntity, assocField) {
142
- return XUtilsMetadata.getXAssoc(xEntity, xEntity.assocToManyMap, assocField);
158
+ return XUtilsMetadata.getXAssoc(xEntity, assocField, ["one-to-many", "many-to-many"]);
143
159
  };
144
160
  XUtilsMetadata.getXAssocToOneByAssocEntity = function (xEntity, assocEntityName) {
145
- return XUtilsMetadata.getXAssocByAssocEntity(xEntity, xEntity.assocToOneMap, assocEntityName);
161
+ return XUtilsMetadata.getXAssocByAssocEntity(xEntity, assocEntityName, ["many-to-one", "one-to-one"]);
146
162
  };
147
163
  XUtilsMetadata.getXAssocToManyByAssocEntity = function (xEntity, assocEntityName) {
148
- return XUtilsMetadata.getXAssocByAssocEntity(xEntity, xEntity.assocToManyMap, assocEntityName);
164
+ return XUtilsMetadata.getXAssocByAssocEntity(xEntity, assocEntityName, ["one-to-many", "many-to-many"]);
149
165
  };
150
166
  XUtilsMetadata.getXEntityForAssocToOne = function (xEntity, assocField) {
151
167
  return XUtilsMetadata.getXEntityForAssoc(XUtilsMetadata.getXAssocToOne(xEntity, assocField));
@@ -160,7 +176,7 @@ var XUtilsMetadata = /** @class */ (function () {
160
176
  for (var _b = __values(Object.entries(xEntity.fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
161
177
  var _d = __read(_c.value, 2), key = _d[0], xField = _d[1];
162
178
  // assoc fieldy sa nachadzaju aj v xEntity.fieldMap ako typ number (netusim preco), preto ich vyfiltrujeme
163
- if (xEntity.assocToOneMap[xField.name] === undefined) {
179
+ if (xEntity.assocMap[xField.name] === undefined) {
164
180
  xFieldList.push(xField);
165
181
  }
166
182
  }
@@ -174,6 +190,27 @@ var XUtilsMetadata = /** @class */ (function () {
174
190
  }
175
191
  return xFieldList;
176
192
  };
193
+ XUtilsMetadata.getXAssocList = function (xEntity, relationTypeList) {
194
+ var e_2, _a;
195
+ //const xAssocList: XAssoc[] = Array.from(xEntity.assocMap, (v: XAssoc, k: string) => v);
196
+ var xAssocList = [];
197
+ try {
198
+ for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
199
+ var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
200
+ if (relationTypeList === undefined || relationTypeList.includes(xAssoc.relationType)) {
201
+ xAssocList.push(xAssoc);
202
+ }
203
+ }
204
+ }
205
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
206
+ finally {
207
+ try {
208
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
+ }
210
+ finally { if (e_2) throw e_2.error; }
211
+ }
212
+ return xAssocList;
213
+ };
177
214
  // docasne sem, kym nemame jednotny XInputDecimal/XInputDecimalDT
178
215
  XUtilsMetadata.getParamsForInputNumber = function (xField) {
179
216
  var useGrouping = true;
@@ -209,7 +246,7 @@ var XUtilsMetadata = /** @class */ (function () {
209
246
  }
210
247
  return { useGrouping: useGrouping, fractionDigits: fractionDigits, min: min, max: max, size: size };
211
248
  };
212
- XUtilsMetadata.computeColumnWidth = function (xField, filterMenuInFilterRow, formColumnType, header, sortableButtonInHeader, filterButtonInHeader) {
249
+ XUtilsMetadata.computeColumnWidth = function (xField, betweenFilter, filterMenuInFilterRow, formColumnType, header, sortableButtonInHeader, filterButtonInHeader) {
213
250
  var width;
214
251
  if (formColumnType === undefined) {
215
252
  // lazy datatable (no inputs, no buttons, only text and padding)
@@ -221,10 +258,10 @@ var XUtilsMetadata = /** @class */ (function () {
221
258
  width = XUtilsMetadata.computeColumnWidthBase(size, 0.5 + 0.5);
222
259
  }
223
260
  else if (xField.type === "date") {
224
- width = XUtilsMetadata.computeColumnWidthBase(10, 0.5 + 0.5); // napr. 31.12.2021
261
+ width = XUtilsMetadata.computeColumnWidthBase(10, 0.25 + 1.25 + 0.25); // napr. 31.12.2021, 1.25 rem date picker button
225
262
  }
226
263
  else if (xField.type === "datetime") {
227
- width = XUtilsMetadata.computeColumnWidthBase(10 + 9, 0.5 + 0.5); // napr. 31.12.2021 03:03:00
264
+ width = XUtilsMetadata.computeColumnWidthBase(10 + 9, 0.25 + 1.25 + 0.25); // napr. 31.12.2021 03:03:00
228
265
  }
229
266
  else if (xField.type === "boolean") {
230
267
  width = 1.43 + 0.5 + 0.5; // checkbox ma sirku 20px
@@ -232,6 +269,9 @@ var XUtilsMetadata = /** @class */ (function () {
232
269
  else {
233
270
  throw "XField ".concat(xField.name, ": unknown xField.type = ").concat(xField.type);
234
271
  }
272
+ if (betweenFilter === "row" && width) {
273
+ width *= 2;
274
+ }
235
275
  }
236
276
  else {
237
277
  // form datatable (formColumnType is defined)
@@ -243,12 +283,25 @@ var XUtilsMetadata = /** @class */ (function () {
243
283
  else if (xField.type === "decimal" || xField.type === "number") {
244
284
  var size = XUtilsMetadata.getParamsForInputNumber(xField).size;
245
285
  width = XUtilsMetadata.computeColumnWidthBase(size, padding + padding);
286
+ if (betweenFilter === "row" && width) {
287
+ width *= 2; // not tested, only estimation
288
+ }
246
289
  }
247
290
  else if (xField.type === "date") {
248
- width = 0.21 + 6 + 2.36 + 0.21; // padding + input (also in App.css defined) + button + padding
291
+ if (betweenFilter === "row") {
292
+ width = (0.21 + 6 + 1.25 + 0.21) * 2; // not tested, only estimation
293
+ }
294
+ else {
295
+ width = 0.21 + 6 + 2.36 + 0.21; // padding + input (also in App.css defined) + button + padding
296
+ }
249
297
  }
250
298
  else if (xField.type === "datetime") {
251
- width = 0.21 + 10 + 2.36 + 0.21; // padding + input (also in App.css defined) + button + padding
299
+ if (betweenFilter === "row") {
300
+ width = (0.21 + 10 + 1.25 + 0.21) * 2; // not tested, only estimation
301
+ }
302
+ else {
303
+ width = 0.21 + 10 + 2.36 + 0.21; // padding + input (also in App.css defined) + button + padding
304
+ }
252
305
  }
253
306
  else if (xField.type === "boolean") {
254
307
  width = 1.43 + 0.5 + 0.5; // checkbox ma sirku 20px
@@ -346,18 +399,22 @@ var XUtilsMetadata = /** @class */ (function () {
346
399
  }
347
400
  return key;
348
401
  };
349
- XUtilsMetadata.getXAssoc = function (xEntity, assocMap, assocField) {
350
- var xAssoc = assocMap[assocField];
402
+ XUtilsMetadata.getXAssoc = function (xEntity, assocField, relationTypeList) {
403
+ var xAssoc = xEntity.assocMap[assocField];
351
404
  if (xAssoc === undefined) {
352
405
  throw "Assoc ".concat(assocField, " was not found in entity = ").concat(xEntity.name);
353
406
  }
407
+ // relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
408
+ if (relationTypeList !== undefined && !relationTypeList.includes(xAssoc.relationType)) {
409
+ throw "Assoc ".concat(assocField, " in entity ").concat(xEntity.name, " is of type ").concat(xAssoc.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
410
+ }
354
411
  return xAssoc;
355
412
  };
356
- XUtilsMetadata.getXAssocByAssocEntity = function (xEntity, assocMap, assocEntityName) {
357
- var e_2, _a;
413
+ XUtilsMetadata.getXAssocByAssocEntity = function (xEntity, assocEntityName, relationTypeList) {
414
+ var e_3, _a;
358
415
  var xAssocFound = undefined;
359
416
  try {
360
- for (var _b = __values(Object.entries(assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
417
+ for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
361
418
  var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
362
419
  if (xAssoc.entityName === assocEntityName) {
363
420
  if (xAssocFound === undefined) {
@@ -369,16 +426,20 @@ var XUtilsMetadata = /** @class */ (function () {
369
426
  }
370
427
  }
371
428
  }
372
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
429
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
373
430
  finally {
374
431
  try {
375
432
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
376
433
  }
377
- finally { if (e_2) throw e_2.error; }
434
+ finally { if (e_3) throw e_3.error; }
378
435
  }
379
436
  if (xAssocFound === undefined) {
380
437
  throw "Assoc for assocEntityName = ".concat(assocEntityName, " not found in entity ").concat(xEntity.name);
381
438
  }
439
+ // relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
440
+ if (relationTypeList !== undefined && !relationTypeList.includes(xAssocFound.relationType)) {
441
+ throw "Assoc for assocEntityName = ".concat(assocEntityName, " in entity ").concat(xEntity.name, " is of type ").concat(xAssocFound.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
442
+ }
382
443
  return xAssocFound;
383
444
  };
384
445
  XUtilsMetadata.getXEntityForAssoc = function (xAssoc) {
@@ -1,4 +1,5 @@
1
1
  import { DataTableFilterMeta, DataTableSortMeta } from "primereact/datatable";
2
+ import { XCustomFilter } from "./FindParam";
2
3
  export declare enum ExportType {
3
4
  Csv = "csv",
4
5
  Json = "json"
@@ -6,6 +7,7 @@ export declare enum ExportType {
6
7
  export interface ExportParam {
7
8
  exportType: ExportType;
8
9
  filters: DataTableFilterMeta;
10
+ customFilter?: XCustomFilter;
9
11
  multiSortMeta?: DataTableSortMeta[];
10
12
  entity: string;
11
13
  fields: string[];
@@ -5,8 +5,7 @@ export interface XEntity {
5
5
  name: string;
6
6
  idField: string;
7
7
  fieldMap: XFieldMap;
8
- assocToOneMap: XAssocMap;
9
- assocToManyMap: XAssocMap;
8
+ assocMap: XAssocMap;
10
9
  }
11
10
  export interface XFieldMap {
12
11
  [name: string]: XField;
@@ -23,7 +22,9 @@ export interface XField {
23
22
  scale?: number;
24
23
  width?: number;
25
24
  }
25
+ export type XRelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
26
26
  export interface XAssoc {
27
+ relationType: XRelationType;
27
28
  name: string;
28
29
  entityName: string;
29
30
  inverseAssocName?: string;
@@ -3,6 +3,7 @@ export declare class XUtilsCommon {
3
3
  static getValueByPath(object: any, path: string): any;
4
4
  static getFieldListForPath(path: string): string[];
5
5
  static getFieldAndRestPath(path: string): [string, string | null];
6
+ static getPathToAssoc(path: string): string;
6
7
  static isSingleField(path: string): boolean;
7
8
  static objectAsJSON(value: any): string;
8
9
  static getDayName(date: Date | null | undefined): string | undefined;
@@ -52,6 +52,15 @@ var XUtilsCommon = /** @class */ (function () {
52
52
  return [assocField, restPath];
53
53
  }
54
54
  };
55
+ XUtilsCommon.getPathToAssoc = function (path) {
56
+ var posDot = path.lastIndexOf(".");
57
+ if (posDot === -1) {
58
+ throw "Path to assoc could not be retrieved. Path ".concat(path, " must have at least 2 items.");
59
+ }
60
+ else {
61
+ return path.substring(0, posDot);
62
+ }
63
+ };
55
64
  XUtilsCommon.isSingleField = function (path) {
56
65
  return path.indexOf(".") === -1;
57
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",