mushroom-cli 1.2.0-alpha.7.1 → 1.2.0-alpha.9

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