mushroom-cli 1.2.0-alpha.10 → 1.2.0-alpha.12

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