zet-lib 1.2.78 → 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 +25 -0
- package/lib/moduleLib.js +15 -0
- package/lib/zAppRouter.js +57 -5
- package/lib/zRoute.js +85 -4
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -448,6 +448,31 @@ Form.field = (obj) => {
|
|
|
448
448
|
displayForm = obj.html
|
|
449
449
|
break
|
|
450
450
|
|
|
451
|
+
case 'dropzone':
|
|
452
|
+
displayForm = `${prepend}<div ${tabindex} ${style} type="text" ${classview} ${id} ${htmlOptions}><label for="files" class="dropzone-container">
|
|
453
|
+
<div class="dz-message" data-dz-message><div class="file-icon"><span class="icon-small icons-primary"><img class="icons-bg-white icon-image-large" src="/assets/icons/file-plus.svg"></span></div>
|
|
454
|
+
<div class="text-center pt-3 px-5">
|
|
455
|
+
<p class="w-80 h5 text-dark fw-bold">Drag your documents, photos or videos here to start uploading.</p>
|
|
456
|
+
</div></div>
|
|
457
|
+
</label></div>${information}${append}`
|
|
458
|
+
break
|
|
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
|
|
451
476
|
default:
|
|
452
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}`
|
|
453
478
|
break
|
package/lib/moduleLib.js
CHANGED
|
@@ -63,6 +63,21 @@ m.datepicker = function (req, res, elem) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
//module for dropzone
|
|
67
|
+
m.dropzone = function (req, res, elem) {
|
|
68
|
+
let script = ''
|
|
69
|
+
let head = ``
|
|
70
|
+
let end = ``
|
|
71
|
+
elem = elem || '.dropzone'
|
|
72
|
+
head += '<link href="/modules/dropzone/dropzone.css" rel="stylesheet">'
|
|
73
|
+
end += '<script src="/modules/dropzone/dropzone.min.js"></script>'
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
head: head,
|
|
77
|
+
end: end,
|
|
78
|
+
script: script,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
66
81
|
//module for datepicker
|
|
67
82
|
m.datetimepicker = function (req, res, elem) {
|
|
68
83
|
let script = ''
|
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]
|
|
@@ -2308,6 +2309,10 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2308
2309
|
case 'email':
|
|
2309
2310
|
obj.type = 'email'
|
|
2310
2311
|
break
|
|
2312
|
+
case 'dropzone':
|
|
2313
|
+
obj.type = 'dropzone'
|
|
2314
|
+
obj.class = 'dropzone boxy-tiny d-block'
|
|
2315
|
+
break
|
|
2311
2316
|
case 'lexical':
|
|
2312
2317
|
obj.type = 'lexical'
|
|
2313
2318
|
if (obj.value) {
|
|
@@ -2666,6 +2671,13 @@ zRoute.viewForm = (req, res, MYMODEL, relations, data = {}, MODEL_TABLE = {}, ke
|
|
|
2666
2671
|
obj[key].type = 'text'
|
|
2667
2672
|
obj[key].value = relations[key + 'Object'][data[key]] || ''
|
|
2668
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
|
|
2669
2681
|
}
|
|
2670
2682
|
}
|
|
2671
2683
|
//forms.build[key] = cForm.build(obj[key]);
|
|
@@ -2985,6 +2997,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2985
2997
|
let hasClockPicker = false
|
|
2986
2998
|
let hasEditor = false
|
|
2987
2999
|
let hasDateTimePicker = false
|
|
3000
|
+
let hasDropzone = false
|
|
3001
|
+
let dropzones = []
|
|
2988
3002
|
let hasTable = false
|
|
2989
3003
|
let chainsObj = {}
|
|
2990
3004
|
let chainsArr = []
|
|
@@ -3034,6 +3048,9 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3034
3048
|
lexicals.push(key)
|
|
3035
3049
|
} else if (widgets[key].name == 'tinymce') {
|
|
3036
3050
|
hasTinymce = true
|
|
3051
|
+
} else if (widgets[key].name == 'dropzone') {
|
|
3052
|
+
hasDropzone = true
|
|
3053
|
+
dropzones.push(key)
|
|
3037
3054
|
}
|
|
3038
3055
|
// has chains
|
|
3039
3056
|
if (widgets[key].name == 'relation') {
|
|
@@ -3067,6 +3084,12 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3067
3084
|
headObj.clockpicker = clockpickerObj.head
|
|
3068
3085
|
endObj.clockpicker = clockpickerObj.end
|
|
3069
3086
|
}
|
|
3087
|
+
if (hasDropzone) {
|
|
3088
|
+
let dropzoneObj = moduleLib.dropzone(req, res)
|
|
3089
|
+
headObj.dropzone = dropzoneObj.head
|
|
3090
|
+
endObj.dropzone = dropzoneObj.end
|
|
3091
|
+
scriptForm += `Dropzone.autoDiscover = false;`
|
|
3092
|
+
}
|
|
3070
3093
|
if (hasEditor) {
|
|
3071
3094
|
let editorObj = moduleLib.editor(req, res)
|
|
3072
3095
|
scriptForm += editorObj.script
|
|
@@ -3156,11 +3179,36 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3156
3179
|
}
|
|
3157
3180
|
})
|
|
3158
3181
|
});
|
|
3159
|
-
})
|
|
3160
|
-
|
|
3182
|
+
});
|
|
3183
|
+
|
|
3161
3184
|
`
|
|
3162
3185
|
}
|
|
3163
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
|
+
|
|
3164
3212
|
defaultScript = `${Util.newLine} $(function () {
|
|
3165
3213
|
$(".isfile").each(function (index, value) {
|
|
3166
3214
|
let filename = $(this).attr("data-filename") || "";
|
|
@@ -3455,12 +3503,43 @@ zRoute.insertSQL = async (req, res, table, data) => {
|
|
|
3455
3503
|
const MYMODELS = myCache.get('MYMODELS')
|
|
3456
3504
|
let MYMODEL = MYMODELS[table]
|
|
3457
3505
|
let fields = MYMODEL.keys
|
|
3506
|
+
let userId = res.locals.userId || 1
|
|
3458
3507
|
if (fields.includes('company_id')) data.company_id = res.locals.companyId || 1
|
|
3459
3508
|
if (fields.includes('updated_at')) data.updated_at = Util.now()
|
|
3460
3509
|
if (fields.includes('created_at')) data.created_at = Util.now()
|
|
3461
|
-
if (fields.includes('updated_by')) data.updated_by =
|
|
3462
|
-
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
|
|
3463
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
|
+
}
|
|
3464
3543
|
const result = await connection.insert({ table: table, data: data })
|
|
3465
3544
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|
|
3466
3545
|
return result
|
|
@@ -3523,6 +3602,8 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3523
3602
|
delete data.created_at
|
|
3524
3603
|
delete data.created_by
|
|
3525
3604
|
delete data.lock
|
|
3605
|
+
delete data.approval_status
|
|
3606
|
+
delete data.approval_history
|
|
3526
3607
|
if (result.lock != 1) {
|
|
3527
3608
|
const myresult = await connection.update({ table: table, where: whereData, data: data })
|
|
3528
3609
|
zRoute.modelsCacheRenew(table, res.locals.companyId)
|