@michalrakus/x-react-web-lib 1.11.1 → 1.13.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 (47) hide show
  1. package/XUtilsConversions.d.ts +1 -1
  2. package/XUtilsConversions.js +1 -1
  3. package/XUtilsMetadataCommon.d.ts +3 -0
  4. package/XUtilsMetadataCommon.js +5 -0
  5. package/gulpfile.js +3 -2
  6. package/lib/components/XAutoComplete.d.ts +3 -1
  7. package/lib/components/XAutoComplete.js +14 -8
  8. package/lib/components/XAutoCompleteBase.d.ts +4 -0
  9. package/lib/components/XAutoCompleteBase.js +33 -2
  10. package/lib/components/XAutoCompleteDT.js +4 -4
  11. package/lib/components/XCalendar.js +1 -1
  12. package/lib/components/XDropdown.js +2 -2
  13. package/lib/components/XDropdownDT.js +4 -4
  14. package/lib/components/XDropdownDTFilter.js +2 -2
  15. package/lib/components/XDropdownForEntity.js +2 -2
  16. package/lib/components/XEditBrowse.js +4 -3
  17. package/lib/components/XExportRowsDialog.js +1 -1
  18. package/lib/components/XFieldSelector.js +4 -4
  19. package/lib/components/XFormDataTable2.js +13 -12
  20. package/lib/components/XFtsInput.d.ts +9 -0
  21. package/lib/components/XFtsInput.js +30 -0
  22. package/lib/components/XInput.js +2 -2
  23. package/lib/components/XInputDT.js +2 -2
  24. package/lib/components/XInputDateDT.js +1 -1
  25. package/lib/components/XInputFileList.js +6 -6
  26. package/lib/components/XInputIntervalBase.js +1 -1
  27. package/lib/components/XInputText.js +1 -1
  28. package/lib/components/XInputTextDT.js +3 -3
  29. package/lib/components/XInputTextarea.js +1 -1
  30. package/lib/components/XLazyDataTable.d.ts +11 -0
  31. package/lib/components/XLazyDataTable.js +58 -55
  32. package/lib/components/XSearchButton.js +4 -4
  33. package/lib/components/XSearchButtonDT.js +3 -3
  34. package/lib/components/XSearchButtonOld.js +5 -5
  35. package/lib/components/XToOneAssocButton.js +3 -3
  36. package/lib/components/XUtils.js +2 -1
  37. package/lib/components/XUtilsMetadata.d.ts +1 -19
  38. package/lib/components/XUtilsMetadata.js +8 -186
  39. package/lib/components/locale/x-en.json +4 -1
  40. package/lib/serverApi/ExportImportParam.d.ts +2 -1
  41. package/lib/serverApi/FindParam.d.ts +6 -0
  42. package/lib/{components → serverApi}/XUtilsConversions.d.ts +18 -1
  43. package/lib/serverApi/XUtilsConversions.js +330 -0
  44. package/lib/serverApi/XUtilsMetadataCommon.d.ts +30 -0
  45. package/lib/serverApi/XUtilsMetadataCommon.js +208 -0
  46. package/package.json +2 -2
  47. package/lib/components/XUtilsConversions.js +0 -177
@@ -35,37 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __values = (this && this.__values) || function(o) {
55
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
56
- if (m) return m.call(o);
57
- if (o && typeof o.length === "number") return {
58
- next: function () {
59
- if (o && i >= o.length) o = void 0;
60
- return { value: o && o[i++], done: !o };
61
- }
62
- };
63
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
64
- };
65
38
  Object.defineProperty(exports, "__esModule", { value: true });
66
39
  exports.XUtilsMetadata = void 0;
67
40
  var XUtils_1 = require("./XUtils");
68
- var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
41
+ var XUtilsMetadataCommon_1 = require("../serverApi/XUtilsMetadataCommon");
69
42
  // idelany nazov: UtilsEntityMetadata - ale strasne dlhy
70
43
  // tato funkcionalita by mala ist bud do tried XEntity, XField alebo lepsie do nejakeho servisu
71
44
  // ekvivalentna funkcionalita sa nachadza aj na servri v servise XEntityMetadataService.ts (TODO - v buducnosti spravit spolocnu triedu/servis)
@@ -74,16 +47,16 @@ var XUtilsMetadata = /** @class */ (function () {
74
47
  }
75
48
  XUtilsMetadata.fetchAndSetXEntityMap = function () {
76
49
  return __awaiter(this, void 0, void 0, function () {
77
- var _a;
78
- return __generator(this, function (_b) {
79
- switch (_b.label) {
50
+ var _a, _b;
51
+ return __generator(this, function (_c) {
52
+ switch (_c.label) {
80
53
  case 0:
81
- if (!(XUtilsMetadata.xEntityMap === undefined)) return [3 /*break*/, 2];
82
- _a = XUtilsMetadata;
54
+ if (!(XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXEntityMap() === undefined)) return [3 /*break*/, 2];
55
+ _b = (_a = XUtilsMetadataCommon_1.XUtilsMetadataCommon).setXEntityMap;
83
56
  return [4 /*yield*/, XUtils_1.XUtils.fetch("getXEntityMap", { dummy: "dummy" })];
84
57
  case 1:
85
- _a.xEntityMap = _b.sent();
86
- _b.label = 2;
58
+ _b.apply(_a, [_c.sent()]);
59
+ _c.label = 2;
87
60
  case 2: return [2 /*return*/];
88
61
  }
89
62
  });
@@ -106,111 +79,6 @@ var XUtilsMetadata = /** @class */ (function () {
106
79
  });
107
80
  });
108
81
  };
109
- XUtilsMetadata.getXEntity = function (entity) {
110
- var xEntity = XUtilsMetadata.xEntityMap[entity];
111
- if (xEntity === undefined) {
112
- throw "Entity ".concat(entity, " was not found in entity metadata");
113
- }
114
- return xEntity;
115
- };
116
- XUtilsMetadata.getXField = function (xEntity, field) {
117
- // TODO - pozor, vo fieldMap su aj asociacie, trebalo by zmenit vytvaranie metadat tak aby tam tie asociacie neboli
118
- var xField = xEntity.fieldMap[field];
119
- if (xField === undefined) {
120
- throw "Field ".concat(field, " was not found in entity ").concat(xEntity.name);
121
- }
122
- return xField;
123
- };
124
- XUtilsMetadata.getXFieldByPath = function (xEntity, path) {
125
- var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
126
- if (restPath === null) {
127
- return XUtilsMetadata.getXField(xEntity, field);
128
- }
129
- else {
130
- var xAssoc = XUtilsMetadata.getXAssoc(xEntity, field);
131
- var xAssocEntity = XUtilsMetadata.getXEntity(xAssoc.entityName);
132
- return XUtilsMetadata.getXFieldByPath(xAssocEntity, restPath);
133
- }
134
- };
135
- XUtilsMetadata.getXFieldByPathStr = function (entity, path) {
136
- return XUtilsMetadata.getXFieldByPath(XUtilsMetadata.getXEntity(entity), path);
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
- };
154
- XUtilsMetadata.getXAssocToOne = function (xEntity, assocField) {
155
- return XUtilsMetadata.getXAssoc(xEntity, assocField, ["many-to-one", "one-to-one"]);
156
- };
157
- XUtilsMetadata.getXAssocToMany = function (xEntity, assocField) {
158
- return XUtilsMetadata.getXAssoc(xEntity, assocField, ["one-to-many", "many-to-many"]);
159
- };
160
- XUtilsMetadata.getXAssocToOneByAssocEntity = function (xEntity, assocEntityName) {
161
- return XUtilsMetadata.getXAssocByAssocEntity(xEntity, assocEntityName, ["many-to-one", "one-to-one"]);
162
- };
163
- XUtilsMetadata.getXAssocToManyByAssocEntity = function (xEntity, assocEntityName) {
164
- return XUtilsMetadata.getXAssocByAssocEntity(xEntity, assocEntityName, ["one-to-many", "many-to-many"]);
165
- };
166
- XUtilsMetadata.getXEntityForAssocToOne = function (xEntity, assocField) {
167
- return XUtilsMetadata.getXEntityForAssoc(XUtilsMetadata.getXAssocToOne(xEntity, assocField));
168
- };
169
- XUtilsMetadata.getXEntityForAssocToMany = function (xEntity, assocField) {
170
- return XUtilsMetadata.getXEntityForAssoc(XUtilsMetadata.getXAssocToMany(xEntity, assocField));
171
- };
172
- XUtilsMetadata.getXFieldList = function (xEntity) {
173
- var e_1, _a;
174
- var xFieldList = [];
175
- try {
176
- for (var _b = __values(Object.entries(xEntity.fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
177
- var _d = __read(_c.value, 2), key = _d[0], xField = _d[1];
178
- // assoc fieldy sa nachadzaju aj v xEntity.fieldMap ako typ number (netusim preco), preto ich vyfiltrujeme
179
- if (xEntity.assocMap[xField.name] === undefined) {
180
- xFieldList.push(xField);
181
- }
182
- }
183
- }
184
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
185
- finally {
186
- try {
187
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
188
- }
189
- finally { if (e_1) throw e_1.error; }
190
- }
191
- return xFieldList;
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
- };
214
82
  // docasne sem, kym nemame jednotny XInputDecimal/XInputDecimalDT
215
83
  XUtilsMetadata.getParamsForInputNumber = function (xField) {
216
84
  var useGrouping = true;
@@ -399,52 +267,6 @@ var XUtilsMetadata = /** @class */ (function () {
399
267
  }
400
268
  return key;
401
269
  };
402
- XUtilsMetadata.getXAssoc = function (xEntity, assocField, relationTypeList) {
403
- var xAssoc = xEntity.assocMap[assocField];
404
- if (xAssoc === undefined) {
405
- throw "Assoc ".concat(assocField, " was not found in entity = ").concat(xEntity.name);
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
- }
411
- return xAssoc;
412
- };
413
- XUtilsMetadata.getXAssocByAssocEntity = function (xEntity, assocEntityName, relationTypeList) {
414
- var e_3, _a;
415
- var xAssocFound = undefined;
416
- try {
417
- for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
418
- var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
419
- if (xAssoc.entityName === assocEntityName) {
420
- if (xAssocFound === undefined) {
421
- xAssocFound = xAssoc;
422
- }
423
- else {
424
- throw "In entity ".concat(xEntity.name, " found more then 1 assoc for assocEntityName = ").concat(assocEntityName);
425
- }
426
- }
427
- }
428
- }
429
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
430
- finally {
431
- try {
432
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
433
- }
434
- finally { if (e_3) throw e_3.error; }
435
- }
436
- if (xAssocFound === undefined) {
437
- throw "Assoc for assocEntityName = ".concat(assocEntityName, " not found in entity ").concat(xEntity.name);
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
- }
443
- return xAssocFound;
444
- };
445
- XUtilsMetadata.getXEntityForAssoc = function (xAssoc) {
446
- return XUtilsMetadata.getXEntity(xAssoc.entityName);
447
- };
448
270
  //static CHAR_SIZE: number = 0.57; // 0.57rem (8px)
449
271
  XUtilsMetadata.CHAR_SIZE = 0.5; // 0.5rem (7px) - skusime
450
272
  return XUtilsMetadata;
@@ -24,6 +24,9 @@
24
24
  "fileDownloadFailed": "File download failed.",
25
25
  "fieldSetSaveEditConfirm": "Are you sure to save the form?",
26
26
  "fieldSetCancelEditConfirm": "Are you sure to cancel editing? All changes will be lost.",
27
- "fieldSetRemoveFieldConfirm": "Are you sure to remove the field?"
27
+ "fieldSetRemoveFieldConfirm": "Are you sure to remove the field?",
28
+ "upload": "Upload",
29
+ "yes": "yes",
30
+ "no": "no"
28
31
  }
29
32
  }
@@ -1,5 +1,5 @@
1
1
  import { DataTableFilterMeta, DataTableSortMeta } from "primereact/datatable";
2
- import { XCustomFilterItem } from "./FindParam";
2
+ import { XCustomFilterItem, XFullTextSearch } from "./FindParam";
3
3
  export declare enum ExportType {
4
4
  Csv = "csv",
5
5
  Json = "json"
@@ -11,6 +11,7 @@ export interface ExportParam {
11
11
  }
12
12
  export interface LazyDataTableQueryParam {
13
13
  filters: DataTableFilterMeta;
14
+ fullTextSearch?: XFullTextSearch;
14
15
  customFilterItems?: XCustomFilterItem[];
15
16
  multiSortMeta?: DataTableSortMeta[];
16
17
  entity: string;
@@ -12,6 +12,11 @@ export interface XCustomFilterItem {
12
12
  params: XParams;
13
13
  }
14
14
  export type XCustomFilter = XCustomFilterItem | XCustomFilterItem[];
15
+ export interface XFullTextSearch {
16
+ fields?: string[];
17
+ value: string;
18
+ matchMode: 'startsWith' | 'contains' | 'endsWith' | 'equals';
19
+ }
15
20
  export declare enum XAggregateType {
16
21
  Min = "MIN",
17
22
  Max = "MAX",
@@ -27,6 +32,7 @@ export interface FindParam {
27
32
  first?: number;
28
33
  rows?: number;
29
34
  filters?: DataTableFilterMeta;
35
+ fullTextSearch?: XFullTextSearch;
30
36
  customFilterItems?: XCustomFilterItem[];
31
37
  multiSortMeta?: DataTableSortMeta[];
32
38
  entity: string;
@@ -1,6 +1,8 @@
1
- import { IPostgresInterval } from "./XUtils";
1
+ import { IPostgresInterval } from "../components/XUtils";
2
+ import { XField } from "./XEntityMetadata";
2
3
  export declare function stringFromUI(stringValue: string): string | null;
3
4
  export declare function stringAsUI(value: string | null): string;
5
+ export declare function stringAsDB(value: string | null): string;
4
6
  export declare function numberFromUI(stringValue: string): number | null;
5
7
  export declare function numberAsUI(value: number | null, fractionDigits?: number): string;
6
8
  export declare function numberFromModel(value: any): number | null;
@@ -13,3 +15,18 @@ export declare function dateFormatCalendar(): string;
13
15
  export declare function datetimeFormatUI(): string;
14
16
  export declare function intervalFromUI(valueString: string): IPostgresInterval | null | undefined;
15
17
  export declare function intervalAsUI(valueInterval: IPostgresInterval | null): string;
18
+ export declare function booleanAsUIText(value: boolean | null): string;
19
+ export declare enum AsUIType {
20
+ Form = 1,
21
+ Text = 2
22
+ }
23
+ /**
24
+ * converts values of object
25
+ *
26
+ * @param entity
27
+ * @param object
28
+ * @param fromModel
29
+ * @param asUI
30
+ */
31
+ export declare function convertObject(entity: string, object: any, fromModel: boolean, asUI: AsUIType | undefined): void;
32
+ export declare function convertValue(xField: XField, value: any, fromModel: boolean, asUI: AsUIType | undefined): any;
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.convertValue = exports.convertObject = exports.AsUIType = exports.booleanAsUIText = exports.intervalAsUI = exports.intervalFromUI = exports.datetimeFormatUI = exports.dateFormatCalendar = exports.dateFormatUI = exports.timeFromModel = exports.datetimeAsUI = exports.dateAsUI = exports.dateFromModel = exports.numberFromModel = exports.numberAsUI = exports.numberFromUI = exports.stringAsDB = exports.stringAsUI = exports.stringFromUI = void 0;
31
+ var XUtilsCommon_1 = require("./XUtilsCommon");
32
+ var XLocale_1 = require("../components/XLocale");
33
+ var XUtilsMetadataCommon_1 = require("./XUtilsMetadataCommon");
34
+ function stringFromUI(stringValue) {
35
+ var value;
36
+ if (stringValue === '') {
37
+ value = null;
38
+ }
39
+ else {
40
+ value = stringValue;
41
+ }
42
+ return value;
43
+ }
44
+ exports.stringFromUI = stringFromUI;
45
+ function stringAsUI(value) {
46
+ return value !== null ? value : "";
47
+ }
48
+ exports.stringAsUI = stringAsUI;
49
+ // aby sme sa vyhli sql injection problemu - tam kde je problematicke pouzivat klasicke params
50
+ function stringAsDB(value) {
51
+ return value !== null ? "'".concat(value.replaceAll("'", "''"), "'") : "NULL";
52
+ }
53
+ exports.stringAsDB = stringAsDB;
54
+ function numberFromUI(stringValue) {
55
+ var value;
56
+ if (stringValue === '') {
57
+ value = null;
58
+ }
59
+ else {
60
+ value = parseInt(stringValue, 10);
61
+ }
62
+ return value;
63
+ }
64
+ exports.numberFromUI = numberFromUI;
65
+ function numberAsUI(value, fractionDigits) {
66
+ if (fractionDigits === undefined) {
67
+ fractionDigits = 2; // default
68
+ }
69
+ if (value !== null) {
70
+ return value.toLocaleString('de-DE', { style: 'decimal', minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits });
71
+ }
72
+ else {
73
+ return "";
74
+ }
75
+ }
76
+ exports.numberAsUI = numberAsUI;
77
+ // v modeli na klientovi by mal byt vzdy number, teraz je tam niekedy string (z json-u zo servera) a niekedy number (z komponentu)
78
+ // provizorne zatial takato konverzia
79
+ function numberFromModel(value) {
80
+ var numberValue = null;
81
+ if (typeof value === 'string') {
82
+ numberValue = parseFloat(value);
83
+ }
84
+ else if (typeof value === 'number') {
85
+ numberValue = value;
86
+ }
87
+ return numberValue;
88
+ }
89
+ exports.numberFromModel = numberFromModel;
90
+ // v modeli na klientovi by mal byt vzdy Date, teraz je tam niekedy string (z json-u zo servera) a niekedy Date (z komponentu)
91
+ // provizorne zatial takato konverzia
92
+ function dateFromModel(value) {
93
+ var dateValue = null;
94
+ if (typeof value === 'string') {
95
+ dateValue = new Date(value);
96
+ }
97
+ else if (typeof value === 'object' && value instanceof Date) {
98
+ dateValue = value;
99
+ }
100
+ return dateValue;
101
+ }
102
+ exports.dateFromModel = dateFromModel;
103
+ function dateAsUI(value) {
104
+ if (value !== null) {
105
+ return (0, XUtilsCommon_1.dateFormat)(value, dateFormatUI());
106
+ }
107
+ else {
108
+ return "";
109
+ }
110
+ }
111
+ exports.dateAsUI = dateAsUI;
112
+ function datetimeAsUI(value) {
113
+ if (value !== null) {
114
+ return (0, XUtilsCommon_1.dateFormat)(value, datetimeFormatUI());
115
+ }
116
+ else {
117
+ return "";
118
+ }
119
+ }
120
+ exports.datetimeAsUI = datetimeAsUI;
121
+ // provizorne zatial takato konverzia
122
+ function timeFromModel(value) {
123
+ var timeValue = null;
124
+ if (typeof value === 'string') {
125
+ // ak prichadza cas priamo z databazy, pride '19:30:00'
126
+ // ak prichadza reloadnuty objekt (napr. cez webservis saveRow), pride '2021-06-07 19:30:00'
127
+ var rowDataCasStr = value;
128
+ if (rowDataCasStr.length < 10) {
129
+ // mame '19:30:00' -> pridame hociaky rok aby sme skonvertovali na validny Date
130
+ rowDataCasStr = '1970-01-01 ' + rowDataCasStr;
131
+ }
132
+ // na safari nefunguje konverzia new Date('2021-06-07 19:30:00') - vrati NaN
133
+ // preto string prehodime na '2021-06-07T19:30:00+01:00'
134
+ // 19:30:00 je cas z timezony Central Europe (taka je nastavena na nodejs)), preto oznacime tento cas touto timezonou
135
+ // (spravne riesenie je posielat time cez json vzdy vo formate '2021-06-07T18:30:00Z', v tomto formate chodia aj datetime atributy)
136
+ rowDataCasStr = rowDataCasStr.replace(' ', 'T');
137
+ if (!rowDataCasStr.endsWith('Z') && rowDataCasStr.indexOf('+') === -1) {
138
+ rowDataCasStr += '+01:00'; // Central Europe timezone
139
+ }
140
+ timeValue = new Date(rowDataCasStr);
141
+ }
142
+ else if (typeof value === 'object' && value instanceof Date) {
143
+ timeValue = value;
144
+ }
145
+ return timeValue;
146
+ }
147
+ exports.timeFromModel = timeFromModel;
148
+ function dateFormatUI() {
149
+ return "dd.mm.yyyy";
150
+ }
151
+ exports.dateFormatUI = dateFormatUI;
152
+ function dateFormatCalendar() {
153
+ return "dd.mm.yy";
154
+ }
155
+ exports.dateFormatCalendar = dateFormatCalendar;
156
+ function datetimeFormatUI() {
157
+ return "dd.mm.yyyy HH:MM:ss";
158
+ }
159
+ exports.datetimeFormatUI = datetimeFormatUI;
160
+ function intervalFromUI(valueString) {
161
+ // convert e.target.value (e.g. 10:29) into IPostgresInterval (e.g. {hours: 10, minutes: 29})
162
+ // if stringValue is invalid, returns undefined
163
+ var valueInterval = undefined;
164
+ if (valueString === '') {
165
+ valueInterval = null;
166
+ }
167
+ else {
168
+ var posColon = valueString.indexOf(':');
169
+ if (posColon === -1) {
170
+ var minutes = parseInt(valueString);
171
+ if (!isNaN(minutes)) {
172
+ var hours = Math.floor(minutes / 60);
173
+ minutes = minutes - (hours * 60);
174
+ valueInterval = { hours: hours, minutes: minutes };
175
+ }
176
+ }
177
+ else {
178
+ var hours = parseInt(valueString.substring(0, posColon));
179
+ var minutes = parseInt(valueString.substring(posColon + 1));
180
+ if (!isNaN(hours) && !isNaN(minutes)) {
181
+ if (minutes >= 60) {
182
+ var hoursFromMinutes = Math.floor(minutes / 60);
183
+ hours += hoursFromMinutes;
184
+ minutes = minutes - (hoursFromMinutes * 60);
185
+ }
186
+ valueInterval = { hours: hours, minutes: minutes };
187
+ }
188
+ }
189
+ }
190
+ return valueInterval;
191
+ }
192
+ exports.intervalFromUI = intervalFromUI;
193
+ function intervalAsUI(valueInterval) {
194
+ var _a, _b;
195
+ // conversion e.g. {hours: 10, minutes: 29} => '10:29'
196
+ var valueString;
197
+ if (valueInterval !== null) {
198
+ var hours = (_a = valueInterval.hours) !== null && _a !== void 0 ? _a : 0;
199
+ var minutes = (_b = valueInterval.minutes) !== null && _b !== void 0 ? _b : 0;
200
+ //const seconds: number = value.seconds ?? 0;
201
+ if (valueInterval.days) {
202
+ hours += valueInterval.days * 24;
203
+ }
204
+ valueString = "".concat(hours.toString(), ":").concat(minutes.toString().padStart(2, '0'));
205
+ }
206
+ else {
207
+ valueString = ''; // null
208
+ }
209
+ return valueString;
210
+ }
211
+ exports.intervalAsUI = intervalAsUI;
212
+ function booleanAsUIText(value) {
213
+ if (value !== null) {
214
+ return value ? (0, XLocale_1.xLocaleOption)('yes') : (0, XLocale_1.xLocaleOption)('no');
215
+ }
216
+ else {
217
+ return "";
218
+ }
219
+ }
220
+ exports.booleanAsUIText = booleanAsUIText;
221
+ var AsUIType;
222
+ (function (AsUIType) {
223
+ AsUIType[AsUIType["Form"] = 1] = "Form";
224
+ AsUIType[AsUIType["Text"] = 2] = "Text"; // reporty - boolean sa konvertuje na ano/nie
225
+ })(AsUIType = exports.AsUIType || (exports.AsUIType = {}));
226
+ /**
227
+ * converts values of object
228
+ *
229
+ * @param entity
230
+ * @param object
231
+ * @param fromModel
232
+ * @param asUI
233
+ */
234
+ function convertObject(entity, object, fromModel, asUI) {
235
+ var e_1, _a, e_2, _b;
236
+ var xEntity = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXEntity(entity);
237
+ try {
238
+ for (var _c = __values(Object.entries(object)), _d = _c.next(); !_d.done; _d = _c.next()) {
239
+ var _e = __read(_d.value, 2), field = _e[0], value = _e[1];
240
+ var xField = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXFieldBase(xEntity, field);
241
+ if (xField) {
242
+ object[field] = convertValue(xField, value, fromModel, asUI);
243
+ }
244
+ else {
245
+ // nenasli sme medzi fieldami, skusime hladat xAssoc
246
+ var xAssoc = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXAssocBase(xEntity, field);
247
+ if (xAssoc) {
248
+ if (value) {
249
+ if (xAssoc.relationType === "many-to-one" || xAssoc.relationType === "one-to-one") {
250
+ convertObject(xAssoc.entityName, value, fromModel, asUI);
251
+ }
252
+ else if (xAssoc.relationType === "one-to-many" || xAssoc.relationType === "many-to-many") {
253
+ if (!Array.isArray(value)) {
254
+ throw "Unexpected error: entity ".concat(entity, " - field ").concat(field, " is expected to be array");
255
+ }
256
+ try {
257
+ for (var value_1 = (e_2 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
258
+ var valueItem = value_1_1.value;
259
+ convertObject(xAssoc.entityName, valueItem, fromModel, asUI);
260
+ }
261
+ }
262
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
263
+ finally {
264
+ try {
265
+ if (value_1_1 && !value_1_1.done && (_b = value_1.return)) _b.call(value_1);
266
+ }
267
+ finally { if (e_2) throw e_2.error; }
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ }
274
+ }
275
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
276
+ finally {
277
+ try {
278
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
279
+ }
280
+ finally { if (e_1) throw e_1.error; }
281
+ }
282
+ }
283
+ exports.convertObject = convertObject;
284
+ function convertValue(xField, value, fromModel, asUI) {
285
+ if (xField.type === "decimal") {
286
+ if (fromModel) {
287
+ value = numberFromModel(value);
288
+ }
289
+ if (asUI) {
290
+ value = numberAsUI(value, xField.scale);
291
+ }
292
+ }
293
+ else if (xField.type === "date") {
294
+ if (fromModel) {
295
+ value = dateFromModel(value);
296
+ }
297
+ if (asUI) {
298
+ value = dateAsUI(value);
299
+ }
300
+ }
301
+ else if (xField.type === "datetime") {
302
+ if (fromModel) {
303
+ value = dateFromModel(value);
304
+ }
305
+ if (asUI) {
306
+ value = datetimeAsUI(value);
307
+ }
308
+ }
309
+ else if (xField.type === "interval") {
310
+ // konverziu z modelu (json objekt-u) netreba
311
+ if (asUI) {
312
+ value = intervalAsUI(value);
313
+ }
314
+ }
315
+ else if (xField.type === "boolean") {
316
+ // konverziu z modelu (json objekt-u) netreba
317
+ // pre AsUIType.Form ponechame typ boolean (spracujeme neskor)
318
+ if (asUI === AsUIType.Text) {
319
+ value = booleanAsUIText(value);
320
+ }
321
+ }
322
+ else {
323
+ // vsetko ostatne
324
+ if (asUI) {
325
+ value = value ? value.toString() : "";
326
+ }
327
+ }
328
+ return value;
329
+ }
330
+ exports.convertValue = convertValue;
@@ -0,0 +1,30 @@
1
+ import { XAssoc, XEntity, XEntityMap, XField, XRelationType } from "./XEntityMetadata";
2
+ /**
3
+ * spolocna funkcionalita pre entity metadata vyuzivana na frontend-e aj backend-e
4
+ * vznikla na zaklade XEntityMetadataService
5
+ * tato funkcionalita by este mohla ist do tried XEntity, XField
6
+ */
7
+ export declare class XUtilsMetadataCommon {
8
+ private static xEntityMap;
9
+ static getXEntityMap(): XEntityMap | undefined;
10
+ static setXEntityMap(xEntityMap: XEntityMap): void;
11
+ static getXEntity(entity: string): XEntity;
12
+ static getXFieldBase(xEntity: XEntity, field: string): XField | undefined;
13
+ static getXField(xEntity: XEntity, field: string): XField;
14
+ static getXFieldByPath(xEntity: XEntity, path: string): XField;
15
+ static getXFieldByPathStr(entity: string, path: string): XField;
16
+ static getXAssocBase(xEntity: XEntity, assocField: string): XAssoc | undefined;
17
+ static getXAssocByPath(xEntity: XEntity, path: string): XAssoc;
18
+ static getLastXAssocByPath(xEntity: XEntity, path: string): XAssoc;
19
+ static getXAssocToOne(xEntity: XEntity, assocField: string): XAssoc;
20
+ static getXAssocToMany(xEntity: XEntity, assocField: string): XAssoc;
21
+ static getXAssocToOneByAssocEntity(xEntity: XEntity, assocEntityName: string): XAssoc;
22
+ static getXAssocToManyByAssocEntity(xEntity: XEntity, assocEntityName: string): XAssoc;
23
+ static getXEntityForAssocToOne(xEntity: XEntity, assocField: string): XEntity;
24
+ static getXEntityForAssocToMany(xEntity: XEntity, assocField: string): XEntity;
25
+ static getXFieldList(xEntity: XEntity): XField[];
26
+ static getXAssocList(xEntity: XEntity, relationTypeList?: XRelationType[]): XAssoc[];
27
+ private static getXAssoc;
28
+ private static getXAssocByAssocEntity;
29
+ private static getXEntityForAssoc;
30
+ }