zet-lib 1.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/zTester.js ADDED
@@ -0,0 +1,93 @@
1
+ const connection = require('./connection');
2
+ const Util = require("./Util");
3
+ const moment = require('moment');
4
+ const zRoute = require('./zRoute');
5
+ const io = require("./io");
6
+ const fs = require("fs");
7
+ const qs = require('qs');
8
+ const axios = require('axios');
9
+ const nodemailer = require('nodemailer')
10
+ const myCache = require("./cache");
11
+ const moduleLib = require("./moduleLib");
12
+ const cForm = require("./Form");
13
+ const zFunction = require("./zFunction");
14
+ const zCache = require("./zCache");
15
+ require('dotenv').config();
16
+
17
+ const zTester = {}
18
+
19
+ zTester.page = async(req,res,scripts) => {
20
+ const MYMODELS = zRoute.MYMODELS();
21
+ let csrf = req.csrfToken();
22
+ let email = req.query.email || "";
23
+ let json = {
24
+ error:false,
25
+ status : 1,
26
+ message:"Success"
27
+ };
28
+ let stringParams = "";
29
+ let CALL = {
30
+ req:req,
31
+ res:res,
32
+ Util: Util,
33
+ connection: connection,
34
+ fs: fs,
35
+ io: io,
36
+ qs: qs,
37
+ moment:moment,
38
+ myCache:myCache,
39
+ moduleLib:moduleLib,
40
+ zRoute:zRoute,
41
+ zCache:zCache,
42
+ zFunction:zFunction,
43
+ MYMODELS:MYMODELS,
44
+ renderData:{},
45
+ emptyFn : function () {}
46
+ };
47
+
48
+ var arr = ['res.json','res.send'];
49
+ var newScript = '';
50
+ for(var i = 0; i < arr.length; i++) {
51
+ scripts = Util.replaceAll(scripts,arr[i],'emptyFn');
52
+ }
53
+
54
+ scripts += `
55
+ return 1`;
56
+ stringParams = "";
57
+ for (var keys in CALL) {
58
+ stringParams += `var ${keys} = this.${keys};`
59
+ }
60
+ const AsyncFunction = Object.getPrototypeOf(async function () {
61
+ }).constructor;
62
+
63
+ return new Promise(async function (resolve, reject) {
64
+ try {
65
+ var t = AsyncFunction(`
66
+ ${stringParams};
67
+ ${scripts};
68
+ `).call(CALL);
69
+ let me = await t;
70
+ if(me == 1) {
71
+ resolve({
72
+ error:false,
73
+ status : 1,
74
+ message:"Success"
75
+ })
76
+ } else {
77
+ resolve({
78
+ error:true,
79
+ status : 0,
80
+ message:"Error"
81
+ })
82
+ }
83
+ } catch (e) {
84
+ resolve({
85
+ error:true,
86
+ status : 0,
87
+ message:e.toString()
88
+ })
89
+ }
90
+ })
91
+ }
92
+
93
+ module.exports = zTester;
package/lib/zapp.js ADDED
@@ -0,0 +1,79 @@
1
+ const config = require('dotenv').config();
2
+ const dirRoot = process.env.dirRoot;
3
+ const menuGenerator = require('./menuGenerator');
4
+ module.exports = (req,res,next) => {
5
+ res.locals.renderHead = "";
6
+ res.locals.renderBody = "";
7
+ res.locals.renderEnd = "";
8
+ res.locals.titleApp = process.env.APP_TITLE;
9
+ res.locals.descriptionApp = process.env.APP_DESCRIPTION;
10
+ res.locals.moduleHead = "";
11
+ res.locals.relationsVariable = "";
12
+ res.locals.moduleEnd = "";
13
+ res.locals.menuApp = "home";
14
+ res.locals.routeName = "index";
15
+ res.locals.userId = -1;
16
+ res.locals.csrfToken = "";
17
+ res.locals.roleId = 0;
18
+ res.locals.token = "guest";
19
+ res.locals.companyId = 0;
20
+ res.locals.userId = 0;
21
+ res.locals.userAvatar = "/img/user.png";
22
+ res.locals.zuser = {
23
+ fullname: 'test',
24
+ role: {name: "test"}
25
+ };
26
+ res.locals.frameworkcss = "bootstrap5";
27
+ res.locals.startup = 0;
28
+ global.frameworkcss = "bootstrap5";
29
+ global.LANGUAGE = require('./languages/lang_en');
30
+ res.locals.socketUrl = process.env.APP_URL;
31
+ res.locals.zcompanies = [];
32
+ res.locals.isLogin = false;
33
+ res.locals.objectStores = {};
34
+ res.locals.MENU = [];
35
+ res.locals.MENU_SYSTEMS = [];
36
+ res.locals.MENU_ALL = [];
37
+ if (req.session) {
38
+ let reqSession = req.session;
39
+ if (reqSession.hasOwnProperty('user')) {
40
+ const tUser = req.session.user;
41
+ if (tUser && Object.prototype.hasOwnProperty.call(tUser, "id")) {
42
+ tUser.role = {
43
+ name: "Admin"
44
+ };
45
+ res.locals.isLogin = true;
46
+ res.locals.token = tUser.token;
47
+ res.locals.roleId = tUser.role_id;
48
+ res.locals.isLogin = true;
49
+ res.locals.zuser = tUser;
50
+ res.locals.userId = tUser.id;
51
+ res.locals.companyId = tUser.company.id;
52
+ res.locals.userAvatar = tUser.image ? tUser.image.indexOf("http") > -1 ? tUser.image : "/uploads/zuser/" + tUser.image : "/img/user.png";
53
+ res.locals.zcompanies = tUser.companies;
54
+ if(tUser.language){
55
+ let objLanguage = {
56
+ 1 : "lang_en",
57
+ 2 : "lang_id",
58
+ 3 : "lang_jp",
59
+ 4 : "lang_fr"
60
+ };
61
+ global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
62
+ }
63
+ global.layout = "two";
64
+ }
65
+ }
66
+ res.locals.MENU = menuGenerator.menu(req, res);
67
+ res.locals.MENU_SYSTEMS = menuGenerator.systems(req, res);
68
+ res.locals.MENU_ALL = menuGenerator.menuPlus(req, res);
69
+ }
70
+ global.COMPANY_ID = res.locals.companyId;
71
+ global.USER_ID = res.locals.userId;
72
+ res.locals.LANGUAGE = global.LANGUAGE;
73
+ res.locals.currency = {};
74
+ res.locals.settings = {};
75
+ res.locals.sessionFlash = req.session.sessionFlash;
76
+ delete req.session.sessionFlash;
77
+ res.locals.sessionFlashc = req.session.sessionFlashc;
78
+ next();
79
+ };
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Created by sintret dev on 1/6/2022.
3
+ */
4
+ const Util = require("./Util");
5
+
6
+ class dataTable {
7
+ constructor(visibles) {
8
+ this.visibles = visibles; //array object
9
+ this.setColumns = "";
10
+ this.setTable = "";
11
+ this.MYMODEL = null;
12
+ this.searchColumns = {};
13
+ this.relations;
14
+ this.routeName;
15
+ this.types = {};
16
+ this.levels = {};
17
+ }
18
+
19
+ // for filter html
20
+ set filterMODEL(obj) {
21
+ this.MYMODEL = obj.MYMODEL;
22
+ this.relations = obj.relations;
23
+ this.routeName = this.MYMODEL.routeName;
24
+ this.types = obj.TYPES;
25
+ delete obj.MYMODEL;
26
+ delete obj.relations;
27
+ delete obj.TYPES;
28
+ this.searchColumns = obj;
29
+ }
30
+
31
+ get columns() {
32
+ if (this.setColumns)
33
+ return this.setColumns;
34
+ let html = '';
35
+ for (var key in this.visibles) {
36
+ html += `<th id="data_${key}">${this.visibles[key]}</th>`;
37
+ }
38
+ return html;
39
+ }
40
+
41
+ /*
42
+ Create table html header
43
+ */
44
+ get table() {
45
+ if (this.setTable)
46
+ return this.setTable;
47
+ return `<table id="dataTable" class="display table table-hover table-responsive" style="width:100%">
48
+ <thead>${this.columns}</thead>
49
+ </table>`;
50
+ }
51
+
52
+ get buttons() {
53
+ let html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`;
54
+ if (this.levels.create) {
55
+ html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><span><i class="fas fa-plus"></i><span>${LANGUAGE.create}</span></span></button>`
56
+ }
57
+ if (this.levels.import) {
58
+ html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><span><i class="fas fa-exchange-alt"></i> <span>${LANGUAGE.import}</span></span></button>`;
59
+ }
60
+ html += `<button title="${LANGUAGE.setting_info}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><span><i class="fas fa-cog"></i> <span>${LANGUAGE.settings}</span></span></button>`;
61
+ html += `<button class="btn refresh gridreload boxy-small dimens2x" title="${LANGUAGE.grid_refresh}" tabindex="0" aria-controls="DataTables_Table_0" type="button"><span><i class="fas fa-sync"></i><span></span></span></button>`;
62
+ if (this.levels.export) {
63
+ html += `<div class="btn-group" role="group">
64
+ <button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
65
+ <i class="fas fa-cloud-download-alt"></i> ${LANGUAGE.download}
66
+ </button>
67
+ <div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`;
68
+ html += `<a class="dropdown-header">Excel</a>`;
69
+ html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`;
70
+ html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`;
71
+ html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`;
72
+ html += `<hr>`;
73
+ html += `<a class="dropdown-header">PDF</a>`;
74
+ html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`;
75
+ html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`;
76
+ html += `</div>`;
77
+ }
78
+ html += `</div></div>`;
79
+
80
+ return html;
81
+ }
82
+
83
+ get buttons2() {
84
+ let html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`;
85
+ if (this.levels.create) {
86
+ html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"> ${LANGUAGE.create}</button>`
87
+ }
88
+ if (this.levels.import) {
89
+ html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`;
90
+ }
91
+ html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" tabindex="0" aria-controls="DataTables_Table_0" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`;
92
+ html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`;
93
+ if (this.levels.export) {
94
+ html += `<div class="btn-group" role="group">
95
+ <button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
96
+ <img src="/assets/icons/download.svg" class="icons-bg-black"> ${LANGUAGE.download}
97
+ </button>
98
+ <div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`;
99
+ html += `<a class="dropdown-header">Excel</a>`;
100
+ html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`;
101
+ html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`;
102
+ html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`;
103
+ html += `<hr>`;
104
+ html += `<a class="dropdown-header">PDF</a>`;
105
+ html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`;
106
+ html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`;
107
+ html += `</div>`;
108
+ }
109
+ html += `</div></div>`;
110
+ return html;
111
+ }
112
+
113
+ get scripts() {
114
+ let script = '<script type="text/javascript" src="https://cdn.datatables.net/v/bs5/dt-1.11.3/date-1.1.1/fc-4.0.1/fh-3.2.1/r-2.2.9/rg-1.1.4/sc-2.0.5/sl-1.3.4/datatables.min.js"></script>';
115
+ script += `<script>${Util.newLine}`;
116
+ script += `var dataTableFilters = ${JSON.stringify(this.searchColumns)};${Util.newLine}`;
117
+ script += `var dataTableFields = ${JSON.stringify(Object.keys(this.visibles,null,2))};${Util.newLine}`;
118
+ script += `var dataTableTypes = ${JSON.stringify(this.types,null,2)};${Util.newLine}`;
119
+ script += `var dataTableRoute = "${this.routeName}";${Util.newLine}`;
120
+ script += `</script>${Util.newLine}`;
121
+ script += `<script type="text/javascript" src="/js/datatableaddon.min.js"></script>${Util.newLine}`;
122
+
123
+ if (this.searchColumns.FILTERKEY) {
124
+ script += `<script>$(function () { setTimeout(function () { ${this.searchColumns.FILTERKEY} },500) });</script>${Util.newLine}`;
125
+ }
126
+ return script;
127
+ }
128
+ }
129
+
130
+ module.exports = dataTable;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "zet-lib",
3
+ "version": "1.0.0",
4
+ "description": "zet is a library that part of zet generator.",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/sintret/zet",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/sintret/zet"
12
+ },
13
+ "keywords": [
14
+ "expressjs"
15
+ ],
16
+ "author": "Andhiefitria Rosmin <sintret@gmail.com>",
17
+ "license": "MIT",
18
+ "main": "./lib/index.js",
19
+ "files": [
20
+ "lib/",
21
+ "!lib/**/__tests__/"
22
+ ],
23
+ "scripts": {
24
+ "lint": "standard",
25
+ "test-find": "find ./lib/**/__tests__ -name *.test.js | xargs mocha",
26
+ "test": "npm run lint && npm run unit",
27
+ "unit": "nyc node test.js"
28
+ },
29
+ "sideEffects": false,
30
+ "dependencies": {
31
+ "axios": "^1.4.0",
32
+ "convert-excel-to-json": "^1.7.0",
33
+ "dotenv": "^16.3.1",
34
+ "ejs": "^3.1.9",
35
+ "exceljs": "^4.3.0",
36
+ "fs-extra": "^11.1.1",
37
+ "js-sha256": "^0.9.0",
38
+ "moment": "^2.29.4",
39
+ "node-cache": "^5.1.2",
40
+ "nodemailer": "^6.9.4",
41
+ "pg": "^8.11.2",
42
+ "pm2": "^5.3.0",
43
+ "puppeteer": "^21.0.1",
44
+ "qs": "^6.11.2",
45
+ "randomstring": "^1.3.0",
46
+ "socket.io": "^4.7.2",
47
+ "uuid": "^9.0.0",
48
+ "xlsx": "^0.18.5"
49
+ }
50
+ }