zet-lib 4.0.0 → 4.0.1
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/zReport.js +43 -13
- package/lib/zRoute.js +0 -1
- package/package.json +5 -5
package/lib/zReport.js
CHANGED
|
@@ -3,7 +3,6 @@ const fs = require('fs-extra')
|
|
|
3
3
|
const nodemailer = require('nodemailer')
|
|
4
4
|
const qs = require('qs')
|
|
5
5
|
const moment = require('moment')
|
|
6
|
-
const XLSX = require('xlsx')
|
|
7
6
|
const Excel = require('exceljs')
|
|
8
7
|
const debug = require('./debug')
|
|
9
8
|
const zRoute = require('./zRoute')
|
|
@@ -25,13 +24,43 @@ if (typeof global.dirRoot === 'undefined') {
|
|
|
25
24
|
/*
|
|
26
25
|
UI For edit excel File
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
function colToLetter (col) {
|
|
28
|
+
let temp = ''
|
|
29
|
+
let n = col
|
|
30
|
+
while (n > 0) {
|
|
31
|
+
const r = (n - 1) % 26
|
|
32
|
+
temp = String.fromCharCode(65 + r) + temp
|
|
33
|
+
n = Math.floor((n - 1) / 26)
|
|
34
|
+
}
|
|
35
|
+
return temp
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function cellToPrimitive (cell) {
|
|
39
|
+
// exceljs cell.text is safest for UI display
|
|
40
|
+
if (!cell) return ''
|
|
41
|
+
if (typeof cell.text === 'string' && cell.text !== '') return cell.text
|
|
42
|
+
const v = cell.value
|
|
43
|
+
if (v == null) return ''
|
|
44
|
+
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') return v
|
|
45
|
+
if (typeof v === 'object') {
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(v, 'result')) return v.result ?? ''
|
|
47
|
+
if (Object.prototype.hasOwnProperty.call(v, 'text')) return v.text ?? ''
|
|
48
|
+
}
|
|
49
|
+
return String(v)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
zReport.reportData = async (filename, data, sessions = {}) => {
|
|
53
|
+
const workbook = new Excel.Workbook()
|
|
54
|
+
await workbook.xlsx.readFile(filename)
|
|
55
|
+
const worksheet = workbook.worksheets[0]
|
|
56
|
+
if (!worksheet) {
|
|
57
|
+
throw new Error('Excel worksheet not found')
|
|
58
|
+
}
|
|
33
59
|
let excel = Util.excelSequence()
|
|
34
|
-
|
|
60
|
+
const dim = worksheet.dimensions
|
|
61
|
+
const right = dim ? dim.right : (worksheet.actualColumnCount || 1)
|
|
62
|
+
const bottom = dim ? dim.bottom : (worksheet.actualRowCount || 1)
|
|
63
|
+
const ref = `A1:${colToLetter(right)}${bottom}`
|
|
35
64
|
let explode = ref.split(':')
|
|
36
65
|
let lastchar = explode[1]
|
|
37
66
|
let stringPattern = /[A-Z]+/i
|
|
@@ -48,23 +77,23 @@ zReport.reportData = (filename, data, sessions = {}) => {
|
|
|
48
77
|
let excelQuery = data.excel_query || {}
|
|
49
78
|
let dataForExcel = excelQuery.excel
|
|
50
79
|
let dataCallback = data.callback || []
|
|
51
|
-
let
|
|
80
|
+
let callbacks = {}
|
|
52
81
|
let objQuery = {}
|
|
53
82
|
let results = []
|
|
54
83
|
|
|
55
84
|
//set callback as object
|
|
56
85
|
dataCallback.map((m) => {
|
|
57
|
-
|
|
86
|
+
callbacks[m.name] = m.value
|
|
58
87
|
})
|
|
59
88
|
|
|
60
89
|
//console.log(JSON.stringify(sessions));
|
|
61
90
|
|
|
62
91
|
//create UI Button in excel cell
|
|
63
92
|
if (dataForExcel) {
|
|
64
|
-
dataForExcel.forEach((datafor
|
|
93
|
+
dataForExcel.forEach((datafor) => {
|
|
65
94
|
let button = '',
|
|
66
95
|
name = datafor.name,
|
|
67
|
-
|
|
96
|
+
callbackValue = datafor.callback || '',
|
|
68
97
|
value = datafor.value || ''
|
|
69
98
|
let split = value.split('.')
|
|
70
99
|
let len = split.length
|
|
@@ -93,7 +122,7 @@ zReport.reportData = (filename, data, sessions = {}) => {
|
|
|
93
122
|
|
|
94
123
|
let labels = value.indexOf('_SESSIONS_') > -1 ? value.replace('_SESSIONS_.', '') : tableKey
|
|
95
124
|
button += `<li class="dragged"> <button class="btn btn-info btn-excel" type="button" title="${name.replace('[', '').replace(']', '')} : ${value}">${MYMODEL.labels[labels]}
|
|
96
|
-
<input type="hidden" class="EXCEL" name="${name}" value='${value}_CALLBACK_SEPARATOR_${
|
|
125
|
+
<input type="hidden" class="EXCEL" name="${name}" value='${value}_CALLBACK_SEPARATOR_${callbackValue}'> <i class="fa fa-code call-me"></i> <i class="fa fa-trash trash-me"></i></button></li>`
|
|
97
126
|
excelValue[name] = button
|
|
98
127
|
})
|
|
99
128
|
}
|
|
@@ -106,7 +135,8 @@ zReport.reportData = (filename, data, sessions = {}) => {
|
|
|
106
135
|
for (var i = 0; i <= maxColumn; i++) {
|
|
107
136
|
let str = excel[i] + x
|
|
108
137
|
let strkey = excel[i] + '[' + x + ']'
|
|
109
|
-
|
|
138
|
+
const cell = worksheet.getCell(str)
|
|
139
|
+
let defaultValue = cellToPrimitive(cell)
|
|
110
140
|
let value = excelValue[strkey] || defaultValue
|
|
111
141
|
table += `<td width="80px" id="${str}" title="${str}" class="mydragable" data-col="${excel[i]}" data-row="${x}">${value}</td>`
|
|
112
142
|
arr.push(value)
|
package/lib/zRoute.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zet-lib",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "zet is a library that part of zet generator.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"axios": "^1.15.0",
|
|
32
|
-
"convert-excel-to-json": "^1.7.0",
|
|
33
32
|
"dotenv": "^16.5.0",
|
|
34
33
|
"dropbox": "^10.34.0",
|
|
35
34
|
"ejs": "^3.1.10",
|
|
@@ -50,13 +49,14 @@
|
|
|
50
49
|
"read-excel-file": "^5.8.0",
|
|
51
50
|
"socket.io": "^4.8.3",
|
|
52
51
|
"uglify-js": "^3.19.3",
|
|
53
|
-
"uuid": "^9.0.1"
|
|
54
|
-
"xlsx": "^0.18.5"
|
|
52
|
+
"uuid": "^9.0.1"
|
|
55
53
|
},
|
|
56
54
|
"optionalDependencies": {
|
|
57
|
-
"pm2": "^6.0.0",
|
|
58
55
|
"sharp": "^0.34.1"
|
|
59
56
|
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"standard": "^17.1.2"
|
|
59
|
+
},
|
|
60
60
|
"overrides": {
|
|
61
61
|
"unzipper": "^0.12.3",
|
|
62
62
|
"rimraf": "^6.1.2",
|