mushroom-cli 1.2.0-alpha.1 → 1.2.0-alpha.11

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,1633 @@
1
+ function toCSharpName(str) {
2
+ if (typeof str != "string" || str === "") return "";
3
+ const name = str.replace(/\W/g, "_");
4
+ return name.charAt(0).toUpperCase() + name.substring(1);
5
+ }
6
+ function encodeHtml(data) {
7
+ if (data === undefined || data === null)
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.substring(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.substring("_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.substring("_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-description").innerText = window.docs.info.description;
485
+
486
+ document.querySelector("#project-roles").innerHTML = window.docs.roles.map(role => renderTemplate("template-project-role", role)).join("") ?? "";
487
+
488
+ if (window.docs.info.security?.crossDomain === false) {
489
+ document.querySelector("#project-security-crossDomain-false").style.display = "block";
490
+ }
491
+ 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("*")) {
492
+ document.querySelector("#project-security-allowOrigins").style.display = "block";
493
+ document.querySelector("#project-security-allowOrigins ul").innerHTML = window.docs.info.security.allowOrigins.map(origin => renderTemplate("template-li-code", {value: origin})).join("");
494
+ }
495
+
496
+ const domRootUrls = document.querySelector("#project-rootUrls");
497
+ const rootUrls = Object.keys(localStorage)
498
+ .filter(key => localStorage.hasOwnProperty(key) && key.startsWith("rootUrl."))
499
+ .map(key => key.substring(8));
500
+ if (!rootUrls.includes(window.docs.info.rootUrl)) rootUrls.unshift(window.docs.info.rootUrl);
501
+
502
+ let selected = localStorage.selected_root_url;
503
+ if (!selected) selected = localStorage.selected_root_url = window.docs.info.rootUrl;
504
+ const onspanclick = function() {
505
+ this.parentNode.parentNode.querySelector(".selected").className = "";
506
+ selected = this.innerText;
507
+ this.className = "selected";
508
+ const old_root_url = localStorage.selected_root_url;
509
+ const new_root_url = this.innerText;
510
+ localStorage.selected_root_url = new_root_url;
511
+ document.querySelectorAll(".contain-root-url").forEach(dom => dom.innerHTML = dom.innerHTML.replace(old_root_url, new_root_url));
512
+ document.querySelectorAll(".root-url").forEach(dom => dom.innerText = new_root_url);
513
+ document.querySelectorAll(".domain").forEach(dom => dom.innerText = getApiDomain(new_root_url))
514
+ };
515
+ const onlabelclick = function() {
516
+ const span = this.parentNode.querySelector("span");
517
+ if (span.className == "selected") return;
518
+
519
+ const rootUrl = span.innerText;
520
+ const index = rootUrls.indexOf(rootUrl);
521
+ if (index !== -1) rootUrls.splice(index, 1);
522
+
523
+ localStorage.removeItem(`rootUrl.${rootUrl}`);
524
+
525
+ this.parentNode.remove();
526
+ };
527
+
528
+ const addRootUrlDom = (rootUrl, liAddNew) => {
529
+ const li = document.createElement("li");
530
+ if (rootUrl == window.docs.info.rootUrl) li.className = "origin";
531
+ const span = document.createElement("span");
532
+ span.innerText = rootUrl;
533
+ if (rootUrl == selected) span.className = "selected";
534
+ li.appendChild(span);
535
+ const label = document.createElement("label");
536
+ label.className = "delete";
537
+ label.title = "Xóa";
538
+ li.appendChild(label);
539
+ domRootUrls.insertBefore(li, liAddNew);
540
+ span.onclick = onspanclick;
541
+ label.onclick = onlabelclick;
542
+ };
543
+
544
+ const li = document.createElement("li");
545
+ const span = document.createElement("span");
546
+ span.innerText = "Thêm mới API root url";
547
+ span.className = "add-new";
548
+ li.appendChild(span);
549
+ domRootUrls.appendChild(li);
550
+
551
+ rootUrls.forEach(rootUrl => addRootUrlDom(rootUrl, li));
552
+ span.onclick = () => {
553
+ const newRootUrl = prompt("Nhập API root url mới:");
554
+ if (!newRootUrl) return;
555
+ if (rootUrls.includes(newRootUrl)) return;
556
+
557
+ if (!newRootUrl.match(/^(https?:)?\/\//i)) {
558
+ alert("API root url không hợp lệ!");
559
+ return;
560
+ }
561
+
562
+ rootUrls.push(newRootUrl);
563
+ localStorage[`rootUrl.${newRootUrl}`] = "";
564
+ addRootUrlDom(newRootUrl, li);
565
+ };
566
+ }
567
+
568
+ function renderEnvironmentVariables() {
569
+ document.querySelector("#extension-env-vars").innerHTML = renderTemplate("template-project-environmentVariables");
570
+ if (!window.docs.environmentVariables) return;
571
+ const keys = Object.keys(window.docs.environmentVariables);
572
+ if (!keys.length) return;
573
+
574
+ document.querySelector("#extension-env-vars-custom").innerHTML = keys.map(name => renderTemplate("template-project-environmentVariables-custom", {
575
+ name,
576
+ description: window.docs.environmentVariables[name].description,
577
+ type: window.docs.environmentVariables[name].type
578
+ })).join("");
579
+ }
580
+
581
+ function renderExtensionAuth() {
582
+ if (!window.docs.features?.includes("auth")) return;
583
+ document.querySelector("#extension-auth").innerHTML = renderTemplate("template-extension-DefaultAuth-module", {
584
+ rootUrl: localStorage.selected_root_url,
585
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
586
+ domain: getApiDomain(localStorage.selected_root_url)
587
+ });
588
+ }
589
+
590
+ function renderExtensionFile() {
591
+ if (!window.docs.features?.includes("file")) return;
592
+ document.querySelector("#extension-file").innerHTML = renderTemplate("template-extension-File-module", {
593
+ rootUrl: localStorage.selected_root_url,
594
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
595
+ domain: getApiDomain(localStorage.selected_root_url)
596
+ });
597
+ }
598
+
599
+ function renderExtensionMail() {
600
+ if (!window.docs.features?.includes("mail")) return;
601
+ document.querySelector("#extension-mailing").innerHTML = renderTemplate("template-extension-Mailing-module", {
602
+ rootUrl: localStorage.selected_root_url,
603
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
604
+ domain: getApiDomain(localStorage.selected_root_url)
605
+ });
606
+ }
607
+
608
+ function renderClientDrivers() {
609
+ if (!window.docs.features?.includes("driver")) return;
610
+ document.querySelector("#extension-client-drivers").innerHTML = renderTemplate("template-client-drivers");
611
+ }
612
+
613
+ function renderEntities() {
614
+ if (!window.docs.entities ||typeof window.docs.entities !== "object" ) return;
615
+ document.querySelector("#project-entities").innerHTML = Object.values(window.docs.entities).map(entity => renderTemplate("template-project-entity", entity)).join("");
616
+ }
617
+
618
+ function renderEntity(entityName) {
619
+ if (this.dataset.rendered) return;
620
+ this.dataset.rendered = true
621
+ const entity = window.docs.entities[entityName];
622
+ if (!entity) return;
623
+ if (entity.actions && typeof(entity.actions) === "object") {
624
+ const dom = this.parentNode.querySelector(".project-entity-actions");
625
+ dom.innerHTML = Object.keys(entity.actions).map(actionName => renderTemplate("template-project-entity-actions", {
626
+ entityName: entity.name,
627
+ actionName,
628
+ className: getPanelClass(actionName),
629
+ actionHttpMethod: getHttpMethod(actionName),
630
+ actionApiUrl: getApiUrl(actionName, localStorage.selected_root_url, entity.name),
631
+ actionDescription: getDescriptionByActionName(actionName, entity.name)
632
+ })).join("");
633
+ initDom(dom);
634
+ }
635
+
636
+ if (entity.views && typeof(entity.views) === "object") {
637
+ const dom = this.parentNode.querySelector(".project-entity-views");
638
+ dom.innerHTML = Object.keys(entity.views).map(viewName => renderTemplate("template-project-entity-views", {
639
+ entityName: entity.name,
640
+ viewName,
641
+ actionApiUrl: getApiViewUrl(localStorage.selected_root_url, entity.name, viewName),
642
+ description: entity.views[viewName]?.[0]?.description ?? ""
643
+ })).join("");
644
+ initDom(dom);
645
+ }
646
+ }
647
+
648
+ function renderEntityAction(entityName, actionName) {
649
+ if (this.dataset.rendered) return;
650
+ this.dataset.rendered = true;
651
+
652
+ const entity = window.docs.entities[entityName];
653
+ const actionRoles = entity.actions[actionName];
654
+
655
+ const navTabs = this.parentNode.querySelector(".nav-tabs");
656
+
657
+ navTabs.innerHTML = actionRoles.map(actionRole => renderTemplate("template-project-entity-action-role", {
658
+ explainedRole: explainRoles(actionRole.grant),
659
+ entityName,
660
+ actionName,
661
+ grant: actionRole.grant
662
+ })).join("");
663
+
664
+ initDom(navTabs);
665
+
666
+ activeFirstChild.call(navTabs);
667
+ }
668
+
669
+ function renderEntityActionRolePage(entityName, actionName, grant) {
670
+ if (this.dataset.rendered) return;
671
+ this.dataset.rendered = true
672
+
673
+ const entity = window.docs.entities[entityName];
674
+ const action = entity.actions[actionName].find(a => a.grant === grant);
675
+
676
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector(".tab-pages");
677
+ tabPages.innerHTML += renderTemplate("template-project-entity-action-page", { grant });
678
+
679
+ let template;
680
+ let callback;
681
+ let codeSnippetName = actionName;
682
+ switch (actionName) {
683
+ case "findMany":
684
+ template = "template-findMany"
685
+ callback = renderFindMany;
686
+ break;
687
+ case "findById":
688
+ template = "template-findById"
689
+ callback = renderFindById;
690
+ break;
691
+ case "createOne":
692
+ template = "template-createOne"
693
+ callback = renderCreateOne;
694
+ break;
695
+ case "createMany":
696
+ template = "template-createMany"
697
+ callback = renderCreateMany;
698
+ break;
699
+ case "updateOne":
700
+ template = "template-updateOne"
701
+ callback = renderUpdateOne;
702
+ break;
703
+ case "updateMany":
704
+ template = "template-updateMany"
705
+ callback = renderUpdateMany;
706
+ break;
707
+ case "updatePartially":
708
+ template = "template-updatePartially"
709
+ callback = renderUpdatePartially;
710
+ break;
711
+ case "deleteOne":
712
+ template = "template-deleteOne"
713
+ callback = renderDeleteOne;
714
+ break;
715
+ case "deleteMany":
716
+ template = "template-deleteMany"
717
+ callback = renderDeleteMany;
718
+ break;
719
+ default:
720
+ template = "template-generalAction"
721
+ callback = renderGeneralAction;
722
+ codeSnippetName = "generalAction";
723
+ break;
724
+ }
725
+ const tabPage = Array.prototype.find.call(tabPages.querySelectorAll(".tab-page"), dom => dom.dataset?.role == action.grant);
726
+ if (!tabPage) return;
727
+ const args = {
728
+ tabPage,
729
+ action,
730
+ actionName,
731
+ entity,
732
+ entityName,
733
+ EntityName: toCSharpName(entityName),
734
+ domain: getApiDomain(localStorage.selected_root_url),
735
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
736
+ };
737
+ const snippet = window.codeSnippets[codeSnippetName] ?? {};
738
+ const data = {
739
+ explainedDenyRoles: explainRoles(action.deny),
740
+ entityName,
741
+ 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(""),
742
+ codeSnippetTabPages: Object.keys(snippet).map((lang, idx) => `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`).join(""),
743
+ EntityName: args.EntityName,
744
+ domain: args.domain,
745
+ rootUrlPath: args.rootUrlPath,
746
+ description: action.description
747
+ };
748
+ tabPage.innerHTML = renderTemplate(template, data) + renderTemplate("template-project-entity-action-page-codeSnippets", data);
749
+ initDom(tabPage);
750
+ if (!action.deny) tabPage.querySelector(".deny-roles")?.remove();
751
+
752
+ if (!action.matches || !Array.isArray(action.matches) || !action.matches.length) tabPage.querySelector(".matches")?.remove();
753
+ else {
754
+ if (action.matches.length === 1) {
755
+ tabPage.querySelector(".matches .matches-length-gt-1")?.remove();
756
+ }
757
+ const dom = tabPage.querySelector(".matches .match-conditions");
758
+ if (dom) {
759
+ dom.innerHTML = action.matches.map(m => renderTemplate("template-li-code", {value: m})).join("");
760
+ }
761
+ }
762
+ if (!action.description) {
763
+ tabPage.querySelector(".description")?.remove();
764
+ }
765
+ callback(args);
766
+ }
767
+
768
+ function renderFindMany(args) {
769
+ if (Array.isArray(args.action.returnableFields)) {
770
+ args.tabPage.querySelector(".output-without-fields").innerHTML = getModelOutput(args.action.defaultFields, args.entity.fields);
771
+ args.tabPage.querySelector(".field-list").innerHTML = args.action.returnableFields.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("");
772
+ args.tabPage.querySelector(".output-with-fields").innerHTML = getModelOutput(args.action.returnableFields, args.entity.fields);
773
+ }
774
+
775
+ if (!args.action.defaultFilters && !args.action.allowFilteringFields && !args.action.requiredFilteringFields && !args.entity.features?.vn_text?.fields?.length) {
776
+ args.tabPage.querySelector(".filters")?.remove()
777
+ }
778
+ else {
779
+ if (Array.isArray(args.action.defaultFilters) && args.action.defaultFilters.length) {
780
+ if (args.action.defaultFilters.length === 1) args.tabPage.querySelector(".defaultFilters-length-gt-1")?.remove();
781
+ args.tabPage.querySelector(".defaultFilters-ul").innerHTML = args.action.defaultFilters.map(filter => renderTemplate("template-li-code", {value: filter})).join("");
782
+ }
783
+ else {
784
+ args.tabPage.querySelector(".defaultFilters")?.remove();
785
+ }
786
+
787
+ if (Array.isArray(args.action.allowFilteringFields) && args.action.allowFilteringFields.length) {
788
+ args.tabPage.querySelector(".allowFilteringFields-list").innerHTML = args.action.allowFilteringFields.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(" ");
789
+ }
790
+ else {
791
+ args.tabPage.querySelector(".allowFilteringFields")?.remove();
792
+ }
793
+
794
+ if (Array.isArray(args.action.requiredFilteringFields) && args.action.requiredFilteringFields.length) {
795
+ args.tabPage.querySelector(".requiredFilteringFields-list").innerHTML = args.action.requiredFilteringFields.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(" ");
796
+ }
797
+ else {
798
+ args.tabPage.querySelector(".requiredFilteringFields")?.remove();
799
+ }
800
+
801
+ if (args.entity.features?.vn_text?.fields?.length) {
802
+ 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(" ");
803
+
804
+ if (args.entity.features?.vn_text?.channels?.length) {
805
+ args.tabPage.querySelector(".features-vn_text-channels-list").innerHTML = args.entity.features.vn_text.channels.map(channel => renderTemplate("template-findMany-vn_text-channel", {
806
+ name: channel.name,
807
+ htmlFields: channel.fields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(" ")
808
+ })).join("");
809
+ }
810
+ }
811
+ else {
812
+ args.tabPage.querySelector(".features-vn_text-fields")?.remove();
813
+ }
814
+ }
815
+
816
+ if (!args.action.allowSortings && !args.action.defaultSortings) {
817
+ args.tabPage.querySelector(".sort")?.remove()
818
+ }
819
+ else {
820
+ if (Array.isArray(args.action.allowSortings) && args.action.allowSortings.length) {
821
+ args.tabPage.querySelector(".allowSortings-fields").innerHTML = args.action.allowSortings.map(item => renderTemplate("template-findMany-sorting", {
822
+ field: item.field,
823
+ sortType: item.type === "Both"
824
+ ? "Cả TĂNG dần và GIẢM dần"
825
+ : item.type === "Asc"
826
+ ? "Chỉ TĂNG dần"
827
+ : item.type === "Desc"
828
+ ? "Chỉ GIẢM dần"
829
+ : item.type === undefined || item.type === null
830
+ ? "Chỉ TĂNG dần"
831
+ : ""
832
+ })).join("");
833
+ }
834
+ else {
835
+ args.tabPage.querySelector(".defaultFilters")?.remove();
836
+ }
837
+
838
+ if (Array.isArray(args.action.defaultSortings) && args.action.defaultSortings.length) {
839
+ args.tabPage.querySelector(".defaultSortings-fields").innerHTML = args.action.defaultSortings.map(item => renderTemplate("template-findMany-sorting", {
840
+ field: item.field,
841
+ sortType: item.type === "Asc"
842
+ ? "TĂNG dần"
843
+ : item.type === "Desc"
844
+ ? "GIẢM dần"
845
+ : item.type === undefined || item.type === null
846
+ ? "TĂNG dần"
847
+ : ""
848
+ })).join("");
849
+ }
850
+ else {
851
+ args.tabPage.querySelector(".defaultSortings")?.remove();
852
+ }
853
+ }
854
+
855
+ args.tabPage.querySelector(".paging").innerHTML = renderTemplate("template-findMany-paging", {
856
+ strPagingType: args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === "None"
857
+ ? "Không phân trang"
858
+ : args.action.pagingType === "LimitOffset"
859
+ ? "Theo limit, offset"
860
+ : args.action.pagingType === "Page"
861
+ ? "Theo page number"
862
+ : "",
863
+ entityName: args.entityName,
864
+ maxPageSize: args.action.maxPageSize,
865
+ maxRecordCount: args.action.maxPageSize === undefined || args.action.maxPageSize === null
866
+ ? (args.action.pageSize ?? 25)
867
+ : Math.min(args.action.maxPageSize, args.action.pageSize ?? 25)
868
+ });
869
+
870
+ if (args.action.pagingType === undefined || args.action.pagingType === null || args.action.pagingType === "None") {
871
+ args.tabPage.querySelector(".pagingType-ne-None")?.remove();
872
+ } else if (args.action.maxPageSize === undefined || args.action.maxPageSize === null) {
873
+ args.tabPage.querySelector(".maxPageSize")?.remove();
874
+ }
875
+
876
+ if (args.action.includeTotal !== true) {
877
+ args.tabPage.querySelector(".includeTotal")?.remove();
878
+ }
879
+
880
+ if (args.action.cache?.enable !== true) {
881
+ args.tabPage.querySelector(".cache")?.remove();
882
+ } else {
883
+ args.tabPage.querySelector(".cache").innerHTML = renderTemplate("template-findMany-cache", {
884
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
885
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy)
886
+ })
887
+ }
888
+ }
889
+
890
+ function renderFindById(args) {
891
+ if (Array.isArray(args.action.returnableFields)) {
892
+ args.tabPage.querySelector(".output-without-fields").innerHTML = getModelOutput(args.action.defaultFields, args.entity.fields);
893
+ args.tabPage.querySelector(".field-list").innerHTML = args.action.returnableFields.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("");
894
+ args.tabPage.querySelector(".output-with-fields").innerHTML = getModelOutput(args.action.returnableFields, args.entity.fields);
895
+ }
896
+
897
+ if (args.action.cache?.enable !== true) {
898
+ args.tabPage.querySelector(".cache")?.remove();
899
+ } else {
900
+ args.tabPage.querySelector(".cache").innerHTML = renderTemplate("template-findMany-cache", {
901
+ serverPolicy: toCachePolicyString(args.action.cache?.server?.policy),
902
+ clientPolicy: toCachePolicyString(args.action.cache?.client?.policy)
903
+ })
904
+ }
905
+ }
906
+
907
+ function renderCreateOne(args) {
908
+ args.tabPage.querySelector(".input-model").innerHTML = getModelInput(args.action.exclude, args.entity.fields, {"excludeId": true, showDefaultValue: true});
909
+ }
910
+
911
+ function renderCreateMany(args) {
912
+ args.tabPage.querySelector(".input-model").innerHTML = getModelInput(args.action.exclude, args.entity.fields, {"excludeId": true, showDefaultValue: true});
913
+ }
914
+
915
+ function renderUpdateOne(args) {
916
+ args.tabPage.querySelector(".input-model").innerHTML = getModelInput(args.action.exclude, args.entity.fields, { showDefaultValue: true });
917
+ }
918
+
919
+ function renderUpdateMany(args) {
920
+ args.tabPage.querySelector(".input-model").innerHTML = getModelInput(args.action.exclude, args.entity.fields, { showDefaultValue: true });
921
+ }
922
+
923
+ function renderUpdatePartially(args) {
924
+ args.tabPage.querySelector(".input-model").innerHTML = getModelInput(args.action.exclude, args.entity.fields, {optionalToAll: true});
925
+ }
926
+
927
+ function renderDeleteOne(args) {
928
+
929
+ }
930
+
931
+ function renderDeleteMany(args) {
932
+
933
+ }
934
+
935
+ function renderGeneralAction(args) {
936
+ if (args.action?.codeHint?.delegator?.param?.fields) {
937
+ args.tabPage.querySelector(".query-string-model").innerHTML = formatHintModel(args.action.codeHint.delegator.param.fields);
938
+ }
939
+ else {
940
+ args.tabPage.querySelector(".query-string")?.remove();
941
+ }
942
+ if (args.action?.codeHint?.delegator?.requestBody?.fields) {
943
+ args.tabPage.querySelector(".request-body-model").innerHTML = formatHintModel(args.action.codeHint.delegator.requestBody.fields);
944
+ }
945
+ else {
946
+ args.tabPage.querySelector(".request-body")?.remove();
947
+ }
948
+ }
949
+
950
+ function renderEntityView(entityName, viewName) {
951
+ if (this.dataset.rendered) return;
952
+ this.dataset.rendered = true;
953
+
954
+ const entity = window.docs.entities[entityName];
955
+ const viewRoles = entity.views[viewName];
956
+
957
+ const navTabs = this.parentNode.querySelector(".nav-tabs");
958
+
959
+ navTabs.innerHTML = viewRoles.map(viewRole => renderTemplate("template-project-entity-view-role", {
960
+ explainedRole: explainRoles(viewRole.grant),
961
+ entityName,
962
+ viewName,
963
+ grant: viewRole.grant
964
+ })).join("");
965
+ initDom(navTabs);
966
+ activeFirstChild.call(navTabs);
967
+ }
968
+
969
+ function renderEntityViewRolePage(entityName, viewName, grant) {
970
+ if (this.dataset.rendered) return;
971
+ this.dataset.rendered = true
972
+
973
+ const entity = window.docs.entities[entityName];
974
+ const view = entity.views[viewName].find(a => a.grant === grant);
975
+
976
+ const tabPages = this.parentNode.parentNode.parentNode.querySelector(".tab-pages");
977
+ tabPages.innerHTML += renderTemplate("template-project-entity-view-page", { grant });
978
+
979
+ const tabPage = Array.prototype.find.call(tabPages.querySelectorAll(".tab-page"), dom => dom.dataset?.role == view.grant);
980
+ if (!tabPage) return;
981
+ const args = {
982
+ tabPage,
983
+ view,
984
+ viewName,
985
+ entity,
986
+ entityName,
987
+ EntityName: toCSharpName(entityName),
988
+ domain: getApiDomain(localStorage.selected_root_url),
989
+ rootUrlPath: getApiPath(localStorage.selected_root_url),
990
+ };
991
+ const snippet = window.codeSnippets.view;
992
+ const data = {
993
+ explainedDenyRoles: explainRoles(view.deny),
994
+ entityName,
995
+ viewName,
996
+ 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(""),
997
+ codeSnippetTabPages: Object.keys(snippet).map((lang, idx) => `<div class="tab-page ${lang} ${idx ? '' : 'active'}" data-role="${lang}">${snippet[lang]?.call(null, args) ?? ''}</div>`).join(""),
998
+ description: view.description,
999
+ outputModel: formatHintModel(view.codeHint?.output?.fields),
1000
+ outputEmptyResult: JSON.stringify(view.emptyResult, null, 4)
1001
+ };
1002
+ tabPage.innerHTML = renderTemplate("template-view", data) + renderTemplate("template-project-entity-view-page-codeSnippets", data);
1003
+ initDom(tabPage);
1004
+ if (!view.deny) tabPage.querySelector(".deny-roles")?.remove();
1005
+
1006
+ if (!Array.isArray(view.parameters) || !view.parameters.length) {
1007
+ tabPage.querySelector(".parameters-input-pane")?.remove();
1008
+ }
1009
+ else {
1010
+ tabPage.querySelector(".parameters-list").innerHTML = view.parameters.map(p => renderTemplate("template-view-parameters", {
1011
+ field: p.field,
1012
+ type: (p.isArray ? "array of " : "") + (p.type ?? "string"),
1013
+ description: p.description ?? "",
1014
+ defaultValue: p.defaultValue ? `, default (${p.defaultValue})` : "",
1015
+ required: p.required ? "required" : "optional"
1016
+ })).join("");
1017
+ }
1018
+ if (!view.codeHint?.output?.fields) {
1019
+ tabPage.querySelector(".output-model")?.remove();
1020
+ }
1021
+ if (!view.emptyResult) {
1022
+ tabPage.querySelector(".output-epmty-result")?.remove();
1023
+ }
1024
+ if (!view.codeHint?.output?.fields && !view.emptyResult) {
1025
+ tabPage.querySelector(".output-pane")?.remove();
1026
+ }
1027
+
1028
+ if (!view.description) {
1029
+ tabPage.querySelector(".description")?.remove();
1030
+ }
1031
+ //callback(args);
1032
+ }
1033
+
1034
+ window.codeSnippets = {
1035
+ findMany: {
1036
+ Javascript: (args) => renderTemplate("template-codeSnippets-findMany-Javascript", {
1037
+ entityName: args.entityName,
1038
+ allowPagingDisplay: args.action.pagingType && args.action.pagingType != 'None' ? 'inline' : 'none',
1039
+ includeTotalDisplay: args.action.includeTotal ? 'inline' : 'none',
1040
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1041
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1042
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join(""),
1043
+ limitDisplay: args.action.pagingType === "LimitOffset" || args.action.pagingType === "Page" ? 'inline' : 'none',
1044
+ offsetDisplay: args.action.pagingType === "LimitOffset" ? 'inline' : 'none',
1045
+ pageDisplay: args.action.pagingType === "Page" ? 'inline' : 'none',
1046
+ vnTextDisplay: args.entity.features?.vn_text?.fields?.length ? 'inline' : 'none',
1047
+ vnTextFields: args.entity.features?.vn_text?.fields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1048
+ countAsyncDisplay: args.action.includeTotal ? 'inline' : 'none'
1049
+ }),
1050
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-findMany-JavascriptModel", {
1051
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model_undefined"}),
1052
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model"}),
1053
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model_null"})
1054
+ }),
1055
+ CSharp: (args) => renderTemplate("template-codeSnippets-findMany-CSharp", {
1056
+ entityName: args.entityName,
1057
+ EntityName: args.EntityName,
1058
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1059
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join("")
1060
+ }),
1061
+ HTTP: (args) => renderTemplate("template-codeSnippets-findMany-HTTP", {
1062
+ domain: args.domain,
1063
+ rootUrlPath: args.rootUrlPath,
1064
+ entityName: args.entityName,
1065
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1066
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1067
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join(""),
1068
+ limitOffsetDisplay: args.action.pagingType === "LimitOffset" ? 'inline' : 'none',
1069
+ pageDisplay: args.action.pagingType === "Page" ? 'inline' : 'none',
1070
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none',
1071
+ }),
1072
+ cURL: (args) => renderTemplate("template-codeSnippets-findMany-cURL", {
1073
+ rootUrl: localStorage.selected_root_url,
1074
+ entityName: args.entityName,
1075
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none',
1076
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1077
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1078
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join(""),
1079
+ limitOffsetDisplay: args.action.pagingType === "LimitOffset" ? 'inline' : 'none',
1080
+ pageDisplay: args.action.pagingType === "Page" ? 'inline' : 'none',
1081
+ }),
1082
+ Java: (args) => renderTemplate("template-codeSnippets-findMany-Java", {
1083
+ entityName: args.entityName,
1084
+ EntityName: args.EntityName,
1085
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1086
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1087
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join(""),
1088
+ }),
1089
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-findMany-JavaAsync", {
1090
+ entityName: args.entityName,
1091
+ EntityName: args.EntityName,
1092
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1093
+ allowSortingsDisplay: args.action.allowSortings ? 'inline' : 'none',
1094
+ sortFields: args.action.allowSortings?.map(sort => (sort.type === "Desc" ? '-' : '') + renderTemplate("template-fields-inline", {fieldName: sort.field})).join(""),
1095
+ })
1096
+ },
1097
+ findById: {
1098
+ Javascript: (args) => renderTemplate("template-codeSnippets-findById-Javascript", {
1099
+ entityName: args.entityName,
1100
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("")
1101
+ }),
1102
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-findById-JavascriptModel", {
1103
+ undefinedModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model_undefined"}),
1104
+ valueModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model"}),
1105
+ nullModel: getModelOutput(args.action.returnableFields, args.entity.fields, {mode: "model_null"})
1106
+ }),
1107
+ CSharp: (args) => renderTemplate("template-codeSnippets-findById-CSharp", {
1108
+ entityName: args.entityName,
1109
+ EntityName: args.EntityName,
1110
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("")
1111
+ }),
1112
+ HTTP: (args) => renderTemplate("template-codeSnippets-findById-HTTP", {
1113
+ domain: args.domain,
1114
+ rootUrlPath: args.rootUrlPath,
1115
+ entityName: args.entityName,
1116
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join(""),
1117
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1118
+ }),
1119
+ cURL: (args) => renderTemplate("template-codeSnippets-findById-cURL", {
1120
+ rootUrl: localStorage.selected_root_url,
1121
+ entityName: args.entityName,
1122
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none',
1123
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("")
1124
+ }),
1125
+ Java: (args) => renderTemplate("template-codeSnippets-findById-Java", {
1126
+ entityName: args.entityName,
1127
+ EntityName: args.EntityName,
1128
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("")
1129
+ }),
1130
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-findById-JavaAsync", {
1131
+ entityName: args.entityName,
1132
+ EntityName: args.EntityName,
1133
+ fields: args.action.returnableFields?.map(fieldName => renderTemplate("template-fields-inline", {fieldName})).join("")
1134
+ })
1135
+ },
1136
+ createOne: {
1137
+ Javascript: (args) => renderTemplate("template-codeSnippets-createOne-Javascript", {
1138
+ entityName: args.entityName
1139
+ }),
1140
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-createOne-JavascriptModel", {
1141
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_undefined", excludeId: true}),
1142
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model", excludeId: true}),
1143
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_null", excludeId: true})
1144
+ }),
1145
+ CSharp: (args) => renderTemplate("template-codeSnippets-createOne-CSharp", {
1146
+ entityName: args.entityName,
1147
+ EntityName: args.EntityName
1148
+ }),
1149
+ HTTP: (args) => renderTemplate("template-codeSnippets-createOne-HTTP", {
1150
+ domain: args.domain,
1151
+ rootUrlPath: args.rootUrlPath,
1152
+ entityName: args.entityName,
1153
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1154
+ }),
1155
+ cURL: (args) => renderTemplate("template-codeSnippets-createOne-cURL", {
1156
+ rootUrl: localStorage.selected_root_url,
1157
+ entityName: args.entityName,
1158
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1159
+ }),
1160
+ Java: (args) => renderTemplate("template-codeSnippets-createOne-Java", {
1161
+ entityName: args.entityName,
1162
+ EntityName: args.EntityName
1163
+ }),
1164
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-createOne-JavaAsync", {
1165
+ entityName: args.entityName,
1166
+ EntityName: args.EntityName
1167
+ })
1168
+ },
1169
+ createMany: {
1170
+ Javascript: (args) => renderTemplate("template-codeSnippets-createMany-Javascript", {
1171
+ entityName: args.entityName
1172
+ }),
1173
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-createMany-JavascriptModel", {
1174
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_undefined", excludeId: true}),
1175
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model", excludeId: true}),
1176
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_null", excludeId: true})
1177
+ }),
1178
+ CSharp: (args) => renderTemplate("template-codeSnippets-createMany-CSharp", {
1179
+ entityName: args.entityName,
1180
+ EntityName: args.EntityName
1181
+ }),
1182
+ HTTP: (args) => renderTemplate("template-codeSnippets-createMany-HTTP", {
1183
+ domain: args.domain,
1184
+ rootUrlPath: args.rootUrlPath,
1185
+ entityName: args.entityName,
1186
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1187
+ }),
1188
+ cURL: (args) => renderTemplate("template-codeSnippets-createMany-cURL", {
1189
+ rootUrl: localStorage.selected_root_url,
1190
+ entityName: args.entityName,
1191
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1192
+ }),
1193
+ Java: (args) => renderTemplate("template-codeSnippets-createMany-Java", {
1194
+ entityName: args.entityName,
1195
+ EntityName: args.EntityName
1196
+ }),
1197
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-createMany-JavaAsync", {
1198
+ entityName: args.entityName,
1199
+ EntityName: args.EntityName
1200
+ })
1201
+ },
1202
+ updateOne: {
1203
+ Javascript: (args) => renderTemplate("template-codeSnippets-updateOne-Javascript", {
1204
+ entityName: args.entityName
1205
+ }),
1206
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-updateOne-JavascriptModel", {
1207
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_undefined"}),
1208
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model"}),
1209
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_null"})
1210
+ }),
1211
+ CSharp: (args) => renderTemplate("template-codeSnippets-updateOne-CSharp", {
1212
+ entityName: args.entityName,
1213
+ EntityName: args.EntityName
1214
+ }),
1215
+ HTTP: (args) => renderTemplate("template-codeSnippets-updateOne-HTTP", {
1216
+ domain: args.domain,
1217
+ rootUrlPath: args.rootUrlPath,
1218
+ entityName: args.entityName,
1219
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1220
+ }),
1221
+ cURL: (args) => renderTemplate("template-codeSnippets-updateOne-cURL", {
1222
+ rootUrl: localStorage.selected_root_url,
1223
+ entityName: args.entityName,
1224
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1225
+ }),
1226
+ Java: (args) => renderTemplate("template-codeSnippets-updateOne-Java", {
1227
+ entityName: args.entityName,
1228
+ EntityName: args.EntityName
1229
+ }),
1230
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-updateOne-JavaAsync", {
1231
+ entityName: args.entityName,
1232
+ EntityName: args.EntityName
1233
+ })
1234
+ },
1235
+ updateMany: {
1236
+ Javascript: (args) => renderTemplate("template-codeSnippets-updateMany-Javascript", {
1237
+ entityName: args.entityName
1238
+ }),
1239
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-updateMany-JavascriptModel", {
1240
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_undefined"}),
1241
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model"}),
1242
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_null"})
1243
+ }),
1244
+ CSharp: (args) => renderTemplate("template-codeSnippets-updateMany-CSharp", {
1245
+ entityName: args.entityName,
1246
+ EntityName: args.EntityName
1247
+ }),
1248
+ HTTP: (args) => renderTemplate("template-codeSnippets-updateMany-HTTP", {
1249
+ domain: args.domain,
1250
+ rootUrlPath: args.rootUrlPath,
1251
+ entityName: args.entityName,
1252
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1253
+ }),
1254
+ cURL: (args) => renderTemplate("template-codeSnippets-updateMany-cURL", {
1255
+ rootUrl: localStorage.selected_root_url,
1256
+ entityName: args.entityName,
1257
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1258
+ }),
1259
+ Java: (args) => renderTemplate("template-codeSnippets-updateMany-Java", {
1260
+ entityName: args.entityName,
1261
+ EntityName: args.EntityName
1262
+ }),
1263
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-updateMany-JavaAsync", {
1264
+ entityName: args.entityName,
1265
+ EntityName: args.EntityName
1266
+ })
1267
+ },
1268
+ updatePartially: {
1269
+ Javascript: (args) => renderTemplate("template-codeSnippets-updatePartially-Javascript", {
1270
+ entityName: args.entityName
1271
+ }),
1272
+ JavascriptModel: (args) => renderTemplate("template-codeSnippets-updatePartially-JavascriptModel", {
1273
+ undefinedModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_undefined", optionalToAll: true}),
1274
+ valueModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model", optionalToAll: true}),
1275
+ nullModel: getModelInput(args.action.exclude, args.entity.fields, {mode: "model_null", optionalToAll: true})
1276
+ }),
1277
+ CSharp: (args) => renderTemplate("template-codeSnippets-updatePartially-CSharp", {
1278
+ entityName: args.entityName,
1279
+ EntityName: args.EntityName
1280
+ }),
1281
+ HTTP: (args) => renderTemplate("template-codeSnippets-updatePartially-HTTP", {
1282
+ domain: args.domain,
1283
+ rootUrlPath: args.rootUrlPath,
1284
+ entityName: args.entityName,
1285
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1286
+ }),
1287
+ cURL: (args) => renderTemplate("template-codeSnippets-updatePartially-cURL", {
1288
+ rootUrl: localStorage.selected_root_url,
1289
+ entityName: args.entityName,
1290
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1291
+ }),
1292
+ Java: (args) => renderTemplate("template-codeSnippets-updatePartially-Java", {
1293
+ entityName: args.entityName,
1294
+ EntityName: args.EntityName
1295
+ }),
1296
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-updatePartially-JavaAsync", {
1297
+ entityName: args.entityName,
1298
+ EntityName: args.EntityName
1299
+ })
1300
+ },
1301
+ deleteOne: {
1302
+ Javascript: (args) => renderTemplate("template-codeSnippets-deleteOne-Javascript", {
1303
+ entityName: args.entityName
1304
+ }),
1305
+ CSharp: (args) => renderTemplate("template-codeSnippets-deleteOne-CSharp", {
1306
+ entityName: args.entityName,
1307
+ EntityName: args.EntityName
1308
+ }),
1309
+ HTTP: (args) => renderTemplate("template-codeSnippets-deleteOne-HTTP", {
1310
+ domain: args.domain,
1311
+ rootUrlPath: args.rootUrlPath,
1312
+ entityName: args.entityName,
1313
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1314
+ }),
1315
+ cURL: (args) => renderTemplate("template-codeSnippets-deleteOne-cURL", {
1316
+ rootUrl: localStorage.selected_root_url,
1317
+ entityName: args.entityName,
1318
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1319
+ }),
1320
+ Java: (args) => renderTemplate("template-codeSnippets-deleteOne-Java", {
1321
+ entityName: args.entityName,
1322
+ EntityName: args.EntityName
1323
+ }),
1324
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-deleteOne-JavaAsync", {
1325
+ entityName: args.entityName,
1326
+ EntityName: args.EntityName
1327
+ })
1328
+ },
1329
+ deleteMany: {
1330
+ Javascript: (args) => renderTemplate("template-codeSnippets-deleteMany-Javascript", {
1331
+ entityName: args.entityName
1332
+ }),
1333
+ CSharp: (args) => renderTemplate("template-codeSnippets-deleteMany-CSharp", {
1334
+ entityName: args.entityName,
1335
+ EntityName: args.EntityName
1336
+ }),
1337
+ HTTP: (args) => renderTemplate("template-codeSnippets-deleteMany-HTTP", {
1338
+ domain: args.domain,
1339
+ rootUrlPath: args.rootUrlPath,
1340
+ entityName: args.entityName,
1341
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1342
+ }),
1343
+ cURL: (args) => renderTemplate("template-codeSnippets-deleteMany-cURL", {
1344
+ rootUrl: localStorage.selected_root_url,
1345
+ entityName: args.entityName,
1346
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1347
+ }),
1348
+ Java: (args) => renderTemplate("template-codeSnippets-deleteMany-Java", {
1349
+ entityName: args.entityName,
1350
+ EntityName: args.EntityName
1351
+ }),
1352
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-deleteMany-JavaAsync", {
1353
+ entityName: args.entityName,
1354
+ EntityName: args.EntityName
1355
+ })
1356
+ },
1357
+ generalAction: {
1358
+ Javascript: (args) => renderTemplate("template-codeSnippets-generalAction-Javascript", {
1359
+ entityName: args.entityName,
1360
+ httpMethod: getHttpMethod(args.actionName),
1361
+ paramDisplay: args.action?.codeHint?.delegator?.param?.fields ? 'inline' : 'none',
1362
+ bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none'
1363
+ }),
1364
+ CSharp: (args) => renderTemplate("template-codeSnippets-generalAction-CSharp", {
1365
+ entityName: args.entityName,
1366
+ EntityName: args.EntityName,
1367
+ MethodName: toCSharpName(getHttpMethod(args.actionName))
1368
+ }),
1369
+ HTTP: (args) => renderTemplate("template-codeSnippets-generalAction-HTTP", {
1370
+ domain: args.domain,
1371
+ rootUrlPath: args.rootUrlPath,
1372
+ entityName: args.entityName,
1373
+ httpMethod: getHttpMethod(args.actionName),
1374
+ bodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'inline' : 'none',
1375
+ noBodyDisplay: args.action?.codeHint?.delegator?.requestBody?.fields ? 'none' : 'inline',
1376
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1377
+ }),
1378
+ cURL: (args) => renderTemplate("template-codeSnippets-generalAction-cURL", {
1379
+ rootUrl: localStorage.selected_root_url,
1380
+ entityName: args.entityName,
1381
+ tokenDisplay: args.action.grant !== "*" ? 'inline' : 'none'
1382
+ }),
1383
+ Java: (args) => renderTemplate("template-codeSnippets-generalAction-Java", {
1384
+ entityName: args.entityName,
1385
+ EntityName: args.EntityName,
1386
+ methodName: getHttpMethod(args.actionName),
1387
+ MethodName: toCSharpName(getHttpMethod(args.actionName))
1388
+ }),
1389
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-generalAction-JavaAsync", {
1390
+ entityName: args.entityName,
1391
+ EntityName: args.EntityName,
1392
+ methodName: getHttpMethod(args.actionName),
1393
+ MethodName: toCSharpName(getHttpMethod(args.actionName))
1394
+ })
1395
+ },
1396
+ view: {
1397
+ Javascript: (args) => renderTemplate("template-codeSnippets-view-Javascript", {
1398
+ entityName: args.entityName,
1399
+ viewName: args.viewName,
1400
+ 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 }" : ""
1401
+ }),
1402
+ JavascriptModel: (args) => args.view.codeHint?.output?.fields ? renderTemplate("template-codeSnippets-view-JavascriptModel", {
1403
+ undefinedModel: formatHintModel(args.view.codeHint.output.fields, undefined, {mode: "model_undefined"}),
1404
+ valueModel: formatHintModel(args.view.codeHint.output.fields, undefined, {mode: "model"}),
1405
+ nullModel: formatHintModel(args.view.codeHint.output.fields, undefined, {mode: "model_null"})
1406
+ }) : "",
1407
+ CSharp: (args) => renderTemplate("template-codeSnippets-view-CSharp", {
1408
+ entityName: args.entityName,
1409
+ EntityName: args.EntityName,
1410
+ grantDisplay: args.view.grant === "*" ? 'none' : "inline",
1411
+ Grant: toCSharpName(args.view.grant),
1412
+ ViewName: toCSharpName(args.viewName),
1413
+ 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 ") : ""
1414
+ }),
1415
+ HTTP: (args) => renderTemplate("template-codeSnippets-view-HTTP", {
1416
+ domain: args.domain,
1417
+ rootUrlPath: args.rootUrlPath,
1418
+ entityName: args.entityName,
1419
+ viewName: args.viewName,
1420
+ tokenDisplay: args.view.grant !== "*" ? 'inline' : 'none',
1421
+ parameters: args.view.parameters ? "?" + args.view.parameters.map(p => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`).join("&") : ""
1422
+ }),
1423
+ cURL: (args) => renderTemplate("template-codeSnippets-view-cURL", {
1424
+ rootUrl: localStorage.selected_root_url,
1425
+ entityName: args.entityName,
1426
+ tokenDisplay: args.view.grant !== "*" ? 'inline' : 'none',
1427
+ parameters: args.view.parameters ? "?" + args.view.parameters.map(p => `${encodeHtml(p.field)}=<span class="place-holder">value_of_${encodeHtml(p.field)}</span>`).join("&") : ""
1428
+ }),
1429
+ Java: (args) => renderTemplate("template-codeSnippets-view-Java", {
1430
+ entityName: args.entityName,
1431
+ EntityName: args.EntityName,
1432
+ viewName: args.viewName,
1433
+ ViewName: toCSharpName(args.viewName),
1434
+ 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 ") : ""
1435
+ }),
1436
+ JavaAsync: (args) => renderTemplate("template-codeSnippets-view-JavaAsync", {
1437
+ entityName: args.entityName,
1438
+ EntityName: args.EntityName,
1439
+ viewName: args.viewName,
1440
+ ViewName: toCSharpName(args.viewName),
1441
+ 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 ") : ""
1442
+ })
1443
+ }
1444
+ }
1445
+
1446
+ function toggleParentClass() {
1447
+ const clazz = $(this).data("toggledClass");
1448
+ $(this).parent().toggleClass(clazz);
1449
+ var hash = $(this).data("hash");
1450
+ if (hash) {
1451
+ location.hash = hash;
1452
+ }
1453
+ const computedStyle = getComputedStyle(this);
1454
+ let stickyTop = 0;
1455
+ if (computedStyle.position === "sticky") {
1456
+ stickyTop = parseInt(computedStyle.top);
1457
+ if (isNaN(stickyTop)) stickyTop = 0;
1458
+ }
1459
+
1460
+ if (!$(this).parent().hasClass(clazz)) {
1461
+ const b = document.body; //IE 'quirks'
1462
+ let d = document.documentElement; //IE with doctype
1463
+ d = (d.clientHeight) ? d : b;
1464
+
1465
+ if (parseInt(d.scrollTop) > this.offsetTop - stickyTop)
1466
+ window.scrollTo(0, this.offsetTop - stickyTop);
1467
+ }
1468
+ }
1469
+
1470
+ function activeRoleTab() {
1471
+ var role = $(this).data("role");
1472
+ $(this).parent().parent().find(".active").removeClass("active");
1473
+ $(this).parent().addClass("active");
1474
+ $(this).parent().parent().parent().find("> .tab-pages > .tab-page").removeClass("active").filter(function () {
1475
+ return $(this).data("role") === role;
1476
+ }).addClass("active");
1477
+ }
1478
+
1479
+ function activeFirstChild() {
1480
+ let dom = this;
1481
+ dom = dom.children.length && dom.children[0];
1482
+ if (!dom) return;
1483
+ dom = dom.children.length && dom.children[0];
1484
+ if (!dom) return;
1485
+ dom.onclick && dom.onclick();
1486
+ }
1487
+
1488
+ function gotoHash() {
1489
+ if (!location.hash) return;
1490
+
1491
+ const m = location.hash.match(/^#(\$[\w-]+|\w+)(\.((views\.)?\w+))?$/);
1492
+ if (!m) return;
1493
+
1494
+ const cardSelector = m[1].charAt(0) === "$" ? "#extension-" + m[1].substring(1) : "#entity-" + m[1];
1495
+ let dom = document.querySelector(cardSelector);
1496
+ if (!dom) return;
1497
+
1498
+ let top = dom.offsetTop;
1499
+ dom = dom.firstElementChild;
1500
+ if (!dom) return;
1501
+ dom.onclick && dom.onclick();
1502
+ let computedStyle = getComputedStyle(dom);
1503
+ let stickyTop = 0;
1504
+ if (computedStyle.position === "sticky") {
1505
+ stickyTop = parseInt(computedStyle.top);
1506
+ if (isNaN(stickyTop)) stickyTop = 0;
1507
+ }
1508
+ window.scrollTo(0, top - stickyTop);
1509
+
1510
+
1511
+ if (!m[3]) return;
1512
+
1513
+ const panelSelector = m[1].charAt(0) === "$"
1514
+ ? "#extension-" + m[1].substring(1) + "-" + m[3].replace(/[.]/g, "-")
1515
+ : "#action-" + m[1] + "-" + m[3].replace(/[.]/g, "-");
1516
+ dom = document.querySelector(panelSelector);
1517
+ if (!dom) return;
1518
+
1519
+ top = dom.offsetTop;
1520
+ dom = dom.firstElementChild;
1521
+ if (!dom) return;
1522
+ dom.onclick && dom.onclick();
1523
+ computedStyle = getComputedStyle(dom);
1524
+ stickyTop = 0;
1525
+ if (computedStyle.position === "sticky") {
1526
+ stickyTop = parseInt(computedStyle.top);
1527
+ if (isNaN(stickyTop)) stickyTop = 0;
1528
+ }
1529
+ window.scrollTo(0, top - stickyTop);
1530
+ }
1531
+
1532
+ function copied() {
1533
+ const dom = document.querySelector("#copied");
1534
+ if (!dom) return;
1535
+
1536
+ dom.classList.add("show");
1537
+ setTimeout(() => dom.classList.remove("show"), 1000);
1538
+ }
1539
+
1540
+ function initDom(dom) {
1541
+ $("pre[data-language]", dom).each(function() {
1542
+ const holder = document.createElement("div");
1543
+ holder.className = "command-bar";
1544
+ const copyButton = document.createElement("a");
1545
+ copyButton.innerHTML = "Copy";
1546
+ holder.appendChild(copyButton);
1547
+ $(this).prepend(holder);
1548
+ copyButton.onclick = function() {
1549
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1550
+ alert("Can not copy, please use https protocol!");
1551
+ return;
1552
+ }
1553
+ const pre = $(this).parent().parent();
1554
+ const commandBar = $(this).parent().detach();
1555
+ try {
1556
+ if (window.ClipboardItem) {
1557
+ const content = pre.text();
1558
+ const blob = new Blob([content], { type: "text/plain" });
1559
+ const text = new ClipboardItem({ "text/plain": blob });
1560
+ navigator.clipboard.write([text]);
1561
+ }
1562
+ else {
1563
+ if (document.body.createTextRange) {
1564
+ const range = document.body.createTextRange();
1565
+ range.moveToElementText(pre[0]);
1566
+ range.select();
1567
+ } else if (window.getSelection) {
1568
+ const selection = window.getSelection();
1569
+ const range = document.createRange();
1570
+ range.selectNodeContents(pre[0]);
1571
+ selection.removeAllRanges();
1572
+ selection.addRange(range);
1573
+ }
1574
+ document.execCommand("copy");
1575
+ }
1576
+ }
1577
+ finally {
1578
+ pre.prepend(commandBar);
1579
+ }
1580
+
1581
+ copied();
1582
+ }
1583
+ });
1584
+
1585
+ $("pre[data-language=json] .command-bar", dom).each(function() {
1586
+ const copyButton = document.createElement("a");
1587
+ copyButton.innerHTML = "Copy (without comment)";
1588
+ $(this).prepend(copyButton);
1589
+ copyButton.onclick = function() {
1590
+ if (location.protocol !== 'https:' && location.protocol !== 'file:') {
1591
+ alert("Can not copy, please use https protocol!");
1592
+ return;
1593
+ }
1594
+ const pre = $(this).parent().parent();
1595
+ const commandBar = $(this).parent().detach();
1596
+ pre.find(".code-comment").each(function() {
1597
+ this.dataset.innerHTML = this.innerHTML;
1598
+ this.innerHTML = "";
1599
+ });
1600
+ try {
1601
+ if (window.ClipboardItem) {
1602
+ const content = pre.text();
1603
+ const blob = new Blob([content], { type: "text/plain" });
1604
+ const text = new ClipboardItem({ "text/plain": blob });
1605
+ navigator.clipboard.write([text]);
1606
+ }
1607
+ else {
1608
+ if (document.body.createTextRange) {
1609
+ const range = document.body.createTextRange();
1610
+ range.moveToElementText(pre[0]);
1611
+ range.select();
1612
+ } else if (window.getSelection) {
1613
+ const selection = window.getSelection();
1614
+ const range = document.createRange();
1615
+ range.selectNodeContents(pre[0]);
1616
+ selection.removeAllRanges();
1617
+ selection.addRange(range);
1618
+ }
1619
+ document.execCommand("copy");
1620
+ }
1621
+ }
1622
+ finally {
1623
+ pre.prepend(commandBar);
1624
+ pre.find(".code-comment").each(function() {
1625
+ this.innerHTML = this.dataset.innerHTML;
1626
+ delete this.dataset.innerHTML;
1627
+ });
1628
+ }
1629
+
1630
+ copied();
1631
+ }
1632
+ });
1633
+ }