zet-lib 3.0.0 → 3.0.2

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.
@@ -1,7 +1,6 @@
1
1
  const router = require('express').Router();
2
- const {csrf} = require('zet-lib');
2
+ const {Util, access, connection, moduleLib, zDebug, zRoute, zRole, zDataTable, zForm, csrf} = require('zet-lib');
3
3
  const csrfProtection = csrf({cookie: true});
4
- const {Util, access, connection, moduleLib, zDebug, zRoute, zRole, zDataTable, zForm} = require('zet-lib');
5
4
  const MYMODEL = require('./../models/[[[TABLE_NAME]]]');
6
5
 
7
6
  router.get('/', async (req, res) => {
package/lib/zAppRouter.js CHANGED
@@ -606,6 +606,29 @@ router.get("/session/:id", access, async (req, res) => {
606
606
  res.redirect(backURL);
607
607
  });
608
608
 
609
+ // change backend layout preference
610
+ router.get("/layout_changes/:layout", access, async (req, res) => {
611
+ const selectedLayout = req.params.layout;
612
+ const backURL = req.header("Referer") || "/";
613
+ try {
614
+ // persist user preference
615
+ await connection.update({
616
+ table: "zuser",
617
+ data: { layout: selectedLayout },
618
+ where: { id: res.locals.userId },
619
+ });
620
+ // update session + locals for next requests
621
+ if (req.session && req.session.user) {
622
+ req.session.user.layout = selectedLayout;
623
+ }
624
+ res.locals.layout = selectedLayout;
625
+ global.layout = selectedLayout;
626
+ } catch (err) {
627
+ debug(req, res, err);
628
+ }
629
+ res.redirect(backURL);
630
+ });
631
+
609
632
  //RESTART
610
633
  router.get("/restart", access, async (req, res) => {
611
634
  var room = res.locals.user.token;
package/lib/zCache.js CHANGED
@@ -85,6 +85,11 @@ const cache = async () => {
85
85
  } else {
86
86
  await zCache.APPROVAL_LEVELS();
87
87
  }
88
+ if (myCache.has("BACKEND_LAYOUTS")) {
89
+ i = i + 1;
90
+ } else {
91
+ await zCache.BACKEND_LAYOUTS();
92
+ }
88
93
  //await zCache.CURRENCIES();
89
94
  //console.log(i)
90
95
  if (i < 5) {
@@ -106,6 +111,7 @@ zCache.renew = async () => {
106
111
  await zCache.MENU_SYSTEMS();
107
112
  await zCache.MODELS_RELATIONS();
108
113
  await zCache.APPROVAL_LEVELS();
114
+ await zCache.BACKEND_LAYOUTS();
109
115
  };
110
116
 
111
117
  zCache.ROUTES = () => {
@@ -139,6 +145,19 @@ zCache.ROLES = async () => {
139
145
  return r;
140
146
  };
141
147
 
148
+
149
+ zCache.BACKEND_LAYOUTS = async () => {
150
+ let results = await connection.results({
151
+ select: 'id,name',
152
+ table: "zlayout",
153
+ where: {
154
+ type:2
155
+ }
156
+ });
157
+ await myCache.set("BACKEND_LAYOUTS", results);
158
+ return results;
159
+ };
160
+
142
161
  zCache.ZFUNCTIONS = async () => {
143
162
  let query = await connection.results({
144
163
  table: "zfunction",
@@ -274,7 +293,7 @@ zCache.updateVersions = (name) => {
274
293
 
275
294
  zCache.MODELS_RELATIONS = async () => {
276
295
  if (process.env.APP_IS_CACHE == 1) {
277
- console.log("cache models");
296
+ console.log("cache MODELS_RELATIONS");
278
297
  if (myCache.has("MODELS_RELATIONS")) {
279
298
  return myCache.get("MODELS_RELATIONS");
280
299
  } else {
package/lib/zapp.js CHANGED
@@ -1,4 +1,6 @@
1
+ const myCache = require("./cache");
1
2
  module.exports = (req,res,next) => {
3
+ res.locals.BACKEND_LAYOUTS = myCache.get("BACKEND_LAYOUTS");
2
4
  res.locals.renderHead = "";
3
5
  res.locals.renderBody = "";
4
6
  res.locals.renderEnd = "";
@@ -28,8 +30,10 @@ module.exports = (req,res,next) => {
28
30
  global.LANGUAGE = require('./languages/lang_en');
29
31
  res.locals.socketUrl = process.env.APP_URL;
30
32
  res.locals.zcompanies = [];
33
+ res.locals.backend_layouts = [];
31
34
  res.locals.isLogin = false;
32
35
  res.locals.objectStores = {};
36
+ global.layout = "backend";
33
37
  if (req.session) {
34
38
  let reqSession = req.session;
35
39
  if (reqSession.hasOwnProperty('user')) {
@@ -53,7 +57,11 @@ module.exports = (req,res,next) => {
53
57
  };
54
58
  global.LANGUAGE = require(`./languages/${objLanguage[tUser.language]}`);
55
59
  }
56
- global.layout = "two";
60
+ if(tUser.layout){
61
+ res.locals.layout = tUser.layout;
62
+ //global.layout = tUser.layout;
63
+ }
64
+ console.log(global.layout)
57
65
  }
58
66
  }
59
67
  }
@@ -62,4 +70,5 @@ module.exports = (req,res,next) => {
62
70
  res.locals.LANGUAGE = global.LANGUAGE;
63
71
 
64
72
  next();
65
- };
73
+
74
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"