zet-lib 1.2.81 → 1.2.83
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 +23 -13
- package/lib/zRoute.js +45 -10
- package/lib/zdataTable.js +0 -2
- 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,44 +1524,55 @@ 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
|
+
let dir = `${dirRoot}/public/zdropzone/${userId}`
|
|
1535
|
+
if (!fs.existsSync(dir)) {
|
|
1536
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
1537
|
+
}
|
|
1536
1538
|
let filename = `${dirRoot}/public/zdropzone/${userId}/${req.body.file}`
|
|
1537
|
-
if(Util.fileExist(filename)) {
|
|
1539
|
+
if (Util.fileExist(filename)) {
|
|
1538
1540
|
await fs.unlink(filename)
|
|
1539
1541
|
}
|
|
1540
1542
|
res.json('ok')
|
|
1541
1543
|
} catch (e) {
|
|
1542
1544
|
console.log(e)
|
|
1543
|
-
res.status(500).send(e+'')
|
|
1545
|
+
res.status(500).send(e + '')
|
|
1544
1546
|
}
|
|
1545
1547
|
})
|
|
1546
1548
|
router.post('/zdropzone-attributes', async (req, res) => {
|
|
1547
1549
|
try {
|
|
1548
1550
|
let userId = res.locals.userId
|
|
1551
|
+
let dir = `${dirRoot}/public/zdropzone/${userId}`
|
|
1552
|
+
if (!fs.existsSync(dir)) {
|
|
1553
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
1554
|
+
}
|
|
1549
1555
|
let body = req.body
|
|
1550
1556
|
let category = body.category
|
|
1551
1557
|
let name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1552
1558
|
let arr = []
|
|
1553
|
-
if (myCache.has(name)) {
|
|
1554
|
-
arr = myCache.get(name)
|
|
1555
|
-
}
|
|
1556
1559
|
if (category === 'add') {
|
|
1560
|
+
if (myCache.has(name)) {
|
|
1561
|
+
arr = myCache.get(name)
|
|
1562
|
+
}
|
|
1557
1563
|
arr.push(body.file)
|
|
1558
1564
|
} else {
|
|
1559
|
-
|
|
1565
|
+
name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
|
|
1566
|
+
if (myCache.has(name)) {
|
|
1567
|
+
arr = myCache.get(name)
|
|
1568
|
+
}
|
|
1569
|
+
arr = Util.arrayDelete(arr, body.file)
|
|
1560
1570
|
}
|
|
1561
1571
|
myCache.set(name, arr)
|
|
1562
1572
|
res.json('ok')
|
|
1563
1573
|
} catch (e) {
|
|
1564
1574
|
console.log(e)
|
|
1565
|
-
res.status(500).send(e+'')
|
|
1575
|
+
res.status(500).send(e + '')
|
|
1566
1576
|
}
|
|
1567
1577
|
})
|
|
1568
1578
|
|
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,
|
package/lib/zdataTable.js
CHANGED
|
@@ -194,10 +194,8 @@ class dataTable {
|
|
|
194
194
|
if (this.hasLevels) {
|
|
195
195
|
//modal-body-approval
|
|
196
196
|
let APPROVAL_LEVELS = myCache.get('APPROVAL_LEVELS')
|
|
197
|
-
console.log(APPROVAL_LEVELS)
|
|
198
197
|
let approvalButtonHtml = ``
|
|
199
198
|
for (let item in this.level_approval) {
|
|
200
|
-
console.log(item)
|
|
201
199
|
let imageapproval = 'brand-bunpo'
|
|
202
200
|
if (item == 22) {
|
|
203
201
|
imageapproval = 'rubber-stamp-off'
|