zet-lib 1.2.79 → 1.2.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/Form.js +16 -0
- package/lib/moduleLib.js +0 -1
- package/lib/zAppRouter.js +68 -13
- package/lib/zRoute.js +91 -5
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -457,6 +457,22 @@ Form.field = (obj) => {
|
|
|
457
457
|
</label></div>${information}${append}`
|
|
458
458
|
break
|
|
459
459
|
|
|
460
|
+
case 'dropzoneview':
|
|
461
|
+
displayForm = `<div class="boxy-tiny">`
|
|
462
|
+
if (obj.value && obj.value.length > 0) {
|
|
463
|
+
obj.value.map((item) => {
|
|
464
|
+
let extFile = Util.fileExtension(item)
|
|
465
|
+
let filename = `/uploads/${obj.table}/${obj.key}/${item}`
|
|
466
|
+
if (extFile.type == 'image') {
|
|
467
|
+
displayForm += `<img src="${filename}" class="boxy zoom mx-2 my-2" width="200px">`
|
|
468
|
+
} else {
|
|
469
|
+
displayForm += Util.fileView(`/uploads/${obj.table}/${obj.key}/`, filename, { withIcon: true })
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
displayForm += `</div>`
|
|
474
|
+
|
|
475
|
+
break
|
|
460
476
|
default:
|
|
461
477
|
displayForm = `${prepend}${inputGroupLeft}<input ${disabled} autocomplete="nope" autofocus="" ${readonly} ${tabindex} type="${type}" ${classview} ${id} ${name} ${placeholder} ${required} value="${value}" data-t="${value}" ${htmlOptions}>${inputGroupRight}${information}${append}`
|
|
462
478
|
break
|
package/lib/moduleLib.js
CHANGED
|
@@ -71,7 +71,6 @@ m.dropzone = function (req, res, elem) {
|
|
|
71
71
|
elem = elem || '.dropzone'
|
|
72
72
|
head += '<link href="/modules/dropzone/dropzone.css" rel="stylesheet">'
|
|
73
73
|
end += '<script src="/modules/dropzone/dropzone.min.js"></script>'
|
|
74
|
-
script = `$("div${elem}").dropzone({ url: "/zdropzone" });`
|
|
75
74
|
|
|
76
75
|
return {
|
|
77
76
|
head: head,
|
package/lib/zAppRouter.js
CHANGED
|
@@ -8,7 +8,7 @@ const access = require('./access')
|
|
|
8
8
|
const myCache = require('./cache')
|
|
9
9
|
const Util = require('./Util')
|
|
10
10
|
const moment = require('moment')
|
|
11
|
-
const fs = require('fs')
|
|
11
|
+
const fs = require('fs-extra')
|
|
12
12
|
const moduleLib = require('./moduleLib')
|
|
13
13
|
var env = process.env.NODE_ENV || 'development'
|
|
14
14
|
var ecosystem = require(`${dirRoot}/ecosystem.config.js`)
|
|
@@ -19,6 +19,7 @@ const Mail = require('./Mail')
|
|
|
19
19
|
const zCache = require('./zCache')
|
|
20
20
|
const pm2 = require('pm2')
|
|
21
21
|
const zFunction = require('./zFunction')
|
|
22
|
+
const qs = require('qs')
|
|
22
23
|
|
|
23
24
|
/*
|
|
24
25
|
ajax Post
|
|
@@ -1369,14 +1370,6 @@ router.post('/zapproval-update/:table', async (req, res) => {
|
|
|
1369
1370
|
canUpdate = false
|
|
1370
1371
|
}
|
|
1371
1372
|
}
|
|
1372
|
-
/*if (approval_history.length > 0) {
|
|
1373
|
-
let lastStatus = +approval_history[approval_history.length - 1].status
|
|
1374
|
-
canUpdate = lastStatus > +value ? false : true
|
|
1375
|
-
let history = approval_history.filter((item) => item.status == value && item.user_id == res.locals.userId)
|
|
1376
|
-
if (history.length > 0) {
|
|
1377
|
-
canUpdate = false
|
|
1378
|
-
}
|
|
1379
|
-
}*/
|
|
1380
1373
|
if (canUpdate) {
|
|
1381
1374
|
approval_history.push({
|
|
1382
1375
|
status: value,
|
|
@@ -1388,11 +1381,11 @@ router.post('/zapproval-update/:table', async (req, res) => {
|
|
|
1388
1381
|
approval_status: value,
|
|
1389
1382
|
approval_history: Util.array_to_jsonb(approval_history),
|
|
1390
1383
|
}
|
|
1391
|
-
if(+value >1 && +value <22) {
|
|
1392
|
-
mydata.lock=1
|
|
1384
|
+
if (+value > 1 && +value < 22) {
|
|
1385
|
+
mydata.lock = 1
|
|
1393
1386
|
}
|
|
1394
|
-
if(
|
|
1395
|
-
mydata.lock=0
|
|
1387
|
+
if (+value === 22) {
|
|
1388
|
+
mydata.lock = 0
|
|
1396
1389
|
}
|
|
1397
1390
|
await connection.update({
|
|
1398
1391
|
table: table,
|
|
@@ -1511,4 +1504,66 @@ router.get('/addapproval-models', async (req, res) => {
|
|
|
1511
1504
|
res.send(text)
|
|
1512
1505
|
})
|
|
1513
1506
|
|
|
1507
|
+
//post dropzone widget
|
|
1508
|
+
router.post('/zdropzone', async (req, res) => {
|
|
1509
|
+
try {
|
|
1510
|
+
let userId = res.locals.userId
|
|
1511
|
+
if (userId) {
|
|
1512
|
+
let dir = `${dirRoot}/public/zdropzone/${userId}`
|
|
1513
|
+
if (!fs.existsSync(dir)){
|
|
1514
|
+
fs.mkdirSync(dir,{ recursive: true });
|
|
1515
|
+
}
|
|
1516
|
+
let filename = req.files.file.name
|
|
1517
|
+
req.files.file.mv(dir + '/' + filename, function (err) {
|
|
1518
|
+
if (err) {
|
|
1519
|
+
//console.log('fileempty move',err); // => null
|
|
1520
|
+
return res.status(500).send(err+'')
|
|
1521
|
+
}
|
|
1522
|
+
})
|
|
1523
|
+
}
|
|
1524
|
+
res.json('ok')
|
|
1525
|
+
} catch (e) {
|
|
1526
|
+
console.log(e)
|
|
1527
|
+
res.status(500)
|
|
1528
|
+
res.send(e+'')
|
|
1529
|
+
}
|
|
1530
|
+
})
|
|
1531
|
+
|
|
1532
|
+
router.post('/zdropzone-remove', async (req, res) => {
|
|
1533
|
+
try {
|
|
1534
|
+
let userId = res.locals.userId
|
|
1535
|
+
//console.log(req.body)
|
|
1536
|
+
let filename = `${dirRoot}/public/zdropzone/${userId}/${req.body.file}`
|
|
1537
|
+
if(Util.fileExist(filename)) {
|
|
1538
|
+
await fs.unlink(filename)
|
|
1539
|
+
}
|
|
1540
|
+
res.json('ok')
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
console.log(e)
|
|
1543
|
+
res.status(500).send(e+'')
|
|
1544
|
+
}
|
|
1545
|
+
})
|
|
1546
|
+
router.post('/zdropzone-attributes', async (req, res) => {
|
|
1547
|
+
try {
|
|
1548
|
+
let userId = res.locals.userId
|
|
1549
|
+
let body = req.body
|
|
1550
|
+
let category = body.category
|
|
1551
|
+
let name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1552
|
+
let arr = []
|
|
1553
|
+
if (myCache.has(name)) {
|
|
1554
|
+
arr = myCache.get(name)
|
|
1555
|
+
}
|
|
1556
|
+
if (category === 'add') {
|
|
1557
|
+
arr.push(body.file)
|
|
1558
|
+
} else {
|
|
1559
|
+
Util.arrayDelete(arr, body.file)
|
|
1560
|
+
}
|
|
1561
|
+
myCache.set(name, arr)
|
|
1562
|
+
res.json('ok')
|
|
1563
|
+
} catch (e) {
|
|
1564
|
+
console.log(e)
|
|
1565
|
+
res.status(500).send(e+'')
|
|
1566
|
+
}
|
|
1567
|
+
})
|
|
1568
|
+
|
|
1514
1569
|
module.exports = router
|
package/lib/zRoute.js
CHANGED
|
@@ -122,6 +122,7 @@ zRoute.post = (req, res, MYMODEL, routeName, body) => {
|
|
|
122
122
|
fs.ensureDir(path_tmp, (err) => {
|
|
123
123
|
//console.log('ensureDir',err); // => null
|
|
124
124
|
})
|
|
125
|
+
|
|
125
126
|
if (!isEmptyFiles) {
|
|
126
127
|
files = qs.parse(req.files)
|
|
127
128
|
let fileRoute = files[routeName]
|
|
@@ -2309,6 +2310,11 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2309
2310
|
obj.type = 'email'
|
|
2310
2311
|
break
|
|
2311
2312
|
case 'dropzone':
|
|
2313
|
+
if(obj.value.length > 0){
|
|
2314
|
+
myCache.set(`dropzone__${res.locals.userId}__${MYMODEL.table}__${key}__${data.id}`, obj.value)
|
|
2315
|
+
}
|
|
2316
|
+
let dropzoneValue = obj.value.length > 0 ? JSON.stringify(obj.value) : '[]'
|
|
2317
|
+
script += `let dropzone_${key}_data = ${dropzoneValue};`
|
|
2312
2318
|
obj.type = 'dropzone'
|
|
2313
2319
|
obj.class = 'dropzone boxy-tiny d-block'
|
|
2314
2320
|
break
|
|
@@ -2670,6 +2676,13 @@ zRoute.viewForm = (req, res, MYMODEL, relations, data = {}, MODEL_TABLE = {}, ke
|
|
|
2670
2676
|
obj[key].type = 'text'
|
|
2671
2677
|
obj[key].value = relations[key + 'Object'][data[key]] || ''
|
|
2672
2678
|
break
|
|
2679
|
+
|
|
2680
|
+
case 'dropzone':
|
|
2681
|
+
obj[key].type = 'dropzoneview'
|
|
2682
|
+
obj[key].value = data[key] || []
|
|
2683
|
+
obj[key].table = MYMODEL.table
|
|
2684
|
+
obj[key].key = key
|
|
2685
|
+
break
|
|
2673
2686
|
}
|
|
2674
2687
|
}
|
|
2675
2688
|
//forms.build[key] = cForm.build(obj[key]);
|
|
@@ -2990,6 +3003,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2990
3003
|
let hasEditor = false
|
|
2991
3004
|
let hasDateTimePicker = false
|
|
2992
3005
|
let hasDropzone = false
|
|
3006
|
+
let dropzones = []
|
|
2993
3007
|
let hasTable = false
|
|
2994
3008
|
let chainsObj = {}
|
|
2995
3009
|
let chainsArr = []
|
|
@@ -3041,6 +3055,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3041
3055
|
hasTinymce = true
|
|
3042
3056
|
} else if (widgets[key].name == 'dropzone') {
|
|
3043
3057
|
hasDropzone = true
|
|
3058
|
+
dropzones.push(key)
|
|
3044
3059
|
}
|
|
3045
3060
|
// has chains
|
|
3046
3061
|
if (widgets[key].name == 'relation') {
|
|
@@ -3076,9 +3091,9 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3076
3091
|
}
|
|
3077
3092
|
if (hasDropzone) {
|
|
3078
3093
|
let dropzoneObj = moduleLib.dropzone(req, res)
|
|
3079
|
-
scriptForm += dropzoneObj.script
|
|
3080
3094
|
headObj.dropzone = dropzoneObj.head
|
|
3081
3095
|
endObj.dropzone = dropzoneObj.end
|
|
3096
|
+
scriptForm += `Dropzone.autoDiscover = false;`
|
|
3082
3097
|
}
|
|
3083
3098
|
if (hasEditor) {
|
|
3084
3099
|
let editorObj = moduleLib.editor(req, res)
|
|
@@ -3169,11 +3184,49 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3169
3184
|
}
|
|
3170
3185
|
})
|
|
3171
3186
|
});
|
|
3172
|
-
})
|
|
3173
|
-
|
|
3187
|
+
});
|
|
3188
|
+
|
|
3174
3189
|
`
|
|
3175
3190
|
}
|
|
3176
3191
|
|
|
3192
|
+
if (hasDropzone) {
|
|
3193
|
+
dropzones.map((item) => {
|
|
3194
|
+
scriptForm += `$("div#${item}").dropzone({
|
|
3195
|
+
url: "/zdropzone",
|
|
3196
|
+
addRemoveLinks: !0,
|
|
3197
|
+
maxFilesize: 30,
|
|
3198
|
+
headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")},
|
|
3199
|
+
removedfile: function(file) {
|
|
3200
|
+
ajaxPost("/zdropzone-remove",{file:file.name},(data) => {
|
|
3201
|
+
file.previewElement.remove();
|
|
3202
|
+
})
|
|
3203
|
+
},
|
|
3204
|
+
init: function() {
|
|
3205
|
+
let dz = this;
|
|
3206
|
+
const type = window.location.href.split("/").pop();
|
|
3207
|
+
dz.on("addedfile", function(file) {
|
|
3208
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3209
|
+
});
|
|
3210
|
+
dz.on("removedfile", function(file) {
|
|
3211
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3212
|
+
});
|
|
3213
|
+
if(dropzone_${item}_data.length > 0) {
|
|
3214
|
+
dropzone_${item}_data.map((item) => {
|
|
3215
|
+
const mockFile = {
|
|
3216
|
+
name: item,
|
|
3217
|
+
id: item,
|
|
3218
|
+
size: 12345,
|
|
3219
|
+
accepted:true
|
|
3220
|
+
};
|
|
3221
|
+
dz.options.addedfile.call(dz, mockFile);
|
|
3222
|
+
dz.options.thumbnail.call(dz, mockFile, "${process.env.APP_URL}/uploads/${MYMODEL.table}/${item}/"+item);
|
|
3223
|
+
})
|
|
3224
|
+
};
|
|
3225
|
+
}
|
|
3226
|
+
}); `
|
|
3227
|
+
})
|
|
3228
|
+
}
|
|
3229
|
+
|
|
3177
3230
|
defaultScript = `${Util.newLine} $(function () {
|
|
3178
3231
|
$(".isfile").each(function (index, value) {
|
|
3179
3232
|
let filename = $(this).attr("data-filename") || "";
|
|
@@ -3468,12 +3521,43 @@ zRoute.insertSQL = async (req, res, table, data) => {
|
|
|
3468
3521
|
const MYMODELS = myCache.get('MYMODELS')
|
|
3469
3522
|
let MYMODEL = MYMODELS[table]
|
|
3470
3523
|
let fields = MYMODEL.keys
|
|
3524
|
+
let userId = res.locals.userId || 1
|
|
3471
3525
|
if (fields.includes('company_id')) data.company_id = res.locals.companyId || 1
|
|
3472
3526
|
if (fields.includes('updated_at')) data.updated_at = Util.now()
|
|
3473
3527
|
if (fields.includes('created_at')) data.created_at = Util.now()
|
|
3474
|
-
if (fields.includes('updated_by')) data.updated_by =
|
|
3475
|
-
if (fields.includes('created_by')) data.created_by =
|
|
3528
|
+
if (fields.includes('updated_by')) data.updated_by = userId
|
|
3529
|
+
if (fields.includes('created_by')) data.created_by = userId
|
|
3476
3530
|
delete data.lock
|
|
3531
|
+
delete data.approval_status
|
|
3532
|
+
delete data.approval_history
|
|
3533
|
+
|
|
3534
|
+
//check dropzone
|
|
3535
|
+
let hasDropzone = false
|
|
3536
|
+
for (let key in MYMODEL.widgets) {
|
|
3537
|
+
if (MYMODEL.widgets[key].name === 'dropzone') {
|
|
3538
|
+
//console.log('has dropzone')
|
|
3539
|
+
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3540
|
+
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.routeName + '/' + key + '/'
|
|
3541
|
+
fs.ensureDir(path_dest, (err) => {
|
|
3542
|
+
//console.log('ensureDir',err); // => null
|
|
3543
|
+
})
|
|
3544
|
+
let name = `dropzone__${res.locals.userId}__${table}__${key}__create`
|
|
3545
|
+
if (myCache.has(name)) {
|
|
3546
|
+
let arr = myCache.get(name)
|
|
3547
|
+
let newArr = []
|
|
3548
|
+
if (arr.length > 0) {
|
|
3549
|
+
let time = new Date().getTime()
|
|
3550
|
+
arr.map((item) => {
|
|
3551
|
+
let newItem = time + item
|
|
3552
|
+
newArr.push(newItem)
|
|
3553
|
+
fs.rename(path_src + item, path_dest + newItem)
|
|
3554
|
+
})
|
|
3555
|
+
|
|
3556
|
+
data[key] = Util.array_to_jsonb(newArr)
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3477
3561
|
const result = await connection.insert({ table: table, data: data })
|
|
3478
3562
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3479
3563
|
return result
|
|
@@ -3536,6 +3620,8 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3536
3620
|
delete data.created_at
|
|
3537
3621
|
delete data.created_by
|
|
3538
3622
|
delete data.lock
|
|
3623
|
+
delete data.approval_status
|
|
3624
|
+
delete data.approval_history
|
|
3539
3625
|
if (result.lock != 1) {
|
|
3540
3626
|
const myresult = await connection.update({ table: table, where: whereData, data: data })
|
|
3541
3627
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|