@webtypen/webframez-core 0.2.64 → 0.2.67

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.
@@ -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 [...prefix, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }, ...aggr];
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 [...prefix, ...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }];
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 [...prefix, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }, ...aggr];
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 [...prefix, ...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }];
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
- return {
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) {
@@ -291,7 +308,7 @@ class Datatable {
291
308
  value = true;
292
309
  }
293
310
  else if (entry.value === "false") {
294
- value = false;
311
+ value = { $ne: true };
295
312
  }
296
313
  }
297
314
  else if (valueClean) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.2.64",
3
+ "version": "0.2.67",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -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 [...prefix, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }, ...aggr];
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 [...prefix, ...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }];
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 [...prefix, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }, ...aggr];
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 [...prefix, ...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }];
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
- return {
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) {
@@ -297,7 +318,7 @@ export class Datatable {
297
318
  if (entry.value === "true") {
298
319
  value = true;
299
320
  } else if (entry.value === "false") {
300
- value = false;
321
+ value = { $ne: true };
301
322
  }
302
323
  } else if (valueClean) {
303
324
  if (valueClean.toString().trim() === "==null") {