zet-lib 1.2.49 → 1.2.51
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/Util.js +14 -0
- package/lib/index.js +1 -0
- package/lib/moduleLib.js +1 -1
- package/lib/zRoute.js +23 -26
- package/package.json +2 -1
package/lib/Util.js
CHANGED
|
@@ -923,6 +923,20 @@ Util.isInteger = (value) => {
|
|
|
923
923
|
)
|
|
924
924
|
}
|
|
925
925
|
|
|
926
|
+
Util.isEmptyArray = (arr = []) => {
|
|
927
|
+
let isArr = false
|
|
928
|
+
if (Array.isArray(arr)) {
|
|
929
|
+
if (arr.length === 0) {
|
|
930
|
+
isArr = true
|
|
931
|
+
} else {
|
|
932
|
+
isArr = arr.reduce((a, b) => (b === null ? a + 0 : a + 1), 0) === 0
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
isArr = true
|
|
936
|
+
}
|
|
937
|
+
return isArr
|
|
938
|
+
}
|
|
939
|
+
|
|
926
940
|
Util.isNumeric = function (value) {
|
|
927
941
|
return /^-?\d+$/.test(value)
|
|
928
942
|
}
|
package/lib/index.js
CHANGED
package/lib/moduleLib.js
CHANGED
|
@@ -448,7 +448,7 @@ m.highlight = (req, res, elem) => {
|
|
|
448
448
|
let head = res.locals.moduleHead
|
|
449
449
|
let end = res.locals.moduleEnd
|
|
450
450
|
if (head.indexOf('highlight') < 0) {
|
|
451
|
-
head += '<link rel="stylesheet" href="/modules/highlight/
|
|
451
|
+
head += '<link rel="stylesheet" href="/modules/highlight/default.min.css"> ' + newLine
|
|
452
452
|
end += '<script src="/modules/highlight/highlight.min.js"></script>' + newLine
|
|
453
453
|
}
|
|
454
454
|
end += '<script>$(function(){ document.querySelectorAll("' + elem + '").forEach((block) => {hljs.highlightBlock(block);}); })</script>' + newLine
|
package/lib/zRoute.js
CHANGED
|
@@ -19,6 +19,7 @@ const moment = require('moment')
|
|
|
19
19
|
const debug = require('./debug')
|
|
20
20
|
const moduleLib = require('./moduleLib')
|
|
21
21
|
const cForm = require('./Form')
|
|
22
|
+
const readXlsxFile = require('read-excel-file/node')
|
|
22
23
|
|
|
23
24
|
const zRoute = {}
|
|
24
25
|
|
|
@@ -3487,33 +3488,26 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3487
3488
|
}
|
|
3488
3489
|
await Util.moveFile(excelFile, filename)
|
|
3489
3490
|
io.to(room).emit('message', LANGUAGE['import_process'])
|
|
3490
|
-
|
|
3491
|
-
let
|
|
3492
|
-
|
|
3493
|
-
let i = 0
|
|
3494
|
-
if (i == 0) result = toJson[prop]
|
|
3495
|
-
i++
|
|
3496
|
-
}
|
|
3497
|
-
if (!result.length) {
|
|
3498
|
-
let message = 'No Data Found!!. Please uploading an excel file into 1 sheet only. Can not Multiple sheets'
|
|
3499
|
-
io.to(room).emit('message', message)
|
|
3500
|
-
res.json(Util.flashError(message))
|
|
3501
|
-
return
|
|
3502
|
-
}
|
|
3491
|
+
let results = await readXlsxFile(filename)
|
|
3492
|
+
let resultsLength = results.length
|
|
3493
|
+
let columnLength = results[1].length
|
|
3503
3494
|
//convert to table header
|
|
3504
3495
|
let hd = '<tr>'
|
|
3505
3496
|
let i = 0
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
headers.push({ i: i, prop: prop, value: result[0][prop] })
|
|
3510
|
-
i++
|
|
3511
|
-
}
|
|
3497
|
+
results[0].map((item) => {
|
|
3498
|
+
hd += `<th>${item}</th>`
|
|
3499
|
+
})
|
|
3512
3500
|
hd += `<th>${LANGUAGE['noted']}</th>`
|
|
3513
3501
|
hd += `</tr>`
|
|
3514
3502
|
|
|
3503
|
+
console.log(results)
|
|
3504
|
+
results[1].map((item, index) => {
|
|
3505
|
+
keys[index] = item
|
|
3506
|
+
})
|
|
3507
|
+
|
|
3508
|
+
console.log(keys)
|
|
3515
3509
|
let isCut = false
|
|
3516
|
-
if (
|
|
3510
|
+
if (columnLength > 20 && resultsLength > 2000) {
|
|
3517
3511
|
io.to(room).emit('message', 'short display data!')
|
|
3518
3512
|
isCut = true
|
|
3519
3513
|
}
|
|
@@ -3521,15 +3515,21 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3521
3515
|
io.to(room).emit('import', hd)
|
|
3522
3516
|
let isInsert = true
|
|
3523
3517
|
mytables += hd
|
|
3524
|
-
for (let i = 2; i <
|
|
3518
|
+
for (let i = 2; i < resultsLength; i++) {
|
|
3525
3519
|
hd = ''
|
|
3520
|
+
if (Util.isEmptyArray(results[i])) {
|
|
3521
|
+
continue
|
|
3522
|
+
}
|
|
3526
3523
|
hd += `<tr>`
|
|
3527
3524
|
const data = {}
|
|
3528
3525
|
//hd += `${i - 2}`
|
|
3529
3526
|
//column cut tidak penting hanya jika kebanyakan dipotong
|
|
3530
3527
|
let columnCut = 0
|
|
3531
|
-
|
|
3532
|
-
|
|
3528
|
+
let result = results[i]
|
|
3529
|
+
//console.log(JSON.stringify(result))
|
|
3530
|
+
for (let prop in keys) {
|
|
3531
|
+
//console.log(prop)
|
|
3532
|
+
let value = result[prop] ? result[prop] : null
|
|
3533
3533
|
if (value) {
|
|
3534
3534
|
if (aliasRelations.includes(keys[prop])) {
|
|
3535
3535
|
let result_alias = await connection.result({
|
|
@@ -3562,9 +3562,6 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3562
3562
|
if (keys[prop] == 'id') isInsert = false
|
|
3563
3563
|
columnCut++
|
|
3564
3564
|
}
|
|
3565
|
-
if (Object.keys(data).length == 0) {
|
|
3566
|
-
continue
|
|
3567
|
-
}
|
|
3568
3565
|
try {
|
|
3569
3566
|
if (isInsert) {
|
|
3570
3567
|
if (Util.in_array('company_id', fields)) data.company_id = res.locals.companyId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zet-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.51",
|
|
4
4
|
"description": "zet is a library that part of zet generator.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"puppeteer": "^21.0.1",
|
|
46
46
|
"qs": "^6.11.2",
|
|
47
47
|
"randomstring": "^1.3.0",
|
|
48
|
+
"read-excel-file": "^5.8.0",
|
|
48
49
|
"socket.io": "^4.7.5",
|
|
49
50
|
"uglify-js": "^3.17.4",
|
|
50
51
|
"uuid": "^9.0.1",
|