mushroom-cli 1.2.0-alpha.8 → 1.2.0

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