@webtypen/webframez-core 0.2.16 → 0.2.17
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request } from "../Router/Request";
|
|
2
|
-
type
|
|
2
|
+
export type DatatableAutoApplyType = "begin" | "end" | null;
|
|
3
3
|
export declare class Datatable {
|
|
4
4
|
collection: string | Function;
|
|
5
5
|
aggregation: {
|
|
@@ -19,8 +19,8 @@ export declare class Datatable {
|
|
|
19
19
|
perPage: number;
|
|
20
20
|
onRow?: Function;
|
|
21
21
|
onAttributes?: Function;
|
|
22
|
-
autoApplyFilter:
|
|
23
|
-
autoApplySearch:
|
|
22
|
+
autoApplyFilter: DatatableAutoApplyType;
|
|
23
|
+
autoApplySearch: DatatableAutoApplyType;
|
|
24
24
|
getInit(req: Request): Promise<any>;
|
|
25
25
|
getAggregation(req: Request): Promise<any>;
|
|
26
26
|
getSubAggregation(req: Request): Promise<any>;
|
|
@@ -39,4 +39,3 @@ export declare class Datatable {
|
|
|
39
39
|
private formatFilterEntryVal;
|
|
40
40
|
getFilterMatch(req: Request, searchOrFilter: any): Promise<any>;
|
|
41
41
|
}
|
|
42
|
-
export {};
|
|
@@ -67,18 +67,18 @@ class Datatable {
|
|
|
67
67
|
const aggr = typeof this.aggregation === "function" ? yield this.aggregation(req) : this.aggregation;
|
|
68
68
|
if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
|
|
69
69
|
if (this.autoApplyFilter === "begin") {
|
|
70
|
-
return [{ $match: Object.assign({}, this.getFilterMatch(req, req.body.filter)) }, ...aggr];
|
|
70
|
+
return [{ $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }, ...aggr];
|
|
71
71
|
}
|
|
72
72
|
else if (this.autoApplyFilter === "end") {
|
|
73
|
-
return [...aggr, { $match: Object.assign({}, this.getFilterMatch(req, req.body.filter)) }];
|
|
73
|
+
return [...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.filter))) }];
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
|
|
77
77
|
if (this.autoApplySearch === "begin") {
|
|
78
|
-
return [{ $match: Object.assign({}, this.getFilterMatch(req, req.body.search)) }, ...aggr];
|
|
78
|
+
return [{ $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }, ...aggr];
|
|
79
79
|
}
|
|
80
80
|
else if (this.autoApplySearch === "end") {
|
|
81
|
-
return [...aggr, { $match: Object.assign({}, this.getFilterMatch(req, req.body.search)) }];
|
|
81
|
+
return [...aggr, { $match: Object.assign({}, (yield this.getFilterMatch(req, req.body.search))) }];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
return aggr;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { DBConnection } from "../Database/DBConnection";
|
|
|
2
2
|
import { NumericFunctions } from "../Functions/NumericFunctions";
|
|
3
3
|
import { Request } from "../Router/Request";
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
export type DatatableAutoApplyType = "begin" | "end" | null;
|
|
6
6
|
|
|
7
7
|
export class Datatable {
|
|
8
8
|
collection: string | Function = "";
|
|
@@ -15,8 +15,8 @@ export class Datatable {
|
|
|
15
15
|
perPage: number = 25;
|
|
16
16
|
onRow?: Function;
|
|
17
17
|
onAttributes?: Function;
|
|
18
|
-
autoApplyFilter:
|
|
19
|
-
autoApplySearch:
|
|
18
|
+
autoApplyFilter: DatatableAutoApplyType = "begin";
|
|
19
|
+
autoApplySearch: DatatableAutoApplyType = null;
|
|
20
20
|
|
|
21
21
|
async getInit(req: Request) {
|
|
22
22
|
const out: any = { table: req.body._table };
|
|
@@ -67,15 +67,15 @@ export class Datatable {
|
|
|
67
67
|
const aggr = typeof this.aggregation === "function" ? await this.aggregation(req) : this.aggregation;
|
|
68
68
|
if (this.autoApplyFilter && req.body.filter && typeof req.body.filter === "object") {
|
|
69
69
|
if (this.autoApplyFilter === "begin") {
|
|
70
|
-
return [{ $match: { ...this.getFilterMatch(req, req.body.filter) } }, ...aggr];
|
|
70
|
+
return [{ $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }, ...aggr];
|
|
71
71
|
} else if (this.autoApplyFilter === "end") {
|
|
72
|
-
return [...aggr, { $match: { ...this.getFilterMatch(req, req.body.filter) } }];
|
|
72
|
+
return [...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.filter)) } }];
|
|
73
73
|
}
|
|
74
74
|
} else if (this.autoApplySearch && req.body.search && typeof req.body.search === "object") {
|
|
75
75
|
if (this.autoApplySearch === "begin") {
|
|
76
|
-
return [{ $match: { ...this.getFilterMatch(req, req.body.search) } }, ...aggr];
|
|
76
|
+
return [{ $match: { ...(await this.getFilterMatch(req, req.body.search)) } }, ...aggr];
|
|
77
77
|
} else if (this.autoApplySearch === "end") {
|
|
78
|
-
return [...aggr, { $match: { ...this.getFilterMatch(req, req.body.search) } }];
|
|
78
|
+
return [...aggr, { $match: { ...(await this.getFilterMatch(req, req.body.search)) } }];
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
return aggr;
|