@webtypen/webframez-core 0.2.25 → 0.2.27
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/DataBuilder/DataBuilder.js +45 -17
- package/dist/Functions/DateFunctions.d.ts +5 -0
- package/dist/Functions/DateFunctions.js +87 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/DataBuilder/DataBuilder.ts +51 -21
- package/src/Functions/DateFunctions.ts +92 -0
- package/src/index.ts +1 -0
|
@@ -215,15 +215,43 @@ class DataBuilder {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
218
|
+
let elementVal = null;
|
|
219
|
+
if (value !== undefined &&
|
|
220
|
+
value !== null &&
|
|
221
|
+
!(typeof value === "string" && value.trim() === "") &&
|
|
222
|
+
!(typeof value === "number" && value.toString().trim() === "")) {
|
|
223
|
+
// Custom field onSave
|
|
224
|
+
if (customType && typeof customType.onSave === "function") {
|
|
225
|
+
elementVal = yield customType.onSave(value, Object.assign(Object.assign({}, payload), fields[key].payload));
|
|
226
|
+
}
|
|
227
|
+
// Float or currency fields
|
|
228
|
+
else if (fields[key].type === "currency" || fields[key].type === "float") {
|
|
229
|
+
elementVal = parseFloat(value.toString().replace(",", "."));
|
|
230
|
+
}
|
|
231
|
+
// Integer field
|
|
232
|
+
else if (fields[key].type === "integer") {
|
|
233
|
+
elementVal = parseInt(value);
|
|
234
|
+
}
|
|
235
|
+
// Standard
|
|
236
|
+
else {
|
|
237
|
+
elementVal = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
console.log("applyField ->", fieldPath, elementVal);
|
|
241
|
+
lodash_1.default.set(element, fieldPath, elementVal);
|
|
242
|
+
// lodash.set(
|
|
243
|
+
// element,
|
|
244
|
+
// fieldPath,
|
|
245
|
+
// value === undefined || value === null || (typeof value === "string" && value.trim() === "")
|
|
246
|
+
// ? null
|
|
247
|
+
// : customType && typeof customType.onSave === "function"
|
|
248
|
+
// ? await customType.onSave(value, { ...payload, ...fields[key].payload })
|
|
249
|
+
// : fields[key].type === "currency" || fields[key].type === "float"
|
|
250
|
+
// ? parseFloat(value.toString().replace(",", "."))
|
|
251
|
+
// : fields[key].type === "integer"
|
|
252
|
+
// ? parseInt(value)
|
|
253
|
+
// : value
|
|
254
|
+
// );
|
|
227
255
|
}
|
|
228
256
|
}
|
|
229
257
|
return element;
|
|
@@ -307,14 +335,6 @@ class DataBuilder {
|
|
|
307
335
|
catch (e) {
|
|
308
336
|
throw e;
|
|
309
337
|
}
|
|
310
|
-
try {
|
|
311
|
-
if (typeof type.schema.afterSave === "function") {
|
|
312
|
-
yield type.schema.afterSave(element, req);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
catch (e) {
|
|
316
|
-
throw e;
|
|
317
|
-
}
|
|
318
338
|
let changedId = null;
|
|
319
339
|
if (updateId) {
|
|
320
340
|
delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
|
|
@@ -339,6 +359,14 @@ class DataBuilder {
|
|
|
339
359
|
: changedId;
|
|
340
360
|
}
|
|
341
361
|
}
|
|
362
|
+
try {
|
|
363
|
+
if (typeof type.schema.afterSave === "function") {
|
|
364
|
+
yield type.schema.afterSave(element, req);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
342
370
|
let redirect = undefined;
|
|
343
371
|
const forms = typeof type.forms === "function" ? yield type.forms(req) : type.forms;
|
|
344
372
|
if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DateFunctions = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
class DateFunctionsFacade {
|
|
9
|
+
formatDateRange(start, end) {
|
|
10
|
+
const startDate = (0, moment_1.default)(start, "YYYY-MM-DD", true);
|
|
11
|
+
const endDate = (0, moment_1.default)(end, "YYYY-MM-DD", true);
|
|
12
|
+
if (!startDate.isValid() || !endDate.isValid()) {
|
|
13
|
+
throw new Error("Ungültiges Datumsformat");
|
|
14
|
+
}
|
|
15
|
+
const startYear = startDate.year();
|
|
16
|
+
const endYear = endDate.year();
|
|
17
|
+
// Ganzes Jahr
|
|
18
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31 && startYear === endYear) {
|
|
19
|
+
return `${startYear}`;
|
|
20
|
+
}
|
|
21
|
+
// Semester
|
|
22
|
+
if (startYear === endYear) {
|
|
23
|
+
// 1. Halbjahr: 01.01 - 30.06
|
|
24
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
25
|
+
return `1. Halbjahr ${startYear}`;
|
|
26
|
+
}
|
|
27
|
+
// 2. Halbjahr: 01.07 - 31.12
|
|
28
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
29
|
+
return `2. Halbjahr ${startYear}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Quartal
|
|
33
|
+
if (startYear === endYear) {
|
|
34
|
+
// Q1: 01.01 - 31.03
|
|
35
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 2 && endDate.date() === 31) {
|
|
36
|
+
return `Q1 ${startYear}`;
|
|
37
|
+
}
|
|
38
|
+
// Q2: 01.04 - 30.06
|
|
39
|
+
if (startDate.month() === 3 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
40
|
+
return `Q2 ${startYear}`;
|
|
41
|
+
}
|
|
42
|
+
// Q3: 01.07 - 30.09
|
|
43
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 8 && endDate.date() === 30) {
|
|
44
|
+
return `Q3 ${startYear}`;
|
|
45
|
+
}
|
|
46
|
+
// Q4: 01.10 - 31.12
|
|
47
|
+
if (startDate.month() === 9 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
48
|
+
return `Q4 ${startYear}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Monat
|
|
52
|
+
if (startYear === endYear && startDate.month() === endDate.month()) {
|
|
53
|
+
if (startDate.date() === 1) {
|
|
54
|
+
const lastDay = startDate.clone().endOf("month").date();
|
|
55
|
+
if (endDate.date() === lastDay) {
|
|
56
|
+
const months = [
|
|
57
|
+
"Januar",
|
|
58
|
+
"Februar",
|
|
59
|
+
"März",
|
|
60
|
+
"April",
|
|
61
|
+
"Mai",
|
|
62
|
+
"Juni",
|
|
63
|
+
"Juli",
|
|
64
|
+
"August",
|
|
65
|
+
"September",
|
|
66
|
+
"Oktober",
|
|
67
|
+
"November",
|
|
68
|
+
"Dezember",
|
|
69
|
+
];
|
|
70
|
+
return `${months[startDate.month()]} ${startYear}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Kalenderwoche (KW)
|
|
75
|
+
const diffDays = endDate.diff(startDate, "days");
|
|
76
|
+
if (diffDays === 6 &&
|
|
77
|
+
startDate.day() === 1 && // Montag
|
|
78
|
+
endDate.day() === 0 // Sonntag
|
|
79
|
+
) {
|
|
80
|
+
const weekNumber = startDate.isoWeek();
|
|
81
|
+
return `KW-${weekNumber} ${startYear}`;
|
|
82
|
+
}
|
|
83
|
+
// Standard
|
|
84
|
+
return `${startDate.format("DD.MM.YYYY")} - ${endDate.format("DD.MM.YYYY")}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DateFunctions = new DateFunctionsFacade();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Config"), exports);
|
|
18
|
+
__exportStar(require("./Functions/DateFunctions"), exports);
|
|
18
19
|
__exportStar(require("./Functions/FileFunctions"), exports);
|
|
19
20
|
__exportStar(require("./Functions/StringFunctions"), exports);
|
|
20
21
|
__exportStar(require("./Functions/NumericFunctions"), exports);
|
package/package.json
CHANGED
|
@@ -276,19 +276,49 @@ export class DataBuilder {
|
|
|
276
276
|
);
|
|
277
277
|
}
|
|
278
278
|
} else {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
value
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
let elementVal = null;
|
|
280
|
+
if (
|
|
281
|
+
value !== undefined &&
|
|
282
|
+
value !== null &&
|
|
283
|
+
!(typeof value === "string" && value.trim() === "") &&
|
|
284
|
+
!(typeof value === "number" && value.toString().trim() === "")
|
|
285
|
+
) {
|
|
286
|
+
// Custom field onSave
|
|
287
|
+
if (customType && typeof customType.onSave === "function") {
|
|
288
|
+
elementVal = await customType.onSave(value, { ...payload, ...fields[key].payload });
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Float or currency fields
|
|
292
|
+
else if (fields[key].type === "currency" || fields[key].type === "float") {
|
|
293
|
+
elementVal = parseFloat(value.toString().replace(",", "."));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Integer field
|
|
297
|
+
else if (fields[key].type === "integer") {
|
|
298
|
+
elementVal = parseInt(value);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Standard
|
|
302
|
+
else {
|
|
303
|
+
elementVal = value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
console.log("applyField ->", fieldPath, elementVal);
|
|
308
|
+
lodash.set(element, fieldPath, elementVal);
|
|
309
|
+
// lodash.set(
|
|
310
|
+
// element,
|
|
311
|
+
// fieldPath,
|
|
312
|
+
// value === undefined || value === null || (typeof value === "string" && value.trim() === "")
|
|
313
|
+
// ? null
|
|
314
|
+
// : customType && typeof customType.onSave === "function"
|
|
315
|
+
// ? await customType.onSave(value, { ...payload, ...fields[key].payload })
|
|
316
|
+
// : fields[key].type === "currency" || fields[key].type === "float"
|
|
317
|
+
// ? parseFloat(value.toString().replace(",", "."))
|
|
318
|
+
// : fields[key].type === "integer"
|
|
319
|
+
// ? parseInt(value)
|
|
320
|
+
// : value
|
|
321
|
+
// );
|
|
292
322
|
}
|
|
293
323
|
}
|
|
294
324
|
|
|
@@ -382,14 +412,6 @@ export class DataBuilder {
|
|
|
382
412
|
throw e;
|
|
383
413
|
}
|
|
384
414
|
|
|
385
|
-
try {
|
|
386
|
-
if (typeof type.schema.afterSave === "function") {
|
|
387
|
-
await type.schema.afterSave(element, req);
|
|
388
|
-
}
|
|
389
|
-
} catch (e: any) {
|
|
390
|
-
throw e;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
415
|
let changedId: any = null;
|
|
394
416
|
if (updateId) {
|
|
395
417
|
delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
|
|
@@ -418,6 +440,14 @@ export class DataBuilder {
|
|
|
418
440
|
}
|
|
419
441
|
}
|
|
420
442
|
|
|
443
|
+
try {
|
|
444
|
+
if (typeof type.schema.afterSave === "function") {
|
|
445
|
+
await type.schema.afterSave(element, req);
|
|
446
|
+
}
|
|
447
|
+
} catch (e: any) {
|
|
448
|
+
throw e;
|
|
449
|
+
}
|
|
450
|
+
|
|
421
451
|
let redirect: any = undefined;
|
|
422
452
|
const forms = typeof type.forms === "function" ? await type.forms(req) : type.forms;
|
|
423
453
|
if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
|
|
3
|
+
class DateFunctionsFacade {
|
|
4
|
+
formatDateRange(start: string, end: string): string {
|
|
5
|
+
const startDate = moment(start, "YYYY-MM-DD", true);
|
|
6
|
+
const endDate = moment(end, "YYYY-MM-DD", true);
|
|
7
|
+
|
|
8
|
+
if (!startDate.isValid() || !endDate.isValid()) {
|
|
9
|
+
throw new Error("Ungültiges Datumsformat");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const startYear = startDate.year();
|
|
13
|
+
const endYear = endDate.year();
|
|
14
|
+
|
|
15
|
+
// Ganzes Jahr
|
|
16
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31 && startYear === endYear) {
|
|
17
|
+
return `${startYear}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Semester
|
|
21
|
+
if (startYear === endYear) {
|
|
22
|
+
// 1. Halbjahr: 01.01 - 30.06
|
|
23
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
24
|
+
return `1. Halbjahr ${startYear}`;
|
|
25
|
+
}
|
|
26
|
+
// 2. Halbjahr: 01.07 - 31.12
|
|
27
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
28
|
+
return `2. Halbjahr ${startYear}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Quartal
|
|
33
|
+
if (startYear === endYear) {
|
|
34
|
+
// Q1: 01.01 - 31.03
|
|
35
|
+
if (startDate.month() === 0 && startDate.date() === 1 && endDate.month() === 2 && endDate.date() === 31) {
|
|
36
|
+
return `Q1 ${startYear}`;
|
|
37
|
+
}
|
|
38
|
+
// Q2: 01.04 - 30.06
|
|
39
|
+
if (startDate.month() === 3 && startDate.date() === 1 && endDate.month() === 5 && endDate.date() === 30) {
|
|
40
|
+
return `Q2 ${startYear}`;
|
|
41
|
+
}
|
|
42
|
+
// Q3: 01.07 - 30.09
|
|
43
|
+
if (startDate.month() === 6 && startDate.date() === 1 && endDate.month() === 8 && endDate.date() === 30) {
|
|
44
|
+
return `Q3 ${startYear}`;
|
|
45
|
+
}
|
|
46
|
+
// Q4: 01.10 - 31.12
|
|
47
|
+
if (startDate.month() === 9 && startDate.date() === 1 && endDate.month() === 11 && endDate.date() === 31) {
|
|
48
|
+
return `Q4 ${startYear}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Monat
|
|
53
|
+
if (startYear === endYear && startDate.month() === endDate.month()) {
|
|
54
|
+
if (startDate.date() === 1) {
|
|
55
|
+
const lastDay = startDate.clone().endOf("month").date();
|
|
56
|
+
if (endDate.date() === lastDay) {
|
|
57
|
+
const months = [
|
|
58
|
+
"Januar",
|
|
59
|
+
"Februar",
|
|
60
|
+
"März",
|
|
61
|
+
"April",
|
|
62
|
+
"Mai",
|
|
63
|
+
"Juni",
|
|
64
|
+
"Juli",
|
|
65
|
+
"August",
|
|
66
|
+
"September",
|
|
67
|
+
"Oktober",
|
|
68
|
+
"November",
|
|
69
|
+
"Dezember",
|
|
70
|
+
];
|
|
71
|
+
return `${months[startDate.month()]} ${startYear}`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Kalenderwoche (KW)
|
|
77
|
+
const diffDays = endDate.diff(startDate, "days");
|
|
78
|
+
if (
|
|
79
|
+
diffDays === 6 &&
|
|
80
|
+
startDate.day() === 1 && // Montag
|
|
81
|
+
endDate.day() === 0 // Sonntag
|
|
82
|
+
) {
|
|
83
|
+
const weekNumber = startDate.isoWeek();
|
|
84
|
+
return `KW-${weekNumber} ${startYear}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Standard
|
|
88
|
+
return `${startDate.format("DD.MM.YYYY")} - ${endDate.format("DD.MM.YYYY")}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const DateFunctions = new DateFunctionsFacade();
|