@steedos/service-object-graphql 3.0.13-beta.9 → 3.0.13
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/generateActionGraphqlProp.js +33 -11
- package/lib/generateActionGraphqlProp.js.map +1 -1
- package/lib/generateSettingsGraphql.js +129 -107
- package/lib/generateSettingsGraphql.js.map +1 -1
- package/lib/getGraphqlActions.js +742 -1020
- package/lib/getGraphqlActions.js.map +1 -1
- package/lib/getPrimaryFieldType.js +9 -9
- package/lib/getPrimaryFieldType.js.map +1 -1
- package/lib/getQueryFields.js +10 -10
- package/lib/getQueryFields.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/utils.js +15 -22
- package/lib/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/getGraphqlActions.ts +2 -6
- package/tsconfig.json +3 -7
package/lib/getGraphqlActions.js
CHANGED
|
@@ -2,100 +2,78 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGraphqlActions = getGraphqlActions;
|
|
4
4
|
exports.translateToUI = translateToUI;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var lodash_1 = require("lodash");
|
|
5
|
+
const _ = require("underscore");
|
|
6
|
+
const i18n_1 = require("@steedos/i18n");
|
|
7
|
+
const moment = require("moment");
|
|
8
|
+
const objectql_1 = require("@steedos/objectql");
|
|
9
|
+
const consts_1 = require("./consts");
|
|
10
|
+
const getQueryFields_1 = require("./getQueryFields");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const lodash_1 = require("lodash");
|
|
14
13
|
function getGraphqlActions() {
|
|
15
|
-
|
|
16
|
-
actions[
|
|
17
|
-
handler: function (ctx) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
case 1:
|
|
47
|
-
result = _c.sent();
|
|
48
|
-
if (id.length > result.length) {
|
|
49
|
-
(0, lodash_1.each)(id, function (_id) {
|
|
50
|
-
var _a;
|
|
51
|
-
if (!(0, lodash_1.find)(result, function (doc) {
|
|
52
|
-
return doc[referenceToField || "_id"] === _id;
|
|
53
|
-
})) {
|
|
54
|
-
result.push((_a = {}, _a[referenceToField || "_id"] = _id, _a));
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (_.isString(ctx.params.id)) {
|
|
59
|
-
return [2, result[0]];
|
|
60
|
-
}
|
|
61
|
-
return [2, (0, lodash_1.sortBy)(result, function (doc) {
|
|
62
|
-
return id.indexOf(doc[referenceToField || "_id"]);
|
|
63
|
-
})];
|
|
14
|
+
let actions = {};
|
|
15
|
+
actions[`${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.EXPAND_SUFFIX}`] = {
|
|
16
|
+
handler: async function (ctx) {
|
|
17
|
+
let { id, objectName, referenceToField } = ctx.params;
|
|
18
|
+
if (!id) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
22
|
+
let obj = steedosSchema.getObject(objectName);
|
|
23
|
+
if (_.isString(id)) {
|
|
24
|
+
id = [id];
|
|
25
|
+
}
|
|
26
|
+
const selector = {
|
|
27
|
+
filters: [[referenceToField || "_id", "in", id]],
|
|
28
|
+
};
|
|
29
|
+
const spaceId = ctx.meta.spaceId || ctx.meta.user?.spaceId;
|
|
30
|
+
if (referenceToField &&
|
|
31
|
+
referenceToField != "_id" &&
|
|
32
|
+
objectName != "users" &&
|
|
33
|
+
objectName != "spaces" &&
|
|
34
|
+
spaceId) {
|
|
35
|
+
selector.filters.push(["space", "=", spaceId]);
|
|
36
|
+
}
|
|
37
|
+
delete selector.fields;
|
|
38
|
+
const result = await obj.find(selector);
|
|
39
|
+
if (id.length > result.length) {
|
|
40
|
+
(0, lodash_1.each)(id, (_id) => {
|
|
41
|
+
if (!(0, lodash_1.find)(result, (doc) => {
|
|
42
|
+
return doc[referenceToField || "_id"] === _id;
|
|
43
|
+
})) {
|
|
44
|
+
result.push({ [referenceToField || "_id"]: _id });
|
|
64
45
|
}
|
|
65
46
|
});
|
|
47
|
+
}
|
|
48
|
+
if (_.isString(ctx.params.id)) {
|
|
49
|
+
return result[0];
|
|
50
|
+
}
|
|
51
|
+
return (0, lodash_1.sortBy)(result, (doc) => {
|
|
52
|
+
return id.indexOf(doc[referenceToField || "_id"]);
|
|
66
53
|
});
|
|
67
54
|
},
|
|
68
55
|
};
|
|
69
|
-
actions[
|
|
70
|
-
handler: function (ctx) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (params.filters) {
|
|
88
|
-
filters.push(params.filters);
|
|
89
|
-
}
|
|
90
|
-
params.filters = filters;
|
|
91
|
-
return [4, object.find(params, userSession)];
|
|
92
|
-
case 1: return [2, _a.sent()];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
56
|
+
actions[`${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.RELATED_PREFIX}_enabled`] = {
|
|
57
|
+
handler: async function (ctx) {
|
|
58
|
+
let params = ctx.params;
|
|
59
|
+
let { _parentId, _related_params } = params;
|
|
60
|
+
let { objectName, parentObjectName, foreignKey } = _related_params;
|
|
61
|
+
let userSession = ctx.meta.user;
|
|
62
|
+
let steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
63
|
+
let object = steedosSchema.getObject(objectName);
|
|
64
|
+
let filters = [];
|
|
65
|
+
filters = [
|
|
66
|
+
[`${foreignKey}.o`, "=", parentObjectName],
|
|
67
|
+
[`${foreignKey}.ids`, "=", _parentId],
|
|
68
|
+
];
|
|
69
|
+
if (params.filters) {
|
|
70
|
+
filters.push(params.filters);
|
|
71
|
+
}
|
|
72
|
+
params.filters = filters;
|
|
73
|
+
return await object.find(params, userSession);
|
|
96
74
|
},
|
|
97
75
|
};
|
|
98
|
-
actions[
|
|
76
|
+
actions[`${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.RELATED_PREFIX}`] = {
|
|
99
77
|
params: {
|
|
100
78
|
fields: { type: "array", items: "string", optional: true },
|
|
101
79
|
filters: [
|
|
@@ -116,961 +94,705 @@ function getGraphqlActions() {
|
|
|
116
94
|
},
|
|
117
95
|
},
|
|
118
96
|
},
|
|
119
|
-
handler: function (ctx) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return [2, []];
|
|
158
|
-
}
|
|
159
|
-
if (params.top > consts_1.QUERY_DOCS_TOP) {
|
|
160
|
-
params.top = consts_1.QUERY_DOCS_TOP;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return [4, object.find(params, userSession)];
|
|
164
|
-
case 2: return [2, _a.sent()];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
97
|
+
handler: async function (ctx) {
|
|
98
|
+
let params = ctx.params;
|
|
99
|
+
let { _parentId, _related_params } = params;
|
|
100
|
+
let { objectName, parentObjectName, fieldName, referenceToParentFieldName, } = _related_params;
|
|
101
|
+
let userSession = ctx.meta.user;
|
|
102
|
+
let steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
103
|
+
let object = steedosSchema.getObject(objectName);
|
|
104
|
+
let parentObj = steedosSchema.getObject(parentObjectName);
|
|
105
|
+
let parent = await parentObj.findOne(_parentId);
|
|
106
|
+
if (!parent) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
let filters = [];
|
|
110
|
+
let _idValue = parent._id;
|
|
111
|
+
if (referenceToParentFieldName) {
|
|
112
|
+
_idValue = parent[referenceToParentFieldName];
|
|
113
|
+
}
|
|
114
|
+
filters = [[fieldName, "=", _idValue]];
|
|
115
|
+
if (params.filters) {
|
|
116
|
+
filters.push(params.filters);
|
|
117
|
+
}
|
|
118
|
+
params.filters = filters;
|
|
119
|
+
const { resolveInfo } = ctx.meta;
|
|
120
|
+
const fieldNames = (0, getQueryFields_1.getQueryFields)(resolveInfo);
|
|
121
|
+
if (!_.isEmpty(fieldNames)) {
|
|
122
|
+
params.fields = fieldNames;
|
|
123
|
+
}
|
|
124
|
+
delete params._related_params;
|
|
125
|
+
delete params._parentId;
|
|
126
|
+
if (_.has(params, "top")) {
|
|
127
|
+
if (params.top < 1) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
if (params.top > consts_1.QUERY_DOCS_TOP) {
|
|
131
|
+
params.top = consts_1.QUERY_DOCS_TOP;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return await object.find(params, userSession);
|
|
168
135
|
},
|
|
169
136
|
};
|
|
170
|
-
actions[
|
|
171
|
-
handler: function (ctx) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (!_.isEmpty(fieldNames)) {
|
|
184
|
-
selectFieldNames = fieldNames;
|
|
185
|
-
}
|
|
186
|
-
return [4, translateToDisplay(__objectName, params, userSession, selectFieldNames)];
|
|
187
|
-
case 1:
|
|
188
|
-
result = _a.sent();
|
|
189
|
-
return [2, result];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
});
|
|
137
|
+
actions[`${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.DISPLAY_PREFIX}`] = {
|
|
138
|
+
handler: async function (ctx) {
|
|
139
|
+
let params = ctx.params;
|
|
140
|
+
let { __objectName } = params;
|
|
141
|
+
let userSession = ctx.meta.user;
|
|
142
|
+
let selectFieldNames = [];
|
|
143
|
+
const { resolveInfo } = ctx.meta;
|
|
144
|
+
const fieldNames = (0, getQueryFields_1.getQueryFields)(resolveInfo);
|
|
145
|
+
if (!_.isEmpty(fieldNames)) {
|
|
146
|
+
selectFieldNames = fieldNames;
|
|
147
|
+
}
|
|
148
|
+
let result = await translateToDisplay(__objectName, params, userSession, selectFieldNames);
|
|
149
|
+
return result;
|
|
193
150
|
},
|
|
194
151
|
};
|
|
195
|
-
actions[
|
|
196
|
-
handler: function (ctx) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
__objectName = params.__objectName;
|
|
204
|
-
userSession = ctx.meta.user;
|
|
205
|
-
return [4, (0, utils_1.callObjectServiceAction)("objectql.getRecordPermissionsById", userSession, {
|
|
206
|
-
objectName: __objectName,
|
|
207
|
-
recordId: params._id,
|
|
208
|
-
})];
|
|
209
|
-
case 1: return [2, _a.sent()];
|
|
210
|
-
}
|
|
211
|
-
});
|
|
152
|
+
actions[`${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.PERMISSIONS_PREFIX}`] = {
|
|
153
|
+
handler: async function (ctx) {
|
|
154
|
+
let params = ctx.params;
|
|
155
|
+
let { __objectName } = params;
|
|
156
|
+
let userSession = ctx.meta.user;
|
|
157
|
+
return await (0, utils_1.callObjectServiceAction)(`objectql.getRecordPermissionsById`, userSession, {
|
|
158
|
+
objectName: __objectName,
|
|
159
|
+
recordId: params._id,
|
|
212
160
|
});
|
|
213
161
|
},
|
|
214
162
|
};
|
|
215
163
|
return actions;
|
|
216
164
|
}
|
|
217
|
-
function translateToDisplay(objectName, doc, userSession, selectorFieldNames) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
return [3, 40];
|
|
312
|
-
case 11:
|
|
313
|
-
if (!(fType == "currency")) return [3, 12];
|
|
314
|
-
displayObj[name] = doc[name]
|
|
315
|
-
? (0, utils_1.numberToString)(doc[name], field.scale, field.enable_thousands === false)
|
|
316
|
-
: "";
|
|
317
|
-
return [3, 40];
|
|
318
|
-
case 12:
|
|
319
|
-
if (!(fType == "percent")) return [3, 13];
|
|
320
|
-
displayObj[name] = doc[name] ? "".concat(doc[name] * 100, "%") : "";
|
|
321
|
-
return [3, 40];
|
|
322
|
-
case 13:
|
|
323
|
-
if (!(fType == "password")) return [3, 14];
|
|
324
|
-
displayObj[name] = "";
|
|
325
|
-
if (_.isString(doc[name])) {
|
|
326
|
-
for (i = 0; i < doc[name].length; i++) {
|
|
327
|
-
displayObj[name] += "*";
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return [3, 40];
|
|
331
|
-
case 14:
|
|
332
|
-
if (!(fType == "lookup" && _.isString(field.reference_to))) return [3, 20];
|
|
333
|
-
refTo = field.reference_to;
|
|
334
|
-
refField = field.reference_to_field || "_id";
|
|
335
|
-
if (refTo === "users") {
|
|
336
|
-
refTo = "space_users";
|
|
337
|
-
refField = "user";
|
|
338
|
-
}
|
|
339
|
-
refValue = doc[name];
|
|
340
|
-
if (!refValue) {
|
|
341
|
-
return [2, "continue"];
|
|
342
|
-
}
|
|
343
|
-
refObj = steedosSchema.getObject(refTo);
|
|
344
|
-
return [4, refObj.getNameFieldKey()];
|
|
345
|
-
case 15:
|
|
346
|
-
nameFieldKey = _c.sent();
|
|
347
|
-
if (!field.multiple) return [3, 17];
|
|
348
|
-
return [4, refObj.find({
|
|
349
|
-
filters: [refField, "in", refValue],
|
|
350
|
-
fields: [nameFieldKey],
|
|
351
|
-
})];
|
|
352
|
-
case 16:
|
|
353
|
-
refRecords = _c.sent();
|
|
354
|
-
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
355
|
-
return [3, 19];
|
|
356
|
-
case 17: return [4, refObj.find({
|
|
357
|
-
filters: [refField, "=", refValue],
|
|
358
|
-
fields: [nameFieldKey],
|
|
359
|
-
})];
|
|
360
|
-
case 18:
|
|
361
|
-
refRecord = (_c.sent())[0];
|
|
362
|
-
if (refRecord) {
|
|
363
|
-
displayObj[name] = refRecord[nameFieldKey];
|
|
364
|
-
}
|
|
365
|
-
_c.label = 19;
|
|
366
|
-
case 19: return [3, 40];
|
|
367
|
-
case 20:
|
|
368
|
-
if (!(fType == "master_detail" &&
|
|
369
|
-
_.isString(field.reference_to))) return [3, 26];
|
|
370
|
-
refTo = field.reference_to;
|
|
371
|
-
refField = field.reference_to_field || "_id";
|
|
372
|
-
if (refTo === "users") {
|
|
373
|
-
refTo = "space_users";
|
|
374
|
-
refField = "user";
|
|
375
|
-
}
|
|
376
|
-
refValue = doc[name];
|
|
377
|
-
if (!refValue) {
|
|
378
|
-
return [2, "continue"];
|
|
379
|
-
}
|
|
380
|
-
refObj = steedosSchema.getObject(refTo);
|
|
381
|
-
return [4, refObj.getNameFieldKey()];
|
|
382
|
-
case 21:
|
|
383
|
-
nameFieldKey = _c.sent();
|
|
384
|
-
if (!field.multiple) return [3, 23];
|
|
385
|
-
return [4, refObj.find({
|
|
386
|
-
filters: [refField, "in", refValue],
|
|
387
|
-
fields: [nameFieldKey],
|
|
388
|
-
})];
|
|
389
|
-
case 22:
|
|
390
|
-
refRecords = _c.sent();
|
|
391
|
-
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
392
|
-
return [3, 25];
|
|
393
|
-
case 23: return [4, refObj.find({
|
|
394
|
-
filters: [refField, "=", refValue],
|
|
395
|
-
fields: [nameFieldKey],
|
|
396
|
-
})];
|
|
397
|
-
case 24:
|
|
398
|
-
refRecord = (_c.sent())[0];
|
|
399
|
-
if (refRecord) {
|
|
400
|
-
displayObj[name] = refRecord[nameFieldKey];
|
|
401
|
-
}
|
|
402
|
-
_c.label = 25;
|
|
403
|
-
case 25: return [3, 40];
|
|
404
|
-
case 26:
|
|
405
|
-
if (!((fType == "master_detail" || fType == "lookup") &&
|
|
406
|
-
field.reference_to &&
|
|
407
|
-
!_.isString(field.reference_to))) return [3, 29];
|
|
408
|
-
refValue = doc[name];
|
|
409
|
-
if (!refValue) {
|
|
410
|
-
return [2, "continue"];
|
|
411
|
-
}
|
|
412
|
-
refTo = refValue.o;
|
|
413
|
-
refValues = refValue.ids;
|
|
414
|
-
if (!refTo) {
|
|
415
|
-
return [2, "continue"];
|
|
416
|
-
}
|
|
417
|
-
refObj = steedosSchema.getObject(refTo);
|
|
418
|
-
return [4, refObj.getNameFieldKey()];
|
|
419
|
-
case 27:
|
|
420
|
-
nameFieldKey = _c.sent();
|
|
421
|
-
return [4, refObj.find({
|
|
422
|
-
filters: ["_id", "in", refValues],
|
|
423
|
-
fields: [nameFieldKey],
|
|
424
|
-
})];
|
|
425
|
-
case 28:
|
|
426
|
-
refRecords = _c.sent();
|
|
427
|
-
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
428
|
-
return [3, 40];
|
|
429
|
-
case 29:
|
|
430
|
-
if (!(fType == "autonumber")) return [3, 30];
|
|
431
|
-
displayObj[name] = doc[name] || "";
|
|
432
|
-
return [3, 40];
|
|
433
|
-
case 30:
|
|
434
|
-
if (!(fType == "url")) return [3, 31];
|
|
435
|
-
displayObj[name] = doc[name] || "";
|
|
436
|
-
return [3, 40];
|
|
437
|
-
case 31:
|
|
438
|
-
if (!(fType == "email")) return [3, 32];
|
|
439
|
-
displayObj[name] = doc[name] || "";
|
|
440
|
-
return [3, 40];
|
|
441
|
-
case 32:
|
|
442
|
-
if (!(fType == "formula")) return [3, 33];
|
|
443
|
-
displayObj[name] = doc[name] || "";
|
|
444
|
-
return [3, 40];
|
|
445
|
-
case 33:
|
|
446
|
-
if (!(fType == "summary")) return [3, 34];
|
|
447
|
-
displayObj[name] = doc[name] || "";
|
|
448
|
-
return [3, 40];
|
|
449
|
-
case 34:
|
|
450
|
-
if (!(fType == "image" || fType == "file")) return [3, 39];
|
|
451
|
-
fileLabel = "";
|
|
452
|
-
value = doc[name];
|
|
453
|
-
if (!value) {
|
|
454
|
-
return [2, "continue"];
|
|
455
|
-
}
|
|
456
|
-
fileObjectName = fType == "image"
|
|
457
|
-
? "cfs_images_filerecord"
|
|
458
|
-
: "cfs_files_filerecord";
|
|
459
|
-
fileObject = steedosSchema.getObject(fileObjectName);
|
|
460
|
-
fileNameFieldKey = "original.name";
|
|
461
|
-
if (!field.multiple) return [3, 36];
|
|
462
|
-
return [4, fileObject.find({
|
|
463
|
-
filters: ["_id", "in", value],
|
|
464
|
-
fields: [fileNameFieldKey],
|
|
465
|
-
})];
|
|
466
|
-
case 35:
|
|
467
|
-
fileRecords = _c.sent();
|
|
468
|
-
fileLabel = _.map(fileRecords, function (fileRecord) {
|
|
469
|
-
var _a;
|
|
470
|
-
return (_a = fileRecord.original) === null || _a === void 0 ? void 0 : _a.name;
|
|
471
|
-
}).join(",");
|
|
472
|
-
return [3, 38];
|
|
473
|
-
case 36: return [4, fileObject.find({
|
|
474
|
-
filters: ["_id", "=", value],
|
|
475
|
-
fields: [fileNameFieldKey],
|
|
476
|
-
})];
|
|
477
|
-
case 37:
|
|
478
|
-
fileRecord = (_c.sent())[0];
|
|
479
|
-
if (fileRecord) {
|
|
480
|
-
fileLabel = fileRecord["original"]["name"];
|
|
481
|
-
}
|
|
482
|
-
_c.label = 38;
|
|
483
|
-
case 38:
|
|
484
|
-
displayObj[name] = fileLabel;
|
|
485
|
-
return [3, 40];
|
|
486
|
-
case 39:
|
|
487
|
-
console.error("Graphql Display: need to handle new field type ".concat(field.type, " for ").concat(objectName, "."));
|
|
488
|
-
displayObj[name] = doc[name] || "";
|
|
489
|
-
_c.label = 40;
|
|
490
|
-
case 40: return [3, 42];
|
|
491
|
-
case 41:
|
|
492
|
-
displayObj[name] = "";
|
|
493
|
-
_c.label = 42;
|
|
494
|
-
case 42: return [2];
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
};
|
|
498
|
-
_b.label = 1;
|
|
499
|
-
case 1:
|
|
500
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
501
|
-
selectorFieldNames_1 = tslib_1.__values(selectorFieldNames), selectorFieldNames_1_1 = selectorFieldNames_1.next();
|
|
502
|
-
_b.label = 2;
|
|
503
|
-
case 2:
|
|
504
|
-
if (!!selectorFieldNames_1_1.done) return [3, 5];
|
|
505
|
-
name = selectorFieldNames_1_1.value;
|
|
506
|
-
return [5, _loop_1(name)];
|
|
507
|
-
case 3:
|
|
508
|
-
_b.sent();
|
|
509
|
-
_b.label = 4;
|
|
510
|
-
case 4:
|
|
511
|
-
selectorFieldNames_1_1 = selectorFieldNames_1.next();
|
|
512
|
-
return [3, 2];
|
|
513
|
-
case 5: return [3, 8];
|
|
514
|
-
case 6:
|
|
515
|
-
e_1_1 = _b.sent();
|
|
516
|
-
e_1 = { error: e_1_1 };
|
|
517
|
-
return [3, 8];
|
|
518
|
-
case 7:
|
|
519
|
-
try {
|
|
520
|
-
if (selectorFieldNames_1_1 && !selectorFieldNames_1_1.done && (_a = selectorFieldNames_1.return)) _a.call(selectorFieldNames_1);
|
|
165
|
+
async function translateToDisplay(objectName, doc, userSession, selectorFieldNames) {
|
|
166
|
+
const lng = (0, objectql_1.getUserLocale)(userSession);
|
|
167
|
+
let steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
168
|
+
let object = steedosSchema.getObject(objectName);
|
|
169
|
+
let objConfig = await object.toConfig();
|
|
170
|
+
let fields = objConfig.fields;
|
|
171
|
+
(0, i18n_1.translationObject)(lng, objConfig.name, objConfig, true);
|
|
172
|
+
let utcOffset = userSession.utcOffset || 8;
|
|
173
|
+
async function _translateToDisplay(doc, selectorFieldNames) {
|
|
174
|
+
let displayObj = {};
|
|
175
|
+
for (const name of selectorFieldNames) {
|
|
176
|
+
if (Object.prototype.hasOwnProperty.call(fields, name)) {
|
|
177
|
+
const field = fields[name];
|
|
178
|
+
if (_.has(doc, name)) {
|
|
179
|
+
const fType = field.type;
|
|
180
|
+
if (fType == "text") {
|
|
181
|
+
displayObj[name] = doc[name] || "";
|
|
182
|
+
}
|
|
183
|
+
else if (fType == "textarea") {
|
|
184
|
+
displayObj[name] = doc[name] || "";
|
|
185
|
+
}
|
|
186
|
+
else if (fType == "html_text") {
|
|
187
|
+
displayObj[name] = doc[name] || "";
|
|
188
|
+
}
|
|
189
|
+
else if (fType == "html") {
|
|
190
|
+
displayObj[name] = doc[name] || "";
|
|
191
|
+
}
|
|
192
|
+
else if (fType == "color") {
|
|
193
|
+
displayObj[name] = doc[name] || "";
|
|
194
|
+
}
|
|
195
|
+
else if (fType == "select") {
|
|
196
|
+
let label = "";
|
|
197
|
+
let map = {};
|
|
198
|
+
let value = doc[name];
|
|
199
|
+
let translatedField = getTranslatedFieldConfig(objConfig, name);
|
|
200
|
+
let translatedFieldOptions = translatedField && translatedField.options;
|
|
201
|
+
_.forEach(translatedFieldOptions, function (o) {
|
|
202
|
+
map[o.value] = o.label;
|
|
203
|
+
});
|
|
204
|
+
if (field.multiple) {
|
|
205
|
+
let labels = [];
|
|
206
|
+
_.forEach(value, function (v) {
|
|
207
|
+
labels.push(map[v]);
|
|
208
|
+
});
|
|
209
|
+
label = labels.join(",");
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
label = map[value];
|
|
213
|
+
}
|
|
214
|
+
displayObj[name] = label;
|
|
215
|
+
}
|
|
216
|
+
else if (fType == "boolean") {
|
|
217
|
+
if (doc[name]) {
|
|
218
|
+
displayObj[name] = "√";
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
displayObj[name] = "";
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (fType == "date") {
|
|
225
|
+
displayObj[name] = doc[name]
|
|
226
|
+
? moment.utc(doc[name]).format("YYYY-MM-DD")
|
|
227
|
+
: "";
|
|
228
|
+
}
|
|
229
|
+
else if (fType == "datetime") {
|
|
230
|
+
displayObj[name] = doc[name]
|
|
231
|
+
? moment(doc[name])
|
|
232
|
+
.utcOffset(utcOffset)
|
|
233
|
+
.format("YYYY-MM-DD HH:mm")
|
|
234
|
+
: "";
|
|
235
|
+
}
|
|
236
|
+
else if (fType == "time") {
|
|
237
|
+
displayObj[name] = doc[name]
|
|
238
|
+
? moment.utc(doc[name]).format("HH:mm")
|
|
239
|
+
: "";
|
|
240
|
+
}
|
|
241
|
+
else if (fType == "number") {
|
|
242
|
+
displayObj[name] = doc[name]
|
|
243
|
+
? (0, utils_1.numberToString)(doc[name], field.scale, field.enable_thousands === false)
|
|
244
|
+
: "";
|
|
245
|
+
}
|
|
246
|
+
else if (fType == "currency") {
|
|
247
|
+
displayObj[name] = doc[name]
|
|
248
|
+
? (0, utils_1.numberToString)(doc[name], field.scale, field.enable_thousands === false)
|
|
249
|
+
: "";
|
|
250
|
+
}
|
|
251
|
+
else if (fType == "percent") {
|
|
252
|
+
displayObj[name] = doc[name] ? `${doc[name] * 100}%` : "";
|
|
253
|
+
}
|
|
254
|
+
else if (fType == "password") {
|
|
255
|
+
displayObj[name] = "";
|
|
256
|
+
if (_.isString(doc[name])) {
|
|
257
|
+
for (let i = 0; i < doc[name].length; i++) {
|
|
258
|
+
displayObj[name] += "*";
|
|
521
259
|
}
|
|
522
|
-
|
|
523
|
-
return [7];
|
|
524
|
-
case 8: return [2, displayObj];
|
|
260
|
+
}
|
|
525
261
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
262
|
+
else if (fType == "lookup" && _.isString(field.reference_to)) {
|
|
263
|
+
let refTo = field.reference_to;
|
|
264
|
+
let refField = field.reference_to_field || "_id";
|
|
265
|
+
if (refTo === "users") {
|
|
266
|
+
refTo = "space_users";
|
|
267
|
+
refField = "user";
|
|
268
|
+
}
|
|
269
|
+
let refValue = doc[name];
|
|
270
|
+
if (!refValue) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
274
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
275
|
+
if (field.multiple) {
|
|
276
|
+
let refRecords = await refObj.find({
|
|
277
|
+
filters: [refField, "in", refValue],
|
|
278
|
+
fields: [nameFieldKey],
|
|
279
|
+
});
|
|
280
|
+
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
let refRecord = (await refObj.find({
|
|
284
|
+
filters: [refField, "=", refValue],
|
|
285
|
+
fields: [nameFieldKey],
|
|
286
|
+
}))[0];
|
|
287
|
+
if (refRecord) {
|
|
288
|
+
displayObj[name] = refRecord[nameFieldKey];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else if (fType == "master_detail" &&
|
|
293
|
+
_.isString(field.reference_to)) {
|
|
294
|
+
let refTo = field.reference_to;
|
|
295
|
+
let refField = field.reference_to_field || "_id";
|
|
296
|
+
if (refTo === "users") {
|
|
297
|
+
refTo = "space_users";
|
|
298
|
+
refField = "user";
|
|
299
|
+
}
|
|
300
|
+
let refValue = doc[name];
|
|
301
|
+
if (!refValue) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
305
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
306
|
+
if (field.multiple) {
|
|
307
|
+
let refRecords = await refObj.find({
|
|
308
|
+
filters: [refField, "in", refValue],
|
|
309
|
+
fields: [nameFieldKey],
|
|
310
|
+
});
|
|
311
|
+
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
let refRecord = (await refObj.find({
|
|
315
|
+
filters: [refField, "=", refValue],
|
|
316
|
+
fields: [nameFieldKey],
|
|
317
|
+
}))[0];
|
|
318
|
+
if (refRecord) {
|
|
319
|
+
displayObj[name] = refRecord[nameFieldKey];
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if ((fType == "master_detail" || fType == "lookup") &&
|
|
324
|
+
field.reference_to &&
|
|
325
|
+
!_.isString(field.reference_to)) {
|
|
326
|
+
let refValue = doc[name];
|
|
327
|
+
if (!refValue) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
let refTo = refValue.o;
|
|
331
|
+
let refValues = refValue.ids;
|
|
332
|
+
if (!refTo) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
336
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
337
|
+
let refRecords = await refObj.find({
|
|
338
|
+
filters: [`_id`, "in", refValues],
|
|
339
|
+
fields: [nameFieldKey],
|
|
340
|
+
});
|
|
341
|
+
displayObj[name] = _.pluck(refRecords, nameFieldKey).join(",");
|
|
342
|
+
}
|
|
343
|
+
else if (fType == "autonumber") {
|
|
344
|
+
displayObj[name] = doc[name] || "";
|
|
345
|
+
}
|
|
346
|
+
else if (fType == "url") {
|
|
347
|
+
displayObj[name] = doc[name] || "";
|
|
348
|
+
}
|
|
349
|
+
else if (fType == "email") {
|
|
350
|
+
displayObj[name] = doc[name] || "";
|
|
351
|
+
}
|
|
352
|
+
else if (fType == "formula") {
|
|
353
|
+
displayObj[name] = doc[name] || "";
|
|
354
|
+
}
|
|
355
|
+
else if (fType == "summary") {
|
|
356
|
+
displayObj[name] = doc[name] || "";
|
|
357
|
+
}
|
|
358
|
+
else if (fType == "image" || fType == "file") {
|
|
359
|
+
let fileLabel = "";
|
|
360
|
+
let value = doc[name];
|
|
361
|
+
if (!value) {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
let fileObjectName = fType == "image"
|
|
365
|
+
? "cfs_images_filerecord"
|
|
366
|
+
: "cfs_files_filerecord";
|
|
367
|
+
let fileObject = steedosSchema.getObject(fileObjectName);
|
|
368
|
+
const fileNameFieldKey = "original.name";
|
|
369
|
+
if (field.multiple) {
|
|
370
|
+
let fileRecords = await fileObject.find({
|
|
371
|
+
filters: [`_id`, "in", value],
|
|
372
|
+
fields: [fileNameFieldKey],
|
|
373
|
+
});
|
|
374
|
+
fileLabel = _.map(fileRecords, (fileRecord) => {
|
|
375
|
+
return fileRecord.original?.name;
|
|
376
|
+
}).join(",");
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
let fileRecord = (await fileObject.find({
|
|
380
|
+
filters: [`_id`, "=", value],
|
|
381
|
+
fields: [fileNameFieldKey],
|
|
382
|
+
}))[0];
|
|
383
|
+
if (fileRecord) {
|
|
384
|
+
fileLabel = fileRecord["original"]["name"];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
displayObj[name] = fileLabel;
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
console.error(`Graphql Display: need to handle new field type ${field.type} for ${objectName}.`);
|
|
391
|
+
displayObj[name] = doc[name] || "";
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
displayObj[name] = "";
|
|
396
|
+
}
|
|
547
397
|
}
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
var getObjectDisplayData = function (graphqlServiceName, objectName, refFieldName, referenceToFieldName, objectDataLoaderHandler, graphqlCtx) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
552
|
-
var actionName;
|
|
553
|
-
var _a;
|
|
554
|
-
return tslib_1.__generator(this, function (_b) {
|
|
555
|
-
switch (_b.label) {
|
|
556
|
-
case 0:
|
|
557
|
-
actionName = "".concat(graphqlServiceName, ".").concat(consts_1.GRAPHQL_ACTION_PREFIX).concat(consts_1.EXPAND_SUFFIX);
|
|
558
|
-
return [4, objectDataLoaderHandler(actionName, {
|
|
559
|
-
objectName: objectName,
|
|
560
|
-
referenceToField: referenceToFieldName,
|
|
561
|
-
}, (_a = {},
|
|
562
|
-
_a[refFieldName] = "id",
|
|
563
|
-
_a), graphqlCtx)];
|
|
564
|
-
case 1: return [2, _b.sent()];
|
|
565
398
|
}
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
else {
|
|
673
|
-
refToObjectsField = _.find(fields, function (_field) {
|
|
674
|
-
return _field.reference_to === "objects";
|
|
675
|
-
});
|
|
676
|
-
if (refToObjectsField) {
|
|
677
|
-
refFilters = [
|
|
678
|
-
["object", "=", parentDoc[refToObjectsField.name]],
|
|
679
|
-
refFilters,
|
|
680
|
-
];
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
if (refTo_1 === "object_actions" && refField == "name") {
|
|
685
|
-
refToObjectsField = _.find(fields, function (_field) {
|
|
686
|
-
return _field.reference_to === "objects";
|
|
687
|
-
});
|
|
688
|
-
if (refToObjectsField) {
|
|
689
|
-
refFilters = [
|
|
690
|
-
["object", "=", parentDoc[refToObjectsField.name]],
|
|
691
|
-
refFilters,
|
|
692
|
-
];
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
if (!field.multiple) return [3, 7];
|
|
696
|
-
return [4, refObj.find({
|
|
697
|
-
filters: refFilters,
|
|
698
|
-
fields: [nameFieldKey_1],
|
|
699
|
-
})];
|
|
700
|
-
case 6:
|
|
701
|
-
refRecords = _h.sent();
|
|
702
|
-
displayObj[name] = _.map(refRecords, function (item) {
|
|
703
|
-
return {
|
|
704
|
-
objectName: refTo_1,
|
|
705
|
-
value: item ? item._id : refValue_1,
|
|
706
|
-
label: item ? item[nameFieldKey_1] : refValue_1,
|
|
707
|
-
};
|
|
708
|
-
});
|
|
709
|
-
return [3, 9];
|
|
710
|
-
case 7: return [4, refObj.find({
|
|
711
|
-
filters: refFilters,
|
|
712
|
-
fields: [nameFieldKey_1],
|
|
713
|
-
})];
|
|
714
|
-
case 8:
|
|
715
|
-
refRecord = (_h.sent())[0];
|
|
716
|
-
if (refRecord) {
|
|
717
|
-
displayObj[name] = {
|
|
718
|
-
objectName: refTo_1,
|
|
719
|
-
value: refRecord._id,
|
|
720
|
-
label: refRecord[nameFieldKey_1],
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
displayObj[name] = {
|
|
725
|
-
objectName: refTo_1,
|
|
726
|
-
value: refValue_1,
|
|
727
|
-
label: refValue_1,
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
_h.label = 9;
|
|
731
|
-
case 9: return [3, 11];
|
|
732
|
-
case 10:
|
|
733
|
-
refValue = doc[name];
|
|
734
|
-
if (!refValue) {
|
|
735
|
-
return [2, "continue"];
|
|
736
|
-
}
|
|
737
|
-
if (field.multiple && _.isArray(refValue)) {
|
|
738
|
-
_.each(refValue, function (item) {
|
|
739
|
-
displayObj[name] = {
|
|
740
|
-
value: item,
|
|
741
|
-
label: item,
|
|
742
|
-
};
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
else {
|
|
746
|
-
displayObj[name] = {
|
|
747
|
-
value: refValue,
|
|
748
|
-
label: refValue,
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
_h.label = 11;
|
|
752
|
-
case 11: return [3, 45];
|
|
753
|
-
case 12:
|
|
754
|
-
if (!(fType == "master_detail" &&
|
|
755
|
-
_.isString(field.reference_to))) return [3, 20];
|
|
756
|
-
refTo_2 = field.reference_to;
|
|
757
|
-
refField = field.reference_to_field || "_id";
|
|
758
|
-
if (refTo_2 === "users") {
|
|
759
|
-
refTo_2 = "space_users";
|
|
760
|
-
refField = "user";
|
|
761
|
-
}
|
|
762
|
-
refValue_2 = doc[name];
|
|
763
|
-
if (!refValue_2) {
|
|
764
|
-
return [2, "continue"];
|
|
765
|
-
}
|
|
766
|
-
refObj = steedosSchema.getObject(refTo_2);
|
|
767
|
-
return [4, refObj.getNameFieldKey()];
|
|
768
|
-
case 13:
|
|
769
|
-
nameFieldKey_2 = _h.sent();
|
|
770
|
-
objectDataLoader = refObj.enable_dataloader != false &&
|
|
771
|
-
process.env.STEEDOS_GRAPHQL_ENABLE_DATALOADER != "false";
|
|
772
|
-
if (!objectDataLoader) return [3, 15];
|
|
773
|
-
return [4, getObjectDisplayData("api", field.reference_to, name, refField, graphqlCtx.objectDataLoaderHandler, graphqlCtx)];
|
|
774
|
-
case 14:
|
|
775
|
-
results = _h.sent();
|
|
776
|
-
if (field.multiple) {
|
|
777
|
-
displayObj[name] = _.map(results, function (item) {
|
|
778
|
-
return {
|
|
779
|
-
objectName: refTo_2,
|
|
780
|
-
value: item ? item._id : refValue_2,
|
|
781
|
-
label: item ? item[nameFieldKey_2] : refValue_2,
|
|
782
|
-
};
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
displayObj[name] = {
|
|
787
|
-
objectName: refTo_2,
|
|
788
|
-
value: results._id || refValue_2,
|
|
789
|
-
label: results[nameFieldKey_2] || refValue_2,
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
return [3, 19];
|
|
793
|
-
case 15:
|
|
794
|
-
if (!field.multiple) return [3, 17];
|
|
795
|
-
return [4, refObj.find({
|
|
796
|
-
filters: [refField, "in", refValue_2],
|
|
797
|
-
fields: [nameFieldKey_2],
|
|
798
|
-
})];
|
|
799
|
-
case 16:
|
|
800
|
-
refRecords = _h.sent();
|
|
801
|
-
displayObj[name] = _.map(refRecords, function (item) {
|
|
802
|
-
return {
|
|
803
|
-
objectName: refTo_2,
|
|
804
|
-
value: item._id,
|
|
805
|
-
label: item[nameFieldKey_2],
|
|
806
|
-
};
|
|
807
|
-
});
|
|
808
|
-
return [3, 19];
|
|
809
|
-
case 17: return [4, refObj.find({
|
|
810
|
-
filters: [refField, "=", refValue_2],
|
|
811
|
-
fields: [nameFieldKey_2],
|
|
812
|
-
})];
|
|
813
|
-
case 18:
|
|
814
|
-
refRecord = (_h.sent())[0];
|
|
815
|
-
if (refRecord) {
|
|
816
|
-
displayObj[name] = {
|
|
817
|
-
objectName: refTo_2,
|
|
818
|
-
value: refRecord._id,
|
|
819
|
-
label: refRecord[nameFieldKey_2],
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
_h.label = 19;
|
|
823
|
-
case 19: return [3, 45];
|
|
824
|
-
case 20:
|
|
825
|
-
if (!((fType == "master_detail" || fType == "lookup") &&
|
|
826
|
-
((field.reference_to && !_.isString(field.reference_to)) ||
|
|
827
|
-
_.isString(field._reference_to)))) return [3, 23];
|
|
828
|
-
refValue = doc[name];
|
|
829
|
-
if (!refValue) {
|
|
830
|
-
return [2, "continue"];
|
|
831
|
-
}
|
|
832
|
-
refTo_3 = refValue.o;
|
|
833
|
-
refValues = refValue.ids;
|
|
834
|
-
if (!refTo_3) {
|
|
835
|
-
return [2, "continue"];
|
|
836
|
-
}
|
|
837
|
-
refObj = steedosSchema.getObject(refTo_3);
|
|
838
|
-
return [4, refObj.getNameFieldKey()];
|
|
839
|
-
case 21:
|
|
840
|
-
nameFieldKey_3 = _h.sent();
|
|
841
|
-
return [4, refObj.find({
|
|
842
|
-
filters: ["_id", "in", refValues],
|
|
843
|
-
fields: [nameFieldKey_3],
|
|
844
|
-
})];
|
|
845
|
-
case 22:
|
|
846
|
-
refRecords = _h.sent();
|
|
847
|
-
displayObj[name] = _.map(refRecords, function (item) {
|
|
848
|
-
return {
|
|
849
|
-
objectName: refTo_3,
|
|
850
|
-
value: item._id,
|
|
851
|
-
label: item[nameFieldKey_3],
|
|
852
|
-
};
|
|
853
|
-
});
|
|
854
|
-
return [3, 45];
|
|
855
|
-
case 23:
|
|
856
|
-
if (!(fType == "formula")) return [3, 24];
|
|
857
|
-
displayObj[name] = (0, utils_1.formatBasicFieldValue)(field.data_type, field, doc[name], objConfig, userSession);
|
|
858
|
-
return [3, 45];
|
|
859
|
-
case 24:
|
|
860
|
-
if (!(fType == "summary")) return [3, 25];
|
|
861
|
-
displayObj[name] = (0, utils_1.formatBasicFieldValue)(dataType, field, doc[name], objConfig, userSession);
|
|
862
|
-
return [3, 45];
|
|
863
|
-
case 25:
|
|
864
|
-
if (!(fType == "image" ||
|
|
865
|
-
fType == "file" ||
|
|
866
|
-
fType === "avatar")) return [3, 30];
|
|
867
|
-
optionsStr_1 = fType == "file" ? "" : "";
|
|
868
|
-
fileValue = null;
|
|
869
|
-
value = doc[name];
|
|
870
|
-
if (!value) {
|
|
871
|
-
return [2, "continue"];
|
|
872
|
-
}
|
|
873
|
-
storageName_1 = (0, utils_1.getFileStorageName)(fType);
|
|
874
|
-
fileObjectName = "cfs_".concat(storageName_1, "_filerecord");
|
|
875
|
-
fileObject = steedosSchema.getObject(fileObjectName);
|
|
876
|
-
fileNameFieldKey = "original.name";
|
|
877
|
-
if (!field.multiple) return [3, 27];
|
|
878
|
-
return [4, fileObject.find({
|
|
879
|
-
filters: ["_id", "in", value],
|
|
880
|
-
fields: [
|
|
881
|
-
"_id",
|
|
882
|
-
fileNameFieldKey,
|
|
883
|
-
"original.size",
|
|
884
|
-
"original.type",
|
|
885
|
-
],
|
|
886
|
-
})];
|
|
887
|
-
case 26:
|
|
888
|
-
fileRecords = _h.sent();
|
|
889
|
-
fileValue = _.map(fileRecords, function (fileRecord) {
|
|
890
|
-
var _a, _b, _c;
|
|
891
|
-
var fName = (_a = fileRecord.original) === null || _a === void 0 ? void 0 : _a.name;
|
|
892
|
-
return {
|
|
893
|
-
name: fName,
|
|
894
|
-
url: (0, objectql_1.absoluteUrl)("/api/v6/files/download/cfs.".concat(storageName_1, ".filerecord/").concat(fileRecord._id, "/").concat(fName).concat(optionsStr_1)),
|
|
895
|
-
size: (_b = fileRecord.original) === null || _b === void 0 ? void 0 : _b.size,
|
|
896
|
-
type: (_c = fileRecord.original) === null || _c === void 0 ? void 0 : _c.type,
|
|
897
|
-
value: fileRecord._id,
|
|
898
|
-
};
|
|
399
|
+
return displayObj;
|
|
400
|
+
}
|
|
401
|
+
let displayDoc = await _translateToDisplay(doc, selectorFieldNames);
|
|
402
|
+
displayDoc["_id"] = doc._id;
|
|
403
|
+
return displayDoc;
|
|
404
|
+
}
|
|
405
|
+
const getObjectDisplayData = async (graphqlServiceName, objectName, refFieldName, referenceToFieldName, objectDataLoaderHandler, graphqlCtx) => {
|
|
406
|
+
const actionName = `${graphqlServiceName}.${consts_1.GRAPHQL_ACTION_PREFIX}${consts_1.EXPAND_SUFFIX}`;
|
|
407
|
+
return await objectDataLoaderHandler(actionName, {
|
|
408
|
+
objectName: objectName,
|
|
409
|
+
referenceToField: referenceToFieldName,
|
|
410
|
+
}, {
|
|
411
|
+
[refFieldName]: "id",
|
|
412
|
+
}, graphqlCtx);
|
|
413
|
+
};
|
|
414
|
+
async function translateToUI(objConfig, doc, userSession, selectorFieldNames, graphqlCtx) {
|
|
415
|
+
const lng = (0, objectql_1.getUserLocale)(userSession);
|
|
416
|
+
let steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
417
|
+
let fields = objConfig.fields;
|
|
418
|
+
(0, i18n_1.translationObject)(lng, objConfig.name, objConfig, true);
|
|
419
|
+
async function _translateToUI(doc, selectorFieldNames, parentDoc) {
|
|
420
|
+
let displayObj = {};
|
|
421
|
+
for (const name of selectorFieldNames) {
|
|
422
|
+
if (Object.prototype.hasOwnProperty.call(fields, name)) {
|
|
423
|
+
const field = fields[name];
|
|
424
|
+
try {
|
|
425
|
+
if (_.has(doc, name)) {
|
|
426
|
+
const fType = field.type;
|
|
427
|
+
const dataType = field.data_type;
|
|
428
|
+
if (fType == "select") {
|
|
429
|
+
let label = "";
|
|
430
|
+
let map = {};
|
|
431
|
+
let value = doc[name];
|
|
432
|
+
let translatedField = getTranslatedFieldConfig(objConfig, name);
|
|
433
|
+
let translatedFieldOptions = translatedField && translatedField.options;
|
|
434
|
+
_.forEach(translatedFieldOptions, function (o) {
|
|
435
|
+
map[o.value] = o.label;
|
|
436
|
+
});
|
|
437
|
+
if (field.multiple) {
|
|
438
|
+
let labels = [];
|
|
439
|
+
_.forEach(value, function (v) {
|
|
440
|
+
labels.push(map[v]);
|
|
441
|
+
});
|
|
442
|
+
label = labels.join(",");
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
label = map[value];
|
|
446
|
+
}
|
|
447
|
+
displayObj[name] = label;
|
|
448
|
+
}
|
|
449
|
+
else if (fType == "lookup" &&
|
|
450
|
+
(_.isString(field.reference_to) ||
|
|
451
|
+
(!_.has(field, "reference_to") &&
|
|
452
|
+
!_.has(field, "_reference_to")))) {
|
|
453
|
+
if (_.isString(field.reference_to)) {
|
|
454
|
+
let refTo = field.reference_to;
|
|
455
|
+
let refField = field.reference_to_field || "_id";
|
|
456
|
+
if (refTo === "users") {
|
|
457
|
+
refTo = "space_users";
|
|
458
|
+
refField = "user";
|
|
459
|
+
}
|
|
460
|
+
let refValue = doc[name];
|
|
461
|
+
if (!refValue || _.isEmpty(refValue)) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
465
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
466
|
+
let objectDataLoader = refObj.enable_dataloader != false &&
|
|
467
|
+
process.env.STEEDOS_GRAPHQL_ENABLE_DATALOADER != "false";
|
|
468
|
+
if (objectDataLoader) {
|
|
469
|
+
const results = await getObjectDisplayData("api", refTo, name, refField, graphqlCtx.objectDataLoaderHandler, graphqlCtx);
|
|
470
|
+
if (field.multiple) {
|
|
471
|
+
displayObj[name] = _.map(results, (item) => {
|
|
472
|
+
return {
|
|
473
|
+
objectName: refTo,
|
|
474
|
+
value: item ? item._id : refValue,
|
|
475
|
+
label: item ? item[nameFieldKey] : refValue,
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
displayObj[name] = {
|
|
481
|
+
objectName: refTo,
|
|
482
|
+
value: results._id || refValue,
|
|
483
|
+
label: results[nameFieldKey] || refValue,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
let refFilters = null;
|
|
489
|
+
if (field.multiple) {
|
|
490
|
+
refFilters = [refField, "in", refValue];
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
refFilters = [refField, "=", refValue];
|
|
494
|
+
}
|
|
495
|
+
if (refTo === "object_fields" && refField == "name") {
|
|
496
|
+
if (objConfig.name === "objects") {
|
|
497
|
+
refFilters = [
|
|
498
|
+
["object", "=", parentDoc["name"]],
|
|
499
|
+
refFilters,
|
|
500
|
+
];
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
const refToObjectsField = _.find(fields, (_field) => {
|
|
504
|
+
return _field.reference_to === "objects";
|
|
899
505
|
});
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
fileNameFieldKey,
|
|
906
|
-
"original.size",
|
|
907
|
-
"original.type",
|
|
908
|
-
],
|
|
909
|
-
})];
|
|
910
|
-
case 28:
|
|
911
|
-
fileRecord = (_h.sent())[0];
|
|
912
|
-
if (fileRecord) {
|
|
913
|
-
fName = fileRecord["original"]["name"];
|
|
914
|
-
fileValue = {
|
|
915
|
-
name: fName,
|
|
916
|
-
url: (0, objectql_1.absoluteUrl)("/api/v6/files/download/cfs.".concat(storageName_1, ".filerecord/").concat(value, "/").concat(fName).concat(optionsStr_1)),
|
|
917
|
-
size: (_b = fileRecord.original) === null || _b === void 0 ? void 0 : _b.size,
|
|
918
|
-
type: (_c = fileRecord.original) === null || _c === void 0 ? void 0 : _c.type,
|
|
919
|
-
value: fileRecord._id,
|
|
920
|
-
};
|
|
506
|
+
if (refToObjectsField) {
|
|
507
|
+
refFilters = [
|
|
508
|
+
["object", "=", parentDoc[refToObjectsField.name]],
|
|
509
|
+
refFilters,
|
|
510
|
+
];
|
|
921
511
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
objectFieldDoc = _h.sent();
|
|
946
|
-
objectDoc_1 = {};
|
|
947
|
-
_.each(objectFieldDoc, function (v, k) {
|
|
948
|
-
var newKey = k.replace("".concat(name, "."), "");
|
|
949
|
-
objectDoc_1[newKey] = v;
|
|
950
|
-
});
|
|
951
|
-
displayObj[name] = objectDoc_1;
|
|
952
|
-
_h.label = 33;
|
|
953
|
-
case 33: return [3, 45];
|
|
954
|
-
case 34:
|
|
955
|
-
if (!(fType === "grid" || "table" === fType)) return [3, 44];
|
|
956
|
-
if (!(doc[name] && _.isArray(doc[name]))) return [3, 43];
|
|
957
|
-
gridDocs = [];
|
|
958
|
-
_loop_3 = function (gridDoc) {
|
|
959
|
-
var _doc, objectFieldDoc, objectDoc;
|
|
960
|
-
return tslib_1.__generator(this, function (_j) {
|
|
961
|
-
switch (_j.label) {
|
|
962
|
-
case 0:
|
|
963
|
-
_doc = {};
|
|
964
|
-
_.each(gridDoc, function (v, k) {
|
|
965
|
-
var newKey = "".concat(name, ".$.").concat(k);
|
|
966
|
-
_doc[newKey] = v;
|
|
967
|
-
});
|
|
968
|
-
return [4, _translateToUI(_doc, Object.keys(_doc), doc)];
|
|
969
|
-
case 1:
|
|
970
|
-
objectFieldDoc = _j.sent();
|
|
971
|
-
objectDoc = {};
|
|
972
|
-
_.each(objectFieldDoc, function (v, k) {
|
|
973
|
-
var newKey = k.replace("".concat(name, ".$."), "");
|
|
974
|
-
objectDoc[newKey] = v;
|
|
975
|
-
});
|
|
976
|
-
gridDocs.push(objectDoc);
|
|
977
|
-
return [2];
|
|
978
|
-
}
|
|
979
|
-
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (refTo === "object_actions" && refField == "name") {
|
|
515
|
+
const refToObjectsField = _.find(fields, (_field) => {
|
|
516
|
+
return _field.reference_to === "objects";
|
|
517
|
+
});
|
|
518
|
+
if (refToObjectsField) {
|
|
519
|
+
refFilters = [
|
|
520
|
+
["object", "=", parentDoc[refToObjectsField.name]],
|
|
521
|
+
refFilters,
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (field.multiple) {
|
|
526
|
+
let refRecords = await refObj.find({
|
|
527
|
+
filters: refFilters,
|
|
528
|
+
fields: [nameFieldKey],
|
|
529
|
+
});
|
|
530
|
+
displayObj[name] = _.map(refRecords, (item) => {
|
|
531
|
+
return {
|
|
532
|
+
objectName: refTo,
|
|
533
|
+
value: item ? item._id : refValue,
|
|
534
|
+
label: item ? item[nameFieldKey] : refValue,
|
|
980
535
|
};
|
|
981
|
-
|
|
982
|
-
case 35:
|
|
983
|
-
_h.trys.push([35, 40, 41, 42]);
|
|
984
|
-
_e = (e_3 = void 0, tslib_1.__values(doc[name])), _f = _e.next();
|
|
985
|
-
_h.label = 36;
|
|
986
|
-
case 36:
|
|
987
|
-
if (!!_f.done) return [3, 39];
|
|
988
|
-
gridDoc = _f.value;
|
|
989
|
-
return [5, _loop_3(gridDoc)];
|
|
990
|
-
case 37:
|
|
991
|
-
_h.sent();
|
|
992
|
-
_h.label = 38;
|
|
993
|
-
case 38:
|
|
994
|
-
_f = _e.next();
|
|
995
|
-
return [3, 36];
|
|
996
|
-
case 39: return [3, 42];
|
|
997
|
-
case 40:
|
|
998
|
-
e_3_1 = _h.sent();
|
|
999
|
-
e_3 = { error: e_3_1 };
|
|
1000
|
-
return [3, 42];
|
|
1001
|
-
case 41:
|
|
1002
|
-
try {
|
|
1003
|
-
if (_f && !_f.done && (_g = _e.return)) _g.call(_e);
|
|
1004
|
-
}
|
|
1005
|
-
finally { if (e_3) throw e_3.error; }
|
|
1006
|
-
return [7];
|
|
1007
|
-
case 42:
|
|
1008
|
-
displayObj[name] = gridDocs;
|
|
1009
|
-
_h.label = 43;
|
|
1010
|
-
case 43: return [3, 45];
|
|
1011
|
-
case 44:
|
|
1012
|
-
displayObj[name] = (0, utils_1.formatBasicFieldValue)(fType, field, doc[name], objConfig, userSession);
|
|
1013
|
-
_h.label = 45;
|
|
1014
|
-
case 45: return [3, 47];
|
|
1015
|
-
case 46:
|
|
1016
|
-
displayObj[name] = "";
|
|
1017
|
-
_h.label = 47;
|
|
1018
|
-
case 47: return [3, 49];
|
|
1019
|
-
case 48:
|
|
1020
|
-
error_1 = _h.sent();
|
|
1021
|
-
displayObj[name] = doc[name];
|
|
1022
|
-
return [3, 49];
|
|
1023
|
-
case 49: return [2];
|
|
536
|
+
});
|
|
1024
537
|
}
|
|
538
|
+
else {
|
|
539
|
+
let refRecord = (await refObj.find({
|
|
540
|
+
filters: refFilters,
|
|
541
|
+
fields: [nameFieldKey],
|
|
542
|
+
}))[0];
|
|
543
|
+
if (refRecord) {
|
|
544
|
+
displayObj[name] = {
|
|
545
|
+
objectName: refTo,
|
|
546
|
+
value: refRecord._id,
|
|
547
|
+
label: refRecord[nameFieldKey],
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
displayObj[name] = {
|
|
552
|
+
objectName: refTo,
|
|
553
|
+
value: refValue,
|
|
554
|
+
label: refValue,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
let refValue = doc[name];
|
|
562
|
+
if (!refValue) {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (field.multiple && _.isArray(refValue)) {
|
|
566
|
+
_.each(refValue, (item) => {
|
|
567
|
+
displayObj[name] = {
|
|
568
|
+
value: item,
|
|
569
|
+
label: item,
|
|
570
|
+
};
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
displayObj[name] = {
|
|
575
|
+
value: refValue,
|
|
576
|
+
label: refValue,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
else if (fType == "master_detail" &&
|
|
582
|
+
_.isString(field.reference_to)) {
|
|
583
|
+
let refTo = field.reference_to;
|
|
584
|
+
let refField = field.reference_to_field || "_id";
|
|
585
|
+
if (refTo === "users") {
|
|
586
|
+
refTo = "space_users";
|
|
587
|
+
refField = "user";
|
|
588
|
+
}
|
|
589
|
+
let refValue = doc[name];
|
|
590
|
+
if (!refValue) {
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
594
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
595
|
+
let objectDataLoader = refObj.enable_dataloader != false &&
|
|
596
|
+
process.env.STEEDOS_GRAPHQL_ENABLE_DATALOADER != "false";
|
|
597
|
+
if (objectDataLoader) {
|
|
598
|
+
const results = await getObjectDisplayData("api", field.reference_to, name, refField, graphqlCtx.objectDataLoaderHandler, graphqlCtx);
|
|
599
|
+
if (field.multiple) {
|
|
600
|
+
displayObj[name] = _.map(results, (item) => {
|
|
601
|
+
return {
|
|
602
|
+
objectName: refTo,
|
|
603
|
+
value: item ? item._id : refValue,
|
|
604
|
+
label: item ? item[nameFieldKey] : refValue,
|
|
605
|
+
};
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
displayObj[name] = {
|
|
610
|
+
objectName: refTo,
|
|
611
|
+
value: results._id || refValue,
|
|
612
|
+
label: results[nameFieldKey] || refValue,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
if (field.multiple) {
|
|
618
|
+
let refRecords = await refObj.find({
|
|
619
|
+
filters: [refField, "in", refValue],
|
|
620
|
+
fields: [nameFieldKey],
|
|
621
|
+
});
|
|
622
|
+
displayObj[name] = _.map(refRecords, (item) => {
|
|
623
|
+
return {
|
|
624
|
+
objectName: refTo,
|
|
625
|
+
value: item._id,
|
|
626
|
+
label: item[nameFieldKey],
|
|
627
|
+
};
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
let refRecord = (await refObj.find({
|
|
632
|
+
filters: [refField, "=", refValue],
|
|
633
|
+
fields: [nameFieldKey],
|
|
634
|
+
}))[0];
|
|
635
|
+
if (refRecord) {
|
|
636
|
+
displayObj[name] = {
|
|
637
|
+
objectName: refTo,
|
|
638
|
+
value: refRecord._id,
|
|
639
|
+
label: refRecord[nameFieldKey],
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
else if ((fType == "master_detail" || fType == "lookup") &&
|
|
646
|
+
((field.reference_to && !_.isString(field.reference_to)) ||
|
|
647
|
+
_.isString(field._reference_to))) {
|
|
648
|
+
let refValue = doc[name];
|
|
649
|
+
if (!refValue) {
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
let refTo = refValue.o;
|
|
653
|
+
let refValues = refValue.ids;
|
|
654
|
+
if (!refTo) {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
let refObj = steedosSchema.getObject(refTo);
|
|
658
|
+
let nameFieldKey = await refObj.getNameFieldKey();
|
|
659
|
+
let refRecords = await refObj.find({
|
|
660
|
+
filters: [`_id`, "in", refValues],
|
|
661
|
+
fields: [nameFieldKey],
|
|
662
|
+
});
|
|
663
|
+
displayObj[name] = _.map(refRecords, (item) => {
|
|
664
|
+
return {
|
|
665
|
+
objectName: refTo,
|
|
666
|
+
value: item._id,
|
|
667
|
+
label: item[nameFieldKey],
|
|
668
|
+
};
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else if (fType == "formula") {
|
|
672
|
+
displayObj[name] = (0, utils_1.formatBasicFieldValue)(field.data_type, field, doc[name], objConfig, userSession);
|
|
673
|
+
}
|
|
674
|
+
else if (fType == "summary") {
|
|
675
|
+
displayObj[name] = (0, utils_1.formatBasicFieldValue)(dataType, field, doc[name], objConfig, userSession);
|
|
676
|
+
}
|
|
677
|
+
else if (fType == "image" ||
|
|
678
|
+
fType == "file" ||
|
|
679
|
+
fType === "avatar") {
|
|
680
|
+
const optionsStr = fType == "file" ? "" : "";
|
|
681
|
+
let fileValue = null;
|
|
682
|
+
let value = doc[name];
|
|
683
|
+
if (!value) {
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
let storageName = (0, utils_1.getFileStorageName)(fType);
|
|
687
|
+
let fileObjectName = `cfs_${storageName}_filerecord`;
|
|
688
|
+
let fileObject = steedosSchema.getObject(fileObjectName);
|
|
689
|
+
const fileNameFieldKey = "original.name";
|
|
690
|
+
if (field.multiple) {
|
|
691
|
+
let fileRecords = await fileObject.find({
|
|
692
|
+
filters: [`_id`, "in", value],
|
|
693
|
+
fields: [
|
|
694
|
+
"_id",
|
|
695
|
+
fileNameFieldKey,
|
|
696
|
+
"original.size",
|
|
697
|
+
"original.type",
|
|
698
|
+
],
|
|
699
|
+
});
|
|
700
|
+
fileValue = _.map(fileRecords, (fileRecord) => {
|
|
701
|
+
const fName = fileRecord.original?.name;
|
|
702
|
+
return {
|
|
703
|
+
name: fName,
|
|
704
|
+
url: `/api/v6/files/download/cfs.${storageName}.filerecord/${fileRecord._id}/${fName}${optionsStr}`,
|
|
705
|
+
size: fileRecord.original?.size,
|
|
706
|
+
type: fileRecord.original?.type,
|
|
707
|
+
value: fileRecord._id,
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
let fileRecord = (await fileObject.find({
|
|
713
|
+
filters: [`_id`, "=", value],
|
|
714
|
+
fields: [
|
|
715
|
+
"_id",
|
|
716
|
+
fileNameFieldKey,
|
|
717
|
+
"original.size",
|
|
718
|
+
"original.type",
|
|
719
|
+
],
|
|
720
|
+
}))[0];
|
|
721
|
+
if (fileRecord) {
|
|
722
|
+
const fName = fileRecord["original"]["name"];
|
|
723
|
+
fileValue = {
|
|
724
|
+
name: fName,
|
|
725
|
+
url: `/api/v6/files/download/cfs.${storageName}.filerecord/${value}/${fName}${optionsStr}`,
|
|
726
|
+
size: fileRecord.original?.size,
|
|
727
|
+
type: fileRecord.original?.type,
|
|
728
|
+
value: fileRecord._id,
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
fileValue = {
|
|
733
|
+
url: value,
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
displayObj[name] = fileValue;
|
|
738
|
+
}
|
|
739
|
+
else if (fType == "filesize") {
|
|
740
|
+
displayObj[name] = (0, utils_1.formatFileSize)(doc[name]);
|
|
741
|
+
}
|
|
742
|
+
else if (fType === "object") {
|
|
743
|
+
if (doc[name] && _.isObject(doc[name])) {
|
|
744
|
+
const _doc = {};
|
|
745
|
+
_.each(doc[name], function (v, k) {
|
|
746
|
+
const newKey = `${name}.${k}`;
|
|
747
|
+
_doc[newKey] = v;
|
|
748
|
+
});
|
|
749
|
+
const objectFieldDoc = await _translateToUI(_doc, Object.keys(_doc), doc);
|
|
750
|
+
const objectDoc = {};
|
|
751
|
+
_.each(objectFieldDoc, function (v, k) {
|
|
752
|
+
const newKey = k.replace(`${name}.`, "");
|
|
753
|
+
objectDoc[newKey] = v;
|
|
1025
754
|
});
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
case 7:
|
|
1048
|
-
try {
|
|
1049
|
-
if (selectorFieldNames_2_1 && !selectorFieldNames_2_1.done && (_a = selectorFieldNames_2.return)) _a.call(selectorFieldNames_2);
|
|
755
|
+
displayObj[name] = objectDoc;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
else if (fType === "grid" || "table" === fType) {
|
|
759
|
+
if (doc[name] && _.isArray(doc[name])) {
|
|
760
|
+
const gridDocs = [];
|
|
761
|
+
for (const gridDoc of doc[name]) {
|
|
762
|
+
const _doc = {};
|
|
763
|
+
_.each(gridDoc, function (v, k) {
|
|
764
|
+
const newKey = `${name}.$.${k}`;
|
|
765
|
+
_doc[newKey] = v;
|
|
766
|
+
});
|
|
767
|
+
const objectFieldDoc = await _translateToUI(_doc, Object.keys(_doc), doc);
|
|
768
|
+
const objectDoc = {};
|
|
769
|
+
_.each(objectFieldDoc, function (v, k) {
|
|
770
|
+
const newKey = k.replace(`${name}.$.`, "");
|
|
771
|
+
objectDoc[newKey] = v;
|
|
772
|
+
});
|
|
773
|
+
gridDocs.push(objectDoc);
|
|
774
|
+
}
|
|
775
|
+
displayObj[name] = gridDocs;
|
|
1050
776
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
displayObj[name] = (0, utils_1.formatBasicFieldValue)(fType, field, doc[name], objConfig, userSession);
|
|
780
|
+
}
|
|
1054
781
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
lng = (0, objectql_1.getUserLocale)(userSession);
|
|
1063
|
-
steedosSchema = (0, objectql_1.getSteedosSchema)();
|
|
1064
|
-
fields = objConfig.fields;
|
|
1065
|
-
(0, i18n_1.translationObject)(lng, objConfig.name, objConfig, true);
|
|
1066
|
-
return [4, _translateToUI(doc, selectorFieldNames, doc)];
|
|
1067
|
-
case 1:
|
|
1068
|
-
uiDoc = _a.sent();
|
|
1069
|
-
uiDoc["_id"] = doc._id;
|
|
1070
|
-
return [2, uiDoc];
|
|
782
|
+
else {
|
|
783
|
+
displayObj[name] = "";
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
catch (error) {
|
|
787
|
+
displayObj[name] = doc[name];
|
|
788
|
+
}
|
|
1071
789
|
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
790
|
+
}
|
|
791
|
+
return displayObj;
|
|
792
|
+
}
|
|
793
|
+
let uiDoc = await _translateToUI(doc, selectorFieldNames, doc);
|
|
794
|
+
uiDoc["_id"] = doc._id;
|
|
795
|
+
return uiDoc;
|
|
1074
796
|
}
|
|
1075
797
|
function getTranslatedFieldConfig(translatedObject, name) {
|
|
1076
798
|
return translatedObject.fields[name.replace(/__label$/, "")];
|