zet-lib 1.0.51 → 1.0.52
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 +878 -867
- package/lib/zRoute.js +30 -17
- package/package.json +1 -1
package/lib/zRoute.js
CHANGED
|
@@ -1050,6 +1050,12 @@ zRoute.handleSession = async (req, user) => {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
|
|
1052
1052
|
zRoute.excelQuery = async (req, res, MYMODEL) => {
|
|
1053
|
+
let virtuals = []
|
|
1054
|
+
for (var key in MYMODEL.widgets) {
|
|
1055
|
+
if (MYMODEL.widgets[key].name === 'virtual') {
|
|
1056
|
+
virtuals.push(key)
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1053
1059
|
//check directory for import not export
|
|
1054
1060
|
const dir = `${dirRoot}/public/excel/tmp`
|
|
1055
1061
|
if (!fs.existsSync(dir)) {
|
|
@@ -1079,9 +1085,10 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
|
|
|
1079
1085
|
body = result.filter
|
|
1080
1086
|
fields = body.fields.filter((item) => item != 'no' && item != 'actionColumn')
|
|
1081
1087
|
select = Util.selectParser(fields, MYMODEL)
|
|
1088
|
+
console.log(virtuals)
|
|
1082
1089
|
if (zall) {
|
|
1083
1090
|
let difference = allfields.filter((x) => !fields.includes(x))
|
|
1084
|
-
arr = [...fields, ...difference]
|
|
1091
|
+
arr = [...fields, ...difference].filter((x) => !virtuals.includes(x))
|
|
1085
1092
|
select = `"${arr.join('","')}"`
|
|
1086
1093
|
}
|
|
1087
1094
|
let whereArray = []
|
|
@@ -1125,6 +1132,7 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
|
|
|
1125
1132
|
if (zall) {
|
|
1126
1133
|
fields = arr
|
|
1127
1134
|
}
|
|
1135
|
+
console.log(select)
|
|
1128
1136
|
|
|
1129
1137
|
const ztype = reqQuery.ztype == 1 ? true : false
|
|
1130
1138
|
if (ztype) {
|
|
@@ -3046,37 +3054,43 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3046
3054
|
hd += `<th>${LANGUAGE['noted']}</th>`
|
|
3047
3055
|
hd += `</tr>`
|
|
3048
3056
|
|
|
3049
|
-
let isCut = false
|
|
3050
|
-
if(i > 20 && result.length > 2000) {
|
|
3051
|
-
io.to(room).emit('message', 'short display data!')
|
|
3052
|
-
isCut = true
|
|
3057
|
+
let isCut = false
|
|
3058
|
+
if (i > 20 && result.length > 2000) {
|
|
3059
|
+
io.to(room).emit('message', 'short display data!')
|
|
3060
|
+
isCut = true
|
|
3053
3061
|
}
|
|
3054
3062
|
//convert to table header
|
|
3055
3063
|
io.to(room).emit('import', hd)
|
|
3056
|
-
let isInsert = true
|
|
3064
|
+
let isInsert = true
|
|
3057
3065
|
|
|
3058
3066
|
for (let i = 3; i < result.length; i++) {
|
|
3059
|
-
hd = ''
|
|
3067
|
+
hd = ''
|
|
3060
3068
|
hd += `<tr>`
|
|
3061
3069
|
const data = {}
|
|
3062
3070
|
hd += `${i - 2}`
|
|
3063
3071
|
//column cut tidak penting hanya jika kebanyakan dipotong
|
|
3064
|
-
let columnCut = 0
|
|
3072
|
+
let columnCut = 0
|
|
3065
3073
|
for (var prop in keys) {
|
|
3066
3074
|
let value = result[i][prop]
|
|
3067
3075
|
if (value) {
|
|
3068
|
-
|
|
3076
|
+
if (MYMODEL.widgets[keys[prop]].name === 'integer') {
|
|
3077
|
+
data[keys[prop]] = parseInt(value) || null
|
|
3078
|
+
} else if (MYMODEL.widgets[keys[prop]].name === 'virtual') {
|
|
3079
|
+
//empty
|
|
3080
|
+
} else {
|
|
3081
|
+
data[keys[prop]] = value
|
|
3082
|
+
}
|
|
3069
3083
|
}
|
|
3070
|
-
if(isCut) {
|
|
3084
|
+
if (isCut) {
|
|
3071
3085
|
console.log('cut and column cut')
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3086
|
+
if (columnCut < 10) {
|
|
3087
|
+
hd += `<td>${value || ''}</td>`
|
|
3088
|
+
}
|
|
3075
3089
|
} else {
|
|
3076
3090
|
hd += `<td>${value || ''}</td>`
|
|
3077
3091
|
}
|
|
3078
3092
|
if (keys[prop] == 'id') isInsert = false
|
|
3079
|
-
columnCut
|
|
3093
|
+
columnCut++
|
|
3080
3094
|
}
|
|
3081
3095
|
try {
|
|
3082
3096
|
if (isInsert) {
|
|
@@ -3099,14 +3113,13 @@ zRoute.import = async (req, res, MYMODEL) => {
|
|
|
3099
3113
|
}
|
|
3100
3114
|
hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
|
|
3101
3115
|
} catch (err) {
|
|
3102
|
-
hd += `<td class='text text-danger'>${err+''}</td>`
|
|
3103
|
-
|
|
3116
|
+
hd += `<td class='text text-danger'>${err + ''}</td>`
|
|
3117
|
+
io.to(room).emit('error', err + '' + ' ')
|
|
3104
3118
|
}
|
|
3105
3119
|
hd += '</tr>'
|
|
3106
3120
|
io.to(room).emit('import', hd)
|
|
3107
3121
|
}
|
|
3108
3122
|
|
|
3109
|
-
|
|
3110
3123
|
fs.removeSync(filename)
|
|
3111
3124
|
//cache for uploading excel
|
|
3112
3125
|
zRoute.modelsCacheRenew(MYMODEL.table, res.locals.companyId)
|