zet-lib 1.5.29 → 2.0.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/lib/Modal.js +85 -30
- package/lib/Model.js +118 -2
- package/lib/config_generator.js +24 -0
- package/lib/generatorApi.js +1328 -0
- package/lib/generatorApp.js +1342 -0
- package/lib/generatorModel.js +733 -0
- package/lib/lang_en.js +115 -0
- package/lib/routes/api.js +52 -0
- package/lib/routes/index.js +9 -0
- package/lib/views/error.ejs +3 -0
- package/lib/views/generatorjs.ejs +855 -852
- package/lib/views/zgenerator/bootstrap3/_form.ejs +24 -0
- package/lib/views/zgenerator/bootstrap3/create.ejs +9 -0
- package/lib/views/zgenerator/bootstrap3/createjs.ejs +3 -0
- package/lib/views/zgenerator/bootstrap3/import.ejs +52 -0
- package/lib/views/zgenerator/bootstrap3/importjs.ejs +3 -0
- package/lib/views/zgenerator/bootstrap3/index.ejs +29 -0
- package/lib/views/zgenerator/bootstrap3/indexcss.ejs +1 -0
- package/lib/views/zgenerator/bootstrap3/indexjs.ejs +307 -0
- package/lib/views/zgenerator/bootstrap3/update.ejs +8 -0
- package/lib/views/zgenerator/bootstrap3/updatejs.ejs +3 -0
- package/lib/views/zgenerator/bootstrap3/view.ejs +57 -0
- package/lib/views/zgenerator/head.ejs +12 -0
- package/lib/views/zgenerator/index.ejs +271 -0
- package/lib/views/zgenerator/indexcss.ejs +87 -0
- package/lib/views/zgenerator/indexjs.ejs +705 -0
- package/lib/views/zgenerator/layout.ejs +198 -0
- package/lib/views/zgenerator/manual_basic.ejs +2 -0
- package/lib/views/zgenerator/manual_dropdown.ejs +126 -0
- package/lib/views/zgenerator/manual_modules.ejs +192 -0
- package/lib/views/zgenerator/manual_virtual.ejs +143 -0
- package/lib/views/zgenerator/mini.ejs +341 -0
- package/lib/views/zgenerator/routerApp.ejs +359 -0
- package/lib/views/zgenerator/views/_form.ejs +25 -0
- package/lib/views/zgenerator/views/approval.ejs +42 -0
- package/lib/views/zgenerator/views/create.ejs +7 -0
- package/lib/views/zgenerator/views/createjs.ejs +16 -0
- package/lib/views/zgenerator/views/import.ejs +49 -0
- package/lib/views/zgenerator/views/importjs.ejs +4 -0
- package/lib/views/zgenerator/views/index.ejs +9 -0
- package/lib/views/zgenerator/views/indexcss.ejs +2 -0
- package/lib/views/zgenerator/views/indexjs.ejs +2 -0
- package/lib/views/zgenerator/views/preview.ejs +34 -0
- package/lib/views/zgenerator/views/update.ejs +7 -0
- package/lib/views/zgenerator/views/updatejs.ejs +16 -0
- package/lib/views/zgenerator/views/view.ejs +36 -0
- package/lib/zGeneratorRouter.js +177 -153
- package/lib/zRoute.js +14 -3
- package/package.json +1 -1
package/lib/zGeneratorRouter.js
CHANGED
|
@@ -15,6 +15,9 @@ const myCache = require("./cache");
|
|
|
15
15
|
const ejs = require("ejs");
|
|
16
16
|
var app = express();
|
|
17
17
|
const path = require("path");
|
|
18
|
+
const Api = require('./generatorApi');
|
|
19
|
+
const Model = require('./Model');
|
|
20
|
+
|
|
18
21
|
|
|
19
22
|
if (typeof global.dirRoot === 'undefined') {
|
|
20
23
|
global.dirRoot = Util.dirRoot;
|
|
@@ -41,22 +44,28 @@ const nots = [
|
|
|
41
44
|
];
|
|
42
45
|
//const nots = [];
|
|
43
46
|
//const generatorUrl = 'http://localhost:3005';
|
|
44
|
-
const generatorUrl = "https://generator.cmsqu.com";
|
|
47
|
+
//const generatorUrl = "https://generator.cmsqu.com";
|
|
45
48
|
|
|
46
49
|
const bodyView = Util.readFile(
|
|
47
|
-
|
|
50
|
+
require.resolve(__dirname + "/views/generator.ejs")
|
|
48
51
|
);
|
|
49
52
|
|
|
50
53
|
router.get("/", csrfProtection, async (req, res) => {
|
|
51
54
|
let table = req.query.table || "",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
route = "",
|
|
56
|
+
jsonData = {},
|
|
57
|
+
zForms = {},
|
|
58
|
+
relations = {},
|
|
59
|
+
approvalDatas = { is_approval: false };
|
|
57
60
|
const MYMODELS = myCache.get("MYMODELS");
|
|
58
|
-
let datas = await axios.post(`${generatorUrl}/api/generator/index`);
|
|
59
|
-
jsonData = datas.data;
|
|
61
|
+
//let datas = await axios.post(`${generatorUrl}/api/generator/index`);
|
|
62
|
+
//jsonData = datas.data;
|
|
63
|
+
jsonData = {
|
|
64
|
+
datas: {table: '', tabs: [], labels: {}, details: {}, hardcode_grid: ""},
|
|
65
|
+
table: table,
|
|
66
|
+
route: table,
|
|
67
|
+
selects: Model.keys,
|
|
68
|
+
}
|
|
60
69
|
jsonData.rows = await zfieldsKeys();
|
|
61
70
|
if (table) {
|
|
62
71
|
jsonData.datas = jsonData.rows[table] || {};
|
|
@@ -66,9 +75,9 @@ router.get("/", csrfProtection, async (req, res) => {
|
|
|
66
75
|
let sorting = "";
|
|
67
76
|
if (table) {
|
|
68
77
|
let contentScript = `var ZFIELDS = ${JSON.stringify(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
jsonData.rows,
|
|
79
|
+
null,
|
|
80
|
+
2
|
|
72
81
|
)};`;
|
|
73
82
|
moduleLib.addScript(req, res, contentScript);
|
|
74
83
|
moduleLib.editor(req, res);
|
|
@@ -87,15 +96,15 @@ router.get("/", csrfProtection, async (req, res) => {
|
|
|
87
96
|
approvalDatas.title = approvalJSON.title || "";
|
|
88
97
|
approvalDatas.type = approvalJSON.type || 1;
|
|
89
98
|
approvalDatas.approvers = approvalJSON.approvers
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
? approvalJSON.approvers
|
|
100
|
+
: [];
|
|
92
101
|
approvalDatas.knowings = approvalJSON.knowings || [];
|
|
93
102
|
approvalDatas.template = approvalJSON.content || "";
|
|
94
103
|
zForms = await zRoute.formsFieldSync(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
req,
|
|
105
|
+
res,
|
|
106
|
+
MYMODEL_APPROVERS,
|
|
107
|
+
approvalDatas
|
|
99
108
|
);
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -103,12 +112,12 @@ router.get("/", csrfProtection, async (req, res) => {
|
|
|
103
112
|
const jsonDatas = jsonData.datas;
|
|
104
113
|
const lock = nots.includes(table) ? 1 : 0;
|
|
105
114
|
const jsonDatasJson =
|
|
106
|
-
|
|
115
|
+
jsonDatas.hasOwnProperty("json") && jsonDatas.json ? jsonDatas.json : {};
|
|
107
116
|
const checkDummy =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
Object.prototype.hasOwnProperty.call(jsonDatasJson, "dummy") &&
|
|
118
|
+
jsonDatasJson.dummy
|
|
119
|
+
? "checked"
|
|
120
|
+
: "";
|
|
112
121
|
const renderData = {
|
|
113
122
|
datas: jsonDatas,
|
|
114
123
|
table: table,
|
|
@@ -127,15 +136,15 @@ router.get("/", csrfProtection, async (req, res) => {
|
|
|
127
136
|
|
|
128
137
|
const bodyHTML = ejs.render(bodyView, renderData);
|
|
129
138
|
const endHTML = ejs.render(
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
Util.readFile(require.resolve(__dirname + "/views/generatorjs.ejs")),
|
|
140
|
+
renderData
|
|
132
141
|
);
|
|
133
142
|
let dataRender = renderData;
|
|
134
143
|
dataRender.bodyHTML = bodyHTML;
|
|
135
144
|
dataRender.endHTML = endHTML;
|
|
136
145
|
res.render(
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
require.resolve(__dirname + "/views/generator_layout.ejs"),
|
|
147
|
+
dataRender
|
|
139
148
|
);
|
|
140
149
|
});
|
|
141
150
|
|
|
@@ -144,8 +153,8 @@ router.post("/fields", async (req, res) => {
|
|
|
144
153
|
let body = req.body;
|
|
145
154
|
let table = body.table || "";
|
|
146
155
|
let result = {},
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
fields = {},
|
|
157
|
+
rowsFields = [];
|
|
149
158
|
if (table) {
|
|
150
159
|
result = await connection.result({
|
|
151
160
|
table: "zfields",
|
|
@@ -160,11 +169,21 @@ router.post("/fields", async (req, res) => {
|
|
|
160
169
|
rowsFields: rowsFields,
|
|
161
170
|
table: table,
|
|
162
171
|
};
|
|
163
|
-
let datas = await axios.post(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
167
|
-
|
|
172
|
+
/* let datas = await axios.post(
|
|
173
|
+
`${generatorUrl}/api/generator/modal`,
|
|
174
|
+
objData
|
|
175
|
+
); */
|
|
176
|
+
let others = result.others || {};
|
|
177
|
+
let othersArr = Object.keys(others) || [];
|
|
178
|
+
let json = {}
|
|
179
|
+
if(othersArr.length) {
|
|
180
|
+
console.log('masuk ke container')
|
|
181
|
+
json = await Api.modalWithContainer(objData);
|
|
182
|
+
} else {
|
|
183
|
+
json = await Api.modalClassic(objData);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
res.json(json);
|
|
168
187
|
} catch (e) {
|
|
169
188
|
console.log(e);
|
|
170
189
|
res.json(e.toString());
|
|
@@ -176,11 +195,12 @@ Create new Module/Table
|
|
|
176
195
|
*/
|
|
177
196
|
router.post("/", csrfProtection, async (req, res) => {
|
|
178
197
|
try {
|
|
179
|
-
let results = await axios.post(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
);
|
|
183
|
-
let
|
|
198
|
+
/* let results = await axios.post(
|
|
199
|
+
`${generatorUrl}/api/generator/create`,
|
|
200
|
+
req.body
|
|
201
|
+
); */
|
|
202
|
+
let body = req.body;
|
|
203
|
+
let datas = Api.createTable(body);
|
|
184
204
|
if (datas.status == 0) {
|
|
185
205
|
res.json(datas);
|
|
186
206
|
} else {
|
|
@@ -207,11 +227,13 @@ router.post("/reset", async (req, res) => {
|
|
|
207
227
|
return res.json(Util.flashError("Table is locked"));
|
|
208
228
|
}
|
|
209
229
|
if (table) {
|
|
210
|
-
let results = await axios.post(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
);
|
|
214
|
-
let
|
|
230
|
+
/* let results = await axios.post(
|
|
231
|
+
`${generatorUrl}/api/generator/reset`,
|
|
232
|
+
req.body
|
|
233
|
+
); */
|
|
234
|
+
let body = req.body;
|
|
235
|
+
let datas = Api.reset(body);
|
|
236
|
+
//let datas = results.data;
|
|
215
237
|
await connection.update({
|
|
216
238
|
table: "zfields",
|
|
217
239
|
data: datas,
|
|
@@ -284,9 +306,9 @@ router.post("/tabs", async (req, res) => {
|
|
|
284
306
|
let details = {};
|
|
285
307
|
//remove Object in array
|
|
286
308
|
let left = leftOri.filter((item) => typeof item !== "object") || [],
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
309
|
+
right = rightOri.filter((item) => typeof item !== "object") || [],
|
|
310
|
+
oneColumn =
|
|
311
|
+
oneColumnOri.filter((item) => typeof item !== "object") || [];
|
|
290
312
|
|
|
291
313
|
details.notabs = detailOri.notabs;
|
|
292
314
|
tabs.map((item, index) => {
|
|
@@ -296,24 +318,24 @@ router.post("/tabs", async (req, res) => {
|
|
|
296
318
|
details[key] = detailOri[objOri[item]] || [];
|
|
297
319
|
//left
|
|
298
320
|
let objLeft =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
321
|
+
leftOri[valueIndex] &&
|
|
322
|
+
leftOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`)
|
|
323
|
+
? leftOri[valueIndex][`arr${arrayOri[item]}`]
|
|
324
|
+
: [];
|
|
303
325
|
left.push({ [key]: objLeft });
|
|
304
326
|
//right
|
|
305
327
|
let objRight =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
328
|
+
rightOri[valueIndex] &&
|
|
329
|
+
rightOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`)
|
|
330
|
+
? rightOri[valueIndex][`arr${arrayOri[item]}`]
|
|
331
|
+
: [];
|
|
310
332
|
right.push({ [key]: objRight });
|
|
311
333
|
//one column
|
|
312
334
|
let objOneColumn =
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
335
|
+
oneColumnOri[valueIndex] &&
|
|
336
|
+
oneColumnOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`)
|
|
337
|
+
? oneColumnOri[valueIndex][`arr${arrayOri[item]}`]
|
|
338
|
+
: [];
|
|
317
339
|
oneColumn.push({ [key]: objOneColumn });
|
|
318
340
|
});
|
|
319
341
|
post.details = JSON.stringify(details);
|
|
@@ -395,8 +417,9 @@ const generate = async (req, res) => {
|
|
|
395
417
|
});
|
|
396
418
|
}
|
|
397
419
|
body.others = others;
|
|
398
|
-
results = await axios.post(`${generatorUrl}/api/generator/properties`, body);
|
|
399
|
-
|
|
420
|
+
//results = await axios.post(`${generatorUrl}/api/generator/properties`, body);
|
|
421
|
+
results = await Api.properties(body);
|
|
422
|
+
datas = results;
|
|
400
423
|
if (datas.create_table.hasOwnProperty("sql")) {
|
|
401
424
|
await connection.query(datas.create_table.sql);
|
|
402
425
|
return generate(body);
|
|
@@ -410,8 +433,8 @@ const generate = async (req, res) => {
|
|
|
410
433
|
},
|
|
411
434
|
});
|
|
412
435
|
let resultJSON = Object.prototype.hasOwnProperty.call(result, "json")
|
|
413
|
-
|
|
414
|
-
|
|
436
|
+
? result.json
|
|
437
|
+
: {};
|
|
415
438
|
if (resultJSON && Object.prototype.hasOwnProperty.call(resultJSON, "dummy")) {
|
|
416
439
|
dummy = resultJSON.dummy == 1 ? true : false;
|
|
417
440
|
}
|
|
@@ -420,11 +443,11 @@ const generate = async (req, res) => {
|
|
|
420
443
|
for (let key in properties) {
|
|
421
444
|
//override
|
|
422
445
|
properties[key].values.required = properties[key].values.required
|
|
423
|
-
|
|
424
|
-
|
|
446
|
+
? true
|
|
447
|
+
: false;
|
|
425
448
|
properties[key].values.unique = properties[key].values.unique
|
|
426
|
-
|
|
427
|
-
|
|
449
|
+
? true
|
|
450
|
+
: false;
|
|
428
451
|
var isChain = properties[key].values.isChain ? true : false;
|
|
429
452
|
properties[key].values.isChain = isChain;
|
|
430
453
|
if (isChain) {
|
|
@@ -460,11 +483,12 @@ const generate = async (req, res) => {
|
|
|
460
483
|
//generate file models routes views
|
|
461
484
|
body.columns = await connection.query(connection.describeTable(table));
|
|
462
485
|
body.constraintList = await connection.query(
|
|
463
|
-
|
|
486
|
+
connection.constraintList(table)
|
|
464
487
|
);
|
|
465
488
|
body.result = result;
|
|
466
|
-
results = await axios.post(`${generatorUrl}/api/generator/generate`, body);
|
|
467
|
-
|
|
489
|
+
//results = await axios.post(`${generatorUrl}/api/generator/generate`, body);
|
|
490
|
+
results = await Api.generate(body);
|
|
491
|
+
datas = results;
|
|
468
492
|
let files = datas.files;
|
|
469
493
|
for (let key in files) {
|
|
470
494
|
let filesKey = files[key];
|
|
@@ -508,7 +532,7 @@ const generate = async (req, res) => {
|
|
|
508
532
|
//check if has chains here
|
|
509
533
|
MYMODEL = filesKey.modelObj;
|
|
510
534
|
//delete/clean zgrid after changes
|
|
511
|
-
|
|
535
|
+
await connection.delete({
|
|
512
536
|
table: 'zgrid',
|
|
513
537
|
where: {
|
|
514
538
|
route_name: table,
|
|
@@ -541,8 +565,8 @@ const generate = async (req, res) => {
|
|
|
541
565
|
});
|
|
542
566
|
|
|
543
567
|
fs.writeFileSync(
|
|
544
|
-
|
|
545
|
-
|
|
568
|
+
`${dirRoot}/models/${filesKey.filename}`,
|
|
569
|
+
filesKey.content
|
|
546
570
|
);
|
|
547
571
|
console.log(`The file model of ${filesKey.filename} is saved!`);
|
|
548
572
|
|
|
@@ -552,8 +576,8 @@ const generate = async (req, res) => {
|
|
|
552
576
|
let isChain = false;
|
|
553
577
|
for (let key in widgets) {
|
|
554
578
|
let hasChains = widgets[key].hasOwnProperty("isChain")
|
|
555
|
-
|
|
556
|
-
|
|
579
|
+
? widgets[key].isChain
|
|
580
|
+
: false;
|
|
557
581
|
if (hasChains) {
|
|
558
582
|
isChain = true;
|
|
559
583
|
if (widgets[key].hasOwnProperty("table")) {
|
|
@@ -580,7 +604,7 @@ const generate = async (req, res) => {
|
|
|
580
604
|
name: widgets[objChains[key].key].fields[1],
|
|
581
605
|
};
|
|
582
606
|
objChains[model_table.widgets[q].table].changes.push(
|
|
583
|
-
|
|
607
|
+
objChanges
|
|
584
608
|
);
|
|
585
609
|
}
|
|
586
610
|
}
|
|
@@ -617,12 +641,12 @@ const generate = async (req, res) => {
|
|
|
617
641
|
fs.writeFileSync(`${DIR_VIEW}/${q}`, filesKey[q]);
|
|
618
642
|
} else {
|
|
619
643
|
fs.writeFileSync(
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
644
|
+
`${DIR_VIEW}/${q}`,
|
|
645
|
+
await minify(filesKey[q], {
|
|
646
|
+
minifyJS: true,
|
|
647
|
+
minifyCSS: true,
|
|
648
|
+
collapseWhitespace: true,
|
|
649
|
+
})
|
|
626
650
|
);
|
|
627
651
|
}
|
|
628
652
|
console.log(`The files views of ${q} is saved!`);
|
|
@@ -632,8 +656,8 @@ const generate = async (req, res) => {
|
|
|
632
656
|
if (!dummy) {
|
|
633
657
|
if (key == "route") {
|
|
634
658
|
fs.writeFileSync(
|
|
635
|
-
|
|
636
|
-
|
|
659
|
+
`${dirRoot}/routes/${filesKey.filename}`,
|
|
660
|
+
filesKey.content
|
|
637
661
|
);
|
|
638
662
|
console.log(`The files route of ${filesKey.filename} is saved!`);
|
|
639
663
|
}
|
|
@@ -687,9 +711,9 @@ router.post("/savetabs", async (req, res) => {
|
|
|
687
711
|
let table = body.table;
|
|
688
712
|
let details = body.details;
|
|
689
713
|
let left = [],
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
714
|
+
right = [],
|
|
715
|
+
tabLeft = {},
|
|
716
|
+
tabRight = {};
|
|
693
717
|
let json = { status: 0, title: "error", message: "error", url: "" };
|
|
694
718
|
let obj = {};
|
|
695
719
|
obj.notabs = [];
|
|
@@ -811,8 +835,8 @@ const buildJoin = async (MYMODEL, result) => {
|
|
|
811
835
|
rows.map((row) => {
|
|
812
836
|
foreignTables.push(row.foreign_table_name);
|
|
813
837
|
foreign_table_name[
|
|
814
|
-
|
|
815
|
-
|
|
838
|
+
row.foreign_table_name
|
|
839
|
+
] = ` LEFT JOIN ${row.foreign_table_name} ON ${row.foreign_table_name}.id = ${table}.${row.column_name} `;
|
|
816
840
|
});
|
|
817
841
|
|
|
818
842
|
//step by step
|
|
@@ -827,15 +851,15 @@ const buildJoin = async (MYMODEL, result) => {
|
|
|
827
851
|
if (table_steps.length > 0) {
|
|
828
852
|
for (let table_steps_item of table_steps) {
|
|
829
853
|
let rows = await connection.query(
|
|
830
|
-
|
|
854
|
+
connection.foreignKeyList(table_steps_item)
|
|
831
855
|
);
|
|
832
856
|
let foreign_table_name = {};
|
|
833
857
|
let foreignTables = [];
|
|
834
858
|
rows.map((row) => {
|
|
835
859
|
foreignTables.push(row.foreign_table_name);
|
|
836
860
|
foreign_table_name[
|
|
837
|
-
|
|
838
|
-
|
|
861
|
+
row.foreign_table_name
|
|
862
|
+
] = ` LEFT JOIN ${row.foreign_table_name} ON ${row.foreign_table_name}.id = ${table_steps_item}.${row.column_name} `;
|
|
839
863
|
});
|
|
840
864
|
console.log(foreignTables);
|
|
841
865
|
table_joins.map((item) => {
|
|
@@ -852,15 +876,15 @@ const buildJoin = async (MYMODEL, result) => {
|
|
|
852
876
|
if (table_steps.length > 0) {
|
|
853
877
|
for (let table_steps_item of table_steps) {
|
|
854
878
|
let rows = await connection.query(
|
|
855
|
-
|
|
879
|
+
connection.foreignKeyList(table_steps_item)
|
|
856
880
|
);
|
|
857
881
|
let foreign_table_name = {};
|
|
858
882
|
let foreignTables = [];
|
|
859
883
|
rows.map((row) => {
|
|
860
884
|
foreignTables.push(row.foreign_table_name);
|
|
861
885
|
foreign_table_name[
|
|
862
|
-
|
|
863
|
-
|
|
886
|
+
row.foreign_table_name
|
|
887
|
+
] = ` LEFT JOIN ${row.foreign_table_name} ON ${row.foreign_table_name}.id = ${table_steps_item}.${row.column_name} `;
|
|
864
888
|
});
|
|
865
889
|
//console.log(foreignTables)
|
|
866
890
|
table_joins.map((item) => {
|
|
@@ -955,45 +979,45 @@ router.delete("/delete-table", csrfProtection, async (req, res) => {
|
|
|
955
979
|
|
|
956
980
|
let runtimeFile = dirRoot + "/public/runtime/script/" + table;
|
|
957
981
|
fs.rm(
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
982
|
+
runtimeFile,
|
|
983
|
+
{
|
|
984
|
+
recursive: true,
|
|
985
|
+
},
|
|
986
|
+
(error) => {
|
|
987
|
+
if (error) {
|
|
988
|
+
console.log(error);
|
|
989
|
+
} else {
|
|
990
|
+
console.log("Recursive: Directories Deleted!");
|
|
991
|
+
}
|
|
967
992
|
}
|
|
968
|
-
}
|
|
969
993
|
);
|
|
970
994
|
let runtimeFileHead = dirRoot + "/public/runtime/head/" + table;
|
|
971
995
|
fs.rm(
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
996
|
+
runtimeFileHead,
|
|
997
|
+
{
|
|
998
|
+
recursive: true,
|
|
999
|
+
},
|
|
1000
|
+
(error) => {
|
|
1001
|
+
if (error) {
|
|
1002
|
+
console.log(error);
|
|
1003
|
+
} else {
|
|
1004
|
+
console.log("Recursive: Directories Deleted!");
|
|
1005
|
+
}
|
|
981
1006
|
}
|
|
982
|
-
}
|
|
983
1007
|
);
|
|
984
1008
|
let runtimeFileEnd = dirRoot + "/public/runtime/end/" + table;
|
|
985
1009
|
fs.rm(
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1010
|
+
runtimeFileEnd,
|
|
1011
|
+
{
|
|
1012
|
+
recursive: true,
|
|
1013
|
+
},
|
|
1014
|
+
(error) => {
|
|
1015
|
+
if (error) {
|
|
1016
|
+
console.log(error);
|
|
1017
|
+
} else {
|
|
1018
|
+
console.log("Recursive: Directories Deleted!");
|
|
1019
|
+
}
|
|
995
1020
|
}
|
|
996
|
-
}
|
|
997
1021
|
);
|
|
998
1022
|
|
|
999
1023
|
await connection.delete({
|
|
@@ -1003,17 +1027,17 @@ router.delete("/delete-table", csrfProtection, async (req, res) => {
|
|
|
1003
1027
|
if (table) {
|
|
1004
1028
|
const viewsFile = dirRoot + "/views/" + table;
|
|
1005
1029
|
fs.rm(
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1030
|
+
viewsFile,
|
|
1031
|
+
{
|
|
1032
|
+
recursive: true,
|
|
1033
|
+
},
|
|
1034
|
+
(error) => {
|
|
1035
|
+
if (error) {
|
|
1036
|
+
console.log(error);
|
|
1037
|
+
} else {
|
|
1038
|
+
console.log("Recursive: Directories Deleted!");
|
|
1039
|
+
}
|
|
1015
1040
|
}
|
|
1016
|
-
}
|
|
1017
1041
|
);
|
|
1018
1042
|
}
|
|
1019
1043
|
await connection.delete({
|
|
@@ -1039,11 +1063,11 @@ router.post("/add_field", csrfProtection, async (req, res) => {
|
|
|
1039
1063
|
table: "zfields",
|
|
1040
1064
|
where: { table: table },
|
|
1041
1065
|
});
|
|
1042
|
-
const results = await axios.post(
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
);
|
|
1046
|
-
const datas =
|
|
1066
|
+
/* const results = await axios.post(
|
|
1067
|
+
`${generatorUrl}/api/generator/create_field`,
|
|
1068
|
+
body
|
|
1069
|
+
); */
|
|
1070
|
+
const datas = Api.create_field(body);
|
|
1047
1071
|
if (datas.status == 1) {
|
|
1048
1072
|
await connection.update({
|
|
1049
1073
|
table: "zfields",
|
|
@@ -1091,17 +1115,17 @@ router.post("/setting_field", csrfProtection, async (req, res) => {
|
|
|
1091
1115
|
table: "zfields",
|
|
1092
1116
|
where: { table: table },
|
|
1093
1117
|
});
|
|
1094
|
-
const results = await axios.post(
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
);
|
|
1098
|
-
const datas =
|
|
1118
|
+
/* const results = await axios.post(
|
|
1119
|
+
`${generatorUrl}/api/generator/modal_settings`,
|
|
1120
|
+
body
|
|
1121
|
+
); */
|
|
1122
|
+
const datas = Api.modal_settings(body);
|
|
1099
1123
|
res.json(datas.html);
|
|
1100
1124
|
});
|
|
1101
1125
|
|
|
1102
1126
|
router.post("/save_setting", async (req, res) => {
|
|
1103
1127
|
const html = "",
|
|
1104
|
-
|
|
1128
|
+
table = req.query.table || "";
|
|
1105
1129
|
let json = Util.jsonSuccess("Success to update");
|
|
1106
1130
|
try {
|
|
1107
1131
|
if (nots.includes(req.body.table)) {
|
|
@@ -1141,7 +1165,7 @@ router.delete("/delete_field", csrfProtection, async (req, res) => {
|
|
|
1141
1165
|
return res.json(Util.flashError("Table is locked"));
|
|
1142
1166
|
}
|
|
1143
1167
|
const table = req.body.table,
|
|
1144
|
-
|
|
1168
|
+
name = req.body.name;
|
|
1145
1169
|
let data = await connection.result({
|
|
1146
1170
|
table: "zfields",
|
|
1147
1171
|
where: { table: table },
|
|
@@ -1178,7 +1202,7 @@ router.delete("/delete_field", csrfProtection, async (req, res) => {
|
|
|
1178
1202
|
//DROP COULUMN
|
|
1179
1203
|
//ALTER TABLE table_name DROP COLUMN IF EXISTS column_name;
|
|
1180
1204
|
await connection.query(
|
|
1181
|
-
|
|
1205
|
+
`ALTER TABLE "${table}" DROP COLUMN IF EXISTS "${name}";`
|
|
1182
1206
|
);
|
|
1183
1207
|
} catch (err) {
|
|
1184
1208
|
json = Util.flashError(err.toString());
|
|
@@ -1190,9 +1214,9 @@ router.delete("/delete_field", csrfProtection, async (req, res) => {
|
|
|
1190
1214
|
|
|
1191
1215
|
router.post("/tab_rename", csrfProtection, async (req, res) => {
|
|
1192
1216
|
const html = "",
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1217
|
+
table = req.body.table || "",
|
|
1218
|
+
name = req.body.name || "",
|
|
1219
|
+
id = req.body.id || 0;
|
|
1196
1220
|
let json = Util.jsonSuccess("Success to rename");
|
|
1197
1221
|
try {
|
|
1198
1222
|
if (table == "") {
|
|
@@ -1452,7 +1476,7 @@ router.post("/import", async (req, res) => {
|
|
|
1452
1476
|
});
|
|
1453
1477
|
}
|
|
1454
1478
|
json = Util.jsonSuccess(
|
|
1455
|
-
|
|
1479
|
+
"Success to add module, please generate tax to make a file"
|
|
1456
1480
|
);
|
|
1457
1481
|
}
|
|
1458
1482
|
}
|
|
@@ -1624,7 +1648,7 @@ const viewsMini = async () => {
|
|
|
1624
1648
|
}
|
|
1625
1649
|
} catch (e) {
|
|
1626
1650
|
notifyObj = Util.flashError(
|
|
1627
|
-
|
|
1651
|
+
`error in item : ${item} , error str :${e.toString()}`
|
|
1628
1652
|
);
|
|
1629
1653
|
}
|
|
1630
1654
|
return notifyObj;
|
package/lib/zRoute.js
CHANGED
|
@@ -547,6 +547,9 @@ zRoute.relationTable = async (req, res, table, visiblesColumns = []) => {
|
|
|
547
547
|
try {
|
|
548
548
|
const MYMODELS = myCache.get("MYMODELS");
|
|
549
549
|
const MYMODEL = MYMODELS[table];
|
|
550
|
+
if (!MYMODEL) {
|
|
551
|
+
return {};
|
|
552
|
+
}
|
|
550
553
|
let relations = {};
|
|
551
554
|
relations["zattributes"] = {};
|
|
552
555
|
relations["zvirtuals"] = {};
|
|
@@ -556,10 +559,12 @@ zRoute.relationTable = async (req, res, table, visiblesColumns = []) => {
|
|
|
556
559
|
let company_id = res.locals.companyId;
|
|
557
560
|
let widgets = {};
|
|
558
561
|
if (visiblesColumns.length == 0) {
|
|
559
|
-
widgets = MYMODEL.widgets;
|
|
562
|
+
widgets = MYMODEL.widgets || {};
|
|
560
563
|
} else {
|
|
561
564
|
visiblesColumns.map((item) => {
|
|
562
|
-
widgets
|
|
565
|
+
if (MYMODEL.widgets && MYMODEL.widgets[item]) {
|
|
566
|
+
widgets[item] = MYMODEL.widgets[item];
|
|
567
|
+
}
|
|
563
568
|
});
|
|
564
569
|
}
|
|
565
570
|
|
|
@@ -819,6 +824,9 @@ zRoute.relations = async (req, res, table, visiblesColumns = []) => {
|
|
|
819
824
|
try {
|
|
820
825
|
const MYMODELS = myCache.get("MYMODELS");
|
|
821
826
|
const MYMODEL = MYMODELS[table];
|
|
827
|
+
if (!MYMODEL) {
|
|
828
|
+
return {};
|
|
829
|
+
}
|
|
822
830
|
let relation = await zRoute.relationTable(req, res, table, visiblesColumns);
|
|
823
831
|
let relations = {};
|
|
824
832
|
if (MYMODEL.joins && MYMODEL.joins.list) {
|
|
@@ -4080,7 +4088,10 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4080
4088
|
}
|
|
4081
4089
|
let obj = {};
|
|
4082
4090
|
const MYMODELS = myCache.get("MYMODELS");
|
|
4083
|
-
|
|
4091
|
+
if (!MYMODEL) {
|
|
4092
|
+
return { script: "", head: "", end: "" };
|
|
4093
|
+
}
|
|
4094
|
+
let widgets = MYMODEL.widgets || {},
|
|
4084
4095
|
widgetsArray = Object.keys(widgets) || [];
|
|
4085
4096
|
|
|
4086
4097
|
let hasTabs = MYMODEL.hasOwnProperty("hasTabs") ? MYMODEL.hasTabs : false;
|