mushroom-cli 1.2.0-alpha.2 → 1.2.0-alpha.20

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.
Files changed (46) hide show
  1. package/README.md +273 -111
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +273 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/bootstrap-theme.min.css +6 -0
  6. package/dist/docs/bootstrap.min.css +6 -0
  7. package/dist/docs/bootstrap.min.js +7 -0
  8. package/{docs → dist/docs}/doc-mt.js +103 -1
  9. package/{docs → dist/docs}/docs.html +83 -22
  10. package/dist/docs/docs.v2.html +5097 -0
  11. package/dist/docs/docs.v2.js +1907 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/gen/gen-api-docs-v1.js +110 -0
  14. package/dist/gen/gen-api-docs.js +306 -0
  15. package/{gen → dist/gen}/gen-csharp.js +1246 -1414
  16. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  17. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  18. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  19. package/dist/gen/gen-ts-driver.js +596 -0
  20. package/{gen.js → dist/gen.js} +109 -120
  21. package/{help.js → dist/help.js} +53 -55
  22. package/dist/init/init-json.js +92 -0
  23. package/dist/init/init-netcore.js +30 -0
  24. package/dist/init.js +23 -0
  25. package/dist/master-file/master-file.js +185 -0
  26. package/dist/merge.js +70 -0
  27. package/dist/mr.js +77 -0
  28. package/dist/types.js +1 -0
  29. package/dist/update/tsCode.js +82 -0
  30. package/dist/update.js +20 -0
  31. package/package.json +64 -27
  32. package/check-update.js +0 -9
  33. package/common.js +0 -236
  34. package/config.js +0 -445
  35. package/gen/gen-api-docs.js +0 -125
  36. package/gen/gen-ts-driver.js +0 -460
  37. package/init/init-json.js +0 -106
  38. package/init/init-netcore.js +0 -32
  39. package/init.js +0 -28
  40. package/master-file/master-file.js +0 -234
  41. package/merge.js +0 -84
  42. package/mr.js +0 -82
  43. package/update/tsCode.js +0 -20
  44. package/update.js +0 -24
  45. /package/{docs → dist/docs}/mt-dom-1.0.js +0 -0
  46. /package/{docs → dist/docs}/mt.extension.js +0 -0
@@ -0,0 +1,1907 @@
1
+ function toCSharpName(str) {
2
+ if (typeof str != 'string' || str === '') return '';
3
+ const name = str.replace(/\W/g, '_');
4
+ return name.charAt(0).toUpperCase() + name.substring(1);
5
+ }
6
+ function encodeHtml(data) {
7
+ if (data === undefined || data === null) return '';
8
+ var html = typeof data === 'string' ? data : data.toString();
9
+ html = html.replace(/&/g, '&');
10
+ html = html.replace(/</g, '&lt;');
11
+ html = html.replace(/>/g, '&gt;');
12
+ html = html.replace(/"/g, '&quot;');
13
+ html = html.replace(/'/g, '&apos;');
14
+ return html;
15
+ }
16
+ function populateTemplates() {
17
+ const templates = {};
18
+ document.querySelectorAll('.mushroom-docs-template').forEach((dom) => {
19
+ templates[dom.id] = dom.innerHTML;
20
+ dom.remove();
21
+ });
22
+ window.templates = templates;
23
+ }
24
+ function renderTemplate(templateId, data) {
25
+ const template = window.templates[templateId];
26
+ if (!template) return '';
27
+ return template.replace(/\{\{(\w+)(:html)?\}\}/g, (_, field, format) =>
28
+ format === ':html' ? (data?.[field] ?? '') : encodeHtml(data?.[field]),
29
+ );
30
+ }
31
+
32
+ function getApiDomain(url) {
33
+ const m = url.match(/^(\w+:)?\/\/(([\w-]+\.)+\w+(:\d+)?)/);
34
+ return m ? m[2] : 'your host';
35
+ }
36
+ function getApiPath(url) {
37
+ const m = url.match(/^(\w+:)?\/\/([\w-]+\.)+\w+(:\d+)?/);
38
+ return m ? url.substring(m[0].length) : url;
39
+ }
40
+
41
+ function getPanelClass(actionName) {
42
+ switch (actionName) {
43
+ case 'findMany':
44
+ case 'findById':
45
+ return 'panel panel-primary';
46
+ case 'createOne':
47
+ case 'createMany':
48
+ return 'panel panel-info';
49
+ case 'updateOne':
50
+ case 'updateMany':
51
+ return 'panel panel-warning';
52
+ case 'updatePartially':
53
+ return 'panel panel-warning';
54
+ case 'deleteOne':
55
+ case 'deleteMany':
56
+ return 'panel panel-danger';
57
+ default:
58
+ return 'panel panel-default';
59
+ }
60
+ }
61
+ function getHttpMethod(actionName) {
62
+ switch (actionName) {
63
+ case 'findMany':
64
+ case 'findById':
65
+ return 'GET';
66
+ case 'createOne':
67
+ case 'createMany':
68
+ return 'POST';
69
+ case 'updateOne':
70
+ case 'updateMany':
71
+ return 'PUT';
72
+ case 'updatePartially':
73
+ return 'PATCH';
74
+ case 'deleteOne':
75
+ case 'deleteMany':
76
+ return 'DELETE';
77
+ default:
78
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1)
79
+ return actionName.substring('_raw_http_method_'.length);
80
+ return 'UNKNOWN(' + actionName + ')';
81
+ }
82
+ }
83
+ function getApiUrl(actionName, rootUrl, entityName) {
84
+ switch (actionName) {
85
+ case 'findMany':
86
+ case 'createOne':
87
+ case 'createMany':
88
+ case 'updateMany':
89
+ case 'deleteMany':
90
+ return rootUrl + entityName + 's';
91
+ case 'findById':
92
+ case 'updateOne':
93
+ case 'updatePartially':
94
+ case 'deleteOne':
95
+ return rootUrl + entityName + 's/{' + entityName + 'Id}';
96
+ default:
97
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1)
98
+ return rootUrl + entityName + 's/' + actionName.substring('_raw_http_method_'.length);
99
+ return 'UNKNOWN(' + actionName + ')';
100
+ }
101
+ }
102
+ function getApiViewUrl(rootUrl, entityName, viewName) {
103
+ return rootUrl + entityName + 's/views/' + viewName;
104
+ }
105
+ function getDescriptionByActionName(actionName, entityName) {
106
+ switch (actionName) {
107
+ case 'findMany':
108
+ return 'Lấy về danh sách các ' + entityName;
109
+ case 'findById':
110
+ return 'Lấy về một ' + entityName + ' theo mã của nó';
111
+ case 'createOne':
112
+ return 'Tạo mới một ' + entityName;
113
+ case 'createMany':
114
+ return 'Tạo mới hàng loạt các ' + entityName;
115
+ case 'updateOne':
116
+ return 'Cập nhật một ' + entityName;
117
+ case 'updateMany':
118
+ return 'Cập nhật hàng loạt các ' + entityName;
119
+ case 'updatePartially':
120
+ return 'Cập nhật một phần dữ liệu của ' + entityName;
121
+ case 'deleteOne':
122
+ return 'Xóa một ' + entityName + ' theo mã của nó';
123
+ case 'deleteMany':
124
+ return 'Xóa hàng loạt ' + entityName;
125
+ default:
126
+ if (actionName && actionName.indexOf('_raw_http_method_') !== -1) return '';
127
+ return 'UNKNOWN(' + actionName + ')';
128
+ }
129
+ }
130
+ function explainRoles(strRoles) {
131
+ if (!strRoles) return '';
132
+
133
+ return strRoles
134
+ .split('|')
135
+ .map(function (item) {
136
+ if (item === '*') return '[Mọi người dùng]';
137
+ const roles = item.split('+');
138
+ let s = '';
139
+ if (roles.length > 1) s += '(';
140
+
141
+ s += roles.join(' và ');
142
+
143
+ if (roles.length > 1) s += ')';
144
+
145
+ return s;
146
+ })
147
+ .join(' hoặc ');
148
+ }
149
+ function getModelOutput(arrFields, fields, options) {
150
+ if (!fields || !arrFields) return '';
151
+
152
+ var obj = {};
153
+ for (var j = 0; j < arrFields.length; j++) {
154
+ if (!arrFields[j]) continue;
155
+ var segs = arrFields[j].split('.');
156
+ var objFields = fields;
157
+ var cur = obj;
158
+ for (var i = 0; i < segs.length; i++) {
159
+ if (segs[i] in objFields) {
160
+ var field = objFields[segs[i]];
161
+
162
+ if (i === segs.length - 1) {
163
+ if (!(segs[i] in cur)) cur[segs[i]] = JSON.parse(JSON.stringify(field));
164
+ } else if (field.type === 'object') {
165
+ objFields = field.fields;
166
+ if (!(segs[i] in cur)) {
167
+ var o = { type: 'object', fields: {} };
168
+ cur[segs[i]] = o;
169
+ cur = o.fields;
170
+ } else cur = cur[segs[i]].fields;
171
+ } else if (field.type === 'array') {
172
+ objFields = field.items.fields;
173
+ if (!(segs[i] in cur)) {
174
+ var a = { type: 'array', items: { type: 'object', fields: {} } };
175
+ cur[segs[i]] = a;
176
+ cur = a.items.fields;
177
+ } else cur = cur[segs[i]].items.fields;
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ return formatModel(obj, '', options).trim();
184
+ }
185
+ function formatModel(obj, strIndent, options) {
186
+ if (!obj) return '';
187
+
188
+ options = options || {};
189
+
190
+ var result = '';
191
+ var nextIndent = strIndent + ' ';
192
+ for (var m in obj) {
193
+ if (!obj.hasOwnProperty(m)) continue;
194
+
195
+ var child = obj[m];
196
+
197
+ var validation = !options.optionalToAll && child.validation && child.validation.required ? 'required' : 'optional';
198
+ if (child.type === 'IdRef' && child.reference) {
199
+ validation +=
200
+ ", ref: <a href='#" +
201
+ encodeHtml(child.reference) +
202
+ "' onclick='setTimeout(gotoHash, 20)'>" +
203
+ encodeHtml(child.reference) +
204
+ '</a>';
205
+ }
206
+
207
+ if (child.validation) {
208
+ if ('validValues' in child.validation)
209
+ validation += ', enum(' + encodeHtml(child.validation.validValues.join(', ')) + ')';
210
+ if ('invalidValues' in child.validation)
211
+ validation += ', not allow(' + encodeHtml(child.validation.invalidValues.join(', ')) + ')';
212
+ if ('pattern' in child.validation) validation += ', pattern: /' + encodeHtml(child.validation.pattern) + '/';
213
+ if ('length' in child.validation) validation += ', length: ' + child.validation.length;
214
+ if ('minLength' in child.validation) validation += ', minLength: ' + child.validation.minLength;
215
+ if ('maxLength' in child.validation) validation += ', maxLength: ' + child.validation.maxLength;
216
+ if ('min' in child.validation) validation += ', min: ' + encodeHtml(child.validation.min);
217
+ if ('max' in child.validation) validation += ', max: ' + encodeHtml(child.validation.max);
218
+ if ('gt' in child.validation) validation += ', gt: ' + encodeHtml(child.validation.gt);
219
+ if ('lt' in child.validation) validation += ', lt: ' + encodeHtml(child.validation.lt);
220
+ }
221
+
222
+ if (child.type === 'array' && child.items && child.items.type != 'object' && child.items.validation) {
223
+ validation +=
224
+ ', array items: ' + (!options.optionalToAll && child.items.validation.required ? 'required' : 'optional');
225
+ if ('validValues' in child.items.validation)
226
+ validation += ', enum(' + encodeHtml(child.items.validation.validValues.join(', ')) + ')';
227
+ if ('invalidValues' in child.items.validation)
228
+ validation += ', not allow(' + encodeHtml(child.items.validation.invalidValues.join(', ')) + ')';
229
+ if ('pattern' in child.items.validation)
230
+ validation += ', pattern: /' + encodeHtml(child.items.validation.pattern) + '/';
231
+ if ('length' in child.items.validation) validation += ', length: ' + child.items.validation.length;
232
+ if ('minLength' in child.items.validation) validation += ', minLength: ' + child.items.validation.minLength;
233
+ if ('maxLength' in child.items.validation) validation += ', maxLength: ' + child.items.validation.maxLength;
234
+ if ('min' in child.items.validation) validation += ', min: ' + encodeHtml(child.items.validation.min);
235
+ if ('max' in child.items.validation) validation += ', max: ' + encodeHtml(child.items.validation.max);
236
+ if ('gt' in child.items.validation) validation += ', gt: ' + encodeHtml(child.items.validation.gt);
237
+ if ('lt' in child.items.validation) validation += ', lt: ' + encodeHtml(child.items.validation.lt);
238
+ }
239
+
240
+ let defaultValueDocs = '';
241
+ if (options.showDefaultValue && child.defaultValue !== undefined && child.defaultValue !== null) {
242
+ defaultValueDocs = `, default: ${encodeHtml(child.type === 'string' ? JSON.stringify(child.defaultValue) : child.defaultValue)}`;
243
+ }
244
+
245
+ var comment = `<span class="code-comment">// ${validation}${defaultValueDocs} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description) : ''}</span>`;
246
+
247
+ if (options.mode === 'model') {
248
+ if (child.type === 'object')
249
+ result +=
250
+ '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(child.fields, nextIndent, options) + ',';
251
+ else if (child.type === 'array') {
252
+ result += `\r\n${nextIndent}"${m}": [`;
253
+ if (child.items.type === 'object')
254
+ result += ' ' + comment + formatModel(child.items.fields, nextIndent, options);
255
+ else if (child.items.type === 'datetime')
256
+ result +=
257
+ `\r\n${nextIndent} ` +
258
+ JSON.stringify(child.items.defaultValue || 'ISODate_ISO_8601') +
259
+ ' ' +
260
+ comment +
261
+ `\r\n${nextIndent}`;
262
+ else if (child.items.type === 'boolean')
263
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || 'false' + ' ' + comment + `\r\n${nextIndent}`;
264
+ else if (child.items.type === 'integer' || child.items.type === 'long' || child.items.type === 'double')
265
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || '0' + ' ' + comment + `\r\n${nextIndent}`;
266
+ else
267
+ result +=
268
+ `\r\n${nextIndent} ` +
269
+ JSON.stringify(child.defaultValue || child.type) +
270
+ ' ' +
271
+ comment +
272
+ `\r\n${nextIndent}`;
273
+ result += `]`;
274
+ } else if (child.type === 'datetime')
275
+ result +=
276
+ `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || 'ISODate_ISO_8601') + ', ' + comment;
277
+ else if (child.type === 'boolean')
278
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || 'false') + ', ' + comment;
279
+ else if (child.type === 'integer' || child.type === 'long' || child.type === 'double')
280
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || '0') + ', ' + comment;
281
+ else result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ', ' + comment;
282
+ } else if (options.mode === 'model_null') {
283
+ if (child.type === 'object')
284
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(child.fields, nextIndent, options);
285
+ else if (child.type === 'array') {
286
+ result += `\r\n${nextIndent}"${m}": [`;
287
+ if (child.items.type === 'object')
288
+ result += ' ' + comment + formatModel(child.items.fields, nextIndent, options) + '],';
289
+ else result += '], ' + comment;
290
+ } else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
291
+ } else if (options.mode === 'model_undefined') {
292
+ if (child.type === 'object')
293
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatModel(child.fields, nextIndent, options);
294
+ else if (child.type === 'array') {
295
+ result += `\r\n${nextIndent}"${m}": [`;
296
+ if (child.items.type === 'object')
297
+ result += ' ' + comment + formatModel(child.items.fields, nextIndent, options) + '], ';
298
+ else result += '], ' + comment;
299
+ } else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
300
+ } else {
301
+ result += '\r\n' + strIndent + encodeHtml(m) + ': ' + encodeHtml(child.type);
302
+ if (child.type === 'array') result += child.items.type === 'object' ? ' of object' : ' of ' + child.items.type;
303
+ if (child.type === 'object') result += ' ' + comment + formatModel(child.fields, strIndent + ' ', options);
304
+ else if (child.type === 'array' && child.items.type === 'object')
305
+ result += ' ' + comment + formatModel(child.items.fields, strIndent + ' ', options);
306
+ else result += ', ' + comment;
307
+ }
308
+ }
309
+
310
+ if (options.mode === 'model' || options.mode === 'model_null' || options.mode === 'model_undefined') {
311
+ return (strIndent ? '\r\n' + strIndent : '') + '{' + result + '\r\n' + strIndent + '}';
312
+ }
313
+
314
+ return result;
315
+ }
316
+ function toCachePolicyString(cachePolicy) {
317
+ if (cachePolicy === undefined || cachePolicy === null || cachePolicy === 'unset') return 'Không thiết lập cấu hình';
318
+ if (cachePolicy === 'required') return 'Bắt buộc phải cache';
319
+ if (cachePolicy === 'allow') return 'Cho phép';
320
+ if (cachePolicy === 'disabled') return 'Bắt buộc không được cache';
321
+ return '';
322
+ }
323
+ function getModelInput(excludedFields, fields, options) {
324
+ fields = JSON.parse(JSON.stringify(fields));
325
+ if (!fields) return '';
326
+
327
+ options = options || {};
328
+
329
+ fields.id = fields.id || {};
330
+ fields.id.type = fields.id.type || 'AutoId';
331
+ fields.id.validation = fields.id.validation || {};
332
+ fields.id.validation.required = true;
333
+
334
+ if (excludedFields && Array.isArray(excludedFields)) {
335
+ if (options.excludeId && fields.id.type === 'AutoId') {
336
+ excludedFields = [...excludedFields, 'id'];
337
+ }
338
+
339
+ excludedFields.forEach((item) => {
340
+ let obj = fields;
341
+ const segs = item.split('.');
342
+ for (let i = 0; i < segs.length; i++) {
343
+ if (!obj) return;
344
+ const seg = segs[i];
345
+ if (!(seg in obj)) return;
346
+
347
+ if (i === segs.length - 1) delete obj[seg];
348
+ else if (obj[seg].type === 'object') obj = obj[seg].fields;
349
+ else if (obj[seg].type === 'array') obj = obj[seg].items?.fields;
350
+ else return;
351
+ }
352
+ });
353
+ }
354
+
355
+ return formatModel(fields, '', { ...options, showValidation: true }).trim();
356
+ }
357
+ function formatHintModel(obj, strIndent, options) {
358
+ if (!obj) return '';
359
+
360
+ strIndent = strIndent || '';
361
+ options = options || {};
362
+
363
+ var result = '';
364
+ var nextIndent = strIndent + ' ';
365
+ for (var m in obj) {
366
+ if (!obj.hasOwnProperty(m)) continue;
367
+
368
+ var child = obj[m];
369
+
370
+ var validation = !options.optionalToAll && child.required ? 'required' : 'optional';
371
+ if (child.type === 'IdRef' && child.reference) {
372
+ validation +=
373
+ ", ref: <a href='#" +
374
+ encodeHtml(child.reference) +
375
+ "' onclick='setTimeout(gotoHash, 20)'>" +
376
+ encodeHtml(child.reference) +
377
+ '</a>';
378
+ }
379
+
380
+ if (child.validValues && Array.isArray(child.validValues)) {
381
+ validation += ', enum(' + encodeHtml(child.validValues.join(', ')) + ')';
382
+ }
383
+
384
+ if (child.type === 'array' && child.items && child.items.type != 'object') {
385
+ validation += ', array items: ' + (!options.optionalToAll && child.items.required ? 'required' : 'optional');
386
+ if (child.items.validValues && Array.isArray(child.items.validValues))
387
+ validation += ', enum(' + encodeHtml(child.items.validValues.join(', ')) + ')';
388
+ }
389
+
390
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === 'string' && child.description !== '' ? '- ' + encodeHtml(child.description) : ''}</span>`;
391
+
392
+ if (options.mode === 'model') {
393
+ if (child.type === 'object')
394
+ result +=
395
+ '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options) + ',';
396
+ else if (child.type === 'array') {
397
+ result += `\r\n${nextIndent}"${m}": [`;
398
+ if (child.items.type === 'object')
399
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options);
400
+ else if (child.items.type === 'datetime')
401
+ result +=
402
+ `\r\n${nextIndent} ` +
403
+ JSON.stringify(child.items.defaultValue || 'ISODate_ISO_8601') +
404
+ ' ' +
405
+ comment +
406
+ `\r\n${nextIndent}`;
407
+ else if (child.items.type === 'boolean')
408
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || 'false' + ' ' + comment + `\r\n${nextIndent}`;
409
+ else if (child.items.type === 'integer' || child.items.type === 'long' || child.items.type === 'double')
410
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || '0' + ' ' + comment + `\r\n${nextIndent}`;
411
+ else
412
+ result +=
413
+ `\r\n${nextIndent} ` +
414
+ JSON.stringify(child.defaultValue || child.type) +
415
+ ' ' +
416
+ comment +
417
+ `\r\n${nextIndent}`;
418
+ result += `]`;
419
+ } else if (child.type === 'datetime')
420
+ result +=
421
+ `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || 'ISODate_ISO_8601') + ', ' + comment;
422
+ else if (child.type === 'boolean')
423
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || 'false') + ', ' + comment;
424
+ else if (child.type === 'integer' || child.type === 'long' || child.type === 'double')
425
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || '0') + ', ' + comment;
426
+ else result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ', ' + comment;
427
+ } else if (options.mode === 'model_null') {
428
+ if (child.type === 'object')
429
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options);
430
+ else if (child.type === 'array') {
431
+ result += `\r\n${nextIndent}"${m}": [`;
432
+ if (child.items.type === 'object')
433
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options) + '],';
434
+ else result += '], ' + comment;
435
+ } else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
436
+ } else if (options.mode === 'model_undefined') {
437
+ if (child.type === 'object')
438
+ result += '\r\n' + nextIndent + '"' + m + '": ' + comment + formatHintModel(child.fields, nextIndent, options);
439
+ else if (child.type === 'array') {
440
+ result += `\r\n${nextIndent}"${m}": [`;
441
+ if (child.items.type === 'object')
442
+ result += ' ' + comment + formatHintModel(child.items.fields, nextIndent, options) + '], ';
443
+ else result += '], ' + comment;
444
+ } else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
445
+ } else {
446
+ result += '\r\n' + strIndent + encodeHtml(m) + ': ' + encodeHtml(child.type);
447
+ if (child.type === 'array') result += child.items.type === 'object' ? ' of object' : ' of ' + child.items.type;
448
+ if (child.type === 'object') result += ' ' + comment + formatHintModel(child.fields, strIndent + ' ', options);
449
+ else if (child.type === 'array' && child.items.type === 'object')
450
+ result += ' ' + comment + formatHintModel(child.items.fields, strIndent + ' ', options);
451
+ else result += ', ' + comment;
452
+ }
453
+ }
454
+
455
+ if (options.mode === 'model' || options.mode === 'model_null' || options.mode === 'model_undefined') {
456
+ return (strIndent ? '\r\n' + strIndent : '') + '{' + result + '\r\n' + strIndent + '}';
457
+ }
458
+
459
+ return result;
460
+ }
461
+
462
+ function renderInfo() {
463
+ document.title = document.querySelector('#project-title').innerText = window.docs.info.name + ' API document';
464
+ document.querySelector('#project-description').innerText = window.docs.info.description;
465
+
466
+ document.querySelector('#project-roles').innerHTML =
467
+ window.docs.roles.map((role) => renderTemplate('template-project-role', role)).join('') ?? '';
468
+
469
+ if (window.docs.info.security?.crossDomain === false) {
470
+ document.querySelector('#project-security-crossDomain-false').style.display = 'block';
471
+ }
472
+ if (
473
+ window.docs.info.security?.crossDomain === true &&
474
+ Array.isArray(window.docs.info.security.allowOrigins) &&
475
+ window.docs.info.security.allowOrigins.length &&
476
+ !window.docs.info.security.allowOrigins.includes('*')
477
+ ) {
478
+ document.querySelector('#project-security-allowOrigins').style.display = 'block';
479
+ document.querySelector('#project-security-allowOrigins ul').innerHTML = window.docs.info.security.allowOrigins
480
+ .map((origin) => renderTemplate('template-li-code', { value: origin }))
481
+ .join('');
482
+ }
483
+
484
+ const domRootUrls = document.querySelector('#project-rootUrls');
485
+ const rootUrls = Object.keys(localStorage)
486
+ .filter((key) => localStorage.hasOwnProperty(key) && key.startsWith('rootUrl.'))
487
+ .map((key) => key.substring(8));
488
+ if (!rootUrls.includes(window.docs.info.rootUrl)) rootUrls.unshift(window.docs.info.rootUrl);
489
+
490
+ let selected = localStorage.selected_root_url;
491
+ if (!selected) selected = localStorage.selected_root_url = window.docs.info.rootUrl;
492
+ const onspanclick = function () {
493
+ this.parentNode.parentNode.querySelector('.selected').className = '';
494
+ selected = this.innerText;
495
+ this.className = 'selected';
496
+ const old_root_url = localStorage.selected_root_url;
497
+ const new_root_url = this.innerText;
498
+ localStorage.selected_root_url = new_root_url;
499
+ document
500
+ .querySelectorAll('.contain-root-url')
501
+ .forEach((dom) => (dom.innerHTML = dom.innerHTML.replace(old_root_url, new_root_url)));
502
+ document.querySelectorAll('.root-url').forEach((dom) => (dom.innerText = new_root_url));
503
+ document.querySelectorAll('.domain').forEach((dom) => (dom.innerText = getApiDomain(new_root_url)));
504
+ };
505
+ const onlabelclick = function () {
506
+ const span = this.parentNode.querySelector('span');
507
+ if (span.className == 'selected') return;
508
+
509
+ const rootUrl = span.innerText;
510
+ const index = rootUrls.indexOf(rootUrl);
511
+ if (index !== -1) rootUrls.splice(index, 1);
512
+
513
+ localStorage.removeItem(`rootUrl.${rootUrl}`);
514
+
515
+ this.parentNode.remove();
516
+ };
517
+
518
+ const addRootUrlDom = (rootUrl, liAddNew) => {
519
+ const li = document.createElement('li');
520
+ if (rootUrl == window.docs.info.rootUrl) li.className = 'origin';
521
+ const span = document.createElement('span');
522
+ span.innerText = rootUrl;
523
+ if (rootUrl == selected) span.className = 'selected';
524
+ li.appendChild(span);
525
+ const label = document.createElement('label');
526
+ label.className = 'delete';
527
+ label.title = 'Xóa';
528
+ li.appendChild(label);
529
+ domRootUrls.insertBefore(li, liAddNew);
530
+ span.onclick = onspanclick;
531
+ label.onclick = onlabelclick;
532
+ };
533
+
534
+ const li = document.createElement('li');
535
+ const span = document.createElement('span');
536
+ span.innerText = 'Thêm mới API root url';
537
+ span.className = 'add-new';
538
+ li.appendChild(span);
539
+ domRootUrls.appendChild(li);
540
+
541
+ rootUrls.forEach((rootUrl) => addRootUrlDom(rootUrl, li));
542
+ span.onclick = () => {
543
+ const newRootUrl = prompt('Nhập API root url mới:');
544
+ if (!newRootUrl) return;
545
+ if (rootUrls.includes(newRootUrl)) return;
546
+
547
+ if (!newRootUrl.match(/^(https?:)?\/\//i)) {
548
+ alert('API root url không hợp lệ!');
549
+ return;
550
+ }
551
+
552
+ rootUrls.push(newRootUrl);
553
+ localStorage[`rootUrl.${newRootUrl}`] = '';
554
+ addRootUrlDom(newRootUrl, li);
555
+ };
556
+ }
557
+
558
+ function renderEnvironmentVariables() {
559
+ document.querySelector('#extension-env-vars').innerHTML = renderTemplate('template-project-environmentVariables');
560
+ if (!window.docs.environmentVariables) return;
561
+ const keys = Object.keys(window.docs.environmentVariables);
562
+ if (!keys.length) return;
563
+
564
+ document.querySelector('#extension-env-vars-custom').innerHTML = keys
565
+ .map((name) =>
566
+ renderTemplate('template-project-environmentVariables-custom', {
567
+ name,
568
+ description: window.docs.environmentVariables[name].description,
569
+ type: window.docs.environmentVariables[name].type,
570
+ }),
571
+ )
572
+ .join('');
573
+ }
574
+
575
+ function renderExtensionAuth() {
576
+ if (!window.docs.features?.includes('auth')) return;
577
+ document.querySelector('#extension-auth').innerHTML = renderTemplate('template-extension-DefaultAuth-module', {
578
+ rootUrl: localStorage.selected_root_url,
579
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
580
+ domain: getApiDomain(localStorage.selected_root_url),
581
+ });
582
+ }
583
+
584
+ function renderExtensionFile() {
585
+ if (!window.docs.features?.includes('file')) return;
586
+ document.querySelector('#extension-file').innerHTML = renderTemplate('template-extension-File-module', {
587
+ rootUrl: localStorage.selected_root_url,
588
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
589
+ domain: getApiDomain(localStorage.selected_root_url),
590
+ });
591
+ }
592
+
593
+ function renderExtensionMail() {
594
+ if (!window.docs.features?.includes('mail')) return;
595
+ document.querySelector('#extension-mailing').innerHTML = renderTemplate('template-extension-Mailing-module', {
596
+ rootUrl: localStorage.selected_root_url,
597
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
598
+ domain: getApiDomain(localStorage.selected_root_url),
599
+ });
600
+ }
601
+
602
+ function renderClientDrivers() {
603
+ if (!window.docs.features?.includes('driver')) return;
604
+ document.querySelector('#extension-client-drivers').innerHTML = renderTemplate('template-client-drivers');
605
+ }
606
+
607
+ function renderEntities() {
608
+ if (!window.docs.entities || typeof window.docs.entities !== 'object') return;
609
+ document.querySelector('#project-entities').innerHTML = Object.values(window.docs.entities)
610
+ .map((entity) => renderTemplate('template-project-entity', entity))
611
+ .join('');
612
+ }
613
+
614
+ function renderEntity(entityName) {
615
+ if (this.dataset.rendered) return;
616
+ this.dataset.rendered = true;
617
+ const entity = window.docs.entities[entityName];
618
+ if (!entity) return;
619
+ if (entity.actions && typeof entity.actions === 'object') {
620
+ const dom = this.parentNode.querySelector('.project-entity-actions');
621
+ dom.innerHTML = Object.keys(entity.actions)
622
+ .map((actionName) =>
623
+ renderTemplate('template-project-entity-actions', {
624
+ entityName: entity.name,
625
+ actionName,
626
+ className: getPanelClass(actionName),
627
+ actionHttpMethod: getHttpMethod(actionName),
628
+ actionApiUrl: getApiUrl(actionName, localStorage.selected_root_url, entity.name),
629
+ actionDescription: getDescriptionByActionName(actionName, entity.name),
630
+ }),
631
+ )
632
+ .join('');
633
+ initDom(dom);
634
+ }
635
+
636
+ if (entity.views && typeof entity.views === 'object') {
637
+ const dom = this.parentNode.querySelector('.project-entity-views');
638
+ dom.innerHTML = Object.keys(entity.views)
639
+ .map((viewName) =>
640
+ renderTemplate('template-project-entity-views', {
641
+ entityName: entity.name,
642
+ viewName,
643
+ actionApiUrl: getApiViewUrl(localStorage.selected_root_url, entity.name, viewName),
644
+ description: entity.views[viewName]?.[0]?.description ?? '',
645
+ }),
646
+ )
647
+ .join('');
648
+ initDom(dom);
649
+ }
650
+ }
651
+
652
+ function renderEntityAction(entityName, actionName) {
653
+ if (this.dataset.rendered) return;
654
+ this.dataset.rendered = true;
655
+
656
+ const entity = window.docs.entities[entityName];
657
+ const actionRoles = entity.actions[actionName];
658
+
659
+ const navTabs = this.parentNode.querySelector('.nav-tabs');
660
+
661
+ navTabs.innerHTML = actionRoles
662
+ .map((actionRole) =>
663
+ renderTemplate('template-project-entity-action-role', {
664
+ explainedRole: explainRoles(actionRole.grant),
665
+ entityName,
666
+ actionName,
667
+ grant: actionRole.grant,
668
+ }),
669
+ )
670
+ .join('');
671
+
672
+ initDom(navTabs);
673
+
674
+ activeFirstChild.call(navTabs);
675
+ }
676
+
677
+ function renderEntityActionRolePage(entityName, actionName, grant) {
678
+ if (this.dataset.rendered) return;
679
+ this.dataset.rendered = true;
680
+
681
+ const entity = window.docs.entities[entityName];
682
+ const action = entity.actions[actionName].find((a) => a.grant === grant);
683
+
684
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector('.tab-pages');
685
+ tabPages.innerHTML += renderTemplate('template-project-entity-action-page', { grant });
686
+
687
+ let template;
688
+ let callback;
689
+ let codeSnippetName = actionName;
690
+ switch (actionName) {
691
+ case 'findMany':
692
+ template = 'template-findMany';
693
+ callback = renderFindMany;
694
+ break;
695
+ case 'findById':
696
+ template = 'template-findById';
697
+ callback = renderFindById;
698
+ break;
699
+ case 'createOne':
700
+ template = 'template-createOne';
701
+ callback = renderCreateOne;
702
+ break;
703
+ case 'createMany':
704
+ template = 'template-createMany';
705
+ callback = renderCreateMany;
706
+ break;
707
+ case 'updateOne':
708
+ template = 'template-updateOne';
709
+ callback = renderUpdateOne;
710
+ break;
711
+ case 'updateMany':
712
+ template = 'template-updateMany';
713
+ callback = renderUpdateMany;
714
+ break;
715
+ case 'updatePartially':
716
+ template = 'template-updatePartially';
717
+ callback = renderUpdatePartially;
718
+ break;
719
+ case 'deleteOne':
720
+ template = 'template-deleteOne';
721
+ callback = renderDeleteOne;
722
+ break;
723
+ case 'deleteMany':
724
+ template = 'template-deleteMany';
725
+ callback = renderDeleteMany;
726
+ break;
727
+ default:
728
+ template = 'template-generalAction';
729
+ callback = renderGeneralAction;
730
+ codeSnippetName = 'generalAction';
731
+ break;
732
+ }
733
+ const tabPage = Array.prototype.find.call(
734
+ tabPages.querySelectorAll('.tab-page'),
735
+ (dom) => dom.dataset?.role == action.grant,
736
+ );
737
+ if (!tabPage) return;
738
+ const args = {
739
+ tabPage,
740
+ action,
741
+ actionName,
742
+ entity,
743
+ entityName,
744
+ EntityName: toCSharpName(entityName),
745
+ domain: getApiDomain(localStorage.selected_root_url),
746
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
747
+ };
748
+ const snippet = window.codeSnippets[codeSnippetName] ?? {};
749
+ const data = {
750
+ explainedDenyRoles: explainRoles(action.deny),
751
+ entityName,
752
+ codeSnippetTabHeaders: Object.keys(snippet)
753
+ .map(
754
+ (lang, idx) =>
755
+ `<li role="presentation" ${idx ? '' : 'class="active"'}><a data-role="${lang}" onclick="activeRoleTab.call(this)">${lang}</a></li>`,
756
+ )
757
+ .join(''),
758
+ codeSnippetTabPages: Object.keys(snippet)
759
+ .map(
760
+ (lang, idx) =>
761
+ `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`,
762
+ )
763
+ .join(''),
764
+ EntityName: args.EntityName,
765
+ domain: args.domain,
766
+ rootUrlPath: args.rootUrlPath,
767
+ description: action.description,
768
+ };
769
+ tabPage.innerHTML =
770
+ renderTemplate(template, data) + renderTemplate('template-project-entity-action-page-codeSnippets', data);
771
+ initDom(tabPage);
772
+ if (!action.deny) tabPage.querySelector('.deny-roles')?.remove();
773
+
774
+ if (!action.matches || !Array.isArray(action.matches) || !action.matches.length)
775
+ tabPage.querySelector('.matches')?.remove();
776
+ else {
777
+ if (action.matches.length === 1) {
778
+ tabPage.querySelector('.matches .matches-length-gt-1')?.remove();
779
+ }
780
+ const dom = tabPage.querySelector('.matches .match-conditions');
781
+ if (dom) {
782
+ dom.innerHTML = action.matches.map((m) => renderTemplate('template-li-code', { value: m })).join('');
783
+ }
784
+ }
785
+ if (!action.description) {
786
+ tabPage.querySelector('.description')?.remove();
787
+ }
788
+ callback(args);
789
+ }
790
+
791
+ function renderFindMany(args) {
792
+ if (Array.isArray(args.action.returnableFields)) {
793
+ args.tabPage.querySelector('.output-without-fields').innerHTML = getModelOutput(
794
+ args.action.defaultFields,
795
+ args.entity.fields,
796
+ );
797
+ args.tabPage.querySelector('.field-list').innerHTML = args.action.returnableFields
798
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
799
+ .join('');
800
+ args.tabPage.querySelector('.output-with-fields').innerHTML = getModelOutput(
801
+ args.action.returnableFields,
802
+ args.entity.fields,
803
+ );
804
+ }
805
+
806
+ if (
807
+ !args.action.defaultFilters &&
808
+ !args.action.allowFilteringFields &&
809
+ !args.action.requiredFilteringFields &&
810
+ !args.entity.features?.vn_text?.fields?.length
811
+ ) {
812
+ args.tabPage.querySelector('.filters')?.remove();
813
+ } else {
814
+ if (Array.isArray(args.action.defaultFilters) && args.action.defaultFilters.length) {
815
+ if (args.action.defaultFilters.length === 1) args.tabPage.querySelector('.defaultFilters-length-gt-1')?.remove();
816
+ args.tabPage.querySelector('.defaultFilters-ul').innerHTML = args.action.defaultFilters
817
+ .map((filter) => renderTemplate('template-li-code', { value: filter }))
818
+ .join('');
819
+ } else {
820
+ args.tabPage.querySelector('.defaultFilters')?.remove();
821
+ }
822
+
823
+ if (Array.isArray(args.action.allowFilteringFields) && args.action.allowFilteringFields.length) {
824
+ args.tabPage.querySelector('.allowFilteringFields-list').innerHTML = args.action.allowFilteringFields
825
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
826
+ .join(' ');
827
+ } else {
828
+ args.tabPage.querySelector('.allowFilteringFields')?.remove();
829
+ }
830
+
831
+ if (Array.isArray(args.action.requiredFilteringFields) && args.action.requiredFilteringFields.length) {
832
+ args.tabPage.querySelector('.requiredFilteringFields-list').innerHTML = args.action.requiredFilteringFields
833
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
834
+ .join(' ');
835
+ } else {
836
+ args.tabPage.querySelector('.requiredFilteringFields')?.remove();
837
+ }
838
+
839
+ if (args.entity.features?.vn_text?.fields?.length) {
840
+ args.tabPage.querySelector('.features-vn_text-fields-channel-default-fields').innerHTML =
841
+ args.entity.features.vn_text.fields
842
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
843
+ .join(' ');
844
+
845
+ if (args.entity.features?.vn_text?.channels?.length) {
846
+ args.tabPage.querySelector('.features-vn_text-channels-list').innerHTML = args.entity.features.vn_text.channels
847
+ .map((channel) =>
848
+ renderTemplate('template-findMany-vn_text-channel', {
849
+ name: channel.name,
850
+ htmlFields: channel.fields
851
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
852
+ .join(' '),
853
+ }),
854
+ )
855
+ .join('');
856
+ }
857
+ } else {
858
+ args.tabPage.querySelector('.features-vn_text-fields')?.remove();
859
+ }
860
+ }
861
+
862
+ if (!args.action.allowSortings && !args.action.defaultSortings) {
863
+ args.tabPage.querySelector('.sort')?.remove();
864
+ } else {
865
+ if (Array.isArray(args.action.allowSortings) && args.action.allowSortings.length) {
866
+ args.tabPage.querySelector('.allowSortings-fields').innerHTML = args.action.allowSortings
867
+ .map((item) =>
868
+ renderTemplate('template-findMany-sorting', {
869
+ field: item.field,
870
+ sortType:
871
+ item.type === 'Both'
872
+ ? 'Cả TĂNG dần và GIẢM dần'
873
+ : item.type === 'Asc'
874
+ ? 'Chỉ TĂNG dần'
875
+ : item.type === 'Desc'
876
+ ? 'Chỉ GIẢM dần'
877
+ : item.type === undefined || item.type === null
878
+ ? 'Chỉ TĂNG dần'
879
+ : '',
880
+ }),
881
+ )
882
+ .join('');
883
+ } else {
884
+ args.tabPage.querySelector('.defaultFilters')?.remove();
885
+ }
886
+
887
+ if (Array.isArray(args.action.defaultSortings) && args.action.defaultSortings.length) {
888
+ args.tabPage.querySelector('.defaultSortings-fields').innerHTML = args.action.defaultSortings
889
+ .map((item) =>
890
+ renderTemplate('template-findMany-sorting', {
891
+ field: item.field,
892
+ sortType:
893
+ item.type === 'Asc'
894
+ ? 'TĂNG dần'
895
+ : item.type === 'Desc'
896
+ ? 'GIẢM dần'
897
+ : item.type === undefined || item.type === null
898
+ ? 'TĂNG dần'
899
+ : '',
900
+ }),
901
+ )
902
+ .join('');
903
+ } else {
904
+ args.tabPage.querySelector('.defaultSortings')?.remove();
905
+ }
906
+ }
907
+
908
+ args.tabPage.querySelector('.paging').innerHTML = renderTemplate('template-findMany-paging', {
909
+ strPagingType:
910
+ args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === 'None'
911
+ ? 'Không phân trang'
912
+ : args.action.pagingType === 'LimitOffset'
913
+ ? 'Theo limit, offset'
914
+ : args.action.pagingType === 'Page'
915
+ ? 'Theo page number'
916
+ : '',
917
+ entityName: args.entityName,
918
+ maxPageSize: args.action.maxPageSize,
919
+ maxRecordCount:
920
+ args.action.maxPageSize === undefined || args.action.maxPageSize === null
921
+ ? (args.action.pageSize ?? 25)
922
+ : Math.min(args.action.maxPageSize, args.action.pageSize ?? 25),
923
+ });
924
+
925
+ if (args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === 'None') {
926
+ args.tabPage.querySelector('.pagingType-ne-None')?.remove();
927
+ } else if (args.action.maxPageSize === undefined || args.action.maxPageSize === null) {
928
+ args.tabPage.querySelector('.maxPageSize')?.remove();
929
+ }
930
+
931
+ if (args.action.includeTotal !== true) {
932
+ args.tabPage.querySelector('.includeTotal')?.remove();
933
+ }
934
+
935
+ if (args.action.cache?.enable !== true) {
936
+ args.tabPage.querySelector('.cache')?.remove();
937
+ } else {
938
+ args.tabPage.querySelector('.cache').innerHTML = renderTemplate('template-findMany-cache', {
939
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
940
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy),
941
+ });
942
+ }
943
+ }
944
+
945
+ function renderFindById(args) {
946
+ if (Array.isArray(args.action.returnableFields)) {
947
+ args.tabPage.querySelector('.output-without-fields').innerHTML = getModelOutput(
948
+ args.action.defaultFields,
949
+ args.entity.fields,
950
+ );
951
+ args.tabPage.querySelector('.field-list').innerHTML = args.action.returnableFields
952
+ .map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
953
+ .join('');
954
+ args.tabPage.querySelector('.output-with-fields').innerHTML = getModelOutput(
955
+ args.action.returnableFields,
956
+ args.entity.fields,
957
+ );
958
+ }
959
+
960
+ if (args.action.cache?.enable !== true) {
961
+ args.tabPage.querySelector('.cache')?.remove();
962
+ } else {
963
+ args.tabPage.querySelector('.cache').innerHTML = renderTemplate('template-findMany-cache', {
964
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
965
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy),
966
+ });
967
+ }
968
+ }
969
+
970
+ function renderCreateOne(args) {
971
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
972
+ excludeId: true,
973
+ showDefaultValue: true,
974
+ });
975
+ }
976
+
977
+ function renderCreateMany(args) {
978
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
979
+ excludeId: true,
980
+ showDefaultValue: true,
981
+ });
982
+ }
983
+
984
+ function renderUpdateOne(args) {
985
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
986
+ showDefaultValue: true,
987
+ });
988
+ }
989
+
990
+ function renderUpdateMany(args) {
991
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
992
+ showDefaultValue: true,
993
+ });
994
+ }
995
+
996
+ function renderUpdatePartially(args) {
997
+ args.tabPage.querySelector('.input-model').innerHTML = getModelInput(args.action.exclude, args.entity.fields, {
998
+ optionalToAll: true,
999
+ });
1000
+ }
1001
+
1002
+ function renderDeleteOne(args) {}
1003
+
1004
+ function renderDeleteMany(args) {}
1005
+
1006
+ function renderGeneralAction(args) {
1007
+ if (args.action?.codeHint?.delegator?.param?.fields) {
1008
+ args.tabPage.querySelector('.query-string-model').innerHTML = formatHintModel(
1009
+ args.action.codeHint.delegator.param.fields,
1010
+ );
1011
+ } else {
1012
+ args.tabPage.querySelector('.query-string')?.remove();
1013
+ }
1014
+ if (args.action?.codeHint?.delegator?.requestBody?.fields) {
1015
+ args.tabPage.querySelector('.request-body-model').innerHTML = formatHintModel(
1016
+ args.action.codeHint.delegator.requestBody.fields,
1017
+ );
1018
+ } else {
1019
+ args.tabPage.querySelector('.request-body')?.remove();
1020
+ }
1021
+ }
1022
+
1023
+ function renderEntityView(entityName, viewName) {
1024
+ if (this.dataset.rendered) return;
1025
+ this.dataset.rendered = true;
1026
+
1027
+ const entity = window.docs.entities[entityName];
1028
+ const viewRoles = entity.views[viewName];
1029
+
1030
+ const navTabs = this.parentNode.querySelector('.nav-tabs');
1031
+
1032
+ navTabs.innerHTML = viewRoles
1033
+ .map((viewRole) =>
1034
+ renderTemplate('template-project-entity-view-role', {
1035
+ explainedRole: explainRoles(viewRole.grant),
1036
+ entityName,
1037
+ viewName,
1038
+ grant: viewRole.grant,
1039
+ }),
1040
+ )
1041
+ .join('');
1042
+ initDom(navTabs);
1043
+ activeFirstChild.call(navTabs);
1044
+ }
1045
+
1046
+ function renderEntityViewRolePage(entityName, viewName, grant) {
1047
+ if (this.dataset.rendered) return;
1048
+ this.dataset.rendered = true;
1049
+
1050
+ const entity = window.docs.entities[entityName];
1051
+ const view = entity.views[viewName].find((a) => a.grant === grant);
1052
+
1053
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector('.tab-pages');
1054
+ tabPages.innerHTML += renderTemplate('template-project-entity-view-page', { grant });
1055
+
1056
+ const tabPage = Array.prototype.find.call(
1057
+ tabPages.querySelectorAll('.tab-page'),
1058
+ (dom) => dom.dataset?.role == view.grant,
1059
+ );
1060
+ if (!tabPage) return;
1061
+ const args = {
1062
+ tabPage,
1063
+ view,
1064
+ viewName,
1065
+ entity,
1066
+ entityName,
1067
+ EntityName: toCSharpName(entityName),
1068
+ domain: getApiDomain(localStorage.selected_root_url),
1069
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
1070
+ };
1071
+ const snippet = window.codeSnippets.view;
1072
+ const data = {
1073
+ explainedDenyRoles: explainRoles(view.deny),
1074
+ entityName,
1075
+ viewName,
1076
+ codeSnippetTabHeaders: Object.keys(snippet)
1077
+ .map(
1078
+ (lang, idx) =>
1079
+ `<li role="presentation" ${idx ? '' : 'class="active"'}><a data-role="${lang}" onclick="activeRoleTab.call(this)">${lang}</a></li>`,
1080
+ )
1081
+ .join(''),
1082
+ codeSnippetTabPages: Object.keys(snippet)
1083
+ .map(
1084
+ (lang, idx) =>
1085
+ `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`,
1086
+ )
1087
+ .join(''),
1088
+ description: view.description,
1089
+ outputModel: formatHintModel(view.codeHint?.output?.fields),
1090
+ outputEmptyResult: JSON.stringify(view.emptyResult, null, 4),
1091
+ };
1092
+ tabPage.innerHTML =
1093
+ renderTemplate('template-view', data) + renderTemplate('template-project-entity-view-page-codeSnippets', data);
1094
+ initDom(tabPage);
1095
+ if (!view.deny) tabPage.querySelector('.deny-roles')?.remove();
1096
+
1097
+ if (!Array.isArray(view.parameters) || !view.parameters.length) {
1098
+ tabPage.querySelector('.parameters-input-pane')?.remove();
1099
+ } else {
1100
+ tabPage.querySelector('.parameters-list').innerHTML = view.parameters
1101
+ .map((p) =>
1102
+ renderTemplate('template-view-parameters', {
1103
+ field: p.field,
1104
+ type: (p.isArray ? 'array of ' : '') + (p.type ?? 'string'),
1105
+ description: p.description ?? '',
1106
+ defaultValue: p.defaultValue ? `, default (${p.defaultValue})` : '',
1107
+ required: p.required ? 'required' : 'optional',
1108
+ }),
1109
+ )
1110
+ .join('');
1111
+ }
1112
+ if (!view.codeHint?.output?.fields) {
1113
+ tabPage.querySelector('.output-model')?.remove();
1114
+ }
1115
+ if (!view.emptyResult) {
1116
+ tabPage.querySelector('.output-epmty-result')?.remove();
1117
+ }
1118
+ if (!view.codeHint?.output?.fields && !view.emptyResult) {
1119
+ tabPage.querySelector('.output-pane')?.remove();
1120
+ }
1121
+
1122
+ if (!view.description) {
1123
+ tabPage.querySelector('.description')?.remove();
1124
+ }
1125
+ //callback(args);
1126
+ }
1127
+
1128
+ window.codeSnippets = {
1129
+ findMany: {
1130
+ Javascript: (args) =>
1131
+ renderTemplate('template-codeSnippets-findMany-Javascript', {
1132
+ entityName: args.entityName,
1133
+ allowPagingDisplay: args.action.pagingType && args.action.pagingType != 'None' ? 'inline' : 'none',
1134
+ includeTotalDisplay: args.action.includeTotal ? 'inline' : 'none',
1135
+ fields: args.action.returnableFields
1136
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1137
+ .join(''),
1138
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1139
+ sortFields: args.action.allowSortings
1140
+ ?.map(
1141
+ (sort) =>
1142
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1143
+ )
1144
+ .join(''),
1145
+ limitDisplay: args.action.pagingType === 'LimitOffset' || args.action.pagingType === 'Page' ? 'inline' : 'none',
1146
+ offsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1147
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1148
+ vnTextDisplay: args.entity.features?.vn_text?.fields?.length ? 'inline' : 'none',
1149
+ vnTextFields: args.entity.features?.vn_text?.fields
1150
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1151
+ .join(''),
1152
+ countAsyncDisplay: args.action.includeTotal ? 'inline' : 'none',
1153
+ }),
1154
+ JavascriptModel: (args) =>
1155
+ renderTemplate('template-codeSnippets-findMany-JavascriptModel', {
1156
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_undefined' }),
1157
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model' }),
1158
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_null' }),
1159
+ }),
1160
+ CSharp: (args) =>
1161
+ renderTemplate('template-codeSnippets-findMany-CSharp', {
1162
+ entityName: args.entityName,
1163
+ EntityName: args.EntityName,
1164
+ fields: args.action.returnableFields
1165
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1166
+ .join(''),
1167
+ sortFields: args.action.allowSortings
1168
+ ?.map(
1169
+ (sort) =>
1170
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1171
+ )
1172
+ .join(''),
1173
+ }),
1174
+ HTTP: (args) =>
1175
+ renderTemplate('template-codeSnippets-findMany-HTTP', {
1176
+ domain: args.domain,
1177
+ rootUrlPath: args.rootUrlPath,
1178
+ entityName: args.entityName,
1179
+ fields: args.action.returnableFields
1180
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1181
+ .join(''),
1182
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1183
+ sortFields: args.action.allowSortings
1184
+ ?.map(
1185
+ (sort) =>
1186
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1187
+ )
1188
+ .join(''),
1189
+ limitOffsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1190
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1191
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1192
+ }),
1193
+ cURL: (args) =>
1194
+ renderTemplate('template-codeSnippets-findMany-cURL', {
1195
+ rootUrl: localStorage.selected_root_url,
1196
+ entityName: args.entityName,
1197
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1198
+ fields: args.action.returnableFields
1199
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1200
+ .join(''),
1201
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1202
+ sortFields: args.action.allowSortings
1203
+ ?.map(
1204
+ (sort) =>
1205
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1206
+ )
1207
+ .join(''),
1208
+ limitOffsetDisplay: args.action.pagingType === 'LimitOffset' ? 'inline' : 'none',
1209
+ pageDisplay: args.action.pagingType === 'Page' ? 'inline' : 'none',
1210
+ }),
1211
+ Java: (args) =>
1212
+ renderTemplate('template-codeSnippets-findMany-Java', {
1213
+ entityName: args.entityName,
1214
+ EntityName: args.EntityName,
1215
+ fields: args.action.returnableFields
1216
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1217
+ .join(''),
1218
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1219
+ sortFields: args.action.allowSortings
1220
+ ?.map(
1221
+ (sort) =>
1222
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1223
+ )
1224
+ .join(''),
1225
+ }),
1226
+ JavaAsync: (args) =>
1227
+ renderTemplate('template-codeSnippets-findMany-JavaAsync', {
1228
+ entityName: args.entityName,
1229
+ EntityName: args.EntityName,
1230
+ fields: args.action.returnableFields
1231
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1232
+ .join(''),
1233
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1234
+ sortFields: args.action.allowSortings
1235
+ ?.map(
1236
+ (sort) =>
1237
+ (sort.type === 'Desc' ? '-' : '') + renderTemplate('template-fields-inline', { fieldName: sort.field }),
1238
+ )
1239
+ .join(''),
1240
+ }),
1241
+ },
1242
+ findById: {
1243
+ Javascript: (args) =>
1244
+ renderTemplate('template-codeSnippets-findById-Javascript', {
1245
+ entityName: args.entityName,
1246
+ fields: args.action.returnableFields
1247
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1248
+ .join(''),
1249
+ }),
1250
+ JavascriptModel: (args) =>
1251
+ renderTemplate('template-codeSnippets-findById-JavascriptModel', {
1252
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_undefined' }),
1253
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model' }),
1254
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, { mode: 'model_null' }),
1255
+ }),
1256
+ CSharp: (args) =>
1257
+ renderTemplate('template-codeSnippets-findById-CSharp', {
1258
+ entityName: args.entityName,
1259
+ EntityName: args.EntityName,
1260
+ fields: args.action.returnableFields
1261
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1262
+ .join(''),
1263
+ }),
1264
+ HTTP: (args) =>
1265
+ renderTemplate('template-codeSnippets-findById-HTTP', {
1266
+ domain: args.domain,
1267
+ rootUrlPath: args.rootUrlPath,
1268
+ entityName: args.entityName,
1269
+ fields: args.action.returnableFields
1270
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1271
+ .join(''),
1272
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1273
+ }),
1274
+ cURL: (args) =>
1275
+ renderTemplate('template-codeSnippets-findById-cURL', {
1276
+ rootUrl: localStorage.selected_root_url,
1277
+ entityName: args.entityName,
1278
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1279
+ fields: args.action.returnableFields
1280
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1281
+ .join(''),
1282
+ }),
1283
+ Java: (args) =>
1284
+ renderTemplate('template-codeSnippets-findById-Java', {
1285
+ entityName: args.entityName,
1286
+ EntityName: args.EntityName,
1287
+ fields: args.action.returnableFields
1288
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1289
+ .join(''),
1290
+ }),
1291
+ JavaAsync: (args) =>
1292
+ renderTemplate('template-codeSnippets-findById-JavaAsync', {
1293
+ entityName: args.entityName,
1294
+ EntityName: args.EntityName,
1295
+ fields: args.action.returnableFields
1296
+ ?.map((fieldName) => renderTemplate('template-fields-inline', { fieldName }))
1297
+ .join(''),
1298
+ }),
1299
+ },
1300
+ createOne: {
1301
+ Javascript: (args) =>
1302
+ renderTemplate('template-codeSnippets-createOne-Javascript', {
1303
+ entityName: args.entityName,
1304
+ }),
1305
+ JavascriptModel: (args) =>
1306
+ renderTemplate('template-codeSnippets-createOne-JavascriptModel', {
1307
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1308
+ mode: 'model_undefined',
1309
+ excludeId: true,
1310
+ }),
1311
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', excludeId: true }),
1312
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', excludeId: true }),
1313
+ }),
1314
+ CSharp: (args) =>
1315
+ renderTemplate('template-codeSnippets-createOne-CSharp', {
1316
+ entityName: args.entityName,
1317
+ EntityName: args.EntityName,
1318
+ }),
1319
+ HTTP: (args) =>
1320
+ renderTemplate('template-codeSnippets-createOne-HTTP', {
1321
+ domain: args.domain,
1322
+ rootUrlPath: args.rootUrlPath,
1323
+ entityName: args.entityName,
1324
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1325
+ }),
1326
+ cURL: (args) =>
1327
+ renderTemplate('template-codeSnippets-createOne-cURL', {
1328
+ rootUrl: localStorage.selected_root_url,
1329
+ entityName: args.entityName,
1330
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1331
+ }),
1332
+ Java: (args) =>
1333
+ renderTemplate('template-codeSnippets-createOne-Java', {
1334
+ entityName: args.entityName,
1335
+ EntityName: args.EntityName,
1336
+ }),
1337
+ JavaAsync: (args) =>
1338
+ renderTemplate('template-codeSnippets-createOne-JavaAsync', {
1339
+ entityName: args.entityName,
1340
+ EntityName: args.EntityName,
1341
+ }),
1342
+ },
1343
+ createMany: {
1344
+ Javascript: (args) =>
1345
+ renderTemplate('template-codeSnippets-createMany-Javascript', {
1346
+ entityName: args.entityName,
1347
+ }),
1348
+ JavascriptModel: (args) =>
1349
+ renderTemplate('template-codeSnippets-createMany-JavascriptModel', {
1350
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1351
+ mode: 'model_undefined',
1352
+ excludeId: true,
1353
+ }),
1354
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', excludeId: true }),
1355
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', excludeId: true }),
1356
+ }),
1357
+ CSharp: (args) =>
1358
+ renderTemplate('template-codeSnippets-createMany-CSharp', {
1359
+ entityName: args.entityName,
1360
+ EntityName: args.EntityName,
1361
+ }),
1362
+ HTTP: (args) =>
1363
+ renderTemplate('template-codeSnippets-createMany-HTTP', {
1364
+ domain: args.domain,
1365
+ rootUrlPath: args.rootUrlPath,
1366
+ entityName: args.entityName,
1367
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1368
+ }),
1369
+ cURL: (args) =>
1370
+ renderTemplate('template-codeSnippets-createMany-cURL', {
1371
+ rootUrl: localStorage.selected_root_url,
1372
+ entityName: args.entityName,
1373
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1374
+ }),
1375
+ Java: (args) =>
1376
+ renderTemplate('template-codeSnippets-createMany-Java', {
1377
+ entityName: args.entityName,
1378
+ EntityName: args.EntityName,
1379
+ }),
1380
+ JavaAsync: (args) =>
1381
+ renderTemplate('template-codeSnippets-createMany-JavaAsync', {
1382
+ entityName: args.entityName,
1383
+ EntityName: args.EntityName,
1384
+ }),
1385
+ },
1386
+ updateOne: {
1387
+ Javascript: (args) =>
1388
+ renderTemplate('template-codeSnippets-updateOne-Javascript', {
1389
+ entityName: args.entityName,
1390
+ }),
1391
+ JavascriptModel: (args) =>
1392
+ renderTemplate('template-codeSnippets-updateOne-JavascriptModel', {
1393
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_undefined' }),
1394
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model' }),
1395
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null' }),
1396
+ }),
1397
+ CSharp: (args) =>
1398
+ renderTemplate('template-codeSnippets-updateOne-CSharp', {
1399
+ entityName: args.entityName,
1400
+ EntityName: args.EntityName,
1401
+ }),
1402
+ HTTP: (args) =>
1403
+ renderTemplate('template-codeSnippets-updateOne-HTTP', {
1404
+ domain: args.domain,
1405
+ rootUrlPath: args.rootUrlPath,
1406
+ entityName: args.entityName,
1407
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1408
+ }),
1409
+ cURL: (args) =>
1410
+ renderTemplate('template-codeSnippets-updateOne-cURL', {
1411
+ rootUrl: localStorage.selected_root_url,
1412
+ entityName: args.entityName,
1413
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1414
+ }),
1415
+ Java: (args) =>
1416
+ renderTemplate('template-codeSnippets-updateOne-Java', {
1417
+ entityName: args.entityName,
1418
+ EntityName: args.EntityName,
1419
+ }),
1420
+ JavaAsync: (args) =>
1421
+ renderTemplate('template-codeSnippets-updateOne-JavaAsync', {
1422
+ entityName: args.entityName,
1423
+ EntityName: args.EntityName,
1424
+ }),
1425
+ },
1426
+ updateMany: {
1427
+ Javascript: (args) =>
1428
+ renderTemplate('template-codeSnippets-updateMany-Javascript', {
1429
+ entityName: args.entityName,
1430
+ }),
1431
+ JavascriptModel: (args) =>
1432
+ renderTemplate('template-codeSnippets-updateMany-JavascriptModel', {
1433
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_undefined' }),
1434
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model' }),
1435
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null' }),
1436
+ }),
1437
+ CSharp: (args) =>
1438
+ renderTemplate('template-codeSnippets-updateMany-CSharp', {
1439
+ entityName: args.entityName,
1440
+ EntityName: args.EntityName,
1441
+ }),
1442
+ HTTP: (args) =>
1443
+ renderTemplate('template-codeSnippets-updateMany-HTTP', {
1444
+ domain: args.domain,
1445
+ rootUrlPath: args.rootUrlPath,
1446
+ entityName: args.entityName,
1447
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1448
+ }),
1449
+ cURL: (args) =>
1450
+ renderTemplate('template-codeSnippets-updateMany-cURL', {
1451
+ rootUrl: localStorage.selected_root_url,
1452
+ entityName: args.entityName,
1453
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1454
+ }),
1455
+ Java: (args) =>
1456
+ renderTemplate('template-codeSnippets-updateMany-Java', {
1457
+ entityName: args.entityName,
1458
+ EntityName: args.EntityName,
1459
+ }),
1460
+ JavaAsync: (args) =>
1461
+ renderTemplate('template-codeSnippets-updateMany-JavaAsync', {
1462
+ entityName: args.entityName,
1463
+ EntityName: args.EntityName,
1464
+ }),
1465
+ },
1466
+ updatePartially: {
1467
+ Javascript: (args) =>
1468
+ renderTemplate('template-codeSnippets-updatePartially-Javascript', {
1469
+ entityName: args.entityName,
1470
+ }),
1471
+ JavascriptModel: (args) =>
1472
+ renderTemplate('template-codeSnippets-updatePartially-JavascriptModel', {
1473
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {
1474
+ mode: 'model_undefined',
1475
+ optionalToAll: true,
1476
+ }),
1477
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model', optionalToAll: true }),
1478
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, { mode: 'model_null', optionalToAll: true }),
1479
+ }),
1480
+ CSharp: (args) =>
1481
+ renderTemplate('template-codeSnippets-updatePartially-CSharp', {
1482
+ entityName: args.entityName,
1483
+ EntityName: args.EntityName,
1484
+ }),
1485
+ HTTP: (args) =>
1486
+ renderTemplate('template-codeSnippets-updatePartially-HTTP', {
1487
+ domain: args.domain,
1488
+ rootUrlPath: args.rootUrlPath,
1489
+ entityName: args.entityName,
1490
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1491
+ }),
1492
+ cURL: (args) =>
1493
+ renderTemplate('template-codeSnippets-updatePartially-cURL', {
1494
+ rootUrl: localStorage.selected_root_url,
1495
+ entityName: args.entityName,
1496
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1497
+ }),
1498
+ Java: (args) =>
1499
+ renderTemplate('template-codeSnippets-updatePartially-Java', {
1500
+ entityName: args.entityName,
1501
+ EntityName: args.EntityName,
1502
+ }),
1503
+ JavaAsync: (args) =>
1504
+ renderTemplate('template-codeSnippets-updatePartially-JavaAsync', {
1505
+ entityName: args.entityName,
1506
+ EntityName: args.EntityName,
1507
+ }),
1508
+ },
1509
+ deleteOne: {
1510
+ Javascript: (args) =>
1511
+ renderTemplate('template-codeSnippets-deleteOne-Javascript', {
1512
+ entityName: args.entityName,
1513
+ }),
1514
+ CSharp: (args) =>
1515
+ renderTemplate('template-codeSnippets-deleteOne-CSharp', {
1516
+ entityName: args.entityName,
1517
+ EntityName: args.EntityName,
1518
+ }),
1519
+ HTTP: (args) =>
1520
+ renderTemplate('template-codeSnippets-deleteOne-HTTP', {
1521
+ domain: args.domain,
1522
+ rootUrlPath: args.rootUrlPath,
1523
+ entityName: args.entityName,
1524
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1525
+ }),
1526
+ cURL: (args) =>
1527
+ renderTemplate('template-codeSnippets-deleteOne-cURL', {
1528
+ rootUrl: localStorage.selected_root_url,
1529
+ entityName: args.entityName,
1530
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1531
+ }),
1532
+ Java: (args) =>
1533
+ renderTemplate('template-codeSnippets-deleteOne-Java', {
1534
+ entityName: args.entityName,
1535
+ EntityName: args.EntityName,
1536
+ }),
1537
+ JavaAsync: (args) =>
1538
+ renderTemplate('template-codeSnippets-deleteOne-JavaAsync', {
1539
+ entityName: args.entityName,
1540
+ EntityName: args.EntityName,
1541
+ }),
1542
+ },
1543
+ deleteMany: {
1544
+ Javascript: (args) =>
1545
+ renderTemplate('template-codeSnippets-deleteMany-Javascript', {
1546
+ entityName: args.entityName,
1547
+ }),
1548
+ CSharp: (args) =>
1549
+ renderTemplate('template-codeSnippets-deleteMany-CSharp', {
1550
+ entityName: args.entityName,
1551
+ EntityName: args.EntityName,
1552
+ }),
1553
+ HTTP: (args) =>
1554
+ renderTemplate('template-codeSnippets-deleteMany-HTTP', {
1555
+ domain: args.domain,
1556
+ rootUrlPath: args.rootUrlPath,
1557
+ entityName: args.entityName,
1558
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1559
+ }),
1560
+ cURL: (args) =>
1561
+ renderTemplate('template-codeSnippets-deleteMany-cURL', {
1562
+ rootUrl: localStorage.selected_root_url,
1563
+ entityName: args.entityName,
1564
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1565
+ }),
1566
+ Java: (args) =>
1567
+ renderTemplate('template-codeSnippets-deleteMany-Java', {
1568
+ entityName: args.entityName,
1569
+ EntityName: args.EntityName,
1570
+ }),
1571
+ JavaAsync: (args) =>
1572
+ renderTemplate('template-codeSnippets-deleteMany-JavaAsync', {
1573
+ entityName: args.entityName,
1574
+ EntityName: args.EntityName,
1575
+ }),
1576
+ },
1577
+ generalAction: {
1578
+ Javascript: (args) =>
1579
+ renderTemplate('template-codeSnippets-generalAction-Javascript', {
1580
+ entityName: args.entityName,
1581
+ httpMethod: getHttpMethod(args.actionName),
1582
+ paramDisplay: args.action?.codeHint?.delegator?.param?.fields ? 'inline' : 'none',
1583
+ bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none',
1584
+ }),
1585
+ CSharp: (args) =>
1586
+ renderTemplate('template-codeSnippets-generalAction-CSharp', {
1587
+ entityName: args.entityName,
1588
+ EntityName: args.EntityName,
1589
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1590
+ }),
1591
+ HTTP: (args) =>
1592
+ renderTemplate('template-codeSnippets-generalAction-HTTP', {
1593
+ domain: args.domain,
1594
+ rootUrlPath: args.rootUrlPath,
1595
+ entityName: args.entityName,
1596
+ httpMethod: getHttpMethod(args.actionName),
1597
+ bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none',
1598
+ noBodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'none' : 'inline',
1599
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1600
+ }),
1601
+ cURL: (args) =>
1602
+ renderTemplate('template-codeSnippets-generalAction-cURL', {
1603
+ rootUrl: localStorage.selected_root_url,
1604
+ entityName: args.entityName,
1605
+ tokenDisplay: args.action.grant !== '*' ? 'inline' : 'none',
1606
+ }),
1607
+ Java: (args) =>
1608
+ renderTemplate('template-codeSnippets-generalAction-Java', {
1609
+ entityName: args.entityName,
1610
+ EntityName: args.EntityName,
1611
+ methodName: getHttpMethod(args.actionName),
1612
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1613
+ }),
1614
+ JavaAsync: (args) =>
1615
+ renderTemplate('template-codeSnippets-generalAction-JavaAsync', {
1616
+ entityName: args.entityName,
1617
+ EntityName: args.EntityName,
1618
+ methodName: getHttpMethod(args.actionName),
1619
+ MethodName: toCSharpName(getHttpMethod(args.actionName)),
1620
+ }),
1621
+ },
1622
+ view: {
1623
+ Javascript: (args) =>
1624
+ renderTemplate('template-codeSnippets-view-Javascript', {
1625
+ entityName: args.entityName,
1626
+ viewName: args.viewName,
1627
+ parameters: args.view.parameters
1628
+ ? '{\n ' +
1629
+ args.view.parameters
1630
+ .map((p) => `${encodeHtml(p.field)}: <span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1631
+ .join(',\n ') +
1632
+ '\n }'
1633
+ : '',
1634
+ }),
1635
+ JavascriptModel: (args) =>
1636
+ args.view.codeHint?.output?.fields
1637
+ ? renderTemplate('template-codeSnippets-view-JavascriptModel', {
1638
+ undefinedModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model_undefined' }),
1639
+ valueModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model' }),
1640
+ nullModel: formatHintModel(args.view.codeHint.output.fields, undefined, { mode: 'model_null' }),
1641
+ })
1642
+ : '',
1643
+ CSharp: (args) =>
1644
+ renderTemplate('template-codeSnippets-view-CSharp', {
1645
+ entityName: args.entityName,
1646
+ EntityName: args.EntityName,
1647
+ grantDisplay: args.view.grant === '*' ? 'none' : 'inline',
1648
+ Grant: toCSharpName(args.view.grant),
1649
+ ViewName: toCSharpName(args.viewName),
1650
+ parameters: args.view.parameters
1651
+ ? args.view.parameters
1652
+ .map(
1653
+ (p) =>
1654
+ `${encodeHtml(toCSharpName(p.field))} = <span class="place-holder">value_of_${encodeHtml(p.field)}</span>`,
1655
+ )
1656
+ .join(',\n ')
1657
+ : '',
1658
+ }),
1659
+ HTTP: (args) =>
1660
+ renderTemplate('template-codeSnippets-view-HTTP', {
1661
+ domain: args.domain,
1662
+ rootUrlPath: args.rootUrlPath,
1663
+ entityName: args.entityName,
1664
+ viewName: args.viewName,
1665
+ tokenDisplay: args.view.grant !== '*' ? 'inline' : 'none',
1666
+ parameters: args.view.parameters
1667
+ ? '?' +
1668
+ args.view.parameters
1669
+ .map((p) => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1670
+ .join('&')
1671
+ : '',
1672
+ }),
1673
+ cURL: (args) =>
1674
+ renderTemplate('template-codeSnippets-view-cURL', {
1675
+ rootUrl: localStorage.selected_root_url,
1676
+ entityName: args.entityName,
1677
+ tokenDisplay: args.view.grant !== '*' ? 'inline' : 'none',
1678
+ parameters: args.view.parameters
1679
+ ? '?' +
1680
+ args.view.parameters
1681
+ .map((p) => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`)
1682
+ .join('&')
1683
+ : '',
1684
+ }),
1685
+ Java: (args) =>
1686
+ renderTemplate('template-codeSnippets-view-Java', {
1687
+ entityName: args.entityName,
1688
+ EntityName: args.EntityName,
1689
+ viewName: args.viewName,
1690
+ ViewName: toCSharpName(args.viewName),
1691
+ parameters: args.view.parameters
1692
+ ? args.view.parameters
1693
+ .map(
1694
+ (p) =>
1695
+ `arg.set${encodeHtml(toCSharpName(p.field))}(<span class="place-holder">value_of_${encodeHtml(p.field)}</span>);`,
1696
+ )
1697
+ .join(',\n ')
1698
+ : '',
1699
+ }),
1700
+ JavaAsync: (args) =>
1701
+ renderTemplate('template-codeSnippets-view-JavaAsync', {
1702
+ entityName: args.entityName,
1703
+ EntityName: args.EntityName,
1704
+ viewName: args.viewName,
1705
+ ViewName: toCSharpName(args.viewName),
1706
+ parameters: args.view.parameters
1707
+ ? args.view.parameters
1708
+ .map(
1709
+ (p) =>
1710
+ `arg.set${encodeHtml(toCSharpName(p.field))}(<span class="place-holder">value_of_${encodeHtml(p.field)}</span>);`,
1711
+ )
1712
+ .join(',\n ')
1713
+ : '',
1714
+ }),
1715
+ },
1716
+ };
1717
+
1718
+ function toggleParentClass() {
1719
+ const clazz = $(this).data('toggledClass');
1720
+ $(this).parent().toggleClass(clazz);
1721
+ var hash = $(this).data('hash');
1722
+ if (hash) {
1723
+ location.hash = hash;
1724
+ }
1725
+ const computedStyle = getComputedStyle(this);
1726
+ let stickyTop = 0;
1727
+ if (computedStyle.position === 'sticky') {
1728
+ stickyTop = parseInt(computedStyle.top);
1729
+ if (isNaN(stickyTop)) stickyTop = 0;
1730
+ }
1731
+
1732
+ if (!$(this).parent().hasClass(clazz)) {
1733
+ const b = document.body; //IE 'quirks'
1734
+ let d = document.documentElement; //IE with doctype
1735
+ d = d.clientHeight ? d : b;
1736
+
1737
+ if (parseInt(d.scrollTop) > this.offsetTop - stickyTop) window.scrollTo(0, this.offsetTop - stickyTop);
1738
+ }
1739
+ }
1740
+
1741
+ function activeRoleTab() {
1742
+ var role = $(this).data('role');
1743
+ $(this).parent().parent().find('.active').removeClass('active');
1744
+ $(this).parent().addClass('active');
1745
+ $(this)
1746
+ .parent()
1747
+ .parent()
1748
+ .parent()
1749
+ .find('> .tab-pages > .tab-page')
1750
+ .removeClass('active')
1751
+ .filter(function () {
1752
+ return $(this).data('role') === role;
1753
+ })
1754
+ .addClass('active');
1755
+ }
1756
+
1757
+ function activeFirstChild() {
1758
+ let dom = this;
1759
+ dom = dom.children.length && dom.children[0];
1760
+ if (!dom) return;
1761
+ dom = dom.children.length && dom.children[0];
1762
+ if (!dom) return;
1763
+ dom.onclick && dom.onclick();
1764
+ }
1765
+
1766
+ function gotoHash() {
1767
+ if (!location.hash) return;
1768
+
1769
+ const m = location.hash.match(/^#(\$[\w-]+|\w+)(\.((views\.)?\w+))?$/);
1770
+ if (!m) return;
1771
+
1772
+ const cardSelector = m[1].charAt(0) === '$' ? '#extension-' + m[1].substring(1) : '#entity-' + m[1];
1773
+ let dom = document.querySelector(cardSelector);
1774
+ if (!dom) return;
1775
+
1776
+ let top = dom.offsetTop;
1777
+ dom = dom.firstElementChild;
1778
+ if (!dom) return;
1779
+ dom.onclick && dom.onclick();
1780
+ let computedStyle = getComputedStyle(dom);
1781
+ let stickyTop = 0;
1782
+ if (computedStyle.position === 'sticky') {
1783
+ stickyTop = parseInt(computedStyle.top);
1784
+ if (isNaN(stickyTop)) stickyTop = 0;
1785
+ }
1786
+ window.scrollTo(0, top - stickyTop);
1787
+
1788
+ if (!m[3]) return;
1789
+
1790
+ const panelSelector =
1791
+ m[1].charAt(0) === '$'
1792
+ ? '#extension-' + m[1].substring(1) + '-' + m[3].replace(/[.]/g, '-')
1793
+ : '#action-' + m[1] + '-' + m[3].replace(/[.]/g, '-');
1794
+ dom = document.querySelector(panelSelector);
1795
+ if (!dom) return;
1796
+
1797
+ top = dom.offsetTop;
1798
+ dom = dom.firstElementChild;
1799
+ if (!dom) return;
1800
+ dom.onclick && dom.onclick();
1801
+ computedStyle = getComputedStyle(dom);
1802
+ stickyTop = 0;
1803
+ if (computedStyle.position === 'sticky') {
1804
+ stickyTop = parseInt(computedStyle.top);
1805
+ if (isNaN(stickyTop)) stickyTop = 0;
1806
+ }
1807
+ window.scrollTo(0, top - stickyTop);
1808
+ }
1809
+
1810
+ function copied() {
1811
+ const dom = document.querySelector('#copied');
1812
+ if (!dom) return;
1813
+
1814
+ dom.classList.add('show');
1815
+ setTimeout(() => dom.classList.remove('show'), 1000);
1816
+ }
1817
+
1818
+ function initDom(dom) {
1819
+ $('pre[data-language]', dom).each(function () {
1820
+ const holder = document.createElement('div');
1821
+ holder.className = 'command-bar';
1822
+ const copyButton = document.createElement('a');
1823
+ copyButton.innerHTML = 'Copy';
1824
+ holder.appendChild(copyButton);
1825
+ $(this).prepend(holder);
1826
+ copyButton.onclick = function () {
1827
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1828
+ alert('Can not copy, please use https protocol!');
1829
+ return;
1830
+ }
1831
+ const pre = $(this).parent().parent();
1832
+ const commandBar = $(this).parent().detach();
1833
+ try {
1834
+ if (window.ClipboardItem) {
1835
+ const content = pre.text();
1836
+ const blob = new Blob([content], { type: 'text/plain' });
1837
+ const text = new ClipboardItem({ 'text/plain': blob });
1838
+ navigator.clipboard.write([text]);
1839
+ } else {
1840
+ if (document.body.createTextRange) {
1841
+ const range = document.body.createTextRange();
1842
+ range.moveToElementText(pre[0]);
1843
+ range.select();
1844
+ } else if (window.getSelection) {
1845
+ const selection = window.getSelection();
1846
+ const range = document.createRange();
1847
+ range.selectNodeContents(pre[0]);
1848
+ selection.removeAllRanges();
1849
+ selection.addRange(range);
1850
+ }
1851
+ document.execCommand('copy');
1852
+ }
1853
+ } finally {
1854
+ pre.prepend(commandBar);
1855
+ }
1856
+
1857
+ copied();
1858
+ };
1859
+ });
1860
+
1861
+ $('pre[data-language=json] .command-bar', dom).each(function () {
1862
+ const copyButton = document.createElement('a');
1863
+ copyButton.innerHTML = 'Copy (without comment)';
1864
+ $(this).prepend(copyButton);
1865
+ copyButton.onclick = function () {
1866
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1867
+ alert('Can not copy, please use https protocol!');
1868
+ return;
1869
+ }
1870
+ const pre = $(this).parent().parent();
1871
+ const commandBar = $(this).parent().detach();
1872
+ pre.find('.code-comment').each(function () {
1873
+ this.dataset.innerHTML = this.innerHTML;
1874
+ this.innerHTML = '';
1875
+ });
1876
+ try {
1877
+ if (window.ClipboardItem) {
1878
+ const content = pre.text();
1879
+ const blob = new Blob([content], { type: 'text/plain' });
1880
+ const text = new ClipboardItem({ 'text/plain': blob });
1881
+ navigator.clipboard.write([text]);
1882
+ } else {
1883
+ if (document.body.createTextRange) {
1884
+ const range = document.body.createTextRange();
1885
+ range.moveToElementText(pre[0]);
1886
+ range.select();
1887
+ } else if (window.getSelection) {
1888
+ const selection = window.getSelection();
1889
+ const range = document.createRange();
1890
+ range.selectNodeContents(pre[0]);
1891
+ selection.removeAllRanges();
1892
+ selection.addRange(range);
1893
+ }
1894
+ document.execCommand('copy');
1895
+ }
1896
+ } finally {
1897
+ pre.prepend(commandBar);
1898
+ pre.find('.code-comment').each(function () {
1899
+ this.innerHTML = this.dataset.innerHTML;
1900
+ delete this.dataset.innerHTML;
1901
+ });
1902
+ }
1903
+
1904
+ copied();
1905
+ };
1906
+ });
1907
+ }