zet-lib 1.2.81 → 1.2.82
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 +1 -1
- package/lib/zAppRouter.js +16 -13
- package/lib/zRoute.js +45 -10
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -466,7 +466,7 @@ Form.field = (obj) => {
|
|
|
466
466
|
if (extFile.type == 'image') {
|
|
467
467
|
displayForm += `<img src="${filename}" class="boxy zoom mx-2 my-2" width="200px">`
|
|
468
468
|
} else {
|
|
469
|
-
displayForm += Util.fileView(`/uploads/${obj.table}/${obj.key}/`,
|
|
469
|
+
displayForm += Util.fileView(`/uploads/${obj.table}/${obj.key}/`, item, { withIcon: true })
|
|
470
470
|
}
|
|
471
471
|
})
|
|
472
472
|
}
|
package/lib/zAppRouter.js
CHANGED
|
@@ -1510,14 +1510,13 @@ router.post('/zdropzone', async (req, res) => {
|
|
|
1510
1510
|
let userId = res.locals.userId
|
|
1511
1511
|
if (userId) {
|
|
1512
1512
|
let dir = `${dirRoot}/public/zdropzone/${userId}`
|
|
1513
|
-
if (!fs.existsSync(dir)){
|
|
1514
|
-
fs.mkdirSync(dir,{ recursive: true })
|
|
1513
|
+
if (!fs.existsSync(dir)) {
|
|
1514
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
1515
1515
|
}
|
|
1516
1516
|
let filename = req.files.file.name
|
|
1517
1517
|
req.files.file.mv(dir + '/' + filename, function (err) {
|
|
1518
1518
|
if (err) {
|
|
1519
|
-
|
|
1520
|
-
return res.status(500).send(err+'')
|
|
1519
|
+
return res.status(500).send(err + '')
|
|
1521
1520
|
}
|
|
1522
1521
|
})
|
|
1523
1522
|
}
|
|
@@ -1525,22 +1524,22 @@ router.post('/zdropzone', async (req, res) => {
|
|
|
1525
1524
|
} catch (e) {
|
|
1526
1525
|
console.log(e)
|
|
1527
1526
|
res.status(500)
|
|
1528
|
-
res.send(e+'')
|
|
1527
|
+
res.send(e + '')
|
|
1529
1528
|
}
|
|
1530
1529
|
})
|
|
1531
1530
|
|
|
1532
1531
|
router.post('/zdropzone-remove', async (req, res) => {
|
|
1533
1532
|
try {
|
|
1534
1533
|
let userId = res.locals.userId
|
|
1535
|
-
|
|
1534
|
+
console.log(req.body)
|
|
1536
1535
|
let filename = `${dirRoot}/public/zdropzone/${userId}/${req.body.file}`
|
|
1537
|
-
if(Util.fileExist(filename)) {
|
|
1536
|
+
if (Util.fileExist(filename)) {
|
|
1538
1537
|
await fs.unlink(filename)
|
|
1539
1538
|
}
|
|
1540
1539
|
res.json('ok')
|
|
1541
1540
|
} catch (e) {
|
|
1542
1541
|
console.log(e)
|
|
1543
|
-
res.status(500).send(e+'')
|
|
1542
|
+
res.status(500).send(e + '')
|
|
1544
1543
|
}
|
|
1545
1544
|
})
|
|
1546
1545
|
router.post('/zdropzone-attributes', async (req, res) => {
|
|
@@ -1550,19 +1549,23 @@ router.post('/zdropzone-attributes', async (req, res) => {
|
|
|
1550
1549
|
let category = body.category
|
|
1551
1550
|
let name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1552
1551
|
let arr = []
|
|
1553
|
-
if (myCache.has(name)) {
|
|
1554
|
-
arr = myCache.get(name)
|
|
1555
|
-
}
|
|
1556
1552
|
if (category === 'add') {
|
|
1553
|
+
if (myCache.has(name)) {
|
|
1554
|
+
arr = myCache.get(name)
|
|
1555
|
+
}
|
|
1557
1556
|
arr.push(body.file)
|
|
1558
1557
|
} else {
|
|
1559
|
-
|
|
1558
|
+
name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1559
|
+
if (myCache.has(name)) {
|
|
1560
|
+
arr = myCache.get(name)
|
|
1561
|
+
}
|
|
1562
|
+
arr = Util.arrayDelete(arr, body.file)
|
|
1560
1563
|
}
|
|
1561
1564
|
myCache.set(name, arr)
|
|
1562
1565
|
res.json('ok')
|
|
1563
1566
|
} catch (e) {
|
|
1564
1567
|
console.log(e)
|
|
1565
|
-
res.status(500).send(e+'')
|
|
1568
|
+
res.status(500).send(e + '')
|
|
1566
1569
|
}
|
|
1567
1570
|
})
|
|
1568
1571
|
|
package/lib/zRoute.js
CHANGED
|
@@ -2310,10 +2310,17 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2310
2310
|
obj.type = 'email'
|
|
2311
2311
|
break
|
|
2312
2312
|
case 'dropzone':
|
|
2313
|
-
|
|
2313
|
+
let dropzone_data_arr = []
|
|
2314
|
+
if (obj.value.length > 0) {
|
|
2315
|
+
obj.value.map((item) => {
|
|
2316
|
+
let filename = `${dirRoot}/public/uploads/${MYMODEL.table}/${key}/${item}`
|
|
2317
|
+
var stats = fs.statSync(filename)
|
|
2318
|
+
var fileSizeInBytes = stats.size
|
|
2319
|
+
dropzone_data_arr.push({ fileName: item, size: fileSizeInBytes })
|
|
2320
|
+
})
|
|
2314
2321
|
myCache.set(`dropzone__${res.locals.userId}__${MYMODEL.table}__${key}__${data.id}`, obj.value)
|
|
2315
2322
|
}
|
|
2316
|
-
let dropzoneValue = obj.value.length > 0 ? JSON.stringify(
|
|
2323
|
+
let dropzoneValue = obj.value.length > 0 ? JSON.stringify(dropzone_data_arr) : '[]'
|
|
2317
2324
|
script += `let dropzone_${key}_data = ${dropzoneValue};`
|
|
2318
2325
|
obj.type = 'dropzone'
|
|
2319
2326
|
obj.class = 'dropzone boxy-tiny d-block'
|
|
@@ -3208,18 +3215,19 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3208
3215
|
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3209
3216
|
});
|
|
3210
3217
|
dz.on("removedfile", function(file) {
|
|
3211
|
-
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
3218
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {});
|
|
3219
|
+
$("div#${item}").find(".dz-message").remove();
|
|
3212
3220
|
});
|
|
3213
3221
|
if(dropzone_${item}_data.length > 0) {
|
|
3214
3222
|
dropzone_${item}_data.map((item) => {
|
|
3215
3223
|
const mockFile = {
|
|
3216
|
-
name: item,
|
|
3224
|
+
name: item.fileName,
|
|
3217
3225
|
id: item,
|
|
3218
|
-
size:
|
|
3226
|
+
size: item.size,
|
|
3219
3227
|
accepted:true
|
|
3220
3228
|
};
|
|
3221
3229
|
dz.options.addedfile.call(dz, mockFile);
|
|
3222
|
-
dz.options.thumbnail.call(dz, mockFile, "${process.env.APP_URL}/uploads/${MYMODEL.table}/${item}/"+item);
|
|
3230
|
+
dz.options.thumbnail.call(dz, mockFile, "${process.env.APP_URL}/uploads/${MYMODEL.table}/${item}/"+item.fileName);
|
|
3223
3231
|
})
|
|
3224
3232
|
};
|
|
3225
3233
|
}
|
|
@@ -3538,9 +3546,9 @@ zRoute.insertSQL = async (req, res, table, data) => {
|
|
|
3538
3546
|
//console.log('has dropzone')
|
|
3539
3547
|
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3540
3548
|
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.routeName + '/' + key + '/'
|
|
3541
|
-
fs.
|
|
3542
|
-
|
|
3543
|
-
}
|
|
3549
|
+
if (!fs.existsSync(path_dest)) {
|
|
3550
|
+
fs.mkdirSync(path_dest, { recursive: true })
|
|
3551
|
+
}
|
|
3544
3552
|
let name = `dropzone__${res.locals.userId}__${table}__${key}__create`
|
|
3545
3553
|
if (myCache.has(name)) {
|
|
3546
3554
|
let arr = myCache.get(name)
|
|
@@ -3567,11 +3575,12 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3567
3575
|
const MYMODELS = myCache.get('MYMODELS')
|
|
3568
3576
|
let MYMODEL = MYMODELS[table]
|
|
3569
3577
|
let fields = MYMODEL.keys
|
|
3578
|
+
const userId = res.locals.userId
|
|
3570
3579
|
if (fields.includes('updated_at')) {
|
|
3571
3580
|
data.updated_at = Util.now()
|
|
3572
3581
|
}
|
|
3573
3582
|
if (fields.includes('updated_by')) {
|
|
3574
|
-
data.updated_by =
|
|
3583
|
+
data.updated_by = userId
|
|
3575
3584
|
}
|
|
3576
3585
|
//check if has table and image/file
|
|
3577
3586
|
let hasImages = false
|
|
@@ -3589,6 +3598,32 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
3589
3598
|
}
|
|
3590
3599
|
}
|
|
3591
3600
|
}
|
|
3601
|
+
if (MYMODEL.widgets[key].name === 'dropzone') {
|
|
3602
|
+
//console.log('has dropzone')
|
|
3603
|
+
let path_src = dirRoot + '/public/zdropzone/' + userId + '/'
|
|
3604
|
+
let path_dest = dirRoot + '/public/uploads/' + MYMODEL.table + '/' + key + '/'
|
|
3605
|
+
if (!fs.existsSync(path_dest)) {
|
|
3606
|
+
fs.mkdirSync(path_dest, { recursive: true })
|
|
3607
|
+
}
|
|
3608
|
+
let name = `dropzone__${userId}__${MYMODEL.table}__${key}__${whereData.id}`
|
|
3609
|
+
if (myCache.has(name)) {
|
|
3610
|
+
let arr = myCache.get(name)
|
|
3611
|
+
let newArr = []
|
|
3612
|
+
if (arr.length > 0) {
|
|
3613
|
+
let time = new Date().getTime()
|
|
3614
|
+
arr.map((item) => {
|
|
3615
|
+
if (!Util.fileExist(path_dest + item)) {
|
|
3616
|
+
let newItem = time + item
|
|
3617
|
+
newArr.push(newItem)
|
|
3618
|
+
fs.rename(path_src + item, path_dest + newItem)
|
|
3619
|
+
} else {
|
|
3620
|
+
newArr.push(item)
|
|
3621
|
+
}
|
|
3622
|
+
})
|
|
3623
|
+
data[key] = Util.array_to_jsonb(newArr)
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3592
3627
|
}
|
|
3593
3628
|
let result = await connection.result({
|
|
3594
3629
|
table: MYMODEL.table,
|