@webtypen/webframez-core 0.2.65 → 0.2.68
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.
|
@@ -201,7 +201,7 @@ class DataBuilder {
|
|
|
201
201
|
newData.forms = yield type.forms(req);
|
|
202
202
|
}
|
|
203
203
|
for (let form in type.forms) {
|
|
204
|
-
if (!type.forms[form] || !type.forms[form].fields
|
|
204
|
+
if (!type.forms[form] || !type.forms[form].fields) {
|
|
205
205
|
continue;
|
|
206
206
|
}
|
|
207
207
|
newData.forms[form] = {};
|
|
@@ -220,6 +220,9 @@ class DataBuilder {
|
|
|
220
220
|
else if (type.forms[form].fields) {
|
|
221
221
|
newData.forms[form].fields = JSON.parse(JSON.stringify(type.forms[form].fields));
|
|
222
222
|
}
|
|
223
|
+
if (!newData.forms[form].fields || newData.forms[form].fields.length < 1) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
223
226
|
newData.forms[form].allowDeletion =
|
|
224
227
|
(typeof type.forms[form].allowDeletion === "boolean" && type.forms[form].allowDeletion) ||
|
|
225
228
|
(typeof type.forms[form].allowDeletion === "function" && (yield type.forms[form].allowDeletion(req)))
|
|
@@ -18,6 +18,8 @@ export declare class Datatable {
|
|
|
18
18
|
perPage: number;
|
|
19
19
|
onRow?: Function;
|
|
20
20
|
onAttributes?: Function;
|
|
21
|
+
onInit?: Function;
|
|
22
|
+
onData?: Function;
|
|
21
23
|
autoApplyFilter: "begin" | "end" | null;
|
|
22
24
|
autoApplySearch: "begin" | "end" | null;
|
|
23
25
|
logAggregation: boolean;
|
|
@@ -66,6 +66,9 @@ class Datatable {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
yield Promise.all(promises);
|
|
69
|
+
if (typeof this.onInit === "function") {
|
|
70
|
+
yield this.onInit(req, out);
|
|
71
|
+
}
|
|
69
72
|
return out;
|
|
70
73
|
});
|
|
71
74
|
}
|
|
@@ -77,19 +80,29 @@ class Datatable {
|
|
|
77
80
|
}
|
|
78
81
|
const aggr = typeof this.aggregation === "function" ? yield this.aggregation(req) : this.aggregation;
|
|
79
82
|
if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
|
|
83
|
+
const filterMatch = yield this.getFilterMatch(req, req.body.filter);
|
|
80
84
|
if (this.autoApplyFilter === "begin") {
|
|
81
|
-
return
|
|
85
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
86
|
+
? [...prefix, { $match: Object.assign({}, filterMatch) }, ...aggr]
|
|
87
|
+
: [...prefix, ...aggr];
|
|
82
88
|
}
|
|
83
89
|
else if (this.autoApplyFilter === "end") {
|
|
84
|
-
return
|
|
90
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
91
|
+
? [...prefix, ...aggr, { $match: Object.assign({}, filterMatch) }]
|
|
92
|
+
: [...prefix, ...aggr];
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
|
|
96
|
+
const filterMatch = yield this.getFilterMatch(req, req.body.search);
|
|
88
97
|
if (this.autoApplySearch === "begin") {
|
|
89
|
-
return
|
|
98
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
99
|
+
? [...prefix, { $match: Object.assign({}, filterMatch) }, ...aggr]
|
|
100
|
+
: [...prefix, ...aggr];
|
|
90
101
|
}
|
|
91
102
|
else if (this.autoApplySearch === "end") {
|
|
92
|
-
return
|
|
103
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
104
|
+
? [...prefix, ...aggr, { $match: Object.assign({}, filterMatch) }]
|
|
105
|
+
: [...prefix, ...aggr];
|
|
93
106
|
}
|
|
94
107
|
}
|
|
95
108
|
if (prefix && prefix.length > 0) {
|
|
@@ -216,7 +229,7 @@ class Datatable {
|
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
|
-
|
|
232
|
+
const data = {
|
|
220
233
|
page: page,
|
|
221
234
|
max_entries: stats && stats[0] && stats[0].count ? stats[0].count : 0,
|
|
222
235
|
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count / perPage) : 0,
|
|
@@ -224,6 +237,10 @@ class Datatable {
|
|
|
224
237
|
entries: results,
|
|
225
238
|
sums: sums,
|
|
226
239
|
};
|
|
240
|
+
if (typeof this.onData === "function") {
|
|
241
|
+
yield this.onData(req, data);
|
|
242
|
+
}
|
|
243
|
+
return data;
|
|
227
244
|
});
|
|
228
245
|
}
|
|
229
246
|
getTotalData(req) {
|
package/package.json
CHANGED
|
@@ -254,7 +254,7 @@ export class DataBuilder {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
for (let form in type.forms) {
|
|
257
|
-
if (!type.forms[form] || !type.forms[form].fields
|
|
257
|
+
if (!type.forms[form] || !type.forms[form].fields) {
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -275,6 +275,10 @@ export class DataBuilder {
|
|
|
275
275
|
newData.forms[form].fields = JSON.parse(JSON.stringify(type.forms[form].fields));
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
if (!newData.forms[form].fields || newData.forms[form].fields.length < 1) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
|
|
278
282
|
newData.forms[form].allowDeletion =
|
|
279
283
|
(typeof type.forms[form].allowDeletion === "boolean" && type.forms[form].allowDeletion) ||
|
|
280
284
|
(typeof type.forms[form].allowDeletion === "function" && (await type.forms[form].allowDeletion(req)))
|
|
@@ -14,6 +14,8 @@ export class Datatable {
|
|
|
14
14
|
perPage: number = 25;
|
|
15
15
|
onRow?: Function;
|
|
16
16
|
onAttributes?: Function;
|
|
17
|
+
onInit?: Function;
|
|
18
|
+
onData?: Function;
|
|
17
19
|
autoApplyFilter: "begin" | "end" | null = "begin";
|
|
18
20
|
autoApplySearch: "begin" | "end" | null = null;
|
|
19
21
|
logAggregation = false;
|
|
@@ -62,6 +64,10 @@ export class Datatable {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
await Promise.all(promises);
|
|
67
|
+
|
|
68
|
+
if (typeof this.onInit === "function") {
|
|
69
|
+
await this.onInit(req, out);
|
|
70
|
+
}
|
|
65
71
|
return out;
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -73,16 +79,26 @@ export class Datatable {
|
|
|
73
79
|
|
|
74
80
|
const aggr = typeof this.aggregation === "function" ? await this.aggregation(req) : this.aggregation;
|
|
75
81
|
if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
|
|
82
|
+
const filterMatch = await this.getFilterMatch(req, req.body.filter);
|
|
76
83
|
if (this.autoApplyFilter === "begin") {
|
|
77
|
-
return
|
|
84
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
85
|
+
? [...prefix, { $match: { ...filterMatch } }, ...aggr]
|
|
86
|
+
: [...prefix, ...aggr];
|
|
78
87
|
} else if (this.autoApplyFilter === "end") {
|
|
79
|
-
return
|
|
88
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
89
|
+
? [...prefix, ...aggr, { $match: { ...filterMatch } }]
|
|
90
|
+
: [...prefix, ...aggr];
|
|
80
91
|
}
|
|
81
92
|
} else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
|
|
93
|
+
const filterMatch = await this.getFilterMatch(req, req.body.search);
|
|
82
94
|
if (this.autoApplySearch === "begin") {
|
|
83
|
-
return
|
|
95
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
96
|
+
? [...prefix, { $match: { ...filterMatch } }, ...aggr]
|
|
97
|
+
: [...prefix, ...aggr];
|
|
84
98
|
} else if (this.autoApplySearch === "end") {
|
|
85
|
-
return
|
|
99
|
+
return filterMatch && Object.keys(filterMatch).length > 0
|
|
100
|
+
? [...prefix, ...aggr, { $match: { ...filterMatch } }]
|
|
101
|
+
: [...prefix, ...aggr];
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
|
|
@@ -222,7 +238,7 @@ export class Datatable {
|
|
|
222
238
|
}
|
|
223
239
|
}
|
|
224
240
|
|
|
225
|
-
|
|
241
|
+
const data = {
|
|
226
242
|
page: page,
|
|
227
243
|
max_entries: stats && stats[0] && stats[0].count ? stats[0].count : 0,
|
|
228
244
|
total_pages: stats && stats[0] && stats[0].count > 0 ? Math.ceil(stats[0].count / perPage) : 0,
|
|
@@ -230,6 +246,11 @@ export class Datatable {
|
|
|
230
246
|
entries: results,
|
|
231
247
|
sums: sums,
|
|
232
248
|
};
|
|
249
|
+
|
|
250
|
+
if (typeof this.onData === "function") {
|
|
251
|
+
await this.onData(req, data);
|
|
252
|
+
}
|
|
253
|
+
return data;
|
|
233
254
|
}
|
|
234
255
|
|
|
235
256
|
async getTotalData(req: Request) {
|