identity-admin 1.15.0 → 1.16.0
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/lib/controllers/DashboardController.d.ts +1 -1
- package/lib/controllers/DashboardController.js +5 -3
- package/lib/helpers/FiltersHelper.d.ts +4 -2
- package/lib/helpers/FiltersHelper.js +85 -51
- package/lib/helpers/ResourceGenerator.js +2 -1
- package/lib/helpers/ResourceHelper.js +7 -2
- package/lib/locales/en.json +3 -1
- package/lib/types/IResourceFile.d.ts +14 -1
- package/lib/types/helpers.d.ts +2 -1
- package/lib/types/helpers.js +1 -0
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ export default class DashboardController {
|
|
|
27
27
|
}, scope: string): {
|
|
28
28
|
[key: string]: any;
|
|
29
29
|
};
|
|
30
|
-
protected
|
|
30
|
+
protected getVisibileExtraActions(currentUser: Document, record: any, resource: IResourceFile, repository: any, modelName: string): Promise<string[] | undefined>;
|
|
31
31
|
index(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
32
32
|
create(req: IRequest, res: Response): Promise<void>;
|
|
33
33
|
update(req: IRequest, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
@@ -81,7 +81,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
81
81
|
getScopeFilter(filter, scope) {
|
|
82
82
|
return {};
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
getVisibileExtraActions(currentUser, record, resource, repository, modelName) {
|
|
85
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
86
|
const data = {
|
|
87
87
|
record: record.toObject(),
|
|
@@ -159,7 +159,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
159
159
|
if (searchableSubString) {
|
|
160
160
|
filter = this.getSearchableSubStringFilter(resource, filter, searchableSubString);
|
|
161
161
|
}
|
|
162
|
-
filter = FiltersHelper_1.default.appendFilters(filter, filters);
|
|
162
|
+
filter = yield FiltersHelper_1.default.appendFilters(filter, filters, resource);
|
|
163
163
|
const crudOperations = resource.properties.crudOperations;
|
|
164
164
|
if (crudOperations && crudOperations.index && crudOperations.index.before) {
|
|
165
165
|
filter = yield crudOperations.index.before(req, filter, currentUser);
|
|
@@ -186,7 +186,9 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
186
186
|
var documents = [];
|
|
187
187
|
for (var i = 0; i < records.length; i++) {
|
|
188
188
|
const record = records[i];
|
|
189
|
-
|
|
189
|
+
//let record: any = records[i]
|
|
190
|
+
//const recordFlatten = await ResourcesHelper.addExtraFields(modifiedResource.listProperties, modifiedResource.properties.model, record.toObject(), StringUtils.lowerCaseFirstLetter(modifiedResource.properties.modelName), resource)
|
|
191
|
+
const extraActionKeys = yield this.getVisibileExtraActions(currentUser, record, resource, repository, modifiedResource.properties.modelName);
|
|
190
192
|
if (extraActionKeys) {
|
|
191
193
|
const recordFlatten = record.toObject();
|
|
192
194
|
recordFlatten.extraActionKeys = extraActionKeys;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { IResourceFile } from "../types/IResourceFile";
|
|
1
2
|
export default class FilterHelper {
|
|
2
3
|
static appendFilters(filterQuery: {
|
|
3
4
|
[key: string]: any;
|
|
4
|
-
}, filters: string[] | undefined): {
|
|
5
|
+
}, filters: string[] | undefined, resource?: IResourceFile): Promise<{
|
|
5
6
|
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
+
}>;
|
|
8
|
+
private static getVirtualFilter;
|
|
7
9
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -8,64 +17,89 @@ const helpers_1 = require("../types/helpers");
|
|
|
8
17
|
const LocalizedStringHelper_1 = __importDefault(require("./LocalizedStringHelper"));
|
|
9
18
|
var pluralize = require('pluralize');
|
|
10
19
|
class FilterHelper {
|
|
11
|
-
static appendFilters(filterQuery, filters) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (var i = 0; i < filters.length; i++) {
|
|
16
|
-
const filter = filters[i];
|
|
17
|
-
if (!filter || filter === '' || !filter.includes(';;')) {
|
|
18
|
-
continue;
|
|
20
|
+
static appendFilters(filterQuery, filters, resource) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (!filters) {
|
|
23
|
+
return filterQuery;
|
|
19
24
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const fieldName = rangeObject[0];
|
|
25
|
-
const fromToObject = rangeObject[1].split(',');
|
|
26
|
-
const from = fromToObject[0].split('=')[1];
|
|
27
|
-
const to = fromToObject[1].split('=')[1];
|
|
28
|
-
var filterRange = {};
|
|
29
|
-
if (from && from !== '' && from !== 'null') {
|
|
30
|
-
filterRange.$gte = from;
|
|
25
|
+
for (var i = 0; i < filters.length; i++) {
|
|
26
|
+
const filter = filters[i];
|
|
27
|
+
if (!filter || filter === '' || !filter.includes(';;')) {
|
|
28
|
+
continue;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const filterQueryString = filter.split(';;');
|
|
31
|
+
const fieldType = filterQueryString[1];
|
|
32
|
+
if (fieldType === helpers_1.FieldTypes.NUMBER || fieldType === helpers_1.FieldTypes.DATE) {
|
|
33
|
+
const rangeObject = filterQueryString[0].split(':');
|
|
34
|
+
const fieldName = rangeObject[0];
|
|
35
|
+
const fromToObject = rangeObject[1].split(',');
|
|
36
|
+
const from = fromToObject[0].split('=')[1];
|
|
37
|
+
const to = fromToObject[1].split('=')[1];
|
|
38
|
+
var filterRange = {};
|
|
39
|
+
if (from && from !== '' && from !== 'null') {
|
|
40
|
+
filterRange.$gte = from;
|
|
41
|
+
}
|
|
42
|
+
if (to && to !== '' && to !== 'null') {
|
|
43
|
+
filterRange.$lte = to;
|
|
44
|
+
}
|
|
45
|
+
if (filterRange.$lte || filterRange.$gte) {
|
|
46
|
+
filterQuery[fieldName] = filterRange;
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
34
49
|
}
|
|
35
|
-
if (
|
|
36
|
-
|
|
50
|
+
if (!filterQueryString[0] || !fieldType || !filterQueryString[0].includes('=')) {
|
|
51
|
+
continue;
|
|
37
52
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case helpers_1.FieldTypes.OBJECTID:
|
|
48
|
-
if (!mongoose_1.default.isValidObjectId(value)) {
|
|
53
|
+
const splittedQueryString = filterQueryString[0].split('=');
|
|
54
|
+
const key = splittedQueryString[0];
|
|
55
|
+
const value = splittedQueryString[1].includes('%20') ? splittedQueryString[1].replace(/%20/g, ' ') : splittedQueryString[1];
|
|
56
|
+
switch (fieldType) {
|
|
57
|
+
case helpers_1.FieldTypes.OBJECTID:
|
|
58
|
+
if (!mongoose_1.default.isValidObjectId(value)) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
filterQuery[key] = value;
|
|
49
62
|
break;
|
|
50
|
-
|
|
63
|
+
case helpers_1.FieldTypes.STRING:
|
|
64
|
+
filterQuery[key] = new RegExp(value, 'i');
|
|
65
|
+
break;
|
|
66
|
+
case helpers_1.FieldTypes.LOCALIZEDSTRING:
|
|
67
|
+
filterQuery.$or = [
|
|
68
|
+
LocalizedStringHelper_1.default.getFilterObject(key, "0", new RegExp(value, 'i')),
|
|
69
|
+
LocalizedStringHelper_1.default.getFilterObject(key, "1", new RegExp(value, 'i')),
|
|
70
|
+
];
|
|
71
|
+
break;
|
|
72
|
+
case helpers_1.FieldTypes.REFERENCE:
|
|
73
|
+
if (value !== 'null' && value !== 'undefined') {
|
|
74
|
+
filterQuery = yield this.getVirtualFilter(filterQuery, key, value, resource);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
if (value !== 'null' && value !== 'undefined') {
|
|
79
|
+
filterQuery[key] = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return filterQuery;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
static getVirtualFilter(filterQuery, key, value, resource) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
if (resource && resource.properties.model) {
|
|
89
|
+
const virtuals = resource.properties.model.virtuals;
|
|
90
|
+
if (virtuals && virtuals[key] && virtuals[key].showIn === helpers_1.Virtuals.FILTER && virtuals[key].handler) {
|
|
91
|
+
const virtual = virtuals[key];
|
|
92
|
+
filterQuery = yield virtual.handler(filterQuery, value);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
51
95
|
filterQuery[key] = value;
|
|
52
|
-
|
|
53
|
-
case helpers_1.FieldTypes.STRING:
|
|
54
|
-
filterQuery[key] = new RegExp(value, 'i');
|
|
55
|
-
break;
|
|
56
|
-
case helpers_1.FieldTypes.LOCALIZEDSTRING:
|
|
57
|
-
filterQuery.$or = [
|
|
58
|
-
LocalizedStringHelper_1.default.getFilterObject(key, "0", new RegExp(value, 'i')),
|
|
59
|
-
LocalizedStringHelper_1.default.getFilterObject(key, "1", new RegExp(value, 'i')),
|
|
60
|
-
];
|
|
61
|
-
break;
|
|
62
|
-
default:
|
|
63
|
-
if (value !== 'null' && value !== 'undefined') {
|
|
64
|
-
filterQuery[key] = value;
|
|
65
|
-
}
|
|
96
|
+
}
|
|
66
97
|
}
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
else {
|
|
99
|
+
filterQuery[key] = value;
|
|
100
|
+
}
|
|
101
|
+
return filterQuery;
|
|
102
|
+
});
|
|
69
103
|
}
|
|
70
104
|
}
|
|
71
105
|
exports.default = FilterHelper;
|
|
@@ -59,6 +59,7 @@ class ResourceGenerator {
|
|
|
59
59
|
const modifiedListProperties = modifiedProperties[0];
|
|
60
60
|
const modifiedShowProperties = modifiedProperties[1];
|
|
61
61
|
const modifiedFormProperties = modifiedProperties[2];
|
|
62
|
+
const modifiedFilterProperties = modifiedProperties[3];
|
|
62
63
|
if (!resource.properties.parent) {
|
|
63
64
|
modifiedResource.properties.parent = SetupParent;
|
|
64
65
|
}
|
|
@@ -76,7 +77,7 @@ class ResourceGenerator {
|
|
|
76
77
|
modifiedResource.showProperties = modifiedShowProperties;
|
|
77
78
|
}
|
|
78
79
|
if (!resource.filterProperties) {
|
|
79
|
-
modifiedResource.filterProperties =
|
|
80
|
+
modifiedResource.filterProperties = modifiedFilterProperties;
|
|
80
81
|
}
|
|
81
82
|
if (!resource.listProperties) {
|
|
82
83
|
modifiedResource.listProperties = ResourceHelper_1.default.exchangeFirstFieldWithTitle(JSON.parse(JSON.stringify(modifiedListProperties)), title);
|
|
@@ -247,8 +247,9 @@ class ResourcesHelper {
|
|
|
247
247
|
var showProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
248
248
|
var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
249
249
|
var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
250
|
+
var filterProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
250
251
|
if (!model || !model.virtuals || !(Object.keys(model.virtuals))) {
|
|
251
|
-
return [listProperties, showProperties, formProperties];
|
|
252
|
+
return [listProperties, showProperties, formProperties, filterProperties];
|
|
252
253
|
}
|
|
253
254
|
const virtualFields = model.virtuals;
|
|
254
255
|
for (const extraField in virtualFields) {
|
|
@@ -263,15 +264,19 @@ class ResourcesHelper {
|
|
|
263
264
|
case helpers_1.Virtuals.FORM:
|
|
264
265
|
formProperties.push(extraField);
|
|
265
266
|
break;
|
|
267
|
+
case helpers_1.Virtuals.FILTER:
|
|
268
|
+
filterProperties.push(extraField);
|
|
269
|
+
break;
|
|
266
270
|
}
|
|
267
271
|
}
|
|
268
272
|
else {
|
|
269
273
|
showProperties.push(extraField);
|
|
270
274
|
listProperties.push(extraField);
|
|
271
275
|
formProperties.push(extraField);
|
|
276
|
+
filterProperties.push(extraField);
|
|
272
277
|
}
|
|
273
278
|
}
|
|
274
|
-
return [listProperties, showProperties, formProperties];
|
|
279
|
+
return [listProperties, showProperties, formProperties, filterProperties];
|
|
275
280
|
}
|
|
276
281
|
static manageFields(schema, title, hiddenProperties) {
|
|
277
282
|
var arrayOfFields = [];
|
package/lib/locales/en.json
CHANGED
|
@@ -212,6 +212,11 @@ export interface IFieldValue {
|
|
|
212
212
|
* @default false
|
|
213
213
|
*/
|
|
214
214
|
withTime?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Specify the api route that to be called for getting the referenced values
|
|
217
|
+
* @default undefined
|
|
218
|
+
*/
|
|
219
|
+
apiRoute?: string;
|
|
215
220
|
}
|
|
216
221
|
export interface IVirtualValue {
|
|
217
222
|
/**
|
|
@@ -234,8 +239,16 @@ export interface IVirtualValue {
|
|
|
234
239
|
* Define Virtual field's resource in case of ref type or array of ref type
|
|
235
240
|
*/
|
|
236
241
|
resource?: Model<any, any>;
|
|
242
|
+
/**
|
|
243
|
+
* Define Filter query creator required in case of showIn Filter
|
|
244
|
+
*/
|
|
245
|
+
handler?: (filterQuery: {
|
|
246
|
+
[key: string]: any;
|
|
247
|
+
}, value: any | any[]) => Promise<{
|
|
248
|
+
[key: string]: any;
|
|
249
|
+
}>;
|
|
237
250
|
}
|
|
238
|
-
interface IModel {
|
|
251
|
+
export interface IModel {
|
|
239
252
|
/**
|
|
240
253
|
* virtual data props
|
|
241
254
|
*/
|
package/lib/types/helpers.d.ts
CHANGED
package/lib/types/helpers.js
CHANGED