zet-lib 1.0.15 → 1.0.17
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/zPage.js +3 -4
- package/lib/zRoute.js +79 -1
- package/lib/zapp.js +3 -1
- package/package.json +1 -1
package/lib/zPage.js
CHANGED
|
@@ -54,8 +54,7 @@ const csrfProtection = csrf({cookie: true});
|
|
|
54
54
|
const fs = require('fs-extra');
|
|
55
55
|
const qs = require('qs');
|
|
56
56
|
const axios = require('axios');
|
|
57
|
-
const
|
|
58
|
-
const {zRoute, zRole, connection, Util, io, zCache, debug, moduleLib, zFunction } = require('zet-lib');
|
|
57
|
+
const {zRoute, zRole, connection, Util, io, zCache, myCache, debug, moduleLib, zFunction, zFn, Mail } = require('zet-lib');
|
|
59
58
|
|
|
60
59
|
`;
|
|
61
60
|
};
|
|
@@ -77,7 +76,7 @@ zpage.createRoute = (obj, token, layoutObj) => {
|
|
|
77
76
|
let renderDataforGet = "";
|
|
78
77
|
let routerforGet = "";
|
|
79
78
|
if (obj.method == 1) {
|
|
80
|
-
renderDataforGet = `renderData.csrfToken = req.csrfToken()
|
|
79
|
+
renderDataforGet = `renderData.csrfToken = req.csrfToken();`;
|
|
81
80
|
routerforGet = "csrfProtection, "
|
|
82
81
|
}
|
|
83
82
|
let commonData = {
|
|
@@ -130,7 +129,7 @@ zpage.createRoute = (obj, token, layoutObj) => {
|
|
|
130
129
|
}
|
|
131
130
|
let scripts = `router.${METHOD[obj.method]}('${obj.page}', ${routerforGet} async(req,res) => {
|
|
132
131
|
try {
|
|
133
|
-
let renderData = {}
|
|
132
|
+
let renderData = {};
|
|
134
133
|
let commonData = ${JSON.stringify(commonData)};
|
|
135
134
|
commonData.updated_at = Util.now();
|
|
136
135
|
commonData.created_at = Util.now();
|
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);
|
|
@@ -3251,7 +3329,7 @@ module.exports = (req, res, next) => {`;
|
|
|
3251
3329
|
if (err) {
|
|
3252
3330
|
console.log(err.toString());
|
|
3253
3331
|
}
|
|
3254
|
-
pm2.restart(process.env.
|
|
3332
|
+
pm2.restart(process.env.PM2_NAME, (err, proc) => {
|
|
3255
3333
|
//io.to(room).emit("message","Restart done")
|
|
3256
3334
|
});
|
|
3257
3335
|
});
|
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 = "";
|