zet-lib 1.2.79 → 1.2.80
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 +57 -5
- package/lib/zRoute.js +73 -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
|
|
@@ -1388,11 +1389,11 @@ router.post('/zapproval-update/:table', async (req, res) => {
|
|
|
1388
1389
|
approval_status: value,
|
|
1389
1390
|
approval_history: Util.array_to_jsonb(approval_history),
|
|
1390
1391
|
}
|
|
1391
|
-
if(+value >1 && +value <22) {
|
|
1392
|
-
mydata.lock=1
|
|
1392
|
+
if (+value > 1 && +value < 22) {
|
|
1393
|
+
mydata.lock = 1
|
|
1393
1394
|
}
|
|
1394
|
-
if(
|
|
1395
|
-
mydata.lock=0
|
|
1395
|
+
if (+value === 22) {
|
|
1396
|
+
mydata.lock = 0
|
|
1396
1397
|
}
|
|
1397
1398
|
await connection.update({
|
|
1398
1399
|
table: table,
|
|
@@ -1511,4 +1512,55 @@ router.get('/addapproval-models', async (req, res) => {
|
|
|
1511
1512
|
res.send(text)
|
|
1512
1513
|
})
|
|
1513
1514
|
|
|
1515
|
+
//post dropzone widget
|
|
1516
|
+
router.post('/zdropzone', async (req, res) => {
|
|
1517
|
+
let userId = res.locals.userId
|
|
1518
|
+
console.log(req.body)
|
|
1519
|
+
if (userId) {
|
|
1520
|
+
let dir = `${dirRoot}/public/zdropzone/${userId}`
|
|
1521
|
+
fs.ensureDir(dir, (err) => {
|
|
1522
|
+
//console.log('ensureDir',err); // => null
|
|
1523
|
+
})
|
|
1524
|
+
let filename = req.files.file.name
|
|
1525
|
+
req.files.file.mv(dir + '/' + filename, function (err) {
|
|
1526
|
+
if (err) {
|
|
1527
|
+
//console.log('fileempty move',err); // => null
|
|
1528
|
+
return res.status(500).send(err)
|
|
1529
|
+
}
|
|
1530
|
+
})
|
|
1531
|
+
}
|
|
1532
|
+
res.json('ok')
|
|
1533
|
+
})
|
|
1534
|
+
|
|
1535
|
+
router.post('/zdropzone-remove', async (req, res) => {
|
|
1536
|
+
try {
|
|
1537
|
+
let userId = res.locals.userId
|
|
1538
|
+
console.log(req.body)
|
|
1539
|
+
let filename = `${dirRoot}/public/zdropzone/${userId}/${req.body.file}`
|
|
1540
|
+
await fs.unlink(filename)
|
|
1541
|
+
} catch (e) {}
|
|
1542
|
+
res.json('ok')
|
|
1543
|
+
})
|
|
1544
|
+
router.post('/zdropzone-attributes', async (req, res) => {
|
|
1545
|
+
try {
|
|
1546
|
+
let userId = res.locals.userId
|
|
1547
|
+
let body = req.body
|
|
1548
|
+
let category = body.category
|
|
1549
|
+
let name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1550
|
+
let arr = []
|
|
1551
|
+
if (myCache.has(name)) {
|
|
1552
|
+
arr = myCache.get(name)
|
|
1553
|
+
}
|
|
1554
|
+
if (category === 'add') {
|
|
1555
|
+
arr.push(body.file)
|
|
1556
|
+
} else {
|
|
1557
|
+
Util.arrayDelete(arr, body.file)
|
|
1558
|
+
}
|
|
1559
|
+
myCache.set(name, arr)
|
|
1560
|
+
} catch (e) {
|
|
1561
|
+
console.log(e)
|
|
1562
|
+
}
|
|
1563
|
+
res.json('ok')
|
|
1564
|
+
})
|
|
1565
|
+
|
|
1514
1566
|
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]
|
|
@@ -2670,6 +2671,13 @@ zRoute.viewForm = (req, res, MYMODEL, relations, data = {}, MODEL_TABLE = {}, ke
|
|
|
2670
2671
|
obj[key].type = 'text'
|
|
2671
2672
|
obj[key].value = relations[key + 'Object'][data[key]] || ''
|
|
2672
2673
|
break
|
|
2674
|
+
|
|
2675
|
+
case 'dropzone':
|
|
2676
|
+
obj[key].type = 'dropzoneview'
|
|
2677
|
+
obj[key].value = data[key] || []
|
|
2678
|
+
obj[key].table = MYMODEL.table
|
|
2679
|
+
obj[key].key = key
|
|
2680
|
+
break
|
|
2673
2681
|
}
|
|
2674
2682
|
}
|
|
2675
2683
|
//forms.build[key] = cForm.build(obj[key]);
|
|
@@ -2990,6 +2998,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2990
2998
|
let hasEditor = false
|
|
2991
2999
|
let hasDateTimePicker = false
|
|
2992
3000
|
let hasDropzone = false
|
|
3001
|
+
let dropzones = []
|
|
2993
3002
|
let hasTable = false
|
|
2994
3003
|
let chainsObj = {}
|
|
2995
3004
|
let chainsArr = []
|
|
@@ -3041,6 +3050,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3041
3050
|
hasTinymce = true
|
|
3042
3051
|
} else if (widgets[key].name == 'dropzone') {
|
|
3043
3052
|
hasDropzone = true
|
|
3053
|
+
dropzones.push(key)
|
|
3044
3054
|
}
|
|
3045
3055
|
// has chains
|
|
3046
3056
|
if (widgets[key].name == 'relation') {
|
|
@@ -3076,9 +3086,9 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3076
3086
|
}
|
|
3077
3087
|
if (hasDropzone) {
|
|
3078
3088
|
let dropzoneObj = moduleLib.dropzone(req, res)
|
|
3079
|
-
scriptForm += dropzoneObj.script
|
|
3080
3089
|
headObj.dropzone = dropzoneObj.head
|
|
3081
3090
|
endObj.dropzone = dropzoneObj.end
|
|
3091
|
+
scriptForm += `Dropzone.autoDiscover = false;`
|
|
3082
3092
|
}
|
|
3083
3093
|
if (hasEditor) {
|
|
3084
3094
|
let editorObj = moduleLib.editor(req, res)
|
|
@@ -3169,11 +3179,36 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3169
3179
|
}
|
|
3170
3180
|
})
|
|
3171
3181
|
});
|
|
3172
|
-
})
|
|
3173
|
-
|
|
3182
|
+
});
|
|
3183
|
+
|
|
3174
3184
|
`
|
|
3175
3185
|
}
|
|
3176
3186
|
|
|
3187
|
+
if (hasDropzone) {
|
|
3188
|
+
dropzones.map((item) => {
|
|
3189
|
+
scriptForm += `$("div#${item}").dropzone({
|
|
3190
|
+
url: "/zdropzone",
|
|
3191
|
+
addRemoveLinks: !0,
|
|
3192
|
+
maxFilesize: 30,
|
|
3193
|
+
headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")},
|
|
3194
|
+
removedfile: function(file) {
|
|
3195
|
+
ajaxPost("/zdropzone-remove",{file:file.name},(data) => {
|
|
3196
|
+
file.previewElement.remove();
|
|
3197
|
+
})
|
|
3198
|
+
},
|
|
3199
|
+
init: function() {
|
|
3200
|
+
let type = window.location.href.split("/").pop();
|
|
3201
|
+
this.on("addedfile", function(file) {
|
|
3202
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3203
|
+
});
|
|
3204
|
+
this.on("removedfile", function(file) {
|
|
3205
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3206
|
+
});
|
|
3207
|
+
}
|
|
3208
|
+
}); `
|
|
3209
|
+
})
|
|
3210
|
+
}
|
|
3211
|
+
|
|
3177
3212
|
defaultScript = `${Util.newLine} $(function () {
|
|
3178
3213
|
$(".isfile").each(function (index, value) {
|
|
3179
3214
|
let filename = $(this).attr("data-filename") || "";
|
|
@@ -3468,12 +3503,43 @@ zRoute.insertSQL = async (req, res, table, data) => {
|
|
|
3468
3503
|
const MYMODELS = myCache.get('MYMODELS')
|
|
3469
3504
|
let MYMODEL = MYMODELS[table]
|
|
3470
3505
|
let fields = MYMODEL.keys
|
|
3506
|
+
let userId = res.locals.userId || 1
|
|
3471
3507
|
if (fields.includes('company_id')) data.company_id = res.locals.companyId || 1
|
|
3472
3508
|
if (fields.includes('updated_at')) data.updated_at = Util.now()
|
|
3473
3509
|
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 =
|
|
3510
|
+
if (fields.includes('updated_by')) data.updated_by = userId
|
|
3511
|
+
if (fields.includes('created_by')) data.created_by = userId
|
|
3476
3512
|
delete data.lock
|
|
3513
|
+
delete data.approval_status
|
|
3514
|
+
delete data.approval_history
|
|
3515
|
+
|
|
3516
|
+
//check dropzone
|
|
3517
|
+
let hasDropzone = false
|
|
3518
|
+
for (let key in MYMODEL.widgets) {
|
|
3519
|
+
if (MYMODEL.widgets[key].name === 'dropzone') {
|
|
3520
|
+
console.log('has dropzone')
|
|
3521
|
+
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3522
|
+
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.routeName + '/' + key + '/'
|
|
3523
|
+
fs.ensureDir(path_dest, (err) => {
|
|
3524
|
+
//console.log('ensureDir',err); // => null
|
|
3525
|
+
})
|
|
3526
|
+
let name = `dropzone__${res.locals.userId}__${table}__${key}__create`
|
|
3527
|
+
if (myCache.has(name)) {
|
|
3528
|
+
let arr = myCache.get(name)
|
|
3529
|
+
let newArr = []
|
|
3530
|
+
if (arr.length > 0) {
|
|
3531
|
+
let time = new Date().getTime()
|
|
3532
|
+
arr.map((item) => {
|
|
3533
|
+
let newItem = time + item
|
|
3534
|
+
newArr.push(newItem)
|
|
3535
|
+
fs.rename(path_src + item, path_dest + newItem)
|
|
3536
|
+
})
|
|
3537
|
+
|
|
3538
|
+
data[key] = Util.array_to_jsonb(newArr)
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3477
3543
|
const result = await connection.insert({ table: table, data: data })
|
|
3478
3544
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3479
3545
|
return result
|
|
@@ -3536,6 +3602,8 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3536
3602
|
delete data.created_at
|
|
3537
3603
|
delete data.created_by
|
|
3538
3604
|
delete data.lock
|
|
3605
|
+
delete data.approval_status
|
|
3606
|
+
delete data.approval_history
|
|
3539
3607
|
if (result.lock != 1) {
|
|
3540
3608
|
const myresult = await connection.update({ table: table, where: whereData, data: data })
|
|
3541
3609
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|