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