mushroom-cli 1.2.0-alpha.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -161
- package/dist/check-update.js +6 -0
- package/dist/common.js +280 -0
- package/dist/config.js +394 -0
- package/dist/docs/bootstrap-theme.min.css +6 -0
- package/dist/docs/bootstrap.min.css +6 -0
- package/dist/docs/bootstrap.min.js +7 -0
- package/dist/docs/doc-mt.js +633 -0
- package/dist/docs/docs.html +5380 -0
- package/{docs → dist/docs}/docs.v2.html +5205 -5065
- package/dist/docs/docs.v2.js +2036 -0
- package/dist/docs/jquery.min.js +4 -0
- package/dist/docs/mt-dom-1.0.js +1398 -0
- package/dist/docs/mt.extension.js +199 -0
- package/dist/gen/gen-api-docs-v1.js +110 -0
- package/dist/gen/gen-api-docs.js +327 -0
- package/{gen → dist/gen}/gen-csharp.js +1256 -1399
- package/{gen → dist/gen}/gen-db-docs.js +204 -222
- package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
- package/{gen → dist/gen}/gen-js-driver.js +116 -133
- package/dist/gen/gen-ts-driver.js +600 -0
- package/{gen.js → dist/gen.js} +109 -124
- package/{help.js → dist/help.js} +53 -55
- package/dist/init/init-json.js +92 -0
- package/dist/init/init-netcore.js +30 -0
- package/dist/init.js +23 -0
- package/dist/master-file/master-file.js +185 -0
- package/dist/merge.js +70 -0
- package/dist/mr.js +77 -0
- package/dist/types.js +1 -0
- package/dist/update/tsCode.js +82 -0
- package/dist/update.js +20 -0
- package/package.json +64 -29
- package/check-update.js +0 -9
- package/common.js +0 -273
- package/config.js +0 -445
- package/docs/doc-mt.js +0 -523
- package/docs/docs.html +0 -5190
- package/docs/docs.v2.js +0 -1558
- package/docs/mt-dom-1.0.js +0 -1268
- package/docs/mt.extension.js +0 -174
- package/gen/gen-api-docs-v1.js +0 -125
- package/gen/gen-api-docs.js +0 -298
- package/gen/gen-ts-driver.js +0 -471
- package/init/init-json.js +0 -106
- package/init/init-netcore.js +0 -32
- package/init.js +0 -28
- package/master-file/master-file.js +0 -234
- package/merge.js +0 -84
- package/mr.js +0 -82
- package/update/tsCode.js +0 -20
- package/update.js +0 -24
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
function toCSharpName(str) {
|
|
2
|
+
var name = str.replace(/\W/g, "_");
|
|
3
|
+
return name.charAt(0).toUpperCase() + name.substr(1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function getHttpMethod(actionName) {
|
|
7
|
+
switch (actionName) {
|
|
8
|
+
case "findMany":
|
|
9
|
+
case "findById":
|
|
10
|
+
return "GET";
|
|
11
|
+
case "createOne":
|
|
12
|
+
case "createMany":
|
|
13
|
+
return "POST";
|
|
14
|
+
case "updateOne":
|
|
15
|
+
case "updateMany":
|
|
16
|
+
return "PUT";
|
|
17
|
+
case "updatePartially":
|
|
18
|
+
return "PATCH";
|
|
19
|
+
case "deleteOne":
|
|
20
|
+
case "deleteMany":
|
|
21
|
+
return "DELETE";
|
|
22
|
+
default:
|
|
23
|
+
if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
|
|
24
|
+
return actionName.substr("_raw_http_method_".length);
|
|
25
|
+
return "UNKNOWN(" + actionName + ")";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getPanelClass(actionName) {
|
|
30
|
+
switch (actionName) {
|
|
31
|
+
case "findMany":
|
|
32
|
+
case "findById":
|
|
33
|
+
return "panel panel-primary";
|
|
34
|
+
case "createOne":
|
|
35
|
+
case "createMany":
|
|
36
|
+
return "panel panel-info";
|
|
37
|
+
case "updateOne":
|
|
38
|
+
case "updateMany":
|
|
39
|
+
return "panel panel-warning";
|
|
40
|
+
case "updatePartially":
|
|
41
|
+
return "panel panel-warning";
|
|
42
|
+
case "deleteOne":
|
|
43
|
+
case "deleteMany":
|
|
44
|
+
return "panel panel-danger";
|
|
45
|
+
default:
|
|
46
|
+
return "panel panel-default";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getApiUrl(actionName, rootUrl, entityName) {
|
|
51
|
+
switch (actionName) {
|
|
52
|
+
case "findMany":
|
|
53
|
+
case "createOne":
|
|
54
|
+
case "createMany":
|
|
55
|
+
case "updateMany":
|
|
56
|
+
case "deleteMany":
|
|
57
|
+
return rootUrl + entityName + "s";
|
|
58
|
+
case "findById":
|
|
59
|
+
case "updateOne":
|
|
60
|
+
case "updatePartially":
|
|
61
|
+
case "deleteOne":
|
|
62
|
+
return rootUrl + entityName + "s/{" + entityName + "Id}";
|
|
63
|
+
default:
|
|
64
|
+
if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
|
|
65
|
+
return (
|
|
66
|
+
rootUrl +
|
|
67
|
+
entityName +
|
|
68
|
+
"s/" +
|
|
69
|
+
actionName.substr("_raw_http_method_".length)
|
|
70
|
+
);
|
|
71
|
+
return "UNKNOWN(" + actionName + ")";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getApiViewUrl(rootUrl, entityName, viewName) {
|
|
76
|
+
return rootUrl + entityName + "s/views/" + viewName;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getDescriptionByActionName(actionName, entityName) {
|
|
80
|
+
switch (actionName) {
|
|
81
|
+
case "findMany":
|
|
82
|
+
return "Lấy về danh sách các " + entityName;
|
|
83
|
+
case "findById":
|
|
84
|
+
return "Lấy về một " + entityName + " theo mã của nó";
|
|
85
|
+
case "createOne":
|
|
86
|
+
return "Tạo mới một " + entityName;
|
|
87
|
+
case "createMany":
|
|
88
|
+
return "Tạo mới hàng loạt các " + entityName;
|
|
89
|
+
case "updateOne":
|
|
90
|
+
return "Cập nhật một " + entityName;
|
|
91
|
+
case "updateMany":
|
|
92
|
+
return "Cập nhật hàng loạt các " + entityName;
|
|
93
|
+
case "updatePartially":
|
|
94
|
+
return "Cập nhật một phần dữ liệu của " + entityName;
|
|
95
|
+
case "deleteOne":
|
|
96
|
+
return "Xóa một " + entityName + " theo mã của nó";
|
|
97
|
+
case "deleteMany":
|
|
98
|
+
return "Xóa hàng loạt " + entityName;
|
|
99
|
+
default:
|
|
100
|
+
if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
|
|
101
|
+
return "";
|
|
102
|
+
return "UNKNOWN(" + actionName + ")";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getModalOutput(arrFields, fields, options) {
|
|
107
|
+
if (!fields || !arrFields) return "";
|
|
108
|
+
|
|
109
|
+
var obj = {};
|
|
110
|
+
for (var j = 0; j < arrFields.length; j++) {
|
|
111
|
+
if (!arrFields[j]) continue;
|
|
112
|
+
var segs = arrFields[j].split(".");
|
|
113
|
+
var objFields = fields;
|
|
114
|
+
var cur = obj;
|
|
115
|
+
for (var i = 0; i < segs.length; i++) {
|
|
116
|
+
if (segs[i] in objFields) {
|
|
117
|
+
var field = objFields[segs[i]];
|
|
118
|
+
|
|
119
|
+
if (i === segs.length - 1) {
|
|
120
|
+
if (!(segs[i] in cur))
|
|
121
|
+
cur[segs[i]] = JSON.parse(JSON.stringify(field));
|
|
122
|
+
} else if (field.type === "object") {
|
|
123
|
+
objFields = field.fields;
|
|
124
|
+
if (!(segs[i] in cur)) {
|
|
125
|
+
var o = { type: "object", fields: {} };
|
|
126
|
+
cur[segs[i]] = o;
|
|
127
|
+
cur = o.fields;
|
|
128
|
+
} else cur = cur[segs[i]].fields;
|
|
129
|
+
} else if (field.type === "array") {
|
|
130
|
+
objFields = field.items.fields;
|
|
131
|
+
if (!(segs[i] in cur)) {
|
|
132
|
+
var a = { type: "array", items: { type: "object", fields: {} } };
|
|
133
|
+
cur[segs[i]] = a;
|
|
134
|
+
cur = a.items.fields;
|
|
135
|
+
} else cur = cur[segs[i]].items.fields;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return formatModal(obj, "", options) /* + JSON.stringify(obj)*/;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function formatModal(obj, strIndent, options) {
|
|
145
|
+
if (!obj) return "";
|
|
146
|
+
|
|
147
|
+
options = options || {};
|
|
148
|
+
|
|
149
|
+
var result = "";
|
|
150
|
+
var nextIndent = strIndent + " ";
|
|
151
|
+
for (var m in obj) {
|
|
152
|
+
if (!obj.hasOwnProperty(m)) continue;
|
|
153
|
+
|
|
154
|
+
var child = obj[m];
|
|
155
|
+
|
|
156
|
+
var validation =
|
|
157
|
+
!options.optionalToAll && child.validation && child.validation.required
|
|
158
|
+
? "required"
|
|
159
|
+
: "optional";
|
|
160
|
+
if (child.type === "IdRef" && child.reference) {
|
|
161
|
+
validation +=
|
|
162
|
+
", ref: <a href='#" +
|
|
163
|
+
encodeHtml(child.reference) +
|
|
164
|
+
"' onclick='setTimeout(gotoHash, 20)'>" +
|
|
165
|
+
encodeHtml(child.reference) +
|
|
166
|
+
"</a>";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (child.validation) {
|
|
170
|
+
if ("validValues" in child.validation)
|
|
171
|
+
validation +=
|
|
172
|
+
", enum(" + encodeHtml(child.validation.validValues.join(", ")) + ")";
|
|
173
|
+
if ("invalidValues" in child.validation)
|
|
174
|
+
validation +=
|
|
175
|
+
", not allow(" +
|
|
176
|
+
encodeHtml(child.validation.invalidValues.join(", ")) +
|
|
177
|
+
")";
|
|
178
|
+
if ("pattern" in child.validation)
|
|
179
|
+
validation +=
|
|
180
|
+
", pattern: /" + encodeHtml(child.validation.pattern) + "/";
|
|
181
|
+
if ("length" in child.validation)
|
|
182
|
+
validation += ", length: " + child.validation.length;
|
|
183
|
+
if ("minLength" in child.validation)
|
|
184
|
+
validation += ", minLength: " + child.validation.minLength;
|
|
185
|
+
if ("maxLength" in child.validation)
|
|
186
|
+
validation += ", maxLength: " + child.validation.maxLength;
|
|
187
|
+
if ("min" in child.validation)
|
|
188
|
+
validation += ", min: " + encodeHtml(child.validation.min);
|
|
189
|
+
if ("max" in child.validation)
|
|
190
|
+
validation += ", max: " + encodeHtml(child.validation.max);
|
|
191
|
+
if ("gt" in child.validation)
|
|
192
|
+
validation += ", gt: " + encodeHtml(child.validation.gt);
|
|
193
|
+
if ("lt" in child.validation)
|
|
194
|
+
validation += ", lt: " + encodeHtml(child.validation.lt);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (
|
|
198
|
+
child.type === "array" &&
|
|
199
|
+
child.items &&
|
|
200
|
+
child.items.type != "object" &&
|
|
201
|
+
child.items.validation
|
|
202
|
+
) {
|
|
203
|
+
validation +=
|
|
204
|
+
", array items: " +
|
|
205
|
+
(!options.optionalToAll && child.items.validation.required
|
|
206
|
+
? "required"
|
|
207
|
+
: "optional");
|
|
208
|
+
if ("validValues" in child.items.validation)
|
|
209
|
+
validation +=
|
|
210
|
+
", enum(" +
|
|
211
|
+
encodeHtml(child.items.validation.validValues.join(", ")) +
|
|
212
|
+
")";
|
|
213
|
+
if ("invalidValues" in child.items.validation)
|
|
214
|
+
validation +=
|
|
215
|
+
", not allow(" +
|
|
216
|
+
encodeHtml(child.items.validation.invalidValues.join(", ")) +
|
|
217
|
+
")";
|
|
218
|
+
if ("pattern" in child.items.validation)
|
|
219
|
+
validation +=
|
|
220
|
+
", pattern: /" + encodeHtml(child.items.validation.pattern) + "/";
|
|
221
|
+
if ("length" in child.items.validation)
|
|
222
|
+
validation += ", length: " + child.items.validation.length;
|
|
223
|
+
if ("minLength" in child.items.validation)
|
|
224
|
+
validation += ", minLength: " + child.items.validation.minLength;
|
|
225
|
+
if ("maxLength" in child.items.validation)
|
|
226
|
+
validation += ", maxLength: " + child.items.validation.maxLength;
|
|
227
|
+
if ("min" in child.items.validation)
|
|
228
|
+
validation += ", min: " + encodeHtml(child.items.validation.min);
|
|
229
|
+
if ("max" in child.items.validation)
|
|
230
|
+
validation += ", max: " + encodeHtml(child.items.validation.max);
|
|
231
|
+
if ("gt" in child.items.validation)
|
|
232
|
+
validation += ", gt: " + encodeHtml(child.items.validation.gt);
|
|
233
|
+
if ("lt" in child.items.validation)
|
|
234
|
+
validation += ", lt: " + encodeHtml(child.items.validation.lt);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
|
|
238
|
+
|
|
239
|
+
if (options.mode === "modal") {
|
|
240
|
+
if (child.type === "object")
|
|
241
|
+
result +=
|
|
242
|
+
"\r\n" +
|
|
243
|
+
nextIndent +
|
|
244
|
+
'"' +
|
|
245
|
+
m +
|
|
246
|
+
'": ' +
|
|
247
|
+
comment +
|
|
248
|
+
formatModal(child.fields, nextIndent, options) +
|
|
249
|
+
",";
|
|
250
|
+
else if (child.type === "array") {
|
|
251
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
252
|
+
if (child.items.type === "object")
|
|
253
|
+
result +=
|
|
254
|
+
" " +
|
|
255
|
+
comment +
|
|
256
|
+
formatModal(child.items.fields, nextIndent, options);
|
|
257
|
+
else if (child.items.type === "datetime")
|
|
258
|
+
result +=
|
|
259
|
+
`\r\n${nextIndent} ` +
|
|
260
|
+
JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") +
|
|
261
|
+
" " +
|
|
262
|
+
comment +
|
|
263
|
+
`\r\n${nextIndent}`;
|
|
264
|
+
else if (child.items.type === "boolean")
|
|
265
|
+
result +=
|
|
266
|
+
`\r\n${nextIndent} ` + child.items.defaultValue ||
|
|
267
|
+
"false" + " " + comment + `\r\n${nextIndent}`;
|
|
268
|
+
else if (
|
|
269
|
+
child.items.type === "integer" ||
|
|
270
|
+
child.items.type === "long" ||
|
|
271
|
+
child.items.type === "double"
|
|
272
|
+
)
|
|
273
|
+
result +=
|
|
274
|
+
`\r\n${nextIndent} ` + child.items.defaultValue ||
|
|
275
|
+
"0" + " " + comment + `\r\n${nextIndent}`;
|
|
276
|
+
else
|
|
277
|
+
result +=
|
|
278
|
+
`\r\n${nextIndent} ` +
|
|
279
|
+
JSON.stringify(child.defaultValue || child.type) +
|
|
280
|
+
" " +
|
|
281
|
+
comment +
|
|
282
|
+
`\r\n${nextIndent}`;
|
|
283
|
+
result += `]`;
|
|
284
|
+
} else if (child.type === "datetime")
|
|
285
|
+
result +=
|
|
286
|
+
`\r\n${nextIndent}"${m}": ` +
|
|
287
|
+
JSON.stringify(child.defaultValue || "ISODate_ISO_8601") +
|
|
288
|
+
", " +
|
|
289
|
+
comment;
|
|
290
|
+
else if (child.type === "boolean")
|
|
291
|
+
result +=
|
|
292
|
+
`\r\n${nextIndent}"${m}": ` +
|
|
293
|
+
(child.defaultValue || "false") +
|
|
294
|
+
", " +
|
|
295
|
+
comment;
|
|
296
|
+
else if (
|
|
297
|
+
child.type === "integer" ||
|
|
298
|
+
child.type === "long" ||
|
|
299
|
+
child.type === "double"
|
|
300
|
+
)
|
|
301
|
+
result +=
|
|
302
|
+
`\r\n${nextIndent}"${m}": ` +
|
|
303
|
+
(child.defaultValue || "0") +
|
|
304
|
+
", " +
|
|
305
|
+
comment;
|
|
306
|
+
else
|
|
307
|
+
result +=
|
|
308
|
+
`\r\n${nextIndent}"${m}": ` +
|
|
309
|
+
JSON.stringify(child.defaultValue || child.type) +
|
|
310
|
+
", " +
|
|
311
|
+
comment;
|
|
312
|
+
} else if (options.mode === "modal_null") {
|
|
313
|
+
if (child.type === "object")
|
|
314
|
+
result +=
|
|
315
|
+
"\r\n" +
|
|
316
|
+
nextIndent +
|
|
317
|
+
'"' +
|
|
318
|
+
m +
|
|
319
|
+
'": ' +
|
|
320
|
+
comment +
|
|
321
|
+
formatModal(child.fields, nextIndent, options);
|
|
322
|
+
else if (child.type === "array") {
|
|
323
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
324
|
+
if (child.items.type === "object")
|
|
325
|
+
result +=
|
|
326
|
+
" " +
|
|
327
|
+
comment +
|
|
328
|
+
formatModal(child.items.fields, nextIndent, options) +
|
|
329
|
+
"],";
|
|
330
|
+
else result += "], " + comment;
|
|
331
|
+
} else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
|
|
332
|
+
} else if (options.mode === "modal_undefined") {
|
|
333
|
+
if (child.type === "object")
|
|
334
|
+
result +=
|
|
335
|
+
"\r\n" +
|
|
336
|
+
nextIndent +
|
|
337
|
+
'"' +
|
|
338
|
+
m +
|
|
339
|
+
'": ' +
|
|
340
|
+
comment +
|
|
341
|
+
formatModal(child.fields, nextIndent, options);
|
|
342
|
+
else if (child.type === "array") {
|
|
343
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
344
|
+
if (child.items.type === "object")
|
|
345
|
+
result +=
|
|
346
|
+
" " +
|
|
347
|
+
comment +
|
|
348
|
+
formatModal(child.items.fields, nextIndent, options) +
|
|
349
|
+
"], ";
|
|
350
|
+
else result += "], " + comment;
|
|
351
|
+
} else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
|
|
352
|
+
} else {
|
|
353
|
+
result +=
|
|
354
|
+
"\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
|
|
355
|
+
if (child.type === "array")
|
|
356
|
+
result +=
|
|
357
|
+
child.items.type === "object"
|
|
358
|
+
? " of object"
|
|
359
|
+
: " of " + child.items.type;
|
|
360
|
+
if (child.type === "object")
|
|
361
|
+
result +=
|
|
362
|
+
" " +
|
|
363
|
+
comment +
|
|
364
|
+
formatModal(child.fields, strIndent + " ", options);
|
|
365
|
+
else if (child.type === "array" && child.items.type === "object")
|
|
366
|
+
result +=
|
|
367
|
+
" " +
|
|
368
|
+
comment +
|
|
369
|
+
formatModal(child.items.fields, strIndent + " ", options);
|
|
370
|
+
else result += ", " + comment;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (
|
|
375
|
+
options.mode === "modal" ||
|
|
376
|
+
options.mode === "modal_null" ||
|
|
377
|
+
options.mode === "modal_undefined"
|
|
378
|
+
) {
|
|
379
|
+
return (
|
|
380
|
+
(strIndent ? "\r\n" + strIndent : "") +
|
|
381
|
+
"{" +
|
|
382
|
+
result +
|
|
383
|
+
"\r\n" +
|
|
384
|
+
strIndent +
|
|
385
|
+
"}"
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function formatHintModal(obj, strIndent, options) {
|
|
393
|
+
if (!obj)
|
|
394
|
+
return "";
|
|
395
|
+
|
|
396
|
+
strIndent = strIndent || "";
|
|
397
|
+
options = options || {};
|
|
398
|
+
|
|
399
|
+
var result = "";
|
|
400
|
+
var nextIndent = strIndent + " ";
|
|
401
|
+
for (var m in obj) {
|
|
402
|
+
if (!obj.hasOwnProperty(m))
|
|
403
|
+
continue;
|
|
404
|
+
|
|
405
|
+
var child = obj[m];
|
|
406
|
+
|
|
407
|
+
var validation = !options.optionalToAll && child.required ? "required" : "optional";
|
|
408
|
+
if (child.type === "IdRef" && child.reference) {
|
|
409
|
+
validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (child.validValues && Array.isArray(child.validValues)) {
|
|
413
|
+
validation += ", enum(" + encodeHtml(child.validValues.join(", ")) + ")";
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (child.type === "array" && child.items && child.items.type != "object") {
|
|
417
|
+
validation += ", array items: " + (!options.optionalToAll && child.items.required ? "required" : "optional");
|
|
418
|
+
if (child.items.validValues && Array.isArray(child.items.validValues))
|
|
419
|
+
validation += ", enum(" + encodeHtml(child.items.validValues.join(", ")) + ")";
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
|
|
423
|
+
|
|
424
|
+
if (options.mode === "modal") {
|
|
425
|
+
if (child.type === "object")
|
|
426
|
+
result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options) + ",";
|
|
427
|
+
else if (child.type === "array") {
|
|
428
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
429
|
+
if (child.items.type === "object")
|
|
430
|
+
result += " " + comment + formatHintModal(child.items.fields, nextIndent, options);
|
|
431
|
+
else if (child.items.type === "datetime")
|
|
432
|
+
result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
|
|
433
|
+
else if (child.items.type === "boolean")
|
|
434
|
+
result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
|
|
435
|
+
else if (child.items.type === "integer" || child.items.type === "long"|| child.items.type === "double")
|
|
436
|
+
result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
|
|
437
|
+
else
|
|
438
|
+
result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
|
|
439
|
+
result += `]`;
|
|
440
|
+
}
|
|
441
|
+
else if (child.type === "datetime")
|
|
442
|
+
result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
|
|
443
|
+
else if (child.type === "boolean")
|
|
444
|
+
result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
|
|
445
|
+
else if (child.type === "integer" || child.type === "long"|| child.type === "double")
|
|
446
|
+
result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
|
|
447
|
+
else
|
|
448
|
+
result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
|
|
449
|
+
} else if (options.mode === "modal_null") {
|
|
450
|
+
if (child.type === "object")
|
|
451
|
+
result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
|
|
452
|
+
else if (child.type === "array") {
|
|
453
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
454
|
+
if (child.items.type === "object")
|
|
455
|
+
result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "],";
|
|
456
|
+
else
|
|
457
|
+
result += "], " + comment;
|
|
458
|
+
}
|
|
459
|
+
else
|
|
460
|
+
result += `\r\n${nextIndent}"${m}": null, ${comment}`;
|
|
461
|
+
} else if (options.mode === "modal_undefined") {
|
|
462
|
+
if (child.type === "object")
|
|
463
|
+
result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
|
|
464
|
+
else if (child.type === "array") {
|
|
465
|
+
result += `\r\n${nextIndent}"${m}": [`;
|
|
466
|
+
if (child.items.type === "object")
|
|
467
|
+
result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "], ";
|
|
468
|
+
else
|
|
469
|
+
result += "], " + comment;
|
|
470
|
+
}
|
|
471
|
+
else
|
|
472
|
+
result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
|
|
473
|
+
} else {
|
|
474
|
+
result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
|
|
475
|
+
if (child.type === "array")
|
|
476
|
+
result += child.items.type === "object" ? " of object" : " of " + child.items.type;
|
|
477
|
+
if (child.type === "object")
|
|
478
|
+
result += " " + comment + formatHintModal(child.fields, strIndent + " ", options);
|
|
479
|
+
else if (child.type === "array" && child.items.type === "object")
|
|
480
|
+
result += " " + comment + formatHintModal(child.items.fields, strIndent + " ", options);
|
|
481
|
+
else
|
|
482
|
+
result += ", " + comment;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
|
|
487
|
+
return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function explainRoles(strRoles) {
|
|
494
|
+
if (!strRoles) return "";
|
|
495
|
+
|
|
496
|
+
return strRoles
|
|
497
|
+
.split("|")
|
|
498
|
+
.map(function (item) {
|
|
499
|
+
if (item === "*") return "[Mọi người dùng]";
|
|
500
|
+
var roles = item.split("+");
|
|
501
|
+
var s = "";
|
|
502
|
+
if (roles.length > 1) s += "(";
|
|
503
|
+
|
|
504
|
+
s += roles.join(" và ");
|
|
505
|
+
|
|
506
|
+
if (roles.length > 1) s += ")";
|
|
507
|
+
|
|
508
|
+
return s;
|
|
509
|
+
})
|
|
510
|
+
.join(" hoặc ");
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function getModalInput(excludedFields, fields, options) {
|
|
514
|
+
fields = JSON.parse(JSON.stringify(fields));
|
|
515
|
+
if (!fields) return "";
|
|
516
|
+
|
|
517
|
+
options = options || {};
|
|
518
|
+
|
|
519
|
+
fields.id = fields.id || {};
|
|
520
|
+
fields.id.type = fields.id.type || "AutoId";
|
|
521
|
+
fields.id.validation = fields.id.validation || {};
|
|
522
|
+
fields.id.validation.required = true;
|
|
523
|
+
|
|
524
|
+
if (excludedFields && Array.isArray(excludedFields)) {
|
|
525
|
+
if (options.excludeId && fields.id.type === "AutoId")
|
|
526
|
+
excludedFields.push("id");
|
|
527
|
+
|
|
528
|
+
excludedFields.forEach(function (item) {
|
|
529
|
+
var obj = fields;
|
|
530
|
+
var segs = item.split(".");
|
|
531
|
+
for (var i = 0; i < segs.length; i++) {
|
|
532
|
+
if (!obj) return;
|
|
533
|
+
var seg = segs[i];
|
|
534
|
+
if (!(seg in obj))
|
|
535
|
+
return;
|
|
536
|
+
|
|
537
|
+
if (i === segs.length - 1)
|
|
538
|
+
delete obj[seg];
|
|
539
|
+
else if (obj[seg].type === "object")
|
|
540
|
+
obj = obj[seg].fields;
|
|
541
|
+
else if (obj[seg].type === "array")
|
|
542
|
+
obj = obj[seg].items?.fields;
|
|
543
|
+
else
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return formatModal(fields, "", {
|
|
550
|
+
showValidation: true,
|
|
551
|
+
optionalToAll: options.optionalToAll,
|
|
552
|
+
mode: options.mode,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function activeFirstChild() {
|
|
557
|
+
$(this).find("> *").eq(0).addClass("active");
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
$("script[type='text/mt-template']").each(function () {
|
|
561
|
+
mt.inlineModuleTemplates[this.id] = this.innerHTML;
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
var data = {};
|
|
565
|
+
|
|
566
|
+
function afterGenerated() {
|
|
567
|
+
var domApiName = document.querySelector("#apiName");
|
|
568
|
+
if (domApiName) document.title = domApiName.textContent + " API Document";
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function generateDocument() {
|
|
572
|
+
// console.log(data);
|
|
573
|
+
mt.bindDom(document.body, data);
|
|
574
|
+
afterGenerated();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function saveDocument() {
|
|
578
|
+
var textFileAsBlob = new Blob(
|
|
579
|
+
["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML],
|
|
580
|
+
{ type: "application/octet-stream" },
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
var downloadLink = document.createElement("a");
|
|
584
|
+
//downloadLink.download = data.name + "-docs.html";
|
|
585
|
+
downloadLink.download = "docs.html";
|
|
586
|
+
if (window.URL) {
|
|
587
|
+
// Firefox requires the link to be added to the DOM
|
|
588
|
+
// before it can be clicked.
|
|
589
|
+
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
|
|
590
|
+
downloadLink.onclick = function () {
|
|
591
|
+
document.body.removeChild(downloadLink);
|
|
592
|
+
};
|
|
593
|
+
downloadLink.style.display = "none";
|
|
594
|
+
document.body.appendChild(downloadLink);
|
|
595
|
+
} else if (window.webkitURL) {
|
|
596
|
+
// Chrome allows the link to be clicked
|
|
597
|
+
// without actually adding it to the DOM.
|
|
598
|
+
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
downloadLink.click();
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function concat() {
|
|
605
|
+
return String.prototype.concat.apply("", arguments);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function getRootApiUrl() {
|
|
609
|
+
return window.data.rootUrl;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function getApiDomain() {
|
|
613
|
+
var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
|
|
614
|
+
if (m) return m[1];
|
|
615
|
+
return "your host";
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function getApiPath() {
|
|
619
|
+
var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
|
|
620
|
+
if (m) return window.data.rootUrl.substr(m[0].length);
|
|
621
|
+
return window.data.rootUrl;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function encodeHtml(data) {
|
|
625
|
+
if (data === undefined || data === null) return "";
|
|
626
|
+
var html = typeof data === "string" ? data : data.toString();
|
|
627
|
+
html = html.replace(/&/g, "&");
|
|
628
|
+
html = html.replace(/</g, "<");
|
|
629
|
+
html = html.replace(/>/g, ">");
|
|
630
|
+
html = html.replace(/"/g, """);
|
|
631
|
+
html = html.replace(/'/g, "'");
|
|
632
|
+
return html;
|
|
633
|
+
}
|