zet-lib 1.3.21 → 1.3.22

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.
@@ -927,4 +927,21 @@
927
927
  }
928
928
  )
929
929
  }
930
+
931
+ function removeJoins(table_join) {
932
+ if (window.confirm('Sure to delete ?')) {
933
+ ajaxPost(
934
+ '/<%- routeName%>/remove-joins',
935
+ {
936
+ table: $('#table').val(),
937
+ table_join: table_join
938
+ },
939
+ function (dt) {
940
+ if (dt.status == 1) {
941
+ location.href = '';
942
+ }
943
+ }
944
+ )
945
+ }
946
+ }
930
947
  </script>
@@ -1344,112 +1344,142 @@ const viewsMini = async () => {
1344
1344
  return notifyObj
1345
1345
  }
1346
1346
 
1347
- router.post('/load-joins', async(req,res) => {
1348
- let jsonNotif = Util.jsonSuccess("Success")
1349
- let html = '';
1350
- try {
1351
- let body = req.body;
1352
- console.log(body)
1353
- let table = body.table;
1354
- html = await loadJoins(table)
1355
- jsonNotif.html=html;
1356
- } catch (e) {
1357
- console.log(e)
1358
- }
1359
- res.json(jsonNotif)
1347
+ router.post('/load-joins', async (req, res) => {
1348
+ let jsonNotif = Util.jsonSuccess('Success')
1349
+ let html = ''
1350
+ try {
1351
+ let body = req.body
1352
+ console.log(body)
1353
+ let table = body.table
1354
+ html = await loadJoins(table)
1355
+ jsonNotif.html = html
1356
+ } catch (e) {
1357
+ console.log(e)
1358
+ }
1359
+ res.json(jsonNotif)
1360
1360
  })
1361
1361
 
1362
- router.post('/joins', async(req,res) => {
1363
- let jsonNotif = Util.jsonSuccess("Success")
1364
- let html = '';
1365
- try {
1366
- let body = req.body;
1367
- console.log(body)
1368
- let table = body.table;
1369
- let table_join = body.table_join;
1370
- let result = await connection.result({
1371
- table:"zfields",
1372
- where : {
1373
- table:table
1374
- }
1375
- })
1376
- let joinsObj = result.joins || {}
1377
- joinsObj[table] = {}
1378
- await connection.update({
1379
- table: 'zfields',
1380
- data: {
1381
- joins:JSON.stringify(joinsObj)
1382
- },
1383
- where: {
1384
- table: table
1385
- },
1386
- })
1387
- jsonNotif.json=joinsObj
1388
- html = await joinHTML(joinsObj)
1389
- } catch (e) {
1390
- console.log(e)
1391
- jsonNotif = Util.flashError(e+'')
1392
- }
1393
- jsonNotif.html = html;
1394
- res.json(jsonNotif)
1362
+ router.post('/remove-joins', async (req, res) => {
1363
+ let jsonNotif = Util.jsonSuccess('Success')
1364
+ let html = ''
1365
+ try {
1366
+ let body = req.body
1367
+ console.log(body)
1368
+ let table = body.table
1369
+ let table_join = body.table_join
1370
+ let result = await connection.result({
1371
+ table: 'zfields',
1372
+ where: {
1373
+ table: table,
1374
+ },
1375
+ })
1376
+ let resultJoins = result.joins || {}
1377
+ delete resultJoins[table_join]
1378
+ await connection.update({
1379
+ table: 'zfields',
1380
+ data: {
1381
+ joins: JSON.stringify(resultJoins),
1382
+ },
1383
+ where: {
1384
+ table: table,
1385
+ },
1386
+ })
1387
+ } catch (e) {
1388
+ console.log(e)
1389
+ }
1390
+ res.json(jsonNotif)
1391
+ })
1392
+
1393
+ router.post('/joins', async (req, res) => {
1394
+ let jsonNotif = Util.jsonSuccess('Success')
1395
+ let html = ''
1396
+ try {
1397
+ let body = req.body
1398
+ console.log(body)
1399
+ let table = body.table
1400
+ let table_join = body.table_join
1401
+ let result = await connection.result({
1402
+ table: 'zfields',
1403
+ where: {
1404
+ table: table,
1405
+ },
1406
+ })
1407
+ let resultJoins = result.joins || {}
1408
+ resultJoins[table_join] = {}
1409
+ await connection.update({
1410
+ table: 'zfields',
1411
+ data: {
1412
+ joins: JSON.stringify(resultJoins),
1413
+ },
1414
+ where: {
1415
+ table: table,
1416
+ },
1417
+ })
1418
+ jsonNotif.json = resultJoins
1419
+ html = await joinHTML(resultJoins)
1420
+ } catch (e) {
1421
+ console.log(e)
1422
+ jsonNotif = Util.flashError(e + '')
1423
+ }
1424
+ jsonNotif.html = html
1425
+ res.json(jsonNotif)
1395
1426
  })
1396
1427
 
1397
1428
  async function loadJoins(table) {
1398
- let html = '';
1399
- try {
1400
- let result = await connection.result({
1401
- table:"zfields",
1402
- where : {
1403
- table:table
1404
- }
1405
- })
1406
- let joinsObj = result.joins || {}
1407
- html = await joinHTML(joinsObj)
1408
- } catch (e) {
1409
- console.log(e)
1410
- html = e + '';
1411
- }
1412
- return html;
1429
+ let html = ''
1430
+ try {
1431
+ let result = await connection.result({
1432
+ table: 'zfields',
1433
+ where: {
1434
+ table: table,
1435
+ },
1436
+ })
1437
+ let joinsObj = result.joins || {}
1438
+ html = await joinHTML(joinsObj)
1439
+ } catch (e) {
1440
+ console.log(e)
1441
+ html = e + ''
1442
+ }
1443
+ return html
1413
1444
  }
1414
1445
 
1415
1446
  async function joinHTML(json) {
1416
- let html = ``
1417
- try {
1418
- let zfields = await connection.results({
1419
- table:"zfields"
1420
- })
1421
- let zfieldsObj = Util.arrayToObject(zfields,"table");
1422
- for(let key in json){
1423
- html += `<div class="joinContainer col-md-4">`
1424
- html += `<h5>${zfieldsObj[key].name} <button class="btn btn-danger" onclick="window.confirm('Sure to delete ?')"><i class="fa fa-trash "></i> </button></h5>`
1425
- html += fieldHTML(zfieldsObj[key]);
1426
- html += `</div>`
1427
- }
1428
- } catch (e) {
1429
- html = e+'';
1447
+ let html = ``
1448
+ try {
1449
+ let zfields = await connection.results({
1450
+ table: 'zfields',
1451
+ })
1452
+ let zfieldsObj = Util.arrayToObject(zfields, 'table')
1453
+ for (let key in json) {
1454
+ html += `<div class="joinContainer col-md-4">`
1455
+ html += `<h5>${zfieldsObj[key].name} <button class="btn btn-danger" onclick="removeJoins('${key}')"><i class="fa fa-trash "></i> </button></h5>`
1456
+ html += fieldHTML(zfieldsObj[key])
1457
+ html += `</div>`
1430
1458
  }
1431
- return html;
1459
+ } catch (e) {
1460
+ html = e + ''
1461
+ }
1462
+ return html
1432
1463
  }
1433
1464
 
1434
1465
  function fieldHTML(obj) {
1435
- let html = ``
1436
- try {
1437
- let labels = obj.labels;
1438
- let table = obj.table;
1439
- for(let key in labels) {
1440
- html += `<div class="input-group">
1466
+ let html = ``
1467
+ try {
1468
+ let labels = obj.labels
1469
+ let table = obj.table
1470
+ for (let key in labels) {
1471
+ html += `<div class="input-group">
1441
1472
  <div class="input-group-prepend">
1442
1473
  <span class="input-group-text"><input type="checkbox" name=""></span>
1443
1474
  <span class="input-group-text">${key}</span>
1444
1475
  <input type="text" class="form-control" name="joins[${table}][${key}]" id="joins___${table}___${key}" value="${labels[key]}">
1445
1476
  </div>
1446
1477
  </div>`
1447
- }
1448
- } catch (e) {
1449
- html = e+'';
1450
1478
  }
1451
- return html;
1479
+ } catch (e) {
1480
+ html = e + ''
1481
+ }
1482
+ return html
1452
1483
  }
1453
1484
 
1454
-
1455
1485
  module.exports = router
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.3.21",
3
+ "version": "1.3.22",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"