zet-lib 1.0.49 → 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 CHANGED
@@ -723,7 +723,6 @@ Util.fileView = function (dir, file, attributes={}) {
723
723
  };
724
724
  /// end files
725
725
 
726
-
727
726
  Util.arrayDelete = function (arr, value) {
728
727
  return arr.filter((item)=> item != value);
729
728
  };
@@ -1125,6 +1124,28 @@ Util.userAvatar = (img) => {
1125
1124
  /*
1126
1125
  MYSQL HELPER
1127
1126
  */
1127
+ Util.selectParser = (fields, MYMODEL) => {
1128
+ fields = fields.filter(e => e !== "actionColumn");
1129
+ let virtuals = [];
1130
+ for(var key in MYMODEL.widgets) {
1131
+ if(MYMODEL.widgets[key].name === "virtual") {
1132
+ virtuals.push(key);
1133
+ }
1134
+ }
1135
+ let arr = []
1136
+ fields.forEach((item) => {
1137
+ if(virtuals.includes(item)) {
1138
+ arr.push(MYMODEL.widgets[item].fields);
1139
+ } else if(item === "no") {
1140
+ arr.push('id');
1141
+ } else {
1142
+ arr.push(item)
1143
+ }
1144
+ })
1145
+
1146
+ let select = `"${arr.join('","')}"`;
1147
+ return select;
1148
+ }
1128
1149
 
1129
1150
  Util.selectMysql = (fields,relations={}) => {
1130
1151
  let obj = {}
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)) {
@@ -1078,10 +1084,11 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
1078
1084
  let result = results[0]
1079
1085
  body = result.filter
1080
1086
  fields = body.fields.filter((item) => item != 'no' && item != 'actionColumn')
1081
- select = Util.selectMysql(fields)
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 = []
@@ -1115,7 +1122,7 @@ zRoute.excelQuery = async (req, res, MYMODEL) => {
1115
1122
  rows = await connection.results(obj)
1116
1123
  } else {
1117
1124
  rows = await connection.results({
1118
- select: Util.selectMysql(fields),
1125
+ select: Util.selectParser(fields, MYMODEL),
1119
1126
  table: MYMODEL.table,
1120
1127
  limit: reqQuery.pageSize,
1121
1128
  offset: parseInt(reqQuery.pageSize) - 1,
@@ -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) {
@@ -1524,7 +1532,7 @@ zRoute.listDataTable = async (req, res, objData = {}) => {
1524
1532
  const MYMODEL = objData.MYMODEL || {}
1525
1533
  const fields = Object.prototype.hasOwnProperty.call(objData, 'fields') ? objData.fields : req.body.fields
1526
1534
  const relations = await zRoute.relations(req, res, MYMODEL.table)
1527
- const select = Object.prototype.hasOwnProperty.call(objData, 'select') ? objData.select : Util.selectMysql(fields, relations)
1535
+ const select = Object.prototype.hasOwnProperty.call(objData, 'select') ? objData.select : Util.selectParser(fields, MYMODEL)
1528
1536
  const columns = Object.prototype.hasOwnProperty.call(objData, 'columns') ? objData.columns : body.columns
1529
1537
  let whereArray = []
1530
1538
  if (objData.hasOwnProperty('whereArray')) {
@@ -1604,7 +1612,7 @@ zRoute.listData = async (req, res, MYMODEL, zRole, actionButtonsFn) => {
1604
1612
  const relations = await zRoute.relations(req, res, MYMODEL.table)
1605
1613
  const body = req.body
1606
1614
  const fields = body.fields
1607
- const select = Util.selectMysql(fields, relations)
1615
+ const select = Util.selectParser(fields, MYMODEL)
1608
1616
  let whereArray = []
1609
1617
  const columns = body.columns
1610
1618
  whereArray.push({
@@ -3036,8 +3044,8 @@ zRoute.import = async (req, res, MYMODEL) => {
3036
3044
  }
3037
3045
  //convert to table header
3038
3046
  let hd = '<tr>'
3047
+ let i = 0
3039
3048
  for (let prop in result[1]) {
3040
- let i = 0
3041
3049
  keys[prop] = result[1][prop]
3042
3050
  hd += `<th>${result[0][prop]}</th>`
3043
3051
  headers.push({ i: i, prop: prop, value: result[0][prop] })
@@ -3045,20 +3053,44 @@ zRoute.import = async (req, res, MYMODEL) => {
3045
3053
  }
3046
3054
  hd += `<th>${LANGUAGE['noted']}</th>`
3047
3055
  hd += `</tr>`
3056
+
3057
+ let isCut = false
3058
+ if (i > 20 && result.length > 2000) {
3059
+ io.to(room).emit('message', 'short display data!')
3060
+ isCut = true
3061
+ }
3048
3062
  //convert to table header
3049
3063
  io.to(room).emit('import', hd)
3050
3064
  let isInsert = true
3051
- hd += `<tr>`
3065
+
3052
3066
  for (let i = 3; i < result.length; i++) {
3067
+ hd = ''
3068
+ hd += `<tr>`
3053
3069
  const data = {}
3054
3070
  hd += `${i - 2}`
3071
+ //column cut tidak penting hanya jika kebanyakan dipotong
3072
+ let columnCut = 0
3055
3073
  for (var prop in keys) {
3056
3074
  let value = result[i][prop]
3057
3075
  if (value) {
3058
- data[keys[prop]] = value
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
+ }
3083
+ }
3084
+ if (isCut) {
3085
+ console.log('cut and column cut')
3086
+ if (columnCut < 10) {
3087
+ hd += `<td>${value || ''}</td>`
3088
+ }
3089
+ } else {
3090
+ hd += `<td>${value || ''}</td>`
3059
3091
  }
3060
- hd += `<td>${value}</td>`
3061
3092
  if (keys[prop] == 'id') isInsert = false
3093
+ columnCut++
3062
3094
  }
3063
3095
  try {
3064
3096
  if (isInsert) {
@@ -3081,13 +3113,13 @@ zRoute.import = async (req, res, MYMODEL) => {
3081
3113
  }
3082
3114
  hd += `<td class='text text-success'>${LANGUAGE['success']}</td>`
3083
3115
  } catch (err) {
3084
- hd += `<td class='text text-danger'>${err.toString()}</td>`
3116
+ hd += `<td class='text text-danger'>${err + ''}</td>`
3117
+ io.to(room).emit('error', err + '' + ' ')
3085
3118
  }
3086
3119
  hd += '</tr>'
3087
3120
  io.to(room).emit('import', hd)
3088
3121
  }
3089
- hd += ''
3090
- io.to(room).emit('import', hd)
3122
+
3091
3123
  fs.removeSync(filename)
3092
3124
  //cache for uploading excel
3093
3125
  zRoute.modelsCacheRenew(MYMODEL.table, res.locals.companyId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.0.49",
3
+ "version": "1.0.52",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -49,4 +49,4 @@
49
49
  "uuid": "^9.0.0",
50
50
  "xlsx": "^0.18.5"
51
51
  }
52
- }
52
+ }