zet-lib 1.0.15 → 1.0.16

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/zRoute.js CHANGED
@@ -1498,6 +1498,84 @@ zRoute.dataTableSave = async (routeName, userId, body) => {
1498
1498
  return "ok";
1499
1499
  };
1500
1500
 
1501
+ /*
1502
+ dynamic list Data Table
1503
+ */
1504
+ zRoute.listDataTable = async (req, res, objData = {}) => {
1505
+ const body = req.body;
1506
+ const MYMODEL = objData.MYMODEL || {};
1507
+ const fields = Object.prototype.hasOwnProperty.call(objData,'fields') ? objData.fields : req.body.fields;
1508
+ const relations = await zRoute.relations(req, res, MYMODEL.table);
1509
+ const select = Object.prototype.hasOwnProperty.call(objData,'select') ? objData.select : Util.selectMysql(fields, relations);
1510
+ const columns = Object.prototype.hasOwnProperty.call(objData,'columns') ? objData.columns : body.columns;
1511
+ let whereArray = [];
1512
+ if(objData.hasOwnProperty('whereArray')) {
1513
+ if(typeof objData.whereArray === 'object') {
1514
+ whereArray = objData.whereArray
1515
+ } else if (typeof objData.whereArray) {
1516
+ whereArray = objData.whereArray(req,res);
1517
+ }
1518
+ } else {
1519
+ whereArray.push({
1520
+ field: "company_id",
1521
+ option: "=",
1522
+ value: res.locals.companyId,
1523
+ operator: "AND"
1524
+ });
1525
+ columns.forEach(function (item) {
1526
+ if (item.search.value) {
1527
+ whereArray.push({
1528
+ field: fields[item.data],
1529
+ option: MYMODEL.options[fields[item.data]],
1530
+ value: item.search.value,
1531
+ operator: "AND"
1532
+ })
1533
+ }
1534
+ });
1535
+ }
1536
+ const orderColumn = fields[body.order[0].column] == "actionColumn" ? "id" : fields[body.order[0].column] == "no" ? "id" : fields[body.order[0].column] == "actionColum" ? "id" : fields[body.order[0].column];
1537
+ const rows = await connection.results({
1538
+ select: select,
1539
+ table: MYMODEL.table,
1540
+ whereArray: whereArray,
1541
+ limit: body.length,
1542
+ offset: body.start,
1543
+ orderBy: [orderColumn, body.order[0].dir]
1544
+ });
1545
+ const count = await connection.result({
1546
+ select: "count(id) as count",
1547
+ table: MYMODEL.table,
1548
+ whereArray: whereArray
1549
+ });
1550
+ let datas = [];
1551
+ const zRole = objData.zRole || {};
1552
+ const levels = objData.hasOwnProperty('levels') ? objData.levels : zRole.myLevel(req, res, MYMODEL.table);
1553
+ rows.forEach(function (row, index) {
1554
+ let arr = [];
1555
+ fields.forEach(function (item) {
1556
+ if (item == "no") {
1557
+ arr.push((index + 1 + parseInt(body.start)));
1558
+ } else if (item == "actionColumn") {
1559
+ let buttons = objData.hasOwnProperty('actionButtons') ? objData.actionButtons(levels, row, MYMODEL.table) : zRoute.actionButtons(levels, row, MYMODEL.table);
1560
+ arr.push(buttons);
1561
+ } else {
1562
+ arr.push(zRoute.dataTableData(item, row[item], MYMODEL, relations));
1563
+ }
1564
+ });
1565
+ datas.push(arr)
1566
+ });
1567
+ const data = {
1568
+ draw: body.draw,
1569
+ recordsTotal: count.count || 0,
1570
+ recordsFiltered: count.count || 0,
1571
+ data: datas
1572
+ };
1573
+ //save grid filter async
1574
+ zRoute.dataTableSave(MYMODEL.routeName, res.locals.userId, body);
1575
+ res.json(data);
1576
+ }
1577
+
1578
+
1501
1579
  zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
1502
1580
  actionButtonsFn = actionButtonsFn || function () {};
1503
1581
  const relations = await zRoute.relations(req, res, MYMODEL.table);
package/lib/zapp.js CHANGED
@@ -2,8 +2,10 @@ const config = require('dotenv').config();
2
2
  module.exports = (req,res,next) => {
3
3
  res.locals.renderHead = "";
4
4
  res.locals.renderBody = "";
5
- res.locals.bodyHTML = '';
6
5
  res.locals.renderEnd = "";
6
+ res.locals.headHTML = '';
7
+ res.locals.bodyHTML = '';
8
+ res.locals.endHTML = '';
7
9
  res.locals.titleApp = process.env.APP_TITLE;
8
10
  res.locals.descriptionApp = process.env.APP_DESCRIPTION;
9
11
  res.locals.moduleHead = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"