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