zet-lib 1.3.21 → 1.3.23
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/views/generator.ejs +20 -15
- package/lib/views/generatorjs.ejs +20 -22
- package/lib/zGeneratorRouter.js +160 -91
- package/package.json +1 -1
package/lib/views/generator.ejs
CHANGED
|
@@ -91,10 +91,6 @@
|
|
|
91
91
|
<form id="formfields" method="post" action="/generator/fields">
|
|
92
92
|
<div id="divtablist" class="row"></div>
|
|
93
93
|
<div id="contentfields"></div>
|
|
94
|
-
<div id="divjoinmodules">
|
|
95
|
-
<h4>Join Modules</h4>
|
|
96
|
-
<div class="row" id="joinlist"></div>
|
|
97
|
-
</div>
|
|
98
94
|
<% if(lock==0) {%>
|
|
99
95
|
<div class="text-center mt-4">
|
|
100
96
|
<button class="btn btn-danger btn-reset text-white mr-2" type="button"><i
|
|
@@ -109,7 +105,7 @@
|
|
|
109
105
|
<!-- Basic dropdown -->
|
|
110
106
|
<button class="btn btn-warning m-0 px-3 waves-effect waves-light mr-2"
|
|
111
107
|
data-toggle="modal" data-target="#modal_joins" type="button"><i
|
|
112
|
-
class="fas fa-dice"></i> Join
|
|
108
|
+
class="fas fa-dice"></i> Join Modules</button>
|
|
113
109
|
<button class="btn m-0 px-3 waves-effect waves-light mr-2" data-toggle="modal"
|
|
114
110
|
data-target="#modal_container" type="button"><i class="fa fa-plus"></i> Add
|
|
115
111
|
Container</button>
|
|
@@ -120,13 +116,26 @@
|
|
|
120
116
|
type="button"><i class="fa fa-paper-plane"></i> Save & Generate</button>
|
|
121
117
|
</div>
|
|
122
118
|
<%}%>
|
|
123
|
-
|
|
124
119
|
</form>
|
|
125
120
|
<!-- Default form reply -->
|
|
126
121
|
</div>
|
|
127
122
|
</div>
|
|
128
123
|
<!--/Generator-->
|
|
129
124
|
|
|
125
|
+
<div class="card mb-4 wow fadeIn card-script">
|
|
126
|
+
<div class="card-header font-weight-bold">
|
|
127
|
+
<span> Join Modules</span>
|
|
128
|
+
</div>
|
|
129
|
+
<div class="card-body">
|
|
130
|
+
<div id="divjoinmodules">
|
|
131
|
+
<form id="formjoin">
|
|
132
|
+
<div class="row" id="joinlist"></div>
|
|
133
|
+
</form>
|
|
134
|
+
</div>
|
|
135
|
+
<hr>
|
|
136
|
+
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
130
139
|
|
|
131
140
|
<!-- Card -->
|
|
132
141
|
<div class="card mb-4 wow fadeIn card-script" style="display: none">
|
|
@@ -304,16 +313,12 @@
|
|
|
304
313
|
</div>
|
|
305
314
|
</div>
|
|
306
315
|
<!--/.Card-->
|
|
307
|
-
|
|
308
316
|
</div>
|
|
309
317
|
</div>
|
|
310
318
|
<!--Grid row-->
|
|
311
319
|
</section>
|
|
312
320
|
<!--Section: Post-->
|
|
313
321
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
322
|
<!-- Modal -->
|
|
318
323
|
<div class="modal fade" id="add_table" tabindex="-1" aria-labelledby="add_table" aria-hidden="true">
|
|
319
324
|
<div class="modal-dialog">
|
|
@@ -445,7 +450,6 @@
|
|
|
445
450
|
</div>
|
|
446
451
|
|
|
447
452
|
|
|
448
|
-
|
|
449
453
|
<div class="modal fade" id="modal_tab" tabindex="-1" aria-labelledby="modal_setting" aria-hidden="true">
|
|
450
454
|
<div class="modal-dialog">
|
|
451
455
|
<div class="modal-content">
|
|
@@ -473,7 +477,7 @@
|
|
|
473
477
|
<div class="modal-dialog">
|
|
474
478
|
<div class="modal-content">
|
|
475
479
|
<div class="modal-header">
|
|
476
|
-
<h5 class="modal-title"
|
|
480
|
+
<h5 class="modal-title">Import zfield File</h5>
|
|
477
481
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i>
|
|
478
482
|
</button>
|
|
479
483
|
</div>
|
|
@@ -501,7 +505,7 @@
|
|
|
501
505
|
<div class="modal-dialog">
|
|
502
506
|
<div class="modal-content">
|
|
503
507
|
<div class="modal-header">
|
|
504
|
-
<h5 class="modal-title"
|
|
508
|
+
<h5 class="modal-title">Add Container</h5>
|
|
505
509
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i>
|
|
506
510
|
</button>
|
|
507
511
|
</div>
|
|
@@ -534,8 +538,9 @@
|
|
|
534
538
|
<div class="modal-dialog">
|
|
535
539
|
<div class="modal-content">
|
|
536
540
|
<div class="modal-header">
|
|
537
|
-
<h5 class="modal-title"
|
|
538
|
-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i
|
|
541
|
+
<h5 class="modal-title">Join Module</h5>
|
|
542
|
+
<button type="button" class="close" id="closejoin" data-dismiss="modal" aria-label="Close"><i
|
|
543
|
+
class="fa fa-times"></i>
|
|
539
544
|
</button>
|
|
540
545
|
</div>
|
|
541
546
|
<div class="modal-body">
|
|
@@ -270,7 +270,7 @@
|
|
|
270
270
|
let html = ``
|
|
271
271
|
let time = new Date().getTime()
|
|
272
272
|
let col_md = `col-md-${12 / columncount}`
|
|
273
|
-
container_time = `container_${time}`
|
|
273
|
+
let container_time = `container_${time}`
|
|
274
274
|
html += `<li class="container-nav"><i class="fa fa-arrows icon-float"></i><div class="row mt-1 mb-1">`
|
|
275
275
|
for (let i = 1; i <= columncount; i++) {
|
|
276
276
|
html += `<div class="${col_md}" style="background-color: rgba(0,0,0,.03)" ><ol class="divboxlittle container-box"><li><i data-container="${container_time}" data-id="${i}" data-split="${columncount}" data-column="ONE_COLUMN" class="fa fa-plus-circle fa-2x add-container text-success"></i></li></ol> </div>`
|
|
@@ -406,6 +406,7 @@
|
|
|
406
406
|
approvers: approvers,
|
|
407
407
|
knowings: knowings,
|
|
408
408
|
others: JSON.stringify(others),
|
|
409
|
+
joins: $('#formjoin').serializeArray(),
|
|
409
410
|
},
|
|
410
411
|
function (data) {
|
|
411
412
|
if (data.status == 0) {
|
|
@@ -815,26 +816,6 @@
|
|
|
815
816
|
})
|
|
816
817
|
})
|
|
817
818
|
}
|
|
818
|
-
/* let myobj = {}
|
|
819
|
-
let isContainer = Object.keys(obj).length ? true : false;
|
|
820
|
-
if(isContainer) {
|
|
821
|
-
for(let key in obj) {
|
|
822
|
-
let arr = obj[key] || [];
|
|
823
|
-
if(arr.length) {
|
|
824
|
-
arr.forEach(function (item) {
|
|
825
|
-
if(Array.isArray(item)) {
|
|
826
|
-
let length = item.length;
|
|
827
|
-
if(isEmpty(item)) {
|
|
828
|
-
obj[key].splice(0,1);
|
|
829
|
-
}
|
|
830
|
-
console.log(length)
|
|
831
|
-
}
|
|
832
|
-
})
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
console.log(JSON.stringify(obj))*/
|
|
837
|
-
|
|
838
819
|
others = obj
|
|
839
820
|
return obj
|
|
840
821
|
}
|
|
@@ -877,10 +858,11 @@
|
|
|
877
858
|
)
|
|
878
859
|
}
|
|
879
860
|
})
|
|
861
|
+
|
|
880
862
|
$("#modal-joins-save").on("click", function (e) {
|
|
881
863
|
let table_join = $('#select_module_joins').val();
|
|
882
864
|
let table = $('#table').val()
|
|
883
|
-
if (table ==
|
|
865
|
+
if (table == table_join) {
|
|
884
866
|
toastr.error("Your selected module is equal with current module");
|
|
885
867
|
return;
|
|
886
868
|
}
|
|
@@ -894,6 +876,7 @@
|
|
|
894
876
|
toastrForm(dt);
|
|
895
877
|
if (dt.status == 1) {
|
|
896
878
|
$("#joinlist").html(dt.html);
|
|
879
|
+
$("#closejoin").click();
|
|
897
880
|
}
|
|
898
881
|
}
|
|
899
882
|
)
|
|
@@ -927,4 +910,19 @@
|
|
|
927
910
|
}
|
|
928
911
|
)
|
|
929
912
|
}
|
|
913
|
+
|
|
914
|
+
function removeJoins(table_join) {
|
|
915
|
+
if (window.confirm('Sure to delete ?')) {
|
|
916
|
+
ajaxPost(
|
|
917
|
+
'/<%- routeName%>/remove-joins',
|
|
918
|
+
{
|
|
919
|
+
table: $('#table').val(),
|
|
920
|
+
table_join: table_join
|
|
921
|
+
},
|
|
922
|
+
function (dt) {
|
|
923
|
+
location.reload();
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
}
|
|
927
|
+
}
|
|
930
928
|
</script>
|
package/lib/zGeneratorRouter.js
CHANGED
|
@@ -266,6 +266,7 @@ router.post('/save_and_generate', csrfProtection, async (req, res) => {
|
|
|
266
266
|
if (nots.includes(req.body.table)) {
|
|
267
267
|
return res.json(Util.flashError('Table is locked'))
|
|
268
268
|
}
|
|
269
|
+
//console.log(JSON.stringify(req.body))
|
|
269
270
|
const json = await generate(req, res)
|
|
270
271
|
res.json(json)
|
|
271
272
|
} catch (e) {
|
|
@@ -1015,6 +1016,7 @@ router.post('/load-form', async (req, res) => {
|
|
|
1015
1016
|
res.json(json)
|
|
1016
1017
|
})
|
|
1017
1018
|
|
|
1019
|
+
//save to table zfields
|
|
1018
1020
|
var saveToZFields = async (body) => {
|
|
1019
1021
|
const table = body.table
|
|
1020
1022
|
let is_approval = body.is_approval
|
|
@@ -1049,6 +1051,29 @@ var saveToZFields = async (body) => {
|
|
|
1049
1051
|
others: body.others,
|
|
1050
1052
|
}
|
|
1051
1053
|
|
|
1054
|
+
let joinsTables = {}
|
|
1055
|
+
let bodyJoins = body.joins || []
|
|
1056
|
+
let bodyJoinsObj = {}
|
|
1057
|
+
if (bodyJoins.length > 0) {
|
|
1058
|
+
bodyJoins.map((item) => {
|
|
1059
|
+
bodyJoinsObj[item.name] = item.value
|
|
1060
|
+
})
|
|
1061
|
+
}
|
|
1062
|
+
for (let key in bodyJoinsObj) {
|
|
1063
|
+
if (key.includes('joins_checks___')) {
|
|
1064
|
+
let tablekeys = key.split('___')
|
|
1065
|
+
let keyName = key.replace('joins_checks___', '')
|
|
1066
|
+
if (!joinsTables[tablekeys[1]]) {
|
|
1067
|
+
joinsTables[tablekeys[1]] = []
|
|
1068
|
+
}
|
|
1069
|
+
joinsTables[tablekeys[1]].push({ key: keyName, value: bodyJoinsObj[`joins_labels___${keyName}`] })
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
//console.log(joinsTables);
|
|
1073
|
+
if (Object.keys(joinsTables).length > 0) {
|
|
1074
|
+
data.joins = JSON.stringify(joinsTables)
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1052
1077
|
await connection.update({
|
|
1053
1078
|
table: 'zfields',
|
|
1054
1079
|
data: data,
|
|
@@ -1344,112 +1369,156 @@ const viewsMini = async () => {
|
|
|
1344
1369
|
return notifyObj
|
|
1345
1370
|
}
|
|
1346
1371
|
|
|
1347
|
-
router.post('/load-joins', async(req,res) => {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1372
|
+
router.post('/load-joins', async (req, res) => {
|
|
1373
|
+
let jsonNotif = Util.jsonSuccess('Success')
|
|
1374
|
+
let html = ''
|
|
1375
|
+
try {
|
|
1376
|
+
let body = req.body
|
|
1377
|
+
console.log(body)
|
|
1378
|
+
let table = body.table
|
|
1379
|
+
html = await loadJoins(table)
|
|
1380
|
+
jsonNotif.html = html
|
|
1381
|
+
} catch (e) {
|
|
1382
|
+
console.log(e)
|
|
1383
|
+
}
|
|
1384
|
+
res.json(jsonNotif)
|
|
1360
1385
|
})
|
|
1361
1386
|
|
|
1362
|
-
router.post('/joins', async(req,res) => {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1387
|
+
router.post('/remove-joins', async (req, res) => {
|
|
1388
|
+
let jsonNotif = Util.jsonSuccess('Success')
|
|
1389
|
+
let html = ''
|
|
1390
|
+
try {
|
|
1391
|
+
let body = req.body
|
|
1392
|
+
console.log(body)
|
|
1393
|
+
let table = body.table
|
|
1394
|
+
let table_join = body.table_join
|
|
1395
|
+
let result = await connection.result({
|
|
1396
|
+
table: 'zfields',
|
|
1397
|
+
where: {
|
|
1398
|
+
table: table,
|
|
1399
|
+
},
|
|
1400
|
+
})
|
|
1401
|
+
let resultJoins = result.joins || {}
|
|
1402
|
+
delete resultJoins[table_join]
|
|
1403
|
+
await connection.update({
|
|
1404
|
+
table: 'zfields',
|
|
1405
|
+
data: {
|
|
1406
|
+
joins: JSON.stringify(resultJoins),
|
|
1407
|
+
},
|
|
1408
|
+
where: {
|
|
1409
|
+
table: table,
|
|
1410
|
+
},
|
|
1411
|
+
})
|
|
1412
|
+
} catch (e) {
|
|
1413
|
+
console.log(e)
|
|
1414
|
+
}
|
|
1415
|
+
res.json(jsonNotif)
|
|
1416
|
+
})
|
|
1417
|
+
|
|
1418
|
+
router.post('/joins', async (req, res) => {
|
|
1419
|
+
let jsonNotif = Util.jsonSuccess('Success')
|
|
1420
|
+
let html = ''
|
|
1421
|
+
try {
|
|
1422
|
+
let body = req.body
|
|
1423
|
+
console.log(body)
|
|
1424
|
+
let table = body.table
|
|
1425
|
+
let table_join = body.table_join
|
|
1426
|
+
let result = await connection.result({
|
|
1427
|
+
table: 'zfields',
|
|
1428
|
+
where: {
|
|
1429
|
+
table: table,
|
|
1430
|
+
},
|
|
1431
|
+
})
|
|
1432
|
+
let resultJoins = result.joins || {}
|
|
1433
|
+
resultJoins[table_join] = {}
|
|
1434
|
+
let myzfield = await connection.update({
|
|
1435
|
+
table: 'zfields',
|
|
1436
|
+
data: {
|
|
1437
|
+
joins: JSON.stringify(resultJoins),
|
|
1438
|
+
},
|
|
1439
|
+
where: {
|
|
1440
|
+
table: table,
|
|
1441
|
+
},
|
|
1442
|
+
})
|
|
1443
|
+
jsonNotif.json = resultJoins
|
|
1444
|
+
html = await joinHTML(resultJoins, myzfield)
|
|
1445
|
+
} catch (e) {
|
|
1446
|
+
console.log(e)
|
|
1447
|
+
jsonNotif = Util.flashError(e + '')
|
|
1448
|
+
}
|
|
1449
|
+
jsonNotif.html = html
|
|
1450
|
+
res.json(jsonNotif)
|
|
1395
1451
|
})
|
|
1396
1452
|
|
|
1397
1453
|
async function loadJoins(table) {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1454
|
+
let html = ''
|
|
1455
|
+
try {
|
|
1456
|
+
/* let sql = `select ${table}.* from ${table} `;
|
|
1457
|
+
console.log(sql)*/
|
|
1458
|
+
let result = await connection.result({
|
|
1459
|
+
table: 'zfields',
|
|
1460
|
+
where: {
|
|
1461
|
+
table: table,
|
|
1462
|
+
},
|
|
1463
|
+
})
|
|
1464
|
+
let joinsObj = result.joins || {}
|
|
1465
|
+
html = await joinHTML(joinsObj, result)
|
|
1466
|
+
} catch (e) {
|
|
1467
|
+
console.log(e)
|
|
1468
|
+
html = e + ''
|
|
1469
|
+
}
|
|
1470
|
+
return html
|
|
1413
1471
|
}
|
|
1414
1472
|
|
|
1415
|
-
async function joinHTML(json) {
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
} catch (e) {
|
|
1429
|
-
html = e+'';
|
|
1473
|
+
async function joinHTML(json, myzfield) {
|
|
1474
|
+
let html = ``
|
|
1475
|
+
try {
|
|
1476
|
+
let zfields = await connection.results({
|
|
1477
|
+
table: 'zfields',
|
|
1478
|
+
})
|
|
1479
|
+
let zfieldsObj = Util.arrayToObject(zfields, 'table')
|
|
1480
|
+
for (let key in json) {
|
|
1481
|
+
html += `<div class="joinContainer col-md-4">`
|
|
1482
|
+
html += `<h5>${zfieldsObj[key].name} <button type="button" class="btn btn-danger" onclick="removeJoins('${key}')"><i class="fa fa-trash "></i> </button></h5>`
|
|
1483
|
+
html += fieldHTML(zfieldsObj[key], myzfield)
|
|
1484
|
+
html += `</div>`
|
|
1430
1485
|
}
|
|
1431
|
-
|
|
1486
|
+
} catch (e) {
|
|
1487
|
+
html = e + ''
|
|
1488
|
+
}
|
|
1489
|
+
return html
|
|
1432
1490
|
}
|
|
1433
1491
|
|
|
1434
|
-
function fieldHTML(obj) {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1492
|
+
function fieldHTML(obj, myzfield) {
|
|
1493
|
+
let html = ``
|
|
1494
|
+
try {
|
|
1495
|
+
let labels = obj.labels
|
|
1496
|
+
let table = obj.table
|
|
1497
|
+
let myzfieldJoins = myzfield.joins || {}
|
|
1498
|
+
for (let key in labels) {
|
|
1499
|
+
let mylabel = labels[key]
|
|
1500
|
+
let selected = ''
|
|
1501
|
+
if (myzfieldJoins[table]) {
|
|
1502
|
+
let arr = myzfieldJoins[table] || []
|
|
1503
|
+
arr.map((item) => {
|
|
1504
|
+
if (item.key == `${table}___${key}`) {
|
|
1505
|
+
selected = ` checked `
|
|
1506
|
+
mylabel = item.value
|
|
1507
|
+
}
|
|
1508
|
+
})
|
|
1509
|
+
}
|
|
1510
|
+
html += `<div class="input-group">
|
|
1441
1511
|
<div class="input-group-prepend">
|
|
1442
|
-
<span class="input-group-text"><input type="checkbox" name=""></span>
|
|
1512
|
+
<span class="input-group-text"><input type="checkbox" ${selected} name="joins_checks___${table}___${key}"></span>
|
|
1443
1513
|
<span class="input-group-text">${key}</span>
|
|
1444
|
-
<input type="text" class="form-control" name="
|
|
1514
|
+
<input type="text" class="form-control" name="joins_labels___${table}___${key}" id="joins___${table}___${key}" value="${mylabel}">
|
|
1445
1515
|
</div>
|
|
1446
1516
|
</div>`
|
|
1447
|
-
}
|
|
1448
|
-
} catch (e) {
|
|
1449
|
-
html = e+'';
|
|
1450
1517
|
}
|
|
1451
|
-
|
|
1518
|
+
} catch (e) {
|
|
1519
|
+
html = e + ''
|
|
1520
|
+
}
|
|
1521
|
+
return html
|
|
1452
1522
|
}
|
|
1453
1523
|
|
|
1454
|
-
|
|
1455
1524
|
module.exports = router
|