zet-lib 1.0.53 → 1.0.54
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/zGeneratorRouter.js +705 -652
- package/package.json +1 -1
package/lib/zGeneratorRouter.js
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
const express = require('express')
|
|
2
|
-
const router = express.Router()
|
|
3
|
-
const csrf = require('csurf')
|
|
4
|
-
const csrfProtection = csrf({cookie: true})
|
|
5
|
-
const fs = require('fs-extra')
|
|
6
|
-
const axios = require('axios')
|
|
7
|
-
const pm2 = require('pm2')
|
|
8
|
-
const uglifyJS = require(
|
|
9
|
-
const {minify} = require('html-minifier-terser')
|
|
10
|
-
const zRoute = require('./zRoute')
|
|
11
|
-
const connection = require('./connection')
|
|
12
|
-
const Util = require('./Util')
|
|
13
|
-
const moduleLib = require('./moduleLib')
|
|
14
|
-
const myCache = require('./cache')
|
|
15
|
-
const ejs = require('ejs')
|
|
16
|
-
var app = express()
|
|
17
|
-
const path = require('path')
|
|
18
|
-
|
|
19
|
-
const nots = ['index','uploads','js','css','log','generator','zmenu','zgenerator','zfields','zrole','zfunction','zgrid','zgrid_default', 'zuser','zreport','zpage','zlayout','zerror','zuser_company','zconfig']
|
|
1
|
+
const express = require('express')
|
|
2
|
+
const router = express.Router()
|
|
3
|
+
const csrf = require('csurf')
|
|
4
|
+
const csrfProtection = csrf({ cookie: true })
|
|
5
|
+
const fs = require('fs-extra')
|
|
6
|
+
const axios = require('axios')
|
|
7
|
+
const pm2 = require('pm2')
|
|
8
|
+
const uglifyJS = require('uglify-js')
|
|
9
|
+
const { minify } = require('html-minifier-terser')
|
|
10
|
+
const zRoute = require('./zRoute')
|
|
11
|
+
const connection = require('./connection')
|
|
12
|
+
const Util = require('./Util')
|
|
13
|
+
const moduleLib = require('./moduleLib')
|
|
14
|
+
const myCache = require('./cache')
|
|
15
|
+
const ejs = require('ejs')
|
|
16
|
+
var app = express()
|
|
17
|
+
const path = require('path')
|
|
18
|
+
|
|
19
|
+
const nots = ['index', 'uploads', 'js', 'css', 'log', 'generator', 'zmenu', 'zgenerator', 'zfields', 'zrole', 'zfunction', 'zgrid', 'zgrid_default', 'zuser', 'zreport', 'zpage', 'zlayout', 'zerror', 'zuser_company', 'zconfig']
|
|
20
20
|
//const nots = [];
|
|
21
|
-
//const generatorUrl = 'http://localhost:
|
|
22
|
-
const generatorUrl = 'https://generator.cmsqu.com'
|
|
21
|
+
//const generatorUrl = 'http://localhost:3005';
|
|
22
|
+
const generatorUrl = 'https://generator.cmsqu.com'
|
|
23
23
|
|
|
24
24
|
router.get('/', csrfProtection, async (req, res) => {
|
|
25
|
-
let table = req.query.table ||
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
let table = req.query.table || '',
|
|
26
|
+
route = '',
|
|
27
|
+
jsonData = {},
|
|
28
|
+
zForms = {},
|
|
29
|
+
relations = {},
|
|
30
|
+
approvalDatas = { is_approval: false }
|
|
31
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
32
|
+
let datas = await axios.post(`${generatorUrl}/api/generator/index`)
|
|
33
|
+
jsonData = datas.data
|
|
34
|
+
jsonData.rows = await zfieldsKeys()
|
|
35
|
+
if (table) {
|
|
36
|
+
jsonData.datas = jsonData.rows[table] || {}
|
|
32
37
|
}
|
|
33
|
-
jsonData.fields =
|
|
34
|
-
zForms.obj = {}
|
|
35
|
-
let sorting =
|
|
38
|
+
jsonData.fields = await connection.query(connection.showFullFields(table))
|
|
39
|
+
zForms.obj = {}
|
|
40
|
+
let sorting = ''
|
|
36
41
|
if (table) {
|
|
37
42
|
let contentScript = `var ZFIELDS = ${JSON.stringify(jsonData.rows, null, 2)};`
|
|
38
|
-
moduleLib.addScript(req, res, contentScript)
|
|
39
|
-
moduleLib.editor(req, res)
|
|
40
|
-
let MYMODEL_APPROVERS = MYMODELS['zapprovals']
|
|
43
|
+
moduleLib.addScript(req, res, contentScript)
|
|
44
|
+
moduleLib.editor(req, res)
|
|
45
|
+
let MYMODEL_APPROVERS = MYMODELS['zapprovals']
|
|
41
46
|
let zfieldData = await connection.result({
|
|
42
|
-
table:
|
|
47
|
+
table: 'zfields',
|
|
43
48
|
where: {
|
|
44
|
-
table: table
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
sorting = JSON.stringify(zfieldData.sorting)
|
|
48
|
-
approvalDatas = MYMODEL_APPROVERS.datas
|
|
49
|
+
table: table,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
sorting = JSON.stringify(zfieldData.sorting)
|
|
53
|
+
approvalDatas = MYMODEL_APPROVERS.datas
|
|
49
54
|
if (zfieldData) {
|
|
50
|
-
let approvalJSON = zfieldData.approval_json || {}
|
|
51
|
-
approvalDatas.is_approval = zfieldData.is_approval || false
|
|
52
|
-
approvalDatas.title = approvalJSON.title ||
|
|
53
|
-
approvalDatas.type = approvalJSON.type || 1
|
|
54
|
-
approvalDatas.approvers = approvalJSON.approvers ? approvalJSON.approvers : []
|
|
55
|
-
approvalDatas.knowings = approvalJSON.knowings || []
|
|
56
|
-
approvalDatas.template = approvalJSON.content ||
|
|
57
|
-
zForms = await zRoute.formsFieldSync(req, res, MYMODEL_APPROVERS, approvalDatas)
|
|
55
|
+
let approvalJSON = zfieldData.approval_json || {}
|
|
56
|
+
approvalDatas.is_approval = zfieldData.is_approval || false
|
|
57
|
+
approvalDatas.title = approvalJSON.title || ''
|
|
58
|
+
approvalDatas.type = approvalJSON.type || 1
|
|
59
|
+
approvalDatas.approvers = approvalJSON.approvers ? approvalJSON.approvers : []
|
|
60
|
+
approvalDatas.knowings = approvalJSON.knowings || []
|
|
61
|
+
approvalDatas.template = approvalJSON.content || ''
|
|
62
|
+
zForms = await zRoute.formsFieldSync(req, res, MYMODEL_APPROVERS, approvalDatas)
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
const jsonDatas = jsonData.datas
|
|
62
|
-
const lock = nots.includes(table) ? 1 : 0
|
|
63
|
-
const jsonDatasJson = jsonDatas.hasOwnProperty('json') && jsonDatas.json ? jsonDatas.json : {}
|
|
64
|
-
const checkDummy = Object.prototype.hasOwnProperty.call(jsonDatasJson, 'dummy') && jsonDatasJson.dummy ? 'checked' : ''
|
|
66
|
+
const jsonDatas = jsonData.datas
|
|
67
|
+
const lock = nots.includes(table) ? 1 : 0
|
|
68
|
+
const jsonDatasJson = jsonDatas.hasOwnProperty('json') && jsonDatas.json ? jsonDatas.json : {}
|
|
69
|
+
const checkDummy = Object.prototype.hasOwnProperty.call(jsonDatasJson, 'dummy') && jsonDatasJson.dummy ? 'checked' : ''
|
|
65
70
|
const renderData = {
|
|
66
71
|
datas: jsonDatas,
|
|
67
72
|
table: table,
|
|
@@ -75,172 +80,219 @@ router.get('/', csrfProtection, async (req, res) => {
|
|
|
75
80
|
approvalDatas: approvalDatas,
|
|
76
81
|
sorting: sorting,
|
|
77
82
|
lock: lock,
|
|
78
|
-
routeName:res.locals.routeName
|
|
79
|
-
}
|
|
83
|
+
routeName: res.locals.routeName,
|
|
84
|
+
}
|
|
80
85
|
|
|
81
|
-
const bodyHTML = ejs.render(body, renderData)
|
|
82
|
-
const endHTML = ejs.render(Util.readFile(require.resolve(__dirname + '/views/generatorjs.ejs')), renderData)
|
|
83
|
-
let dataRender = renderData
|
|
84
|
-
dataRender.bodyHTML = bodyHTML
|
|
85
|
-
dataRender.endHTML = endHTML
|
|
86
|
-
res.render(require.resolve(__dirname + '/views/generator_layout.ejs'), dataRender)
|
|
87
|
-
})
|
|
86
|
+
const bodyHTML = ejs.render(body, renderData)
|
|
87
|
+
const endHTML = ejs.render(Util.readFile(require.resolve(__dirname + '/views/generatorjs.ejs')), renderData)
|
|
88
|
+
let dataRender = renderData
|
|
89
|
+
dataRender.bodyHTML = bodyHTML
|
|
90
|
+
dataRender.endHTML = endHTML
|
|
91
|
+
res.render(require.resolve(__dirname + '/views/generator_layout.ejs'), dataRender)
|
|
92
|
+
})
|
|
88
93
|
|
|
89
94
|
router.post('/fields', async (req, res) => {
|
|
90
95
|
try {
|
|
91
|
-
let body = req.body
|
|
92
|
-
let table = body.table ||
|
|
93
|
-
let result = {},
|
|
96
|
+
let body = req.body
|
|
97
|
+
let table = body.table || ''
|
|
98
|
+
let result = {},
|
|
99
|
+
fields = {},
|
|
100
|
+
rowsFields = []
|
|
94
101
|
if (table) {
|
|
95
|
-
result = await connection.result({table: 'zfields', where: {table: table}})
|
|
96
|
-
fields = await connection.query(connection.showFullFields(table))
|
|
102
|
+
result = await connection.result({ table: 'zfields', where: { table: table } })
|
|
103
|
+
fields = await connection.query(connection.showFullFields(table))
|
|
97
104
|
rowsFields = await connection.query(connection.describeTable(table))
|
|
98
105
|
}
|
|
99
106
|
let objData = {
|
|
100
107
|
result: result,
|
|
101
108
|
fields: fields,
|
|
102
109
|
rowsFields: rowsFields,
|
|
103
|
-
table: table
|
|
104
|
-
}
|
|
105
|
-
let datas = await axios.post(`${generatorUrl}/api/generator/modal`, objData)
|
|
110
|
+
table: table,
|
|
111
|
+
}
|
|
112
|
+
let datas = await axios.post(`${generatorUrl}/api/generator/modal`, objData)
|
|
106
113
|
res.json(datas.data)
|
|
107
114
|
} catch (e) {
|
|
108
|
-
console.log(e)
|
|
115
|
+
console.log(e)
|
|
109
116
|
res.json(e.toString())
|
|
110
117
|
}
|
|
111
|
-
})
|
|
118
|
+
})
|
|
112
119
|
|
|
113
120
|
/*
|
|
114
121
|
Create new Module/Table
|
|
115
122
|
*/
|
|
116
|
-
router.post(
|
|
123
|
+
router.post('/', csrfProtection, async (req, res) => {
|
|
117
124
|
try {
|
|
118
|
-
let results = await axios.post(`${generatorUrl}/api/generator/create`, req.body)
|
|
119
|
-
let datas = results.data
|
|
125
|
+
let results = await axios.post(`${generatorUrl}/api/generator/create`, req.body)
|
|
126
|
+
let datas = results.data
|
|
120
127
|
if (datas.status == 0) {
|
|
121
128
|
res.json(datas)
|
|
122
129
|
} else {
|
|
123
130
|
if (nots.includes(datas.post.table)) {
|
|
124
|
-
return res.json(Util.flashError(
|
|
131
|
+
return res.json(Util.flashError('Table is locked'))
|
|
125
132
|
}
|
|
126
133
|
await connection.insert({
|
|
127
|
-
table:
|
|
128
|
-
data: datas.post
|
|
129
|
-
})
|
|
130
|
-
await connection.query(datas.sql)
|
|
131
|
-
res.json(datas)
|
|
134
|
+
table: 'zfields',
|
|
135
|
+
data: datas.post,
|
|
136
|
+
})
|
|
137
|
+
await connection.query(datas.sql)
|
|
138
|
+
res.json(datas)
|
|
132
139
|
}
|
|
133
140
|
} catch (err) {
|
|
134
|
-
res.json(Util.flashError(err.toString()))
|
|
141
|
+
res.json(Util.flashError(err.toString()))
|
|
135
142
|
}
|
|
136
|
-
})
|
|
143
|
+
})
|
|
137
144
|
|
|
138
|
-
router.post(
|
|
145
|
+
router.post('/reset', async (req, res) => {
|
|
139
146
|
try {
|
|
140
|
-
let json = Util.jsonSuccess(
|
|
141
|
-
let table = req.body.table
|
|
147
|
+
let json = Util.jsonSuccess('Reset Success')
|
|
148
|
+
let table = req.body.table
|
|
142
149
|
if (nots.includes(table)) {
|
|
143
|
-
return res.json(Util.flashError(
|
|
150
|
+
return res.json(Util.flashError('Table is locked'))
|
|
144
151
|
}
|
|
145
152
|
if (table) {
|
|
146
|
-
let results = await axios.post(`${generatorUrl}/api/generator/reset`, req.body)
|
|
147
|
-
let datas = results.data
|
|
153
|
+
let results = await axios.post(`${generatorUrl}/api/generator/reset`, req.body)
|
|
154
|
+
let datas = results.data
|
|
148
155
|
await connection.update({
|
|
149
|
-
table:
|
|
156
|
+
table: 'zfields',
|
|
150
157
|
data: datas,
|
|
151
158
|
where: {
|
|
152
|
-
table: table
|
|
153
|
-
}
|
|
154
|
-
})
|
|
159
|
+
table: table,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
155
162
|
} else {
|
|
156
|
-
json = Util.flashError(
|
|
163
|
+
json = Util.flashError('error')
|
|
157
164
|
}
|
|
158
165
|
res.json(json)
|
|
159
166
|
} catch (e) {
|
|
160
167
|
console.log(e.toString())
|
|
161
|
-
json = Util.flashError(
|
|
168
|
+
json = Util.flashError('error')
|
|
162
169
|
res.json(json)
|
|
163
170
|
}
|
|
164
|
-
})
|
|
171
|
+
})
|
|
165
172
|
|
|
166
173
|
router.post('/tabs', async (req, res) => {
|
|
167
|
-
let json = {status: 0, title: 'error', url: ''}
|
|
168
|
-
let body = req.body
|
|
169
|
-
let table = body.table ||
|
|
170
|
-
let title = body.title ||
|
|
171
|
-
let tabs = body.tabs || []
|
|
172
|
-
if (table ==
|
|
173
|
-
json.title =
|
|
174
|
+
let json = { status: 0, title: 'error', url: '' }
|
|
175
|
+
let body = req.body
|
|
176
|
+
let table = body.table || ''
|
|
177
|
+
let title = body.title || ''
|
|
178
|
+
let tabs = body.tabs || []
|
|
179
|
+
if (table == '') {
|
|
180
|
+
json.title = 'table is empty'
|
|
174
181
|
return res.send(json)
|
|
175
182
|
}
|
|
176
|
-
if (title ==
|
|
177
|
-
json.title =
|
|
183
|
+
if (title == '') {
|
|
184
|
+
json.title = 'title is empty'
|
|
178
185
|
return res.send(json)
|
|
179
186
|
}
|
|
180
187
|
if (nots.includes(table)) {
|
|
181
|
-
return res.json(Util.flashError(
|
|
188
|
+
return res.json(Util.flashError('Table is locked'))
|
|
182
189
|
}
|
|
183
|
-
let post = {}
|
|
184
|
-
post.table = table
|
|
185
|
-
post.tabs = JSON.stringify(tabs)
|
|
186
|
-
post.name = title
|
|
190
|
+
let post = {}
|
|
191
|
+
post.table = table
|
|
192
|
+
post.tabs = JSON.stringify(tabs)
|
|
193
|
+
post.name = title
|
|
187
194
|
if (body.hasOwnProperty('json')) {
|
|
188
|
-
post.json = JSON.stringify(body.json)
|
|
195
|
+
post.json = JSON.stringify(body.json)
|
|
189
196
|
} else {
|
|
190
|
-
post.json = JSON.stringify({dummy: 0})
|
|
197
|
+
post.json = JSON.stringify({ dummy: 0 })
|
|
191
198
|
}
|
|
192
199
|
let results = await connection.results({
|
|
193
|
-
table:
|
|
200
|
+
table: 'zfields',
|
|
194
201
|
where: {
|
|
195
|
-
table: table
|
|
196
|
-
}
|
|
197
|
-
})
|
|
202
|
+
table: table,
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
|
|
198
206
|
if (results.length == 0) {
|
|
199
|
-
await connection.insert({table:
|
|
207
|
+
await connection.insert({ table: 'zfields', data: post })
|
|
200
208
|
} else {
|
|
201
|
-
|
|
209
|
+
//original data
|
|
210
|
+
let tabOri = results[0].tabs || []
|
|
211
|
+
let detailOri = results[0].details || {}
|
|
212
|
+
let leftOri = results[0].left
|
|
213
|
+
let rightOri = results[0].right
|
|
214
|
+
let oneColumnOri = results[0].one_column
|
|
215
|
+
let objOri = {}
|
|
216
|
+
let arrayOri = {}
|
|
217
|
+
tabOri.map((item, index) => {
|
|
218
|
+
objOri[item] = `arr${index}`
|
|
219
|
+
arrayOri[item] = index
|
|
220
|
+
})
|
|
221
|
+
//end original data
|
|
222
|
+
if (tabOri.length > 0) {
|
|
223
|
+
if (JSON.stringify(tabs) !== JSON.stringify(tabOri)) {
|
|
224
|
+
let details = {}
|
|
225
|
+
|
|
226
|
+
//remove Object in array
|
|
227
|
+
let left = leftOri.filter((item) => typeof item !== 'object') || [],
|
|
228
|
+
right = rightOri.filter((item) => typeof item !== 'object') || [],
|
|
229
|
+
oneColumn = oneColumnOri.filter((item) => typeof item !== 'object') || []
|
|
230
|
+
|
|
231
|
+
details.notabs = detailOri.notabs
|
|
232
|
+
tabs.map((item, index) => {
|
|
233
|
+
let key = `arr${index}`
|
|
234
|
+
let valueIndex = arrayOri[item]
|
|
235
|
+
//details
|
|
236
|
+
details[key] = detailOri[objOri[item]] || []
|
|
237
|
+
//left
|
|
238
|
+
let objLeft = leftOri[valueIndex] && leftOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`) ? leftOri[valueIndex][`arr${arrayOri[item]}`] : []
|
|
239
|
+
left.push({ [key]: objLeft })
|
|
240
|
+
//right
|
|
241
|
+
let objRight = rightOri[valueIndex] && rightOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`) ? rightOri[valueIndex][`arr${arrayOri[item]}`] : []
|
|
242
|
+
right.push({ [key]: objRight })
|
|
243
|
+
//one column
|
|
244
|
+
let objOneColumn = oneColumnOri[valueIndex] && oneColumnOri[valueIndex].hasOwnProperty(`arr${arrayOri[item]}`) ? oneColumnOri[valueIndex][`arr${arrayOri[item]}`] : []
|
|
245
|
+
oneColumn.push({ [key]: objOneColumn })
|
|
246
|
+
})
|
|
247
|
+
post.details = JSON.stringify(details)
|
|
248
|
+
post.left = JSON.stringify(left)
|
|
249
|
+
post.right = JSON.stringify(right)
|
|
250
|
+
post.one_column = JSON.stringify(oneColumn)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
await connection.update({ table: 'zfields', where: { id: results[0].id }, data: post })
|
|
202
254
|
}
|
|
203
|
-
json.status = 1;
|
|
204
|
-
json.url = '/generator?table=' + table;
|
|
205
|
-
res.send(json)
|
|
206
|
-
});
|
|
207
255
|
|
|
256
|
+
json.status = 1
|
|
257
|
+
json.url = '/generator?table=' + table
|
|
258
|
+
res.send(json)
|
|
259
|
+
})
|
|
208
260
|
|
|
209
261
|
//after drag and drop then save
|
|
210
262
|
// and generate
|
|
211
|
-
router.post(
|
|
263
|
+
router.post('/save_and_generate', csrfProtection, async (req, res) => {
|
|
212
264
|
try {
|
|
213
265
|
if (nots.includes(req.body.table)) {
|
|
214
|
-
return res.json(Util.flashError(
|
|
266
|
+
return res.json(Util.flashError('Table is locked'))
|
|
215
267
|
}
|
|
216
|
-
const json = await generate(req, res)
|
|
217
|
-
res.json(json)
|
|
268
|
+
const json = await generate(req, res)
|
|
269
|
+
res.json(json)
|
|
218
270
|
} catch (e) {
|
|
219
|
-
console.log(e)
|
|
220
|
-
res.status(400).json({message: e.toString()})
|
|
271
|
+
console.log(e)
|
|
272
|
+
res.status(400).json({ message: e.toString() })
|
|
221
273
|
}
|
|
222
|
-
})
|
|
274
|
+
})
|
|
223
275
|
|
|
224
276
|
const generate = async (req, res) => {
|
|
225
|
-
const body = req.body
|
|
226
|
-
const table = body.table
|
|
227
|
-
const MYMODELS = myCache.get('MYMODELS')
|
|
228
|
-
let MYMODEL = {}
|
|
229
|
-
let chains = []
|
|
230
|
-
let datas
|
|
231
|
-
let results
|
|
232
|
-
let dummy = false
|
|
277
|
+
const body = req.body
|
|
278
|
+
const table = body.table
|
|
279
|
+
const MYMODELS = myCache.get('MYMODELS')
|
|
280
|
+
let MYMODEL = {}
|
|
281
|
+
let chains = []
|
|
282
|
+
let datas
|
|
283
|
+
let results
|
|
284
|
+
let dummy = false
|
|
233
285
|
|
|
234
286
|
//save data into table zfields
|
|
235
287
|
//console.log(JSON.stringify(body.others))
|
|
236
|
-
const others = body.others
|
|
288
|
+
const others = body.others
|
|
237
289
|
//return;
|
|
238
|
-
await saveToZFields(body)
|
|
290
|
+
await saveToZFields(body)
|
|
239
291
|
|
|
240
|
-
let exist = await connection.query(connection.describeTable(table))
|
|
292
|
+
let exist = await connection.query(connection.describeTable(table))
|
|
241
293
|
if (exist.length) {
|
|
242
|
-
body.rows = await connection.results({table:
|
|
243
|
-
body.checks = await connection.query(`SELECT 'public.${table}'::regclass`)
|
|
294
|
+
body.rows = await connection.results({ table: 'zfields', where: { table: table } })
|
|
295
|
+
body.checks = await connection.query(`SELECT 'public.${table}'::regclass`)
|
|
244
296
|
} else {
|
|
245
297
|
let sql = `
|
|
246
298
|
CREATE TABLE ${table} (
|
|
@@ -251,164 +303,164 @@ const generate = async (req, res) => {
|
|
|
251
303
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
252
304
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
253
305
|
CONSTRAINT fk_${table}_company_id FOREIGN KEY (company_id) REFERENCES zcompany (id)
|
|
254
|
-
)
|
|
255
|
-
await connection.query(sql)
|
|
256
|
-
body.checks = await connection.query(`SELECT 'public.${table}'::regclass`)
|
|
257
|
-
body.rows = await connection.results({table:
|
|
306
|
+
);`
|
|
307
|
+
await connection.query(sql)
|
|
308
|
+
body.checks = await connection.query(`SELECT 'public.${table}'::regclass`)
|
|
309
|
+
body.rows = await connection.results({ table: 'zfields', where: { table: table } })
|
|
258
310
|
}
|
|
259
|
-
body.others = others
|
|
260
|
-
results = await axios.post(`${generatorUrl}/api/generator/properties`, body)
|
|
261
|
-
datas = results.data
|
|
262
|
-
if (datas.create_table.hasOwnProperty(
|
|
263
|
-
await connection.query(datas.create_table.sql)
|
|
264
|
-
return generate(body)
|
|
311
|
+
body.others = others
|
|
312
|
+
results = await axios.post(`${generatorUrl}/api/generator/properties`, body)
|
|
313
|
+
datas = results.data
|
|
314
|
+
if (datas.create_table.hasOwnProperty('sql')) {
|
|
315
|
+
await connection.query(datas.create_table.sql)
|
|
316
|
+
return generate(body)
|
|
265
317
|
}
|
|
266
318
|
|
|
267
319
|
let result = await connection.update({
|
|
268
320
|
table: 'zfields',
|
|
269
321
|
data: datas.updateFields.post,
|
|
270
322
|
where: {
|
|
271
|
-
id: datas.updateFields.id
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
let resultJSON = Object.prototype.hasOwnProperty.call(result,'json') ? result.json : {}
|
|
275
|
-
if(resultJSON && Object.prototype.hasOwnProperty.call(resultJSON,'dummy')){
|
|
276
|
-
dummy = resultJSON.dummy == 1 ? true : false
|
|
323
|
+
id: datas.updateFields.id,
|
|
324
|
+
},
|
|
325
|
+
})
|
|
326
|
+
let resultJSON = Object.prototype.hasOwnProperty.call(result, 'json') ? result.json : {}
|
|
327
|
+
if (resultJSON && Object.prototype.hasOwnProperty.call(resultJSON, 'dummy')) {
|
|
328
|
+
dummy = resultJSON.dummy == 1 ? true : false
|
|
277
329
|
}
|
|
278
|
-
let properties = result.properties
|
|
330
|
+
let properties = result.properties
|
|
279
331
|
//update if any chains
|
|
280
332
|
for (let key in properties) {
|
|
281
333
|
//override
|
|
282
|
-
properties[key].values.required = properties[key].values.required ? true : false
|
|
283
|
-
properties[key].values.unique = properties[key].values.unique ? true : false
|
|
284
|
-
var isChain = properties[key].values.isChain ? true : false
|
|
285
|
-
properties[key].values.isChain = isChain
|
|
334
|
+
properties[key].values.required = properties[key].values.required ? true : false
|
|
335
|
+
properties[key].values.unique = properties[key].values.unique ? true : false
|
|
336
|
+
var isChain = properties[key].values.isChain ? true : false
|
|
337
|
+
properties[key].values.isChain = isChain
|
|
286
338
|
if (isChain) {
|
|
287
339
|
chains.push(key)
|
|
288
340
|
}
|
|
289
341
|
}
|
|
290
342
|
if (chains.length && chains.length < 2) {
|
|
291
|
-
return Util.flashError(
|
|
343
|
+
return Util.flashError('Chains min 2 fields number...')
|
|
292
344
|
}
|
|
293
345
|
if (chains.length) {
|
|
294
|
-
let prop = chainings(table, chains)
|
|
346
|
+
let prop = chainings(table, chains)
|
|
295
347
|
for (const key in prop) {
|
|
296
|
-
if (prop[key].hasOwnProperty(
|
|
297
|
-
chains = Object.keys(prop[key].chains)
|
|
348
|
+
if (prop[key].hasOwnProperty('chains')) {
|
|
349
|
+
chains = Object.keys(prop[key].chains)
|
|
298
350
|
if (chains.length) {
|
|
299
|
-
properties[key].values.chains = prop[key].chains
|
|
351
|
+
properties[key].values.chains = prop[key].chains
|
|
300
352
|
}
|
|
301
353
|
}
|
|
302
354
|
}
|
|
303
355
|
}
|
|
304
356
|
//update properties
|
|
305
357
|
result = await connection.update({
|
|
306
|
-
table:
|
|
358
|
+
table: 'zfields',
|
|
307
359
|
data: {
|
|
308
|
-
properties: JSON.stringify(properties)
|
|
360
|
+
properties: JSON.stringify(properties),
|
|
309
361
|
},
|
|
310
362
|
where: {
|
|
311
|
-
table: table
|
|
312
|
-
}
|
|
313
|
-
})
|
|
363
|
+
table: table,
|
|
364
|
+
},
|
|
365
|
+
})
|
|
314
366
|
//end chains
|
|
315
367
|
|
|
316
368
|
//generate file models routes views
|
|
317
|
-
body.columns = await connection.query(connection.describeTable(table))
|
|
318
|
-
body.constraintList = await connection.query(connection.constraintList(table))
|
|
319
|
-
body.result = result
|
|
320
|
-
results = await axios.post(`${generatorUrl}/api/generator/generate`, body)
|
|
321
|
-
datas = results.data
|
|
322
|
-
let files = datas.files
|
|
369
|
+
body.columns = await connection.query(connection.describeTable(table))
|
|
370
|
+
body.constraintList = await connection.query(connection.constraintList(table))
|
|
371
|
+
body.result = result
|
|
372
|
+
results = await axios.post(`${generatorUrl}/api/generator/generate`, body)
|
|
373
|
+
datas = results.data
|
|
374
|
+
let files = datas.files
|
|
323
375
|
for (let key in files) {
|
|
324
|
-
let filesKey = files[key]
|
|
325
|
-
if (key ==
|
|
326
|
-
if (filesKey.hasOwnProperty(
|
|
327
|
-
const sql = filesKey.sql || []
|
|
376
|
+
let filesKey = files[key]
|
|
377
|
+
if (key == 'model') {
|
|
378
|
+
if (filesKey.hasOwnProperty('sql')) {
|
|
379
|
+
const sql = filesKey.sql || []
|
|
328
380
|
for (let i = 0; i < sql.length; i++) {
|
|
329
|
-
console.log(i +
|
|
330
|
-
await connection.query(sql[i])
|
|
381
|
+
console.log(i + 'sql : ' + sql[i])
|
|
382
|
+
await connection.query(sql[i])
|
|
331
383
|
}
|
|
332
384
|
}
|
|
333
|
-
if (filesKey.hasOwnProperty(
|
|
334
|
-
const alter = filesKey.alter || []
|
|
385
|
+
if (filesKey.hasOwnProperty('alter')) {
|
|
386
|
+
const alter = filesKey.alter || []
|
|
335
387
|
for (let i = 0; i < alter.length; i++) {
|
|
336
388
|
console.log(alter[i])
|
|
337
|
-
await connection.query(alter[i])
|
|
389
|
+
await connection.query(alter[i])
|
|
338
390
|
}
|
|
339
391
|
}
|
|
340
|
-
if (filesKey.hasOwnProperty(
|
|
341
|
-
const index = filesKey.index || []
|
|
392
|
+
if (filesKey.hasOwnProperty('index')) {
|
|
393
|
+
const index = filesKey.index || []
|
|
342
394
|
for (let i = 0; i < index.length; i++) {
|
|
343
395
|
console.log(index[i])
|
|
344
|
-
await connection.query(index[i])
|
|
396
|
+
await connection.query(index[i])
|
|
345
397
|
}
|
|
346
398
|
}
|
|
347
|
-
if (filesKey.hasOwnProperty(
|
|
348
|
-
let fk = filesKey.fk || []
|
|
399
|
+
if (filesKey.hasOwnProperty('fk')) {
|
|
400
|
+
let fk = filesKey.fk || []
|
|
349
401
|
for (let i = 0; i < fk.length; i++) {
|
|
350
402
|
console.log(fk[i])
|
|
351
|
-
await connection.query(fk[i])
|
|
403
|
+
await connection.query(fk[i])
|
|
352
404
|
}
|
|
353
405
|
}
|
|
354
|
-
if (filesKey.hasOwnProperty(
|
|
355
|
-
const defaultValue = filesKey.defaultValue || []
|
|
406
|
+
if (filesKey.hasOwnProperty('defaultValue')) {
|
|
407
|
+
const defaultValue = filesKey.defaultValue || []
|
|
356
408
|
for (let i = 0; i < defaultValue.length; i++) {
|
|
357
409
|
console.log(defaultValue[i])
|
|
358
|
-
await connection.query(defaultValue[i])
|
|
410
|
+
await connection.query(defaultValue[i])
|
|
359
411
|
}
|
|
360
412
|
}
|
|
361
413
|
//console.log(JSON.stringify(filesKey.modelObj))
|
|
362
414
|
//check if has chains here
|
|
363
|
-
MYMODEL = filesKey.modelObj
|
|
415
|
+
MYMODEL = filesKey.modelObj
|
|
364
416
|
|
|
365
417
|
//delete/clean zgrid after changes
|
|
366
418
|
await connection.delete({
|
|
367
|
-
table:
|
|
419
|
+
table: 'zgrid',
|
|
368
420
|
where: {
|
|
369
|
-
route_name: table
|
|
370
|
-
}
|
|
371
|
-
})
|
|
421
|
+
route_name: table,
|
|
422
|
+
},
|
|
423
|
+
})
|
|
372
424
|
await connection.delete({
|
|
373
425
|
table: 'zgrid_default',
|
|
374
426
|
where: {
|
|
375
|
-
table: table
|
|
376
|
-
}
|
|
377
|
-
})
|
|
427
|
+
table: table,
|
|
428
|
+
},
|
|
429
|
+
})
|
|
378
430
|
//insert into zgrid default
|
|
379
431
|
let datagrid = {
|
|
380
432
|
company_id: 1,
|
|
381
433
|
updated_by: 1,
|
|
382
434
|
created_by: 1,
|
|
383
435
|
created_at: Util.now(),
|
|
384
|
-
updated_at: Util.now()
|
|
385
|
-
}
|
|
386
|
-
datagrid.table = table
|
|
387
|
-
datagrid.visibles = JSON.stringify(MYMODEL.grids.visibles)
|
|
388
|
-
datagrid.invisibles = JSON.stringify(MYMODEL.grids.invisibles)
|
|
389
|
-
datagrid.fields = JSON.stringify([...MYMODEL.grids.visibles, ...MYMODEL.grids.invisibles])
|
|
436
|
+
updated_at: Util.now(),
|
|
437
|
+
}
|
|
438
|
+
datagrid.table = table
|
|
439
|
+
datagrid.visibles = JSON.stringify(MYMODEL.grids.visibles)
|
|
440
|
+
datagrid.invisibles = JSON.stringify(MYMODEL.grids.invisibles)
|
|
441
|
+
datagrid.fields = JSON.stringify([...MYMODEL.grids.visibles, ...MYMODEL.grids.invisibles])
|
|
390
442
|
await connection.insert({
|
|
391
443
|
table: 'zgrid_default',
|
|
392
|
-
data: datagrid
|
|
393
|
-
})
|
|
444
|
+
data: datagrid,
|
|
445
|
+
})
|
|
394
446
|
|
|
395
|
-
fs.writeFileSync(`${dirRoot}/models/${filesKey.filename}`, filesKey.content)
|
|
396
|
-
console.log(`The file model of ${filesKey.filename} is saved!`)
|
|
447
|
+
fs.writeFileSync(`${dirRoot}/models/${filesKey.filename}`, filesKey.content)
|
|
448
|
+
console.log(`The file model of ${filesKey.filename} is saved!`)
|
|
397
449
|
|
|
398
|
-
let widgets = MYMODEL.widgets
|
|
450
|
+
let widgets = MYMODEL.widgets
|
|
399
451
|
let objChains = {}
|
|
400
|
-
let chainsTable = []
|
|
401
|
-
let isChain = false
|
|
452
|
+
let chainsTable = []
|
|
453
|
+
let isChain = false
|
|
402
454
|
for (let key in widgets) {
|
|
403
|
-
let hasChains = widgets[key].hasOwnProperty(
|
|
455
|
+
let hasChains = widgets[key].hasOwnProperty('isChain') ? widgets[key].isChain : false
|
|
404
456
|
if (hasChains) {
|
|
405
|
-
isChain = true
|
|
406
|
-
if (widgets[key].hasOwnProperty(
|
|
407
|
-
chainsTable.push(widget_table)
|
|
408
|
-
var widget_table = widgets[key].table
|
|
457
|
+
isChain = true
|
|
458
|
+
if (widgets[key].hasOwnProperty('table')) {
|
|
459
|
+
chainsTable.push(widget_table)
|
|
460
|
+
var widget_table = widgets[key].table
|
|
409
461
|
objChains[widget_table] = {
|
|
410
462
|
key: key,
|
|
411
|
-
changes: []
|
|
463
|
+
changes: [],
|
|
412
464
|
}
|
|
413
465
|
}
|
|
414
466
|
}
|
|
@@ -416,17 +468,17 @@ const generate = async (req, res) => {
|
|
|
416
468
|
|
|
417
469
|
if (isChain) {
|
|
418
470
|
for (let key in objChains) {
|
|
419
|
-
const model_table = MYMODELS[key]
|
|
471
|
+
const model_table = MYMODELS[key] // require(`./../models/${key}`);
|
|
420
472
|
for (let q in model_table.widgets) {
|
|
421
|
-
if (model_table.widgets[q].hasOwnProperty(
|
|
473
|
+
if (model_table.widgets[q].hasOwnProperty('table')) {
|
|
422
474
|
if (Util.in_array(model_table.widgets[q].table, chainsTable)) {
|
|
423
475
|
const objChanges = {
|
|
424
476
|
target: objChains[key].key,
|
|
425
477
|
table: key,
|
|
426
478
|
column: q,
|
|
427
|
-
name: widgets[objChains[key].key].fields[1]
|
|
428
|
-
}
|
|
429
|
-
objChains[model_table.widgets[q].table].changes.push(objChanges)
|
|
479
|
+
name: widgets[objChains[key].key].fields[1],
|
|
480
|
+
}
|
|
481
|
+
objChains[model_table.widgets[q].table].changes.push(objChanges)
|
|
430
482
|
}
|
|
431
483
|
}
|
|
432
484
|
}
|
|
@@ -434,507 +486,510 @@ const generate = async (req, res) => {
|
|
|
434
486
|
//console.log(JSON.stringify(objChains))
|
|
435
487
|
//update model
|
|
436
488
|
for (let key in objChains) {
|
|
437
|
-
const keykey = objChains[key].key
|
|
489
|
+
const keykey = objChains[key].key
|
|
438
490
|
widgets[keykey].chains = objChains[key].changes
|
|
439
491
|
}
|
|
440
|
-
MYMODEL.widgets = widgets
|
|
441
|
-
let newModel = `module.exports = ${Util.newLine}${Util.tab}{${Util.newLine}
|
|
492
|
+
MYMODEL.widgets = widgets
|
|
493
|
+
let newModel = `module.exports = ${Util.newLine}${Util.tab}{${Util.newLine}`
|
|
442
494
|
//newModel += JSON.stringify(MYMODEL, null, 2)
|
|
443
|
-
newModel += zRoute.buildFileModel(MYMODEL)
|
|
444
|
-
newModel += `${Util.tab}}
|
|
495
|
+
newModel += zRoute.buildFileModel(MYMODEL)
|
|
496
|
+
newModel += `${Util.tab}};`
|
|
445
497
|
|
|
446
|
-
fs.writeFileSync(`${dirRoot}/models/${filesKey.filename}`, newModel)
|
|
498
|
+
fs.writeFileSync(`${dirRoot}/models/${filesKey.filename}`, newModel)
|
|
447
499
|
}
|
|
448
500
|
//check model if it has select relation in concat
|
|
449
|
-
await scanning(MYMODEL)
|
|
501
|
+
await scanning(MYMODEL)
|
|
450
502
|
}
|
|
451
503
|
//generate views
|
|
452
|
-
let DIR_VIEW = `${dirRoot}/views/${table}
|
|
453
|
-
if (key ==
|
|
504
|
+
let DIR_VIEW = `${dirRoot}/views/${table}`
|
|
505
|
+
if (key == 'views') {
|
|
454
506
|
if (!fs.existsSync(DIR_VIEW)) {
|
|
455
|
-
fs.mkdirSync(DIR_VIEW)
|
|
507
|
+
fs.mkdirSync(DIR_VIEW)
|
|
456
508
|
}
|
|
457
|
-
let compilesJS = ['createjs.ejs', 'updatejs.ejs', 'importjs.ejs']
|
|
458
|
-
if(!dummy) {
|
|
509
|
+
let compilesJS = ['createjs.ejs', 'updatejs.ejs', 'importjs.ejs']
|
|
510
|
+
if (!dummy) {
|
|
459
511
|
for (const q in filesKey) {
|
|
460
|
-
console.log(q)
|
|
512
|
+
console.log(q)
|
|
461
513
|
if (Util.in_array(q, compilesJS)) {
|
|
462
|
-
fs.writeFileSync(`${DIR_VIEW}/${q}`, filesKey[q])
|
|
514
|
+
fs.writeFileSync(`${DIR_VIEW}/${q}`, filesKey[q])
|
|
463
515
|
} else {
|
|
464
|
-
fs.writeFileSync(
|
|
465
|
-
{
|
|
516
|
+
fs.writeFileSync(
|
|
517
|
+
`${DIR_VIEW}/${q}`,
|
|
518
|
+
await minify(filesKey[q], {
|
|
466
519
|
minifyJS: true,
|
|
467
520
|
minifyCSS: true,
|
|
468
|
-
collapseWhitespace: true
|
|
469
|
-
}
|
|
470
|
-
)
|
|
521
|
+
collapseWhitespace: true,
|
|
522
|
+
})
|
|
523
|
+
)
|
|
471
524
|
}
|
|
472
|
-
console.log(`The files views of ${q} is saved!`)
|
|
525
|
+
console.log(`The files views of ${q} is saved!`)
|
|
473
526
|
}
|
|
474
527
|
}
|
|
475
528
|
}
|
|
476
|
-
if(!dummy) {
|
|
477
|
-
if (key ==
|
|
478
|
-
fs.writeFileSync(`${dirRoot}/routes/${filesKey.filename}`, filesKey.content)
|
|
479
|
-
console.log(`The files route of ${filesKey.filename} is saved!`)
|
|
529
|
+
if (!dummy) {
|
|
530
|
+
if (key == 'route') {
|
|
531
|
+
fs.writeFileSync(`${dirRoot}/routes/${filesKey.filename}`, filesKey.content)
|
|
532
|
+
console.log(`The files route of ${filesKey.filename} is saved!`)
|
|
480
533
|
}
|
|
481
534
|
}
|
|
482
535
|
}
|
|
483
536
|
|
|
484
537
|
//make a directory
|
|
485
|
-
if(!dummy) {
|
|
486
|
-
let path_script = `${dirRoot}/public/runtime/script/${table}
|
|
487
|
-
Util.dirExist(path_script, true)
|
|
488
|
-
let path_head = `${dirRoot}/public/runtime/head/${table}
|
|
489
|
-
Util.dirExist(path_head, true)
|
|
490
|
-
let path_end = `${dirRoot}/public/runtime/end/${table}
|
|
491
|
-
Util.dirExist(path_end, true)
|
|
538
|
+
if (!dummy) {
|
|
539
|
+
let path_script = `${dirRoot}/public/runtime/script/${table}`
|
|
540
|
+
Util.dirExist(path_script, true)
|
|
541
|
+
let path_head = `${dirRoot}/public/runtime/head/${table}`
|
|
542
|
+
Util.dirExist(path_head, true)
|
|
543
|
+
let path_end = `${dirRoot}/public/runtime/end/${table}`
|
|
544
|
+
Util.dirExist(path_end, true)
|
|
492
545
|
//we need to generate javascript code into runtime
|
|
493
|
-
let relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
546
|
+
let relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
494
547
|
//add script
|
|
495
|
-
let jsObj = zRoute.generateJS(req, res, MYMODEL, relations)
|
|
548
|
+
let jsObj = zRoute.generateJS(req, res, MYMODEL, relations)
|
|
496
549
|
//minify script
|
|
497
|
-
let script = uglifyJS.minify(jsObj.script)
|
|
550
|
+
let script = uglifyJS.minify(jsObj.script)
|
|
498
551
|
if (script.error) {
|
|
499
|
-
console.log(jsObj.script)
|
|
500
|
-
throw script.error
|
|
552
|
+
console.log(jsObj.script)
|
|
553
|
+
throw script.error
|
|
501
554
|
}
|
|
502
|
-
let time = new Date().getTime()
|
|
503
|
-
Util.deleteAllFiles(path_script)
|
|
504
|
-
Util.deleteAllFiles(path_head)
|
|
505
|
-
Util.deleteAllFiles(path_end)
|
|
506
|
-
Util.writeFile(`${path_script}/${time}.js`, script.code)
|
|
507
|
-
Util.writeFile(`${path_head}/head.txt`, jsObj.head)
|
|
508
|
-
Util.writeFile(`${path_end}/end.txt`, jsObj.end)
|
|
555
|
+
let time = new Date().getTime()
|
|
556
|
+
Util.deleteAllFiles(path_script)
|
|
557
|
+
Util.deleteAllFiles(path_head)
|
|
558
|
+
Util.deleteAllFiles(path_end)
|
|
559
|
+
Util.writeFile(`${path_script}/${time}.js`, script.code)
|
|
560
|
+
Util.writeFile(`${path_head}/head.txt`, jsObj.head)
|
|
561
|
+
Util.writeFile(`${path_end}/end.txt`, jsObj.end)
|
|
509
562
|
}
|
|
510
563
|
|
|
511
564
|
//restart pm2 module in production
|
|
512
|
-
if (process.env.NODE_ENV ==
|
|
565
|
+
if (process.env.NODE_ENV == 'production') {
|
|
513
566
|
pm2.connect(function (err) {
|
|
514
567
|
if (err) {
|
|
515
|
-
console.log(err.toString())
|
|
568
|
+
console.log(err.toString())
|
|
516
569
|
}
|
|
517
570
|
pm2.restart(process.env.PM2_NAME, (err, proc) => {
|
|
518
571
|
//io.to(room).emit("message","Restart done")
|
|
519
|
-
})
|
|
520
|
-
})
|
|
572
|
+
})
|
|
573
|
+
})
|
|
521
574
|
}
|
|
522
575
|
|
|
523
|
-
return Util.jsonSuccess(
|
|
524
|
-
}
|
|
576
|
+
return Util.jsonSuccess('Success')
|
|
577
|
+
}
|
|
525
578
|
|
|
526
579
|
router.post('/savetabs', async (req, res) => {
|
|
527
|
-
let body = req.body
|
|
528
|
-
let table = body.table
|
|
529
|
-
let details = body.details
|
|
530
|
-
let left = [],
|
|
531
|
-
|
|
580
|
+
let body = req.body
|
|
581
|
+
let table = body.table
|
|
582
|
+
let details = body.details
|
|
583
|
+
let left = [],
|
|
584
|
+
right = [],
|
|
585
|
+
tabLeft = {},
|
|
586
|
+
tabRight = {}
|
|
587
|
+
let json = { status: 0, title: 'error', message: 'error', url: '' }
|
|
532
588
|
let obj = {}
|
|
533
589
|
obj.notabs = []
|
|
534
|
-
let labels = {}
|
|
535
|
-
let hasTab = false
|
|
590
|
+
let labels = {}
|
|
591
|
+
let hasTab = false
|
|
536
592
|
if (nots.includes(table)) {
|
|
537
|
-
return res.json(Util.flashError(
|
|
593
|
+
return res.json(Util.flashError('Table is locked'))
|
|
538
594
|
}
|
|
539
595
|
|
|
540
|
-
let rows = await connection.results({table:
|
|
596
|
+
let rows = await connection.results({ table: 'zfields', where: { table: table } })
|
|
541
597
|
if (rows.length > 0) {
|
|
542
|
-
let tabsValue = rows[0].tabs +
|
|
598
|
+
let tabsValue = rows[0].tabs + ''
|
|
543
599
|
if (tabsValue.length > 5) {
|
|
544
|
-
hasTab = true
|
|
545
|
-
let tabs = rows[0].tabs
|
|
600
|
+
hasTab = true
|
|
601
|
+
let tabs = rows[0].tabs
|
|
546
602
|
for (let i = 0; i < tabs.length; i++) {
|
|
547
|
-
obj['arr' + i] = []
|
|
548
|
-
tabLeft['arr' + i] = []
|
|
549
|
-
tabRight['arr' + i] = []
|
|
603
|
+
obj['arr' + i] = []
|
|
604
|
+
tabLeft['arr' + i] = []
|
|
605
|
+
tabRight['arr' + i] = []
|
|
550
606
|
}
|
|
551
607
|
}
|
|
552
608
|
}
|
|
553
609
|
|
|
554
610
|
for (let i = 0; i < details.length; i++) {
|
|
555
|
-
let name = details[i].name
|
|
556
|
-
let value = details[i].value
|
|
557
|
-
if (name.indexOf(
|
|
558
|
-
let explode = name.split(
|
|
611
|
+
let name = details[i].name
|
|
612
|
+
let value = details[i].value
|
|
613
|
+
if (name.indexOf('___') > -1) {
|
|
614
|
+
let explode = name.split('___')
|
|
559
615
|
obj[explode[1]].push(explode[0])
|
|
560
|
-
labels[explode[0]] = value
|
|
616
|
+
labels[explode[0]] = value
|
|
561
617
|
} else {
|
|
562
618
|
if (name == 'LEFT') {
|
|
563
|
-
if (value.indexOf(
|
|
564
|
-
var explode = value.split(
|
|
619
|
+
if (value.indexOf('___') > -1) {
|
|
620
|
+
var explode = value.split('___')
|
|
565
621
|
tabLeft[explode[1]].push(explode[0])
|
|
566
622
|
} else {
|
|
567
|
-
left.push(value)
|
|
623
|
+
left.push(value)
|
|
568
624
|
}
|
|
569
625
|
} else if (name == 'RIGHT') {
|
|
570
|
-
if (value.indexOf(
|
|
571
|
-
let explode = value.split(
|
|
626
|
+
if (value.indexOf('___') > -1) {
|
|
627
|
+
let explode = value.split('___')
|
|
572
628
|
tabRight[explode[1]].push(explode[0])
|
|
573
629
|
} else {
|
|
574
|
-
right.push(value)
|
|
630
|
+
right.push(value)
|
|
575
631
|
}
|
|
576
632
|
} else {
|
|
577
|
-
obj['notabs'].push(name)
|
|
578
|
-
labels[name] = value
|
|
633
|
+
obj['notabs'].push(name)
|
|
634
|
+
labels[name] = value
|
|
579
635
|
}
|
|
580
636
|
}
|
|
581
637
|
}
|
|
582
638
|
let post = {}
|
|
583
|
-
post.labels = JSON.stringify(labels)
|
|
584
|
-
post.details = JSON.stringify(obj)
|
|
585
|
-
post.left = hasTab ? JSON.stringify(tabLeft) : JSON.stringify(left)
|
|
586
|
-
post.right = hasTab ? JSON.stringify(tabRight) : JSON.stringify(right)
|
|
639
|
+
post.labels = JSON.stringify(labels)
|
|
640
|
+
post.details = JSON.stringify(obj)
|
|
641
|
+
post.left = hasTab ? JSON.stringify(tabLeft) : JSON.stringify(left)
|
|
642
|
+
post.right = hasTab ? JSON.stringify(tabRight) : JSON.stringify(right)
|
|
587
643
|
//console.log(post.left)
|
|
588
644
|
//console.log(JSON.stringify(post))
|
|
589
645
|
try {
|
|
590
646
|
if (rows.length > 0) {
|
|
591
|
-
await connection.update({table:
|
|
647
|
+
await connection.update({ table: 'zfields', data: post, where: { id: rows[0].id } })
|
|
592
648
|
} else {
|
|
593
|
-
post.table = table
|
|
594
|
-
await connection.insert({table:
|
|
649
|
+
post.table = table
|
|
650
|
+
await connection.insert({ table: 'zfields', data: post })
|
|
595
651
|
}
|
|
596
|
-
json = {status: 1, title: 'Success', message: 'Success', url: ''}
|
|
652
|
+
json = { status: 1, title: 'Success', message: 'Success', url: '' }
|
|
597
653
|
} catch (error) {
|
|
598
|
-
json = Util.flashError(error.sqlMessage)
|
|
654
|
+
json = Util.flashError(error.sqlMessage)
|
|
599
655
|
}
|
|
600
656
|
|
|
601
657
|
res.send(json)
|
|
602
|
-
})
|
|
658
|
+
})
|
|
603
659
|
|
|
604
660
|
const columnLR = (items, dataName) => {
|
|
605
|
-
return `<div class="col-md-6"><ol class="mydragable divboxlittle" data-name="${dataName}">${items}</ol></div
|
|
606
|
-
}
|
|
661
|
+
return `<div class="col-md-6"><ol class="mydragable divboxlittle" data-name="${dataName}">${items}</ol></div>`
|
|
662
|
+
}
|
|
607
663
|
|
|
608
664
|
const columnOne = (items) => {
|
|
609
|
-
return `<div class="row sortable"><i class="fa fa-arrows icon-float"></i><div class="col-md-12"><ol class="mydragable divboxlittle" data-name="ONE_COLUMN">${items}</ol></div></div
|
|
610
|
-
}
|
|
665
|
+
return `<div class="row sortable"><i class="fa fa-arrows icon-float"></i><div class="col-md-12"><ol class="mydragable divboxlittle" data-name="ONE_COLUMN">${items}</ol></div></div>`
|
|
666
|
+
}
|
|
611
667
|
|
|
612
668
|
const reformatProperties = async (position, item, table, arr) => {
|
|
613
|
-
const newData = JSON.stringify(Util.arrayDelete(arr, item))
|
|
669
|
+
const newData = JSON.stringify(Util.arrayDelete(arr, item))
|
|
614
670
|
const data = {
|
|
615
|
-
[position]: newData
|
|
616
|
-
}
|
|
671
|
+
[position]: newData,
|
|
672
|
+
}
|
|
617
673
|
await connection.update({
|
|
618
|
-
table:
|
|
674
|
+
table: 'zfields',
|
|
619
675
|
data: data,
|
|
620
676
|
where: {
|
|
621
|
-
table: table
|
|
622
|
-
}
|
|
677
|
+
table: table,
|
|
678
|
+
},
|
|
623
679
|
})
|
|
624
|
-
}
|
|
680
|
+
}
|
|
625
681
|
|
|
626
|
-
router.delete(
|
|
627
|
-
let table = req.body.table
|
|
628
|
-
let json = Util.jsonSuccess(
|
|
682
|
+
router.delete('/delete-table', csrfProtection, async (req, res) => {
|
|
683
|
+
let table = req.body.table
|
|
684
|
+
let json = Util.jsonSuccess('Successfully delete module')
|
|
629
685
|
if (Util.in_array(table, nots)) {
|
|
630
|
-
return res.json(Util.flashError(
|
|
686
|
+
return res.json(Util.flashError('Can not be deleted!'))
|
|
631
687
|
}
|
|
632
688
|
if (nots.includes(table)) {
|
|
633
|
-
return res.json(Util.flashError(
|
|
689
|
+
return res.json(Util.flashError('Table is locked'))
|
|
634
690
|
}
|
|
635
691
|
try {
|
|
636
692
|
await connection.delete({
|
|
637
|
-
table:
|
|
693
|
+
table: 'zfields',
|
|
638
694
|
where: {
|
|
639
|
-
table: table
|
|
640
|
-
}
|
|
641
|
-
})
|
|
695
|
+
table: table,
|
|
696
|
+
},
|
|
697
|
+
})
|
|
642
698
|
//await connection.query("DELETE FROM zfields WHERE `table` = ?", [table]);
|
|
643
|
-
await connection.query(`DROP table "${table}";`)
|
|
699
|
+
await connection.query(`DROP table "${table}";`)
|
|
644
700
|
//delete file
|
|
645
|
-
let modelFile = dirRoot +
|
|
701
|
+
let modelFile = dirRoot + '/models/' + table + '.js'
|
|
646
702
|
fs.stat(modelFile, function (err, stats) {
|
|
647
|
-
console.log(stats)
|
|
703
|
+
console.log(stats) //here we got all information of file in stats variable
|
|
648
704
|
if (err) {
|
|
649
|
-
return console.error(err)
|
|
705
|
+
return console.error(err)
|
|
650
706
|
} else {
|
|
651
707
|
fs.unlink(modelFile, function (err) {
|
|
652
|
-
if (err) return console.log(err)
|
|
653
|
-
console.log('file deleted successfully')
|
|
654
|
-
})
|
|
708
|
+
if (err) return console.log(err)
|
|
709
|
+
console.log('file deleted successfully')
|
|
710
|
+
})
|
|
655
711
|
}
|
|
656
|
-
})
|
|
712
|
+
})
|
|
657
713
|
|
|
658
|
-
let routesFile = dirRoot +
|
|
714
|
+
let routesFile = dirRoot + '/routes/' + table + '.js'
|
|
659
715
|
fs.stat(routesFile, function (err, stats) {
|
|
660
|
-
console.log(stats)
|
|
716
|
+
console.log(stats) //here we got all information of file in stats variable
|
|
661
717
|
if (err) {
|
|
662
|
-
return console.error(err)
|
|
718
|
+
return console.error(err)
|
|
663
719
|
} else {
|
|
664
720
|
fs.unlink(routesFile, function (err) {
|
|
665
|
-
if (err) return console.log(err)
|
|
666
|
-
console.log('file deleted successfully')
|
|
667
|
-
})
|
|
721
|
+
if (err) return console.log(err)
|
|
722
|
+
console.log('file deleted successfully')
|
|
723
|
+
})
|
|
668
724
|
}
|
|
669
|
-
})
|
|
725
|
+
})
|
|
670
726
|
|
|
671
|
-
let runtimeFile = dirRoot +
|
|
727
|
+
let runtimeFile = dirRoot + '/runtime/scripts/' + table + '.js'
|
|
672
728
|
fs.stat(runtimeFile, function (err, stats) {
|
|
673
729
|
if (err) {
|
|
674
|
-
return console.error(err)
|
|
730
|
+
return console.error(err)
|
|
675
731
|
} else {
|
|
676
732
|
fs.unlink(runtimeFile, function (err) {
|
|
677
|
-
if (err) return console.log(err)
|
|
678
|
-
console.log('file deleted successfully')
|
|
679
|
-
})
|
|
733
|
+
if (err) return console.log(err)
|
|
734
|
+
console.log('file deleted successfully')
|
|
735
|
+
})
|
|
680
736
|
}
|
|
681
|
-
|
|
682
|
-
});
|
|
737
|
+
})
|
|
683
738
|
await connection.delete({
|
|
684
|
-
table:
|
|
685
|
-
where: {route_name: table}
|
|
686
|
-
})
|
|
739
|
+
table: 'zgrid',
|
|
740
|
+
where: { route_name: table },
|
|
741
|
+
})
|
|
687
742
|
if (table) {
|
|
688
|
-
const viewsFile = dirRoot +
|
|
743
|
+
const viewsFile = dirRoot + '/views/' + table
|
|
689
744
|
fs.stat(viewsFile, function (err, stats) {
|
|
690
745
|
if (err) {
|
|
691
|
-
return console.error(err)
|
|
746
|
+
return console.error(err)
|
|
692
747
|
} else {
|
|
693
|
-
fs.rmdirSync(viewsFile, {recursive: true})
|
|
748
|
+
fs.rmdirSync(viewsFile, { recursive: true })
|
|
694
749
|
}
|
|
695
|
-
})
|
|
750
|
+
})
|
|
696
751
|
}
|
|
697
752
|
await connection.delete({
|
|
698
|
-
table:
|
|
699
|
-
where: {table: table}
|
|
700
|
-
})
|
|
753
|
+
table: 'zgrid_default',
|
|
754
|
+
where: { table: table },
|
|
755
|
+
})
|
|
701
756
|
} catch (e) {
|
|
702
|
-
json = Util.flashError(e.toString(),
|
|
757
|
+
json = Util.flashError(e.toString(), '')
|
|
703
758
|
}
|
|
704
759
|
|
|
705
760
|
res.json(json)
|
|
706
|
-
})
|
|
761
|
+
})
|
|
707
762
|
|
|
708
|
-
router.post(
|
|
763
|
+
router.post('/add_field', csrfProtection, async (req, res) => {
|
|
709
764
|
try {
|
|
710
|
-
const body = req.body
|
|
765
|
+
const body = req.body
|
|
711
766
|
//console.log(JSON.stringify(body.others))
|
|
712
|
-
const table = body.table
|
|
767
|
+
const table = body.table
|
|
713
768
|
if (nots.includes(table)) {
|
|
714
|
-
return res.json(Util.flashError(
|
|
769
|
+
return res.json(Util.flashError('Table is locked'))
|
|
715
770
|
}
|
|
716
|
-
body.zFields = await connection.results({table:
|
|
717
|
-
const results = await axios.post(`${generatorUrl}/api/generator/create_field`, body)
|
|
718
|
-
const datas = results.data
|
|
771
|
+
body.zFields = await connection.results({ table: 'zfields', where: { table: table } })
|
|
772
|
+
const results = await axios.post(`${generatorUrl}/api/generator/create_field`, body)
|
|
773
|
+
const datas = results.data
|
|
719
774
|
if (datas.status == 1) {
|
|
720
|
-
await connection.update({table: 'zfields', where: {table: table}, data: datas.post})
|
|
775
|
+
await connection.update({ table: 'zfields', where: { table: table }, data: datas.post })
|
|
721
776
|
}
|
|
722
777
|
res.json(datas)
|
|
723
778
|
} catch (e) {
|
|
724
|
-
res.json(Util.flashError(e.toString()))
|
|
779
|
+
res.json(Util.flashError(e.toString()))
|
|
725
780
|
}
|
|
726
|
-
})
|
|
781
|
+
})
|
|
727
782
|
|
|
728
783
|
router.post('/add_container', async (req, res) => {
|
|
729
|
-
let others = req.body.others
|
|
730
|
-
let table = req.body.table
|
|
784
|
+
let others = req.body.others
|
|
785
|
+
let table = req.body.table
|
|
731
786
|
//console.log(JSON.stringify(req.body))
|
|
732
787
|
try {
|
|
733
788
|
if (others && table) {
|
|
734
789
|
await connection.update({
|
|
735
790
|
table: 'zfields',
|
|
736
791
|
data: {
|
|
737
|
-
others: others
|
|
792
|
+
others: others,
|
|
738
793
|
},
|
|
739
794
|
where: {
|
|
740
|
-
table: table
|
|
741
|
-
}
|
|
795
|
+
table: table,
|
|
796
|
+
},
|
|
742
797
|
})
|
|
743
798
|
}
|
|
744
799
|
} catch (e) {
|
|
745
800
|
return res.json(Util.flashError(e.toString()))
|
|
746
801
|
}
|
|
747
802
|
|
|
748
|
-
res.json(Util.jsonSuccess(
|
|
749
|
-
})
|
|
750
|
-
|
|
803
|
+
res.json(Util.jsonSuccess('Success'))
|
|
804
|
+
})
|
|
751
805
|
|
|
752
|
-
router.post(
|
|
806
|
+
router.post('/setting_field', csrfProtection, async (req, res) => {
|
|
753
807
|
if (nots.includes(req.body.table)) {
|
|
754
|
-
return res.json(Util.flashError(
|
|
808
|
+
return res.json(Util.flashError('Table is locked'))
|
|
755
809
|
}
|
|
756
|
-
const body = req.body
|
|
757
|
-
const table = body.table
|
|
758
|
-
const html =
|
|
759
|
-
body.result = await connection.result({table:
|
|
760
|
-
const results = await axios.post(`${generatorUrl}/api/generator/modal_settings`, body)
|
|
761
|
-
const datas = results.data
|
|
810
|
+
const body = req.body
|
|
811
|
+
const table = body.table
|
|
812
|
+
const html = ''
|
|
813
|
+
body.result = await connection.result({ table: 'zfields', where: { table: table } })
|
|
814
|
+
const results = await axios.post(`${generatorUrl}/api/generator/modal_settings`, body)
|
|
815
|
+
const datas = results.data
|
|
762
816
|
res.json(datas.html)
|
|
763
|
-
})
|
|
764
|
-
|
|
817
|
+
})
|
|
765
818
|
|
|
766
|
-
router.post(
|
|
767
|
-
const html =
|
|
768
|
-
|
|
819
|
+
router.post('/save_setting', async (req, res) => {
|
|
820
|
+
const html = '',
|
|
821
|
+
table = req.query.table || ''
|
|
822
|
+
let json = Util.jsonSuccess('Success to update')
|
|
769
823
|
try {
|
|
770
824
|
if (nots.includes(req.body.table)) {
|
|
771
|
-
return res.json(Util.flashError(
|
|
825
|
+
return res.json(Util.flashError('Table is locked'))
|
|
772
826
|
}
|
|
773
|
-
const post = req.body
|
|
827
|
+
const post = req.body
|
|
774
828
|
let data = await connection.result({
|
|
775
|
-
table:
|
|
776
|
-
where: {table: table}
|
|
829
|
+
table: 'zfields',
|
|
830
|
+
where: { table: table },
|
|
777
831
|
})
|
|
778
|
-
let properties = data.properties ? data.properties : {}
|
|
779
|
-
let propertyKey =
|
|
832
|
+
let properties = data.properties ? data.properties : {}
|
|
833
|
+
let propertyKey = ''
|
|
780
834
|
for (var key in post) {
|
|
781
|
-
propertyKey = key
|
|
835
|
+
propertyKey = key
|
|
782
836
|
}
|
|
783
837
|
|
|
784
|
-
properties[propertyKey].values = post[propertyKey]
|
|
838
|
+
properties[propertyKey].values = post[propertyKey]
|
|
785
839
|
let insert = {
|
|
786
|
-
properties: JSON.stringify(properties)
|
|
787
|
-
}
|
|
840
|
+
properties: JSON.stringify(properties),
|
|
841
|
+
}
|
|
788
842
|
await connection.update({
|
|
789
|
-
table:
|
|
843
|
+
table: 'zfields',
|
|
790
844
|
data: insert,
|
|
791
|
-
where: {table: table}
|
|
792
|
-
})
|
|
793
|
-
|
|
845
|
+
where: { table: table },
|
|
846
|
+
})
|
|
794
847
|
} catch (e) {
|
|
795
848
|
json = Util.flashError(e.toString())
|
|
796
849
|
}
|
|
797
850
|
|
|
798
|
-
res.json(json)
|
|
799
|
-
})
|
|
800
|
-
|
|
851
|
+
res.json(json)
|
|
852
|
+
})
|
|
801
853
|
|
|
802
|
-
router.delete(
|
|
803
|
-
let json = Util.jsonSuccess(
|
|
854
|
+
router.delete('/delete_field', csrfProtection, async (req, res) => {
|
|
855
|
+
let json = Util.jsonSuccess('Success to update')
|
|
804
856
|
try {
|
|
805
857
|
if (nots.includes(req.body.table)) {
|
|
806
|
-
return res.json(Util.flashError(
|
|
858
|
+
return res.json(Util.flashError('Table is locked'))
|
|
807
859
|
}
|
|
808
|
-
const table = req.body.table,
|
|
860
|
+
const table = req.body.table,
|
|
861
|
+
name = req.body.name
|
|
809
862
|
let data = await connection.result({
|
|
810
|
-
table:
|
|
811
|
-
where: {table: table}
|
|
812
|
-
})
|
|
813
|
-
let properties = data.properties ? data.properties : {}
|
|
814
|
-
delete properties[name]
|
|
815
|
-
let labels = data.labels ? data.labels : {}
|
|
816
|
-
delete labels[name]
|
|
817
|
-
|
|
818
|
-
let left = data.left ? data.left : []
|
|
819
|
-
left = Util.arrayDelete(left, name)
|
|
820
|
-
let right = data.right ? data.right : []
|
|
821
|
-
right = Util.arrayDelete(right, name)
|
|
822
|
-
let oneColumn = data.one_column ? data.one_column : []
|
|
823
|
-
oneColumn = Util.arrayDelete(oneColumn, name)
|
|
824
|
-
let details = data.details ? data.details : {}
|
|
863
|
+
table: 'zfields',
|
|
864
|
+
where: { table: table },
|
|
865
|
+
})
|
|
866
|
+
let properties = data.properties ? data.properties : {}
|
|
867
|
+
delete properties[name]
|
|
868
|
+
let labels = data.labels ? data.labels : {}
|
|
869
|
+
delete labels[name]
|
|
870
|
+
|
|
871
|
+
let left = data.left ? data.left : []
|
|
872
|
+
left = Util.arrayDelete(left, name)
|
|
873
|
+
let right = data.right ? data.right : []
|
|
874
|
+
right = Util.arrayDelete(right, name)
|
|
875
|
+
let oneColumn = data.one_column ? data.one_column : []
|
|
876
|
+
oneColumn = Util.arrayDelete(oneColumn, name)
|
|
877
|
+
let details = data.details ? data.details : {}
|
|
825
878
|
let detailsTemp = {}
|
|
826
879
|
for (var keys in details) {
|
|
827
|
-
detailsTemp[keys] = Util.arrayDelete(details[keys], name)
|
|
880
|
+
detailsTemp[keys] = Util.arrayDelete(details[keys], name)
|
|
828
881
|
}
|
|
829
|
-
let newProperty = {}
|
|
830
|
-
newProperty.properties = JSON.stringify(properties)
|
|
831
|
-
newProperty.labels = JSON.stringify(labels)
|
|
832
|
-
newProperty.left = JSON.stringify(left)
|
|
833
|
-
newProperty.right = JSON.stringify(right)
|
|
834
|
-
newProperty.one_column = JSON.stringify(oneColumn)
|
|
835
|
-
newProperty.details = JSON.stringify(detailsTemp)
|
|
836
|
-
newProperty.sorting = JSON.stringify(data.sorting)
|
|
882
|
+
let newProperty = {}
|
|
883
|
+
newProperty.properties = JSON.stringify(properties)
|
|
884
|
+
newProperty.labels = JSON.stringify(labels)
|
|
885
|
+
newProperty.left = JSON.stringify(left)
|
|
886
|
+
newProperty.right = JSON.stringify(right)
|
|
887
|
+
newProperty.one_column = JSON.stringify(oneColumn)
|
|
888
|
+
newProperty.details = JSON.stringify(detailsTemp)
|
|
889
|
+
newProperty.sorting = JSON.stringify(data.sorting)
|
|
837
890
|
await connection.update({
|
|
838
|
-
table:
|
|
891
|
+
table: 'zfields',
|
|
839
892
|
data: newProperty,
|
|
840
|
-
where: {table: table}
|
|
841
|
-
})
|
|
893
|
+
where: { table: table },
|
|
894
|
+
})
|
|
842
895
|
//DROP COULUMN
|
|
843
896
|
//ALTER TABLE table_name DROP COLUMN IF EXISTS column_name;
|
|
844
897
|
await connection.query(`ALTER TABLE "${table}" DROP COLUMN IF EXISTS "${name}";`)
|
|
845
898
|
} catch (err) {
|
|
846
899
|
json = Util.flashError(err.toString())
|
|
847
|
-
console.log(err)
|
|
848
|
-
console.log(
|
|
900
|
+
console.log(err)
|
|
901
|
+
console.log('ada error di update zfields')
|
|
849
902
|
}
|
|
850
|
-
res.json(json)
|
|
851
|
-
})
|
|
852
|
-
|
|
903
|
+
res.json(json)
|
|
904
|
+
})
|
|
853
905
|
|
|
854
|
-
router.post(
|
|
855
|
-
const html =
|
|
856
|
-
|
|
906
|
+
router.post('/tab_rename', csrfProtection, async (req, res) => {
|
|
907
|
+
const html = '',
|
|
908
|
+
table = req.body.table || '',
|
|
909
|
+
name = req.body.name || '',
|
|
910
|
+
id = req.body.id || 0
|
|
911
|
+
let json = Util.jsonSuccess('Success to rename')
|
|
857
912
|
try {
|
|
858
|
-
if (table ==
|
|
859
|
-
return res.json(Util.flashError(
|
|
913
|
+
if (table == '') {
|
|
914
|
+
return res.json(Util.flashError('table empty'))
|
|
860
915
|
}
|
|
861
|
-
if (name ==
|
|
862
|
-
return res.json(Util.flashError(
|
|
916
|
+
if (name == '') {
|
|
917
|
+
return res.json(Util.flashError('name empty'))
|
|
863
918
|
}
|
|
864
919
|
let data = await connection.result({
|
|
865
|
-
table:
|
|
866
|
-
where: {table: table}
|
|
867
|
-
})
|
|
868
|
-
const tabs = data.tabs || []
|
|
920
|
+
table: 'zfields',
|
|
921
|
+
where: { table: table },
|
|
922
|
+
})
|
|
923
|
+
const tabs = data.tabs || []
|
|
869
924
|
let arr = []
|
|
870
925
|
tabs.forEach(function (item, index) {
|
|
871
926
|
if (index == id) {
|
|
872
|
-
arr.push(name)
|
|
927
|
+
arr.push(name)
|
|
873
928
|
} else {
|
|
874
|
-
arr.push(item)
|
|
929
|
+
arr.push(item)
|
|
875
930
|
}
|
|
876
|
-
})
|
|
931
|
+
})
|
|
877
932
|
let post = {
|
|
878
|
-
tabs: JSON.stringify(arr)
|
|
933
|
+
tabs: JSON.stringify(arr),
|
|
879
934
|
}
|
|
880
935
|
await connection.update({
|
|
881
|
-
table:
|
|
936
|
+
table: 'zfields',
|
|
882
937
|
data: post,
|
|
883
938
|
where: {
|
|
884
|
-
table: table
|
|
885
|
-
}
|
|
886
|
-
})
|
|
939
|
+
table: table,
|
|
940
|
+
},
|
|
941
|
+
})
|
|
887
942
|
} catch (e) {
|
|
888
943
|
json = Util.flashError(e.toString())
|
|
889
944
|
}
|
|
890
|
-
res.json(json)
|
|
891
|
-
})
|
|
945
|
+
res.json(json)
|
|
946
|
+
})
|
|
892
947
|
|
|
893
948
|
const zfields = async () => {
|
|
894
949
|
return await connection.results({
|
|
895
950
|
select: `id, "table", "name", "route",tabs,labels, details, "left","right",one_column, sorting, properties,hardcode_grid,others,json`,
|
|
896
|
-
table:
|
|
897
|
-
orderBy: ['table', 'asc']
|
|
898
|
-
})
|
|
899
|
-
}
|
|
951
|
+
table: 'zfields',
|
|
952
|
+
orderBy: ['table', 'asc'],
|
|
953
|
+
})
|
|
954
|
+
}
|
|
900
955
|
|
|
901
|
-
const zfieldsKeys = async() => {
|
|
902
|
-
return Util.arrayToObject(await zfields(),
|
|
956
|
+
const zfieldsKeys = async () => {
|
|
957
|
+
return Util.arrayToObject(await zfields(), 'table')
|
|
903
958
|
}
|
|
904
959
|
|
|
905
960
|
router.post('/load-form', async (req, res) => {
|
|
906
|
-
const table = req.body.table
|
|
907
|
-
let json = Util.flashError(
|
|
961
|
+
const table = req.body.table
|
|
962
|
+
let json = Util.flashError('error')
|
|
908
963
|
const result = await connection.result({
|
|
909
|
-
table:
|
|
964
|
+
table: 'zfields',
|
|
910
965
|
where: {
|
|
911
|
-
table: table
|
|
912
|
-
}
|
|
913
|
-
})
|
|
966
|
+
table: table,
|
|
967
|
+
},
|
|
968
|
+
})
|
|
914
969
|
if (result.id) {
|
|
915
|
-
json = Util.jsonSuccess(
|
|
916
|
-
json.data = result
|
|
970
|
+
json = Util.jsonSuccess('success')
|
|
971
|
+
json.data = result
|
|
917
972
|
}
|
|
918
973
|
res.json(json)
|
|
919
|
-
})
|
|
974
|
+
})
|
|
920
975
|
|
|
921
976
|
var saveToZFields = async (body) => {
|
|
922
|
-
const table = body.table
|
|
923
|
-
let is_approval = body.is_approval
|
|
924
|
-
if (typeof body.is_approval ==
|
|
925
|
-
if (body.is_approval ==
|
|
926
|
-
is_approval = 0
|
|
927
|
-
} else if (body.is_approval ==
|
|
928
|
-
is_approval = 1
|
|
977
|
+
const table = body.table
|
|
978
|
+
let is_approval = body.is_approval
|
|
979
|
+
if (typeof body.is_approval == 'string') {
|
|
980
|
+
if (body.is_approval == 'false') {
|
|
981
|
+
is_approval = 0
|
|
982
|
+
} else if (body.is_approval == 'true') {
|
|
983
|
+
is_approval = 1
|
|
929
984
|
}
|
|
930
985
|
}
|
|
931
986
|
|
|
932
|
-
const zapprovals = {}
|
|
933
|
-
zapprovals.title = body.approval_title
|
|
934
|
-
zapprovals.type = body.type
|
|
935
|
-
zapprovals.approvers = body.approvers
|
|
936
|
-
zapprovals.knowings = body.knowings
|
|
937
|
-
zapprovals.content = body.template
|
|
987
|
+
const zapprovals = {}
|
|
988
|
+
zapprovals.title = body.approval_title
|
|
989
|
+
zapprovals.type = body.type
|
|
990
|
+
zapprovals.approvers = body.approvers
|
|
991
|
+
zapprovals.knowings = body.knowings
|
|
992
|
+
zapprovals.content = body.template
|
|
938
993
|
var data = {
|
|
939
994
|
index_ejs: body.index_ejs,
|
|
940
995
|
indexcss_ejs: body.indexcss_ejs,
|
|
@@ -949,146 +1004,145 @@ var saveToZFields = async (body) => {
|
|
|
949
1004
|
view_ejs: body.view_ejs,
|
|
950
1005
|
is_approval: is_approval || 0,
|
|
951
1006
|
approval_json: JSON.stringify(zapprovals),
|
|
952
|
-
others: body.others
|
|
1007
|
+
others: body.others,
|
|
953
1008
|
}
|
|
954
1009
|
|
|
955
1010
|
await connection.update({
|
|
956
|
-
table:
|
|
1011
|
+
table: 'zfields',
|
|
957
1012
|
data: data,
|
|
958
1013
|
where: {
|
|
959
|
-
table: table
|
|
960
|
-
}
|
|
1014
|
+
table: table,
|
|
1015
|
+
},
|
|
961
1016
|
})
|
|
962
|
-
}
|
|
963
|
-
|
|
1017
|
+
}
|
|
964
1018
|
|
|
965
1019
|
//drop down chains effect
|
|
966
1020
|
const chainings = async (table, arr) => {
|
|
967
|
-
const results = await connection.query(connection.showFields(table))
|
|
968
|
-
const obj = {}
|
|
969
|
-
const tableObj = {}
|
|
1021
|
+
const results = await connection.query(connection.showFields(table))
|
|
1022
|
+
const obj = {}
|
|
1023
|
+
const tableObj = {}
|
|
970
1024
|
for (let i = 0; i < results.length; i++) {
|
|
971
|
-
const result = results[i]
|
|
1025
|
+
const result = results[i]
|
|
972
1026
|
if (Util.in_array(result.COLUMN_NAME, arr)) {
|
|
973
1027
|
obj[result.COLUMN_NAME] = {
|
|
974
|
-
table: result.REFERENCED_TABLE_NAME
|
|
1028
|
+
table: result.REFERENCED_TABLE_NAME,
|
|
975
1029
|
}
|
|
976
|
-
tableObj[result.REFERENCED_TABLE_NAME] = result.COLUMN_NAME
|
|
1030
|
+
tableObj[result.REFERENCED_TABLE_NAME] = result.COLUMN_NAME
|
|
977
1031
|
}
|
|
978
1032
|
}
|
|
979
1033
|
|
|
980
1034
|
for (const key in obj) {
|
|
981
|
-
const rows = await connection.query(connection.showFields(obj[key].table))
|
|
1035
|
+
const rows = await connection.query(connection.showFields(obj[key].table))
|
|
982
1036
|
rows.forEach(function (row) {
|
|
983
1037
|
for (var q in obj) {
|
|
984
1038
|
if (row.REFERENCED_TABLE_NAME == obj[q].table) {
|
|
985
1039
|
if (!obj[q].chains) {
|
|
986
|
-
obj[q].chains = {}
|
|
1040
|
+
obj[q].chains = {}
|
|
987
1041
|
}
|
|
988
1042
|
obj[q].chains[key] = {
|
|
989
1043
|
column: row.COLUMN_NAME,
|
|
990
|
-
table: row.TABLE_NAME
|
|
1044
|
+
table: row.TABLE_NAME,
|
|
991
1045
|
}
|
|
992
1046
|
}
|
|
993
1047
|
}
|
|
994
|
-
})
|
|
1048
|
+
})
|
|
995
1049
|
}
|
|
996
|
-
return obj
|
|
997
|
-
}
|
|
1050
|
+
return obj
|
|
1051
|
+
}
|
|
998
1052
|
|
|
999
1053
|
router.post('/sorting', async (req, res) => {
|
|
1000
|
-
let sorting = req.body.sorting
|
|
1001
|
-
let table = req.body.table
|
|
1054
|
+
let sorting = req.body.sorting
|
|
1055
|
+
let table = req.body.table
|
|
1002
1056
|
await connection.update({
|
|
1003
|
-
table:
|
|
1057
|
+
table: 'zfields',
|
|
1004
1058
|
data: {
|
|
1005
|
-
sorting: sorting
|
|
1059
|
+
sorting: sorting,
|
|
1006
1060
|
},
|
|
1007
|
-
where: {table: table}
|
|
1008
|
-
})
|
|
1009
|
-
res.send(
|
|
1010
|
-
})
|
|
1011
|
-
|
|
1012
|
-
router.post(
|
|
1013
|
-
const table = req.body.table
|
|
1014
|
-
let json = Util.jsonSuccess(
|
|
1061
|
+
where: { table: table },
|
|
1062
|
+
})
|
|
1063
|
+
res.send('OK')
|
|
1064
|
+
})
|
|
1065
|
+
|
|
1066
|
+
router.post('/export', async (req, res) => {
|
|
1067
|
+
const table = req.body.table
|
|
1068
|
+
let json = Util.jsonSuccess('file Complete')
|
|
1015
1069
|
if (table) {
|
|
1016
1070
|
const result = await connection.result({
|
|
1017
|
-
table:
|
|
1071
|
+
table: 'zfields',
|
|
1018
1072
|
where: {
|
|
1019
|
-
table: table
|
|
1020
|
-
}
|
|
1021
|
-
})
|
|
1022
|
-
const dir = `${dirRoot}/public/uploads/zgenerator
|
|
1073
|
+
table: table,
|
|
1074
|
+
},
|
|
1075
|
+
})
|
|
1076
|
+
const dir = `${dirRoot}/public/uploads/zgenerator`
|
|
1023
1077
|
if (!fs.existsSync(dir)) {
|
|
1024
|
-
fs.mkdirSync(dir)
|
|
1078
|
+
fs.mkdirSync(dir)
|
|
1025
1079
|
}
|
|
1026
|
-
const text = JSON.stringify(result)
|
|
1027
|
-
fs.writeFileSync(`${dir}/${table}.json`, text)
|
|
1080
|
+
const text = JSON.stringify(result)
|
|
1081
|
+
fs.writeFileSync(`${dir}/${table}.json`, text)
|
|
1028
1082
|
} else {
|
|
1029
|
-
json = Util.flashError(
|
|
1083
|
+
json = Util.flashError('no table selected')
|
|
1030
1084
|
}
|
|
1031
1085
|
res.json(json)
|
|
1032
1086
|
})
|
|
1033
1087
|
|
|
1034
|
-
router.post(
|
|
1035
|
-
let json = Util.flashError(
|
|
1036
|
-
let table =
|
|
1088
|
+
router.post('/import', async (req, res) => {
|
|
1089
|
+
let json = Util.flashError('Error File')
|
|
1090
|
+
let table = ''
|
|
1037
1091
|
try {
|
|
1038
|
-
let isEmptyFiles = Util.isEmptyObject(req.files)
|
|
1092
|
+
let isEmptyFiles = Util.isEmptyObject(req.files)
|
|
1039
1093
|
if (!isEmptyFiles) {
|
|
1040
|
-
const file = req.files[
|
|
1041
|
-
const name = file.name
|
|
1042
|
-
const mime = file.mimetype
|
|
1043
|
-
if (mime ==
|
|
1044
|
-
const string = file.data.toString('utf8')
|
|
1045
|
-
const jsonFile = JSON.parse(string)
|
|
1046
|
-
table = jsonFile.table
|
|
1047
|
-
delete jsonFile.id
|
|
1094
|
+
const file = req.files['import-file']
|
|
1095
|
+
const name = file.name
|
|
1096
|
+
const mime = file.mimetype
|
|
1097
|
+
if (mime == 'application/json') {
|
|
1098
|
+
const string = file.data.toString('utf8')
|
|
1099
|
+
const jsonFile = JSON.parse(string)
|
|
1100
|
+
table = jsonFile.table
|
|
1101
|
+
delete jsonFile.id
|
|
1048
1102
|
const data = {}
|
|
1049
1103
|
for (const key in jsonFile) {
|
|
1050
|
-
let value = jsonFile[key]
|
|
1051
|
-
if (typeof value ==
|
|
1104
|
+
let value = jsonFile[key]
|
|
1105
|
+
if (typeof value == 'object') {
|
|
1052
1106
|
value = JSON.stringify(value)
|
|
1053
1107
|
}
|
|
1054
|
-
data[key] = value
|
|
1108
|
+
data[key] = value
|
|
1055
1109
|
}
|
|
1056
1110
|
if (!data.tabs) {
|
|
1057
|
-
data.tabs =
|
|
1111
|
+
data.tabs = '[]'
|
|
1058
1112
|
}
|
|
1059
|
-
data.company_id = 1
|
|
1060
|
-
data.created_by = res.locals.userId || 1
|
|
1061
|
-
data.updated_by = res.locals.userId || 1
|
|
1113
|
+
data.company_id = 1
|
|
1114
|
+
data.created_by = res.locals.userId || 1
|
|
1115
|
+
data.updated_by = res.locals.userId || 1
|
|
1062
1116
|
const results = await connection.results({
|
|
1063
|
-
table:
|
|
1117
|
+
table: 'zfields',
|
|
1064
1118
|
where: {
|
|
1065
|
-
table: table
|
|
1066
|
-
}
|
|
1119
|
+
table: table,
|
|
1120
|
+
},
|
|
1067
1121
|
})
|
|
1068
1122
|
if (results.length) {
|
|
1069
1123
|
await connection.update({
|
|
1070
|
-
table:
|
|
1124
|
+
table: 'zfields',
|
|
1071
1125
|
data: data,
|
|
1072
1126
|
where: {
|
|
1073
|
-
table: table
|
|
1074
|
-
}
|
|
1127
|
+
table: table,
|
|
1128
|
+
},
|
|
1075
1129
|
})
|
|
1076
1130
|
} else {
|
|
1077
1131
|
await connection.insert({
|
|
1078
|
-
table:
|
|
1132
|
+
table: 'zfields',
|
|
1079
1133
|
data: data,
|
|
1080
1134
|
})
|
|
1081
1135
|
}
|
|
1082
|
-
json = Util.jsonSuccess(
|
|
1136
|
+
json = Util.jsonSuccess('Success to add module, please generate tax to make a file')
|
|
1083
1137
|
}
|
|
1084
1138
|
}
|
|
1085
1139
|
} catch (e) {
|
|
1086
1140
|
console.log(e)
|
|
1087
|
-
json.message = e.toString()
|
|
1141
|
+
json.message = e.toString()
|
|
1088
1142
|
}
|
|
1089
|
-
json.table = table
|
|
1143
|
+
json.table = table
|
|
1090
1144
|
res.json(json)
|
|
1091
|
-
})
|
|
1145
|
+
})
|
|
1092
1146
|
|
|
1093
1147
|
/*
|
|
1094
1148
|
Scanning relation id to name
|
|
@@ -1096,34 +1150,34 @@ Scanning relation id to name
|
|
|
1096
1150
|
const scanning = async (MYMODEL) => {
|
|
1097
1151
|
//let MYMODEL = require(`${dirRoot}/models/${table}`);
|
|
1098
1152
|
//console.log(JSON.stringify(MYMODEL))
|
|
1099
|
-
let table = MYMODEL.table
|
|
1100
|
-
const widgets = MYMODEL.widgets
|
|
1101
|
-
const not_scanning = ['created_by', 'updated_by']
|
|
1102
|
-
const concat_bracket = /(?<=\().+?(?=\))/g
|
|
1153
|
+
let table = MYMODEL.table
|
|
1154
|
+
const widgets = MYMODEL.widgets
|
|
1155
|
+
const not_scanning = ['created_by', 'updated_by']
|
|
1156
|
+
const concat_bracket = /(?<=\().+?(?=\))/g
|
|
1103
1157
|
let changeWidgets = {}
|
|
1104
|
-
let changes = []
|
|
1158
|
+
let changes = []
|
|
1105
1159
|
for (let key in widgets) {
|
|
1106
|
-
if (widgets[key].name ==
|
|
1160
|
+
if (widgets[key].name == 'relation' || widgets[key].name == 'dropdown_multi' || widgets[key].name == 'typeahead') {
|
|
1107
1161
|
if (!Util.in_array(key, not_scanning)) {
|
|
1108
|
-
let fields = widgets[key].fields
|
|
1162
|
+
let fields = widgets[key].fields
|
|
1109
1163
|
//let concat = fields[1].indexOf('CONCAT(') > -1 ? fields[1].substring()
|
|
1110
|
-
let arr = fields[1].match(concat_bracket) || []
|
|
1164
|
+
let arr = fields[1].match(concat_bracket) || []
|
|
1111
1165
|
if (arr.length) {
|
|
1112
|
-
let str = Util.replaceAll(arr[0], '"', '')
|
|
1113
|
-
let mysplits = str.indexOf(',') > -1 ? str.split(',') : [str]
|
|
1114
|
-
let MYMODEL_TABLE = require(`${dirRoot}/models/${widgets[key].table}`)
|
|
1115
|
-
let widgetsRelations = MYMODEL_TABLE.widgets
|
|
1116
|
-
let relationsKeys = []
|
|
1166
|
+
let str = Util.replaceAll(arr[0], '"', '')
|
|
1167
|
+
let mysplits = str.indexOf(',') > -1 ? str.split(',') : [str]
|
|
1168
|
+
let MYMODEL_TABLE = require(`${dirRoot}/models/${widgets[key].table}`)
|
|
1169
|
+
let widgetsRelations = MYMODEL_TABLE.widgets
|
|
1170
|
+
let relationsKeys = []
|
|
1117
1171
|
let relationsKeysObject = {}
|
|
1118
1172
|
for (let k in widgetsRelations) {
|
|
1119
1173
|
if (widgetsRelations[k].name == 'relation') {
|
|
1120
1174
|
if (!Util.in_array(k, not_scanning)) {
|
|
1121
|
-
relationsKeys.push(k)
|
|
1175
|
+
relationsKeys.push(k)
|
|
1122
1176
|
relationsKeysObject[k] = `(SELECT ${widgetsRelations[k].fields[1]} FROM ${widgetsRelations[k].table} where id = `
|
|
1123
1177
|
}
|
|
1124
1178
|
}
|
|
1125
1179
|
}
|
|
1126
|
-
let myarr = []
|
|
1180
|
+
let myarr = []
|
|
1127
1181
|
mysplits.forEach(function (item) {
|
|
1128
1182
|
if (Util.in_array(item, relationsKeys)) {
|
|
1129
1183
|
changes.push(key)
|
|
@@ -1131,9 +1185,9 @@ const scanning = async (MYMODEL) => {
|
|
|
1131
1185
|
} else {
|
|
1132
1186
|
myarr.push(item)
|
|
1133
1187
|
}
|
|
1134
|
-
})
|
|
1135
|
-
let myjoin = `CONCAT(${myarr.join(',')})
|
|
1136
|
-
widgets[key].fields = ['id', myjoin]
|
|
1188
|
+
})
|
|
1189
|
+
let myjoin = `CONCAT(${myarr.join(',')})`
|
|
1190
|
+
widgets[key].fields = ['id', myjoin]
|
|
1137
1191
|
}
|
|
1138
1192
|
}
|
|
1139
1193
|
}
|
|
@@ -1141,109 +1195,108 @@ const scanning = async (MYMODEL) => {
|
|
|
1141
1195
|
|
|
1142
1196
|
if (changes.length) {
|
|
1143
1197
|
//rewrite model
|
|
1144
|
-
MYMODEL.widgets = widgets
|
|
1145
|
-
let newModel = `module.exports = { ${Util.newLine}
|
|
1146
|
-
newModel += zRoute.buildFileModel(MYMODEL)
|
|
1147
|
-
newModel += `${Util.newLine}
|
|
1148
|
-
newModel += `}
|
|
1149
|
-
fs.writeFileSync(`${dirRoot}/models/${MYMODEL.table}.js`, newModel)
|
|
1198
|
+
MYMODEL.widgets = widgets
|
|
1199
|
+
let newModel = `module.exports = { ${Util.newLine}`
|
|
1200
|
+
newModel += zRoute.buildFileModel(MYMODEL)
|
|
1201
|
+
newModel += `${Util.newLine}`
|
|
1202
|
+
newModel += `}`
|
|
1203
|
+
fs.writeFileSync(`${dirRoot}/models/${MYMODEL.table}.js`, newModel)
|
|
1150
1204
|
}
|
|
1151
1205
|
|
|
1152
1206
|
//return MYMODEL;
|
|
1153
|
-
}
|
|
1207
|
+
}
|
|
1154
1208
|
|
|
1155
1209
|
//generate all css/js assets
|
|
1156
1210
|
router.post('/generate-assets', async (req, res) => {
|
|
1157
|
-
let notifObj = Util.jsonSuccess(
|
|
1211
|
+
let notifObj = Util.jsonSuccess('Success, generate all assets')
|
|
1158
1212
|
try {
|
|
1159
|
-
let MYMODELS = zRoute.MYMODELS()
|
|
1160
|
-
delete MYMODELS.zrole
|
|
1213
|
+
let MYMODELS = zRoute.MYMODELS()
|
|
1214
|
+
delete MYMODELS.zrole
|
|
1161
1215
|
for (let key in MYMODELS) {
|
|
1162
|
-
let MYMODEL = MYMODELS[key]
|
|
1163
|
-
let table = MYMODEL.table
|
|
1164
|
-
let path_script = `${dirRoot}/public/runtime/script/${table}
|
|
1165
|
-
Util.dirExist(path_script, true)
|
|
1166
|
-
let path_head = `${dirRoot}/public/runtime/head/${table}
|
|
1167
|
-
Util.dirExist(path_head, true)
|
|
1168
|
-
let path_end = `${dirRoot}/public/runtime/end/${table}
|
|
1169
|
-
Util.dirExist(path_end, true)
|
|
1216
|
+
let MYMODEL = MYMODELS[key]
|
|
1217
|
+
let table = MYMODEL.table
|
|
1218
|
+
let path_script = `${dirRoot}/public/runtime/script/${table}`
|
|
1219
|
+
Util.dirExist(path_script, true)
|
|
1220
|
+
let path_head = `${dirRoot}/public/runtime/head/${table}`
|
|
1221
|
+
Util.dirExist(path_head, true)
|
|
1222
|
+
let path_end = `${dirRoot}/public/runtime/end/${table}`
|
|
1223
|
+
Util.dirExist(path_end, true)
|
|
1170
1224
|
//we need to generate javascript code into runtime
|
|
1171
|
-
let relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
1225
|
+
let relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
1172
1226
|
//add script
|
|
1173
|
-
let jsObj = zRoute.generateJS(req, res, MYMODEL, relations)
|
|
1174
|
-
let time = new Date().getTime()
|
|
1175
|
-
Util.deleteAllFiles(path_head)
|
|
1176
|
-
Util.deleteAllFiles(path_end)
|
|
1177
|
-
Util.deleteAllFiles(path_script)
|
|
1227
|
+
let jsObj = zRoute.generateJS(req, res, MYMODEL, relations)
|
|
1228
|
+
let time = new Date().getTime()
|
|
1229
|
+
Util.deleteAllFiles(path_head)
|
|
1230
|
+
Util.deleteAllFiles(path_end)
|
|
1231
|
+
Util.deleteAllFiles(path_script)
|
|
1178
1232
|
|
|
1179
1233
|
//minify script
|
|
1180
|
-
let script = uglifyJS.minify(jsObj.script)
|
|
1181
|
-
if (script.error) throw script.error
|
|
1182
|
-
Util.writeFile(`${path_script}/${time}.js`, script.code)
|
|
1183
|
-
Util.writeFile(`${path_head}/head.txt`, jsObj.head)
|
|
1184
|
-
Util.writeFile(`${path_end}/end.txt`, jsObj.end)
|
|
1234
|
+
let script = uglifyJS.minify(jsObj.script)
|
|
1235
|
+
if (script.error) throw script.error
|
|
1236
|
+
Util.writeFile(`${path_script}/${time}.js`, script.code)
|
|
1237
|
+
Util.writeFile(`${path_head}/head.txt`, jsObj.head)
|
|
1238
|
+
Util.writeFile(`${path_end}/end.txt`, jsObj.end)
|
|
1185
1239
|
}
|
|
1186
1240
|
} catch (e) {
|
|
1187
|
-
notifObj = Util.flashError(e.toString())
|
|
1241
|
+
notifObj = Util.flashError(e.toString())
|
|
1188
1242
|
}
|
|
1189
|
-
res.json(notifObj)
|
|
1190
|
-
})
|
|
1191
|
-
|
|
1243
|
+
res.json(notifObj)
|
|
1244
|
+
})
|
|
1192
1245
|
|
|
1193
1246
|
router.post('/minify', async (req, res) => {
|
|
1194
|
-
let notifyObj = Util.jsonSuccess(
|
|
1247
|
+
let notifyObj = Util.jsonSuccess('Success to cached')
|
|
1195
1248
|
try {
|
|
1196
|
-
notifyObj = await viewsMini()
|
|
1249
|
+
notifyObj = await viewsMini()
|
|
1197
1250
|
} catch (e) {
|
|
1198
|
-
console.log(e)
|
|
1251
|
+
console.log(e)
|
|
1199
1252
|
notifyObj = Util.flashError(e.toString())
|
|
1200
1253
|
}
|
|
1201
|
-
res.json(notifyObj)
|
|
1202
|
-
})
|
|
1254
|
+
res.json(notifyObj)
|
|
1255
|
+
})
|
|
1203
1256
|
|
|
1204
1257
|
const viewsMini = async () => {
|
|
1205
|
-
let notifyObj = Util.jsonSuccess(
|
|
1206
|
-
const viewDir = `${dirRoot}/views
|
|
1207
|
-
const layoutsDir = `${dirRoot}/views/layouts
|
|
1208
|
-
let item
|
|
1258
|
+
let notifyObj = Util.jsonSuccess('Success')
|
|
1259
|
+
const viewDir = `${dirRoot}/views`
|
|
1260
|
+
const layoutsDir = `${dirRoot}/views/layouts`
|
|
1261
|
+
let item
|
|
1209
1262
|
try {
|
|
1210
|
-
let views = Util.getAllFiles(viewDir)
|
|
1263
|
+
let views = Util.getAllFiles(viewDir)
|
|
1211
1264
|
let options = {
|
|
1212
1265
|
minifyJS: true,
|
|
1213
1266
|
minifyCSS: true,
|
|
1214
|
-
collapseWhitespace: true
|
|
1215
|
-
}
|
|
1216
|
-
const notViewDir = ['zgenerator', 'layouts', 'index', 'zindex']
|
|
1267
|
+
collapseWhitespace: true,
|
|
1268
|
+
}
|
|
1269
|
+
const notViewDir = ['zgenerator', 'layouts', 'index', 'zindex']
|
|
1217
1270
|
for (const dir of views) {
|
|
1218
|
-
console.log('dir :', dir)
|
|
1271
|
+
console.log('dir :', dir)
|
|
1219
1272
|
if (!Util.in_array(dir, notViewDir)) {
|
|
1220
|
-
let files = Util.getAllFiles(`${viewDir}/${dir}`)
|
|
1273
|
+
let files = Util.getAllFiles(`${viewDir}/${dir}`)
|
|
1221
1274
|
//console.log(files);
|
|
1222
1275
|
for (item of files) {
|
|
1223
1276
|
if (item.includes('.ejs')) {
|
|
1224
|
-
let filename = `${viewDir}/${dir}/${item}
|
|
1225
|
-
let content = Util.readFile(filename)
|
|
1226
|
-
let contentChange = await minify(content, options)
|
|
1227
|
-
fs.writeFileSync(filename, contentChange)
|
|
1277
|
+
let filename = `${viewDir}/${dir}/${item}`
|
|
1278
|
+
let content = Util.readFile(filename)
|
|
1279
|
+
let contentChange = await minify(content, options)
|
|
1280
|
+
fs.writeFileSync(filename, contentChange)
|
|
1228
1281
|
}
|
|
1229
1282
|
}
|
|
1230
1283
|
}
|
|
1231
1284
|
}
|
|
1232
1285
|
|
|
1233
|
-
let layouts = Util.getAllFiles(layoutsDir)
|
|
1286
|
+
let layouts = Util.getAllFiles(layoutsDir)
|
|
1234
1287
|
for (item of layouts) {
|
|
1235
1288
|
if (item.includes('.ejs')) {
|
|
1236
|
-
let filename = `${layoutsDir}//${item}
|
|
1237
|
-
let content = Util.readFile(filename)
|
|
1238
|
-
let contentChange = await minify(content, options)
|
|
1239
|
-
fs.writeFileSync(filename, contentChange)
|
|
1289
|
+
let filename = `${layoutsDir}//${item}`
|
|
1290
|
+
let content = Util.readFile(filename)
|
|
1291
|
+
let contentChange = await minify(content, options)
|
|
1292
|
+
fs.writeFileSync(filename, contentChange)
|
|
1240
1293
|
}
|
|
1241
1294
|
}
|
|
1242
1295
|
} catch (e) {
|
|
1243
|
-
notifyObj = Util.flashError(`error in item : ${item} , error str :${e.toString()}`)
|
|
1296
|
+
notifyObj = Util.flashError(`error in item : ${item} , error str :${e.toString()}`)
|
|
1244
1297
|
}
|
|
1245
|
-
return notifyObj
|
|
1246
|
-
}
|
|
1298
|
+
return notifyObj
|
|
1299
|
+
}
|
|
1247
1300
|
|
|
1248
1301
|
const body = `<section class="mt-4">
|
|
1249
1302
|
<!--Grid row-->
|
|
@@ -1297,7 +1350,7 @@ const body = `<section class="mt-4">
|
|
|
1297
1350
|
</div>
|
|
1298
1351
|
</div>
|
|
1299
1352
|
</div>
|
|
1300
|
-
<div id="tabs"></div>
|
|
1353
|
+
<div class="storetabs"><ul id="tabs" class="sortable-list"></ul></div>
|
|
1301
1354
|
<%} %>
|
|
1302
1355
|
|
|
1303
1356
|
<%if(lock==0) {%>
|
|
@@ -1771,6 +1824,6 @@ const body = `<section class="mt-4">
|
|
|
1771
1824
|
</div>
|
|
1772
1825
|
</div>
|
|
1773
1826
|
</div>
|
|
1774
|
-
|
|
1827
|
+
`
|
|
1775
1828
|
|
|
1776
|
-
module.exports = router
|
|
1829
|
+
module.exports = router
|