zet-lib 1.0.78 → 1.0.81
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/Mail.js +0 -1
- package/lib/Util.js +3 -3
- package/lib/zCache.js +277 -278
- package/lib/zFn.js +41 -42
- package/lib/zdataTable.js +32 -36
- package/package.json +1 -1
package/lib/Mail.js
CHANGED
package/lib/Util.js
CHANGED
|
@@ -207,7 +207,7 @@ Util.tableArrayToObj = (arr = []) => {
|
|
|
207
207
|
return arr.map((m) => Object.values(m)[0])
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
Util.escapeRegExp = function (str
|
|
210
|
+
Util.escapeRegExp = function (str = '') {
|
|
211
211
|
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1')
|
|
212
212
|
}
|
|
213
213
|
|
|
@@ -221,7 +221,7 @@ Util.validateEmail = function (email) {
|
|
|
221
221
|
example : Util.replaceAll("abd","a","")
|
|
222
222
|
*/
|
|
223
223
|
|
|
224
|
-
Util.replaceAll = function (str =
|
|
224
|
+
Util.replaceAll = function (str = '', find, replace) {
|
|
225
225
|
let t = ''
|
|
226
226
|
if (Array.isArray(find)) {
|
|
227
227
|
t = str
|
|
@@ -295,7 +295,7 @@ Util.arrayToObject = (array = [], keyField, isInteger = false) => {
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
//chase id:1,name:'test' t0 {1:'test'}
|
|
298
|
-
Util.modulesSwitch = (arr =[]) => {
|
|
298
|
+
Util.modulesSwitch = (arr = []) => {
|
|
299
299
|
let stores = []
|
|
300
300
|
stores.push({ id: '', name: '' })
|
|
301
301
|
arr.forEach((ar, index) => {
|
package/lib/zCache.js
CHANGED
|
@@ -1,309 +1,308 @@
|
|
|
1
|
-
const myCache = require(
|
|
2
|
-
const connection = require('./connection')
|
|
3
|
-
const Util = require('./Util')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const fs = require('fs-extra')
|
|
6
|
-
const directory =
|
|
7
|
-
const zRoute = require('./zRoute')
|
|
1
|
+
const myCache = require('./cache')
|
|
2
|
+
const connection = require('./connection')
|
|
3
|
+
const Util = require('./Util')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const fs = require('fs-extra')
|
|
6
|
+
const directory = './'
|
|
7
|
+
const zRoute = require('./zRoute')
|
|
8
8
|
|
|
9
|
-
const zCache = {}
|
|
9
|
+
const zCache = {}
|
|
10
10
|
|
|
11
11
|
//constants
|
|
12
12
|
zCache.KEYS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
ROUTES: 'ROUTES',
|
|
14
|
+
MYMODELS: 'MYMODELS',
|
|
15
|
+
ROLES: 'ROLES',
|
|
16
|
+
CONFIG: 'CONFIG',
|
|
17
|
+
MENU: 'MENU',
|
|
18
|
+
MENU_SYSTEMS: 'MENU_SYSTEMS',
|
|
19
|
+
ZFUNCTIONS: 'ZFUNCTIONS',
|
|
20
|
+
VERSIONS: 'VERSIONS',
|
|
21
|
+
MODELS_RELATIONS: 'MODELS_RELATIONS',
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
zCache.STATICS = zCache.KEYS
|
|
25
|
-
zCache.myCache = myCache
|
|
24
|
+
zCache.STATICS = zCache.KEYS
|
|
25
|
+
zCache.myCache = myCache
|
|
26
26
|
|
|
27
|
-
zCache.get = (name) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
27
|
+
zCache.get = (name = '') => {
|
|
28
|
+
if (!myCache.has(name)) {
|
|
29
|
+
zCache[name]()
|
|
30
|
+
} else {
|
|
31
|
+
return myCache.get(name)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
34
|
|
|
35
35
|
zCache.set = (X, Y) => {
|
|
36
|
-
|
|
37
|
-
}
|
|
36
|
+
myCache.set(X, Y)
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
zCache.cache = async(req, res, next) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
39
|
+
zCache.cache = async (req, res, next) => {
|
|
40
|
+
await cache()
|
|
41
|
+
next()
|
|
42
|
+
}
|
|
43
43
|
|
|
44
|
-
const cache = async()=> {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
44
|
+
const cache = async () => {
|
|
45
|
+
zCache.VERSIONS()
|
|
46
|
+
let i = 0
|
|
47
|
+
if (myCache.has('ROLES')) {
|
|
48
|
+
//console.log("cache ROLES has exist " + i)
|
|
49
|
+
i = i + 1
|
|
50
|
+
} else {
|
|
51
|
+
//console.log("cache ROLES not exist " + i)
|
|
52
|
+
await zCache.ROLES()
|
|
53
|
+
}
|
|
54
|
+
if (myCache.has('ROUTES')) {
|
|
55
|
+
i = i + 1
|
|
56
|
+
} else {
|
|
57
|
+
await zCache.ROUTES()
|
|
58
|
+
}
|
|
59
|
+
if (myCache.has('MYMODELS')) {
|
|
60
|
+
i = i + 1
|
|
61
|
+
} else {
|
|
62
|
+
await zCache.MYMODELS()
|
|
63
|
+
}
|
|
64
|
+
if (myCache.has('CONFIG')) {
|
|
65
|
+
i = i + 1
|
|
66
|
+
} else {
|
|
67
|
+
//console.log("cache CONFIG not exist " + i)
|
|
68
|
+
await zCache.CONFIG()
|
|
69
|
+
}
|
|
70
|
+
if (myCache.has('MENU')) {
|
|
71
|
+
i = i + 1
|
|
72
|
+
} else {
|
|
73
|
+
//console.log("cache MENU not exist " + i);
|
|
74
|
+
//zup.menu();
|
|
75
|
+
await zCache.MENU()
|
|
76
|
+
}
|
|
77
|
+
if (myCache.has('MENU_SYSTEMS')) {
|
|
78
|
+
//i = i + 1;
|
|
79
|
+
} else {
|
|
80
|
+
await zCache.MENU_SYSTEMS()
|
|
81
|
+
}
|
|
82
|
+
//console.log(i)
|
|
83
|
+
if (myCache.has('ZFUNCTIONS')) {
|
|
84
|
+
//i = i + 1;
|
|
85
|
+
} else {
|
|
86
|
+
await zCache.ZFUNCTIONS()
|
|
87
|
+
}
|
|
88
|
+
//await zCache.CURRENCIES();
|
|
89
|
+
//console.log(i)
|
|
90
|
+
if (i < 5) {
|
|
91
|
+
await cache()
|
|
92
|
+
} else {
|
|
93
|
+
return i
|
|
94
|
+
}
|
|
95
|
+
//cache relations on startup
|
|
96
|
+
await zCache.MODELS_RELATIONS()
|
|
97
|
+
}
|
|
98
98
|
|
|
99
|
-
zCache.renew = async()=> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
99
|
+
zCache.renew = async () => {
|
|
100
|
+
zCache.VERSIONS()
|
|
101
|
+
await zCache.ROLES()
|
|
102
|
+
await zCache.MENU()
|
|
103
|
+
await zCache.CONFIG()
|
|
104
|
+
await zCache.ROUTES()
|
|
105
|
+
await zCache.MYMODELS()
|
|
106
|
+
await zCache.MENU_SYSTEMS()
|
|
107
|
+
await zCache.MODELS_RELATIONS()
|
|
108
|
+
}
|
|
109
109
|
|
|
110
110
|
zCache.ROUTES = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
111
|
+
if (myCache.has('ROUTES')) {
|
|
112
|
+
return myCache.get('ROUTES')
|
|
113
|
+
} else {
|
|
114
|
+
const routes = zRoute.ROUTES()
|
|
115
|
+
myCache.set('ROUTES', routes)
|
|
116
|
+
return routes
|
|
117
|
+
}
|
|
118
|
+
}
|
|
120
119
|
|
|
121
120
|
zCache.MYMODELS = () => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
if (myCache.has('MYMODELS')) {
|
|
122
|
+
return myCache.get('MYMODELS')
|
|
123
|
+
} else {
|
|
124
|
+
const models = zRoute.MYMODELS()
|
|
125
|
+
myCache.set('MYMODELS', models)
|
|
126
|
+
return models
|
|
127
|
+
}
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
zCache.ROLES = async() => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
130
|
+
zCache.ROLES = async () => {
|
|
131
|
+
let r = 0
|
|
132
|
+
let results = await connection.results({ table: 'zrole' })
|
|
133
|
+
let obj = Util.arrayToObject(results, 'id')
|
|
134
|
+
await myCache.set('ROLES', obj)
|
|
135
|
+
//add to version after set
|
|
136
|
+
zCache.updateVersions('ROLES')
|
|
137
|
+
r = 1
|
|
138
|
+
return r
|
|
139
|
+
}
|
|
141
140
|
|
|
142
|
-
zCache.ZFUNCTIONS = async() => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
141
|
+
zCache.ZFUNCTIONS = async () => {
|
|
142
|
+
let query = await connection.results({
|
|
143
|
+
table: 'zfunction',
|
|
144
|
+
where: {
|
|
145
|
+
active: 1,
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
if (query.length) {
|
|
149
|
+
let results = await connection.results({ table: 'zfunction' })
|
|
150
|
+
let obj = Util.arrayToObject(results, 'title')
|
|
151
|
+
await myCache.set('ZFUNCTIONS', obj)
|
|
152
|
+
//add to version after set
|
|
153
|
+
zCache.updateVersions('ZFUNCTIONS')
|
|
154
|
+
}
|
|
155
|
+
}
|
|
157
156
|
|
|
158
157
|
zCache.VERSIONS = () => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
myCache.set("VERSIONS",obj);
|
|
168
|
-
//console.log(JSON.stringify(myCache.get("VERSIONS")))
|
|
169
|
-
return obj;
|
|
158
|
+
if (myCache.has('VERSIONS')) {
|
|
159
|
+
//console.log("VERSIONS")
|
|
160
|
+
return myCache.get('VERSIONS')
|
|
161
|
+
} else {
|
|
162
|
+
let obj = {}
|
|
163
|
+
for (let key in zCache.KEYS) {
|
|
164
|
+
obj[key] = 0
|
|
170
165
|
}
|
|
171
|
-
|
|
166
|
+
myCache.set('VERSIONS', obj)
|
|
167
|
+
//console.log(JSON.stringify(myCache.get("VERSIONS")))
|
|
168
|
+
return obj
|
|
169
|
+
}
|
|
170
|
+
}
|
|
172
171
|
|
|
173
|
-
zCache.CONFIG = async() => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
172
|
+
zCache.CONFIG = async () => {
|
|
173
|
+
let results = async () => {
|
|
174
|
+
return await connection.results({
|
|
175
|
+
table: 'zconfig',
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
let companies = await connection.results({
|
|
179
|
+
table: 'zcompany',
|
|
180
|
+
})
|
|
181
|
+
let r = await results()
|
|
182
|
+
let configObj = Util.arrayToObject(r, 'company_id')
|
|
183
|
+
for (let i = 0; i < companies.length; i++) {
|
|
184
|
+
let item = companies[i]
|
|
185
|
+
if (!configObj[item.id]) {
|
|
186
|
+
await connection.insert({
|
|
187
|
+
table: 'zconfig',
|
|
188
|
+
data: {
|
|
189
|
+
company_id: item.id,
|
|
190
|
+
layout: 0,
|
|
191
|
+
json: JSON.stringify(CONFIG),
|
|
192
|
+
created_at: Util.now(),
|
|
193
|
+
updated_at: Util.now(),
|
|
194
|
+
},
|
|
195
|
+
})
|
|
198
196
|
}
|
|
197
|
+
}
|
|
199
198
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
199
|
+
myCache.set(zCache.KEYS.CONFIG, Util.arrayToObject(await results(), 'company_id'))
|
|
200
|
+
//add to version after set
|
|
201
|
+
zCache.updateVersions(zCache.KEYS.CONFIG)
|
|
202
|
+
}
|
|
205
203
|
|
|
206
|
-
zCache.MENU = async() => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
204
|
+
zCache.MENU = async () => {
|
|
205
|
+
let results = async () => {
|
|
206
|
+
return await connection.results({
|
|
207
|
+
table: 'zmenu',
|
|
208
|
+
where: {
|
|
209
|
+
active: 1,
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
const r = await results()
|
|
214
|
+
const builder = async () => {
|
|
215
|
+
let obj = {}
|
|
216
|
+
let arr = await results()
|
|
217
|
+
arr.map((item) => {
|
|
218
|
+
obj[item.company_id] = item.json || []
|
|
219
|
+
})
|
|
220
|
+
myCache.set('MENU', obj)
|
|
221
|
+
//add to version after set
|
|
222
|
+
zCache.updateVersions('MENU')
|
|
223
|
+
}
|
|
224
|
+
if (r.length) {
|
|
225
|
+
await builder()
|
|
226
|
+
}
|
|
227
|
+
}
|
|
230
228
|
|
|
231
229
|
zCache.MENU_SYSTEMS = () => {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
let obj = {}
|
|
231
|
+
obj.users = [
|
|
232
|
+
{
|
|
233
|
+
text: 'LANGUAGE.users',
|
|
234
|
+
href: 'zuser',
|
|
236
235
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
zCache.updateVersions = (name)=> {
|
|
287
|
-
let obj = myCache.get("VERSIONS") || {}
|
|
288
|
-
if(!obj.ROLES){
|
|
289
|
-
zCache.VERSIONS();
|
|
290
|
-
obj = myCache.get("VERSIONS");
|
|
291
|
-
}
|
|
292
|
-
let value = obj[name] || 0;
|
|
293
|
-
value++;
|
|
294
|
-
obj[name] = value;
|
|
295
|
-
myCache.set("VERSIONS",obj);
|
|
296
|
-
};
|
|
236
|
+
{
|
|
237
|
+
text: 'LANGUAGE.company',
|
|
238
|
+
href: 'zcompany',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
text: 'LANGUAGE.user_access',
|
|
242
|
+
href: 'zuser_company',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
text: 'LANGUAGE.access_role',
|
|
246
|
+
href: 'zrole',
|
|
247
|
+
},
|
|
248
|
+
]
|
|
249
|
+
obj.systems = [
|
|
250
|
+
{
|
|
251
|
+
text: 'Generator',
|
|
252
|
+
href: 'zgenerator',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
text: 'Menu Generator',
|
|
256
|
+
href: 'zmenu',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
text: 'Grid Default',
|
|
260
|
+
href: 'zgrid_default',
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
text: 'Routers',
|
|
264
|
+
href: 'zpage',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
text: 'Functions',
|
|
268
|
+
href: 'zfunction',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
text: 'Layouts',
|
|
272
|
+
href: 'zlayout',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
text: 'Custom Report',
|
|
276
|
+
href: 'zreport',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
text: 'Log Errors',
|
|
280
|
+
href: 'zerror',
|
|
281
|
+
},
|
|
282
|
+
]
|
|
283
|
+
myCache.set('MENU_SYSTEMS', obj)
|
|
284
|
+
}
|
|
297
285
|
|
|
286
|
+
zCache.updateVersions = (name) => {
|
|
287
|
+
let obj = myCache.get('VERSIONS') || {}
|
|
288
|
+
if (!obj.ROLES) {
|
|
289
|
+
zCache.VERSIONS()
|
|
290
|
+
obj = myCache.get('VERSIONS')
|
|
291
|
+
}
|
|
292
|
+
let value = obj[name] || 0
|
|
293
|
+
value++
|
|
294
|
+
obj[name] = value
|
|
295
|
+
myCache.set('VERSIONS', obj)
|
|
296
|
+
}
|
|
298
297
|
|
|
299
|
-
zCache.MODELS_RELATIONS = async() => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
298
|
+
zCache.MODELS_RELATIONS = async () => {
|
|
299
|
+
if (myCache.has('MODELS_RELATIONS')) {
|
|
300
|
+
return myCache.get('MODELS_RELATIONS')
|
|
301
|
+
} else {
|
|
302
|
+
const obj = await zRoute.modelsCache()
|
|
303
|
+
myCache.set('MODELS_RELATIONS', obj)
|
|
304
|
+
return obj
|
|
305
|
+
}
|
|
306
|
+
}
|
|
308
307
|
|
|
309
|
-
module.exports = zCache
|
|
308
|
+
module.exports = zCache
|
package/lib/zFn.js
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
|
-
const moment = require('moment')
|
|
2
|
-
const zRoute = require('./zRoute')
|
|
3
|
-
const io = require(
|
|
4
|
-
const qs = require('qs')
|
|
5
|
-
const axios = require('axios')
|
|
6
|
-
const myCache = require(
|
|
7
|
-
const connection = require('./connection')
|
|
8
|
-
const Util = require(
|
|
9
|
-
const moduleLib = require('./moduleLib')
|
|
10
|
-
const zCache = require('./zCache')
|
|
1
|
+
const moment = require('moment')
|
|
2
|
+
const zRoute = require('./zRoute')
|
|
3
|
+
const io = require('./io')
|
|
4
|
+
const qs = require('qs')
|
|
5
|
+
const axios = require('axios')
|
|
6
|
+
const myCache = require('./cache')
|
|
7
|
+
const connection = require('./connection')
|
|
8
|
+
const Util = require('./Util')
|
|
9
|
+
const moduleLib = require('./moduleLib')
|
|
10
|
+
const zCache = require('./zCache')
|
|
11
11
|
|
|
12
|
-
const running =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
const running = (scripts = '', params = {}, obj = {}) => {
|
|
13
|
+
const MYMODELS = zRoute.MYMODELS()
|
|
14
|
+
let stringParams = ''
|
|
15
|
+
const defaultCall = {
|
|
16
|
+
Util: Util,
|
|
17
|
+
connection: connection,
|
|
18
|
+
io: io,
|
|
19
|
+
qs: qs,
|
|
20
|
+
moment: moment,
|
|
21
|
+
axios: axios,
|
|
22
|
+
myCache: myCache,
|
|
23
|
+
zCache: zCache,
|
|
24
|
+
params: params,
|
|
25
|
+
MYMODELS: MYMODELS,
|
|
26
|
+
moduleLib: moduleLib,
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const CALL = Object.assign(defaultCall, obj)
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
stringParams = ''
|
|
32
|
+
for (const keys in CALL) {
|
|
33
|
+
stringParams += `var ${keys} = this.${keys};`
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
}).constructor;
|
|
36
|
+
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
try {
|
|
39
|
+
return AsyncFunction(`
|
|
41
40
|
try {
|
|
42
41
|
${stringParams};
|
|
43
42
|
${scripts};
|
|
@@ -49,11 +48,11 @@ const running = (scripts, params, obj={}) => {
|
|
|
49
48
|
message:error.toString()
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
|
-
`).call(CALL)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
51
|
+
`).call(CALL)
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error(e)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
}
|
|
58
57
|
|
|
59
|
-
module.exports = running
|
|
58
|
+
module.exports = running
|
package/lib/zdataTable.js
CHANGED
|
@@ -9,13 +9,13 @@ class dataTable {
|
|
|
9
9
|
this.setColumns = ''
|
|
10
10
|
this.setTable = ''
|
|
11
11
|
this.srcScript = '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'
|
|
12
|
-
this.dataTableScript = '/js/datatable-default.js'
|
|
13
|
-
this.dataTableButtons = '/js/datatable-buttons.min.js'
|
|
14
|
-
this.customButtons = ''
|
|
12
|
+
this.dataTableScript = '/js/datatable-default.js'
|
|
13
|
+
this.dataTableButtons = '/js/datatable-buttons.min.js'
|
|
14
|
+
this.customButtons = ''
|
|
15
15
|
this.MYMODEL = null
|
|
16
16
|
this.searchColumns = {}
|
|
17
|
-
this.relations
|
|
18
|
-
this.routeName
|
|
17
|
+
this.relations
|
|
18
|
+
this.routeName
|
|
19
19
|
this.types = {}
|
|
20
20
|
this.levels = {}
|
|
21
21
|
}
|
|
@@ -33,8 +33,7 @@ class dataTable {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
get columns() {
|
|
36
|
-
if (this.setColumns)
|
|
37
|
-
return this.setColumns
|
|
36
|
+
if (this.setColumns) return this.setColumns
|
|
38
37
|
let html = ''
|
|
39
38
|
for (const key in this.visibles) {
|
|
40
39
|
html += `<th id="data_${key}_label">${this.visibles[key]}</th>`
|
|
@@ -55,42 +54,41 @@ class dataTable {
|
|
|
55
54
|
Create table html header
|
|
56
55
|
*/
|
|
57
56
|
get table() {
|
|
58
|
-
if (this.setTable)
|
|
59
|
-
return this.setTable
|
|
57
|
+
if (this.setTable) return this.setTable
|
|
60
58
|
return `<table id="dataTable" class="display table table-hover table-responsive" style="width:100%">
|
|
61
59
|
<thead>${this.columns} ${this.columnsFilter}</thead>
|
|
62
60
|
</table>`
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
get buttons() {
|
|
64
|
+
let html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
65
|
+
if (this.levels.create) {
|
|
66
|
+
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>`
|
|
67
|
+
}
|
|
68
|
+
if (this.levels.import) {
|
|
69
|
+
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>`
|
|
70
|
+
}
|
|
71
|
+
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>`
|
|
72
|
+
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>`
|
|
73
|
+
if (this.levels.export) {
|
|
74
|
+
html += `<div class="btn-group" role="group">
|
|
77
75
|
<button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
78
76
|
<img src="/assets/icons/download.svg" class="icons-bg-black"> ${LANGUAGE.download}
|
|
79
77
|
</button>
|
|
80
78
|
<div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
html += `</div></div>`
|
|
92
|
-
return html
|
|
79
|
+
html += `<a class="dropdown-header">Excel</a>`
|
|
80
|
+
html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`
|
|
81
|
+
html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`
|
|
82
|
+
html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`
|
|
83
|
+
html += `<hr>`
|
|
84
|
+
html += `<a class="dropdown-header">PDF</a>`
|
|
85
|
+
html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`
|
|
86
|
+
html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`
|
|
87
|
+
html += `</div>`
|
|
93
88
|
}
|
|
89
|
+
html += `</div></div>`
|
|
90
|
+
return html
|
|
91
|
+
}
|
|
94
92
|
|
|
95
93
|
get buttons2() {
|
|
96
94
|
let html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
@@ -122,13 +120,12 @@ class dataTable {
|
|
|
122
120
|
return html
|
|
123
121
|
}
|
|
124
122
|
|
|
125
|
-
|
|
126
123
|
get scripts() {
|
|
127
124
|
let script = `<script type="text/javascript" src="${this.srcScript}"></script>`
|
|
128
125
|
script += `<script>${Util.newLine}`
|
|
129
126
|
script += `var dataTableFields = ${JSON.stringify(Object.keys(this.visibles, null, 2))};${Util.newLine}`
|
|
130
127
|
script += `var dataTableTypes = ${JSON.stringify(this.types, null, 2)};${Util.newLine}`
|
|
131
|
-
script += `var dataTableRoute = "${this.routeName}";${Util.newLine}
|
|
128
|
+
script += `var dataTableRoute = "${this.routeName}";${Util.newLine}`
|
|
132
129
|
script += `</script>${Util.newLine}`
|
|
133
130
|
script += `<script type="text/javascript" src="${this.dataTableScript}"></script>${Util.newLine}`
|
|
134
131
|
if (this.searchColumns.FILTERKEY) {
|
|
@@ -138,7 +135,6 @@ class dataTable {
|
|
|
138
135
|
|
|
139
136
|
return script
|
|
140
137
|
}
|
|
141
|
-
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
module.exports = dataTable
|