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.
Files changed (3) hide show
  1. package/lib/Util.js +878 -867
  2. package/lib/zRoute.js +30 -17
  3. package/package.json +1 -1
package/lib/Util.js CHANGED
@@ -1,69 +1,69 @@
1
- const moment = require('moment')
2
- const path = require('path')
3
- const randomstring = require('randomstring')
4
- const fs = require('fs-extra')
5
- const { v4: uuidv4 } = require('uuid')
6
- const sha256 = require('js-sha256')
1
+ const moment = require('moment');
2
+ const path = require('path');
3
+ const randomstring = require("randomstring");
4
+ const fs = require('fs-extra');
5
+ const { v4: uuidv4 } = require('uuid');
6
+ const sha256 = require('js-sha256');
7
7
 
8
8
  const Util = {}
9
9
 
10
- Util.tab = '\t'
10
+ Util.tab = '\t';
11
11
  Util.tabs = (n) => {
12
- let ret = ''
13
- for (var i = 0; i < n; i++) {
14
- ret += Util.tab
15
- }
16
- return ret
17
- }
12
+ let ret = '';
13
+ for (var i = 0; i < n; i++) {
14
+ ret += Util.tab;
15
+ }
16
+ return ret;
17
+ };
18
18
 
19
- Util.NEW_LINE = '\n'
20
- Util.newLine = '\r\n'
19
+ Util.NEW_LINE = '\n';
20
+ Util.newLine = '\r\n';
21
21
  Util.newLines = (n) => {
22
- let ret = ''
23
- for (var i = 0; i < n; i++) {
24
- ret += Util.newLine
25
- }
26
- return ret
27
- }
22
+ let ret = '';
23
+ for (var i = 0; i < n; i++) {
24
+ ret += Util.newLine;
25
+ }
26
+ return ret;
27
+ };
28
28
 
29
29
  //sha256
30
30
  Util.hash = (string) => {
31
- return sha256(string)
32
- }
31
+ return sha256(string);
32
+ };
33
33
 
34
34
  Util.hashCompare = (myPlaintextPassword, hash) => {
35
- return Util.hash(myPlaintextPassword) == hash
36
- }
35
+ return Util.hash(myPlaintextPassword) == hash;
36
+ };
37
37
 
38
38
  Util.excelSequence = function () {
39
- let abjads = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
40
- let arr = abjads
41
- let char = 0
42
- let num = 26
43
- for (let x = 2; x < 15; x++) {
44
- let idx = 0
45
- for (let i = 1; i <= 26; i++) {
46
- arr[num] = abjads[char] + abjads[idx]
47
- idx++
48
- num++
39
+ let abjads = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
40
+ let arr = abjads;
41
+ let char = 0;
42
+ let num = 26;
43
+ for (let x = 2; x < 15; x++) {
44
+ let idx = 0;
45
+ for (let i = 1; i <= 26; i++) {
46
+ arr[num] = abjads[char] + abjads[idx];
47
+ idx++;
48
+ num++;
49
+ }
50
+ char++;
49
51
  }
50
- char++
51
- }
52
52
 
53
- return arr
54
- }
53
+ return arr;
54
+ };
55
55
 
56
56
  Util.now = function () {
57
- return moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
58
- }
57
+ return moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
58
+ };
59
59
 
60
60
  Util.nowShort = function () {
61
- return moment(new Date()).format('YYYY-MM-DD')
62
- }
61
+ return moment(new Date()).format("YYYY-MM-DD");
62
+ };
63
63
 
64
64
  Util.ago = (data) => {
65
- return moment(data).fromNow()
66
- }
65
+ return moment(data).fromNow();
66
+ };
67
67
  /*
68
68
  moment get one month ago from current
69
69
  var monthago = moment().subtract(1, 'months').format('YYYY-MM-DD');
@@ -71,150 +71,156 @@ Util.ago = (data) => {
71
71
  */
72
72
 
73
73
  Util.dateSql = function (date, format) {
74
- format = format || 'YYYY-MM-DD'
75
- if (date && date != '0000-00-00') return moment(date).format(format)
76
- else return ''
77
- }
74
+ format = format || "YYYY-MM-DD";
75
+ if (date && date != "0000-00-00")
76
+ return moment(date).format(format);
77
+ else
78
+ return '';
79
+ };
78
80
 
79
81
  Util.dateFormat = function (date, format) {
80
- format = format || 'YYYY-MM-DD'
81
- if (date && date != '0000-00-00') return moment(date).format(format)
82
- else return ''
83
- }
82
+ format = format || "YYYY-MM-DD";
83
+ if (date && date != "0000-00-00")
84
+ return moment(date).format(format);
85
+ else
86
+ return '';
87
+ };
84
88
 
85
89
  Util.timePublic = function (date) {
86
- if (date) return moment(date).format('DD MMM YYYY')
87
- else return ''
88
- }
90
+ if (date)
91
+ return moment(date).format("DD MMM YYYY");
92
+ else
93
+ return '';
94
+ };
89
95
 
90
96
  Util.timeSql = function (date, format) {
91
- if (date && date != '0000-00-00 00:00:00') {
92
- format = format || 'YYYY-MM-DD HH:mm:ss'
93
- return moment(date).format(format)
94
- } else return ''
95
- }
97
+ if (date && date != "0000-00-00 00:00:00"){
98
+ format = format || "YYYY-MM-DD HH:mm:ss";
99
+ return moment(date).format(format);
100
+ }
101
+ else
102
+ return '';
103
+ };
96
104
 
97
105
  Util.getDate = function (date) {
98
- date = date + '' || ''
99
- if (date != '') {
100
- let explode = date.split('-')
101
- return {
102
- year: parseInt(explode[0]),
103
- month: parseInt(explode[1]),
104
- date: parseInt(explode[2]),
105
- }
106
- } else {
107
- return {
108
- year: 0,
109
- month: 0,
110
- date: 0,
106
+ date = date + "" || "";
107
+ if (date != "") {
108
+ let explode = date.split("-");
109
+ return {
110
+ year: parseInt(explode[0]),
111
+ month: parseInt(explode[1]),
112
+ date: parseInt(explode[2]),
113
+ }
114
+ } else {
115
+ return {
116
+ year: 0,
117
+ month: 0,
118
+ date: 0
119
+ }
111
120
  }
112
- }
113
- }
121
+ };
114
122
 
115
123
  Util.dateIsBetween = (compare, start, end) => {
116
- if (compare == '' || compare == '0000-00-00') {
117
- return false
118
- }
119
- compare = moment(compare).format('YYYY-MM-DD')
120
- start = moment(start).format('YYYY-MM-DD')
121
- end = moment(end).format('YYYY-MM-DD')
122
- let today = moment(compare)
123
- let startDate = moment(start)
124
- let endDate = moment(end)
125
-
126
- if (compare == start) {
127
- return true
128
- } else if (compare == end) {
129
- return true
130
- } else {
131
- return today.isBetween(startDate, endDate)
132
- }
133
- }
124
+ if (compare == "" || compare == "0000-00-00") {
125
+ return false;
126
+ }
127
+ compare = moment(compare).format("YYYY-MM-DD");
128
+ start = moment(start).format("YYYY-MM-DD");
129
+ end = moment(end).format("YYYY-MM-DD");
130
+ let today = moment(compare);
131
+ let startDate = moment(start);
132
+ let endDate = moment(end);
133
+
134
+ if (compare == start) {
135
+ return true;
136
+ } else if (compare == end) {
137
+ return true;
138
+ } else {
139
+ return today.isBetween(startDate, endDate);
140
+ }
141
+ };
134
142
 
135
143
  Util.getMonth = function (date) {
136
- if (date.length > 5) {
137
- let n = new Date(date)
138
- let m = n.getMonth()
139
- return parseInt(m) + 1
140
- }
141
- return 0
142
- }
144
+ if (date.length > 5) {
145
+ let n = new Date(date)
146
+ let m = n.getMonth();
147
+ return parseInt(m) + 1;
148
+ }
149
+ return 0;
150
+ };
143
151
 
144
152
  Util.getYear = function (date) {
145
- date = Util.dateSql(date) || ''
146
- return date.slice(0, 4)
147
- }
153
+ date = Util.dateSql(date) || "";
154
+ return date.slice(0, 4);
155
+ };
148
156
 
149
157
  //first is smaller than second
150
158
  Util.calculateDay = function (from, to, holidayInWeek = 0) {
151
- holidayInWeek = parseInt(holidayInWeek) || 0
152
- let count = 0
153
- if (holidayInWeek == 1) {
154
- let days = Util.enumerateDaysBetweenDates(moment(from).format('YYYY-MM-DD'), moment(to).format('YYYY-MM-DD'))
155
- let countdays = days.filter((item) => parseInt(moment(item).format('d')) != 0)
156
- count = countdays.length
157
- } else if (holidayInWeek == 2) {
158
- let days = Util.enumerateDaysBetweenDates(moment(from).format('YYYY-MM-DD'), moment(to).format('YYYY-MM-DD'))
159
- let countdays = days.filter((item) => parseInt(moment(item).format('d')) != 0 && parseInt(moment(item).format('d')) != 6)
160
- count = countdays.length
161
- } else {
162
- let a = moment(from)
163
- let b = moment(to)
164
- count = b.diff(a, 'days') + 1
165
- }
166
-
167
- return count
168
- }
159
+ holidayInWeek = parseInt(holidayInWeek) || 0;
160
+ let count = 0;
161
+ if (holidayInWeek == 1) {
162
+ let days = Util.enumerateDaysBetweenDates(moment(from).format("YYYY-MM-DD"), moment(to).format("YYYY-MM-DD"));
163
+ let countdays = days.filter((item) => parseInt(moment(item).format("d")) != 0);
164
+ count = countdays.length;
165
+ } else if (holidayInWeek == 2) {
166
+ let days = Util.enumerateDaysBetweenDates(moment(from).format("YYYY-MM-DD"), moment(to).format("YYYY-MM-DD"));
167
+ let countdays = days.filter((item) => parseInt(moment(item).format("d")) != 0 && parseInt(moment(item).format("d")) != 6);
168
+ count = countdays.length;
169
+ } else {
170
+ let a = moment(from);
171
+ let b = moment(to);
172
+ count = b.diff(a, 'days') + 1;
173
+ }
174
+
175
+ return count;
176
+ };
169
177
 
170
178
  var getDaysBetweenDates = function (startDate, endDate) {
171
- let now = startDate.clone(),
172
- dates = []
173
- while (now.isSameOrBefore(endDate)) {
174
- dates.push(now.format('MM/DD/YYYY'))
175
- now.add(1, 'days')
176
- }
177
- return dates
178
- }
179
+ let now = startDate.clone(), dates = [];
180
+ while (now.isSameOrBefore(endDate)) {
181
+ dates.push(now.format('MM/DD/YYYY'));
182
+ now.add(1, 'days');
183
+ }
184
+ return dates;
185
+ };
179
186
 
180
187
  //itterate days in array
181
188
  Util.enumerateDaysBetweenDates = function (startDate, endDate) {
182
- let now = moment(startDate).clone(),
183
- dates = []
184
- while (now.isSameOrBefore(endDate)) {
185
- dates.push(now.format('MM/DD/YYYY'))
186
- now.add(1, 'days')
187
- }
188
- return dates
189
- }
189
+ let now = moment(startDate).clone(), dates = [];
190
+ while (now.isSameOrBefore(endDate)) {
191
+ dates.push(now.format('MM/DD/YYYY'));
192
+ now.add(1, 'days');
193
+ }
194
+ return dates;
195
+ };
190
196
 
191
197
  Util.tableArray = function (arr) {
192
- let r = []
193
- let tables = arr[0]
194
- for (let i = 0; i < tables.length; i++) {
195
- for (let obj in tables[i]) {
196
- r.push(tables[i][obj])
198
+ let r = [];
199
+ let tables = arr[0];
200
+ for (let i = 0; i < tables.length; i++) {
201
+ for (let obj in tables[i]) {
202
+ r.push(tables[i][obj]);
203
+ }
197
204
  }
198
- }
199
- return r
200
- }
205
+ return r;
206
+ };
201
207
 
202
208
  /*
203
209
  table array in sql to arr table name
204
210
  only for generator
205
211
  */
206
212
  Util.tableArrayToObj = (arr) => {
207
- return arr.map((m) => Object.values(m)[0])
208
- }
213
+ return arr.map(m => Object.values(m)[0]);
214
+ };
209
215
 
210
216
  Util.escapeRegExp = function (str) {
211
- return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1')
212
- }
217
+ return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
218
+ };
213
219
 
214
220
  Util.validateEmail = function (email) {
215
- let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
216
- return re.test(email)
217
- }
221
+ let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
222
+ return re.test(email);
223
+ };
218
224
 
219
225
  /*
220
226
  Replace All like str_replace in PHP
@@ -222,296 +228,294 @@ Util.validateEmail = function (email) {
222
228
  */
223
229
 
224
230
  Util.replaceAll = function (str, find, replace) {
225
- let t = ''
226
- if (Array.isArray(find)) {
227
- t = str
228
- for (let i = 0; i < find.length; i++) {
229
- if (str.indexOf(find[i]) > -1) {
230
- t = str.replace(new RegExp(Util.escapeRegExp(find[i]), 'g'), replace)
231
- }
232
- }
233
- } else {
234
- if (typeof str == 'string') {
235
- t = str.replace(new RegExp(Util.escapeRegExp(find), 'g'), replace)
231
+ let t = ''
232
+ if (Array.isArray(find)) {
233
+ t = str;
234
+ for (let i = 0; i < find.length; i++) {
235
+ if (str.indexOf(find[i]) > -1) {
236
+ t = str.replace(new RegExp(Util.escapeRegExp(find[i]), 'g'), replace);
237
+ }
238
+ }
239
+ } else {
240
+ if(typeof str == "string") {
241
+ t = str.replace(new RegExp(Util.escapeRegExp(find), 'g'), replace);
242
+ }
236
243
  }
237
- }
238
- return t
239
- }
244
+ return t;
245
+ };
240
246
 
241
247
  Util.phoneFixed = function (str) {
242
- let ret = ''
243
- str = Util.replaceAll(str, ' ', '')
244
- let phone = str.trim()
245
- phone = Util.replaceAll(phone, '-', '')
246
- let first = phone.charAt(0)
247
- if (first == '') {
248
- ret = ''
249
- } else if (first == '+') {
250
- ret = phone
251
- } else if (first == '0') {
252
- ret = '+62' + phone.replace('0', '')
253
- } else {
254
- ret = '+' + phone
255
- }
256
-
257
- return ret
258
- }
248
+ let ret = ''
249
+ str = Util.replaceAll(str, ' ', '')
250
+ let phone = str.trim()
251
+ phone = Util.replaceAll(phone, '-', '')
252
+ let first = phone.charAt(0)
253
+ if (first == '') {
254
+ ret = '';
255
+ } else if (first == '+') {
256
+ ret = phone;
257
+ } else if (first == '0') {
258
+ ret = '+62' + phone.replace('0', '');
259
+ } else {
260
+ ret = '+' + phone
261
+ }
262
+
263
+ return ret;
264
+ };
259
265
 
260
266
  Util.jsonSuccess = function (message) {
261
- message = message || LANGUAGE.data_saved
262
- let json = { type: 'success', status: 1, title: LANGUAGE.success, message: message }
267
+ message = message || LANGUAGE.data_saved;
268
+ let json = {type: 'success', status: 1, title: LANGUAGE.success, message: message}
263
269
 
264
- return json
265
- }
270
+ return json;
271
+ };
266
272
 
267
273
  Util.flashError = function (message, errors) {
268
- errors = errors || []
269
- message = message || LANGUAGE.data_not_found
270
- let json = { type: 'error', status: 0, title: 'Error', message: message, errors: errors }
274
+ errors = errors || [];
275
+ message = message || LANGUAGE.data_not_found;
276
+ let json = {type: 'error', status: 0, title: 'Error', message: message, errors: errors}
271
277
 
272
- return json
273
- }
278
+ return json;
279
+ };
274
280
 
275
281
  Util.jsonError = function (path, message) {
276
- let json = {}
277
- json.errorLog = 1
278
- json.type = 'error'
279
- json.status = 0
280
- json.title = path + ' Error!'
281
- json.message = message
282
- json.errors = [{ path: path, message: message }]
283
-
284
- return json
285
- }
282
+ let json = {}
283
+ json.errorLog = 1;
284
+ json.type = 'error';
285
+ json.status = 0;
286
+ json.title = path + ' Error!';
287
+ json.message = message;
288
+ json.errors = [{path: path, message: message}]
289
+
290
+ return json;
291
+ };
286
292
 
287
293
  Util.arrayToObject = (array, keyField, isInteger = false) => {
288
- let obj = {}
289
- if (array.length) {
290
- array.forEach(function (item) {
291
- var name = item[keyField] == null ? 'xxxxxx' : item[keyField] == 'null' ? 'xxxxxx' : isInteger ? item[keyField] : item[keyField] + ''
292
- obj[name] = item
293
- })
294
- }
295
- return obj
296
- }
294
+ let obj = {}
295
+ if(array.length) {
296
+ array.forEach(function (item) {
297
+ var name = item[keyField] == null ? 'xxxxxx' : item[keyField] == 'null' ? 'xxxxxx' : isInteger ? item[keyField] : item[keyField] + "";
298
+ obj[name]=item
299
+ });
300
+ }
301
+ return obj;
302
+ };
297
303
 
298
304
  //chase id:1,name:'test' t0 {1:'test'}
299
305
  Util.modulesSwitch = (arr) => {
300
- let stores = []
301
- stores.push({ id: '', name: '' })
302
- arr.forEach((ar, index) => {
303
- stores.push({ id: index, name: ar })
304
- })
305
- return stores
306
- }
306
+ let stores = [];
307
+ stores.push({id: '', name: ''});
308
+ arr.forEach((ar, index) => {
309
+ stores.push({id: index, name: ar})
310
+ });
311
+ return stores;
312
+ };
313
+
307
314
 
308
315
  Util.buildArrayObjectPrefix = function (arr) {
309
- return Util.modulesSwitch(arr)
310
- }
316
+ return Util.modulesSwitch(arr);
317
+ };
311
318
 
312
319
  Util.arrayWithObject = (array, key, field) => {
313
- if (array.length) {
314
- return array.reduce((obj, item) => {
315
- obj[item[key]] = item[field]
316
- return obj
317
- }, {})
318
- }
319
- }
320
+ if(array.length) {
321
+ return array.reduce((obj, item) => {
322
+ obj[item[key]] = item[field];
323
+ return obj;
324
+ }, {});
325
+ }
326
+ };
320
327
 
321
328
  /*
322
329
  for movedupload file using single file
323
330
  */
324
331
  Util.moveFile = function (buffer, filename) {
325
- return new Promise(function (resolve, reject) {
326
- buffer.mv(filename, function (err) {
327
- if (err) {
328
- reject(err)
329
- } else {
330
- resolve(filename)
331
- }
332
- })
333
- })
334
- }
332
+ return new Promise(function (resolve, reject) {
333
+ buffer.mv(filename, function (err) {
334
+ if (err) {
335
+ reject(err)
336
+ } else {
337
+ resolve(filename)
338
+ }
339
+ });
340
+ });
341
+ };
335
342
 
336
343
  Util.generateUnique = function (length, charset) {
337
- let random = Util.generate(length, charset)
338
- let uid = new Date().valueOf().toString(36)
344
+ let random = Util.generate(length, charset);
345
+ let uid = (new Date().valueOf()).toString(36)
339
346
 
340
- return uid + random
341
- }
347
+ return uid + random;
348
+ };
342
349
 
343
350
  Util.generate = function (length, charset) {
344
- length = length || 50
345
- //alphanumeric - [0-9 a-z A-Z] alphabetic - [a-z A-Z] numeric - [0-9] hex - [0-9 a-f] custom - any given characters
346
- charset = charset || 'alphanumeric'
347
- return randomstring.generate({
348
- length: length,
349
- charset: charset,
350
- })
351
- }
351
+ length = length || 50;
352
+ //alphanumeric - [0-9 a-z A-Z] alphabetic - [a-z A-Z] numeric - [0-9] hex - [0-9 a-f] custom - any given characters
353
+ charset = charset || "alphanumeric";
354
+ return randomstring.generate({
355
+ length: length,
356
+ charset: charset
357
+ });
358
+ };
359
+
352
360
 
353
361
  Util.uuid = () => {
354
- return uuidv4()
355
- }
362
+ return uuidv4();
363
+ };
356
364
  /*
357
365
  generate random string 8
358
366
  */
359
367
  Util.random = function (length) {
360
- length = length || 5
361
- let text = ''
362
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
363
- for (let i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length))
368
+ length = length || 5;
369
+ let text = "";
370
+ const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
371
+ for (let i = 0; i < length; i++)
372
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
364
373
 
365
- return text
366
- }
374
+ return text;
375
+ };
367
376
 
368
377
  Util.whitelist = function () {
369
- return ['www', 'app', 'my', 'sintret', 'https', 'https']
370
- }
378
+ return ['www', 'app', 'my', 'sintret', 'https', 'https'];
379
+ };
371
380
 
372
381
  Util.convertDate = function (d) {
373
- d = d.trim()
374
- let myarr = d.split(' ')
375
- return myarr[2] + '-' + Util.monthConvert(myarr[1]) + '-' + myarr[0]
376
- }
382
+ d = d.trim()
383
+ let myarr = d.split(" ");
384
+ return myarr[2] + '-' + Util.monthConvert(myarr[1]) + '-' + myarr[0];
385
+ };
377
386
 
378
387
  // get string start from to
379
388
  Util.cut = function (text, start, end) {
380
- return text.substr(start, end)
381
- }
389
+ return text.substr(start, end)
390
+ };
382
391
 
383
392
  Util.getFormattedDate = function (date) {
384
- let year = date.getFullYear()
385
- let month = (1 + date.getMonth()).toString()
386
- month = month.length > 1 ? month : '0' + month
387
- let day = date.getDate().toString()
388
- day = day.length > 1 ? day : '0' + day
389
- let time = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds()
390
- return year + '-' + month + '-' + day + ' ' + time
391
- }
393
+ let year = date.getFullYear();
394
+ let month = (1 + date.getMonth()).toString();
395
+ month = month.length > 1 ? month : '0' + month;
396
+ let day = date.getDate().toString();
397
+ day = day.length > 1 ? day : '0' + day;
398
+ let time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
399
+ return year + '-' + month + '-' + day + ' ' + time;
400
+ };
392
401
 
393
402
  Util.uniqueId = function () {
394
- return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase()
395
- }
403
+ return (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
404
+ };
396
405
 
397
406
  Util.typePaperSize = [
398
- { title: 'F4', description: 'FOLIO', width: 215, height: 330 },
399
- { title: 'LEGAL', description: 'LEGAL', width: 216, height: 356 },
400
- { title: 'LETTER', description: 'LETTER', width: 216, height: 279 },
401
- { title: 'A3', description: 'A3', width: 297, height: 420 },
402
- { title: 'A4', description: 'A4', width: 210, height: 297 },
403
- { title: 'A5', description: 'A5', width: 148, height: 210 },
404
- { title: 'A6', description: 'A6', width: 105, height: 148 },
405
- { title: 'A7', description: 'A7', width: 74, height: 105 },
406
- { title: 'A8', description: 'A8', width: 52, height: 74 },
407
- { title: 'A9', description: 'A9', width: 37, height: 52 },
408
- { title: 'CUSTOM', description: 'CUSTOM', width: 105, height: 148 },
407
+ {title: "F4", description: "FOLIO", width: 215, height: 330},
408
+ {title: "LEGAL", description: "LEGAL", width: 216, height: 356},
409
+ {title: "LETTER", description: "LETTER", width: 216, height: 279},
410
+ {title: "A3", description: "A3", width: 297, height: 420},
411
+ {title: "A4", description: "A4", width: 210, height: 297},
412
+ {title: "A5", description: "A5", width: 148, height: 210},
413
+ {title: "A6", description: "A6", width: 105, height: 148},
414
+ {title: "A7", description: "A7", width: 74, height: 105},
415
+ {title: "A8", description: "A8", width: 52, height: 74},
416
+ {title: "A9", description: "A9", width: 37, height: 52},
417
+ {title: "CUSTOM", description: "CUSTOM", width: 105, height: 148},
409
418
  ]
410
419
 
411
420
  Util.typeFont = [
412
- 'Verdana, Geneva, sans-serif',
413
- '"Times New Roman", Times, serif',
414
- 'Georgia, serif',
415
- '"Palatino Linotype", "Book Antiqua", Palatino, serif',
416
- 'Arial, Helvetica, sans-serif',
417
- '"Arial Black", Gadget, sans-serif',
418
- '"Comic Sans MS", cursive, sans-serif',
419
- 'Impact, Charcoal, sans-serif',
420
- '"Lucida Sans Unicode", "Lucida Grande", sans-serif',
421
- 'Tahoma, Geneva, sans-serif',
422
- '"Trebuchet MS", Helvetica, sans-serif',
423
- '"Courier New", Courier, monospace',
424
- '"Lucida Console", Monaco, monospace',
421
+ 'Verdana, Geneva, sans-serif',
422
+ '"Times New Roman", Times, serif',
423
+ 'Georgia, serif',
424
+ '"Palatino Linotype", "Book Antiqua", Palatino, serif',
425
+ 'Arial, Helvetica, sans-serif',
426
+ '"Arial Black", Gadget, sans-serif',
427
+ '"Comic Sans MS", cursive, sans-serif',
428
+ 'Impact, Charcoal, sans-serif',
429
+ '"Lucida Sans Unicode", "Lucida Grande", sans-serif',
430
+ 'Tahoma, Geneva, sans-serif',
431
+ '"Trebuchet MS", Helvetica, sans-serif',
432
+ '"Courier New", Courier, monospace',
433
+ '"Lucida Console", Monaco, monospace'
425
434
  ]
426
435
 
427
436
  Util.objectToGridFormat = function (obj, isInteger) {
428
- isInteger = isInteger || false
429
- let arr = []
430
- arr.push({ id: '', name: '' })
431
- for (let keys in obj) {
432
- if (isInteger) {
433
- arr.push({ id: parseInt(keys), name: obj[keys] })
434
- } else {
435
- arr.push({ id: keys, name: obj[keys] })
437
+ isInteger = isInteger || false;
438
+ let arr = []
439
+ arr.push({id: '', name: ''});
440
+ for (let keys in obj) {
441
+ if (isInteger) {
442
+ arr.push({id: parseInt(keys), name: obj[keys]})
443
+ } else {
444
+ arr.push({id: keys, name: obj[keys]})
445
+ }
436
446
  }
437
- }
438
- return arr
447
+ return arr;
439
448
  }
440
449
 
441
450
  Util.random = function (length) {
442
- length = length || 5
443
- let text = ''
444
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
445
- for (let i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length))
451
+ length = length || 5;
452
+ let text = "";
453
+ const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
454
+ for (let i = 0; i < length; i++)
455
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
446
456
 
447
- return text
457
+ return text;
448
458
  }
449
459
 
450
460
  Util.typePrint = {
451
- register: '{"paper_size":"F4","paper_size_width":"215","paper_size_height":"330","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"10","header":"SURAT PERINTAH KERJA","header_font":"0","header_font_size":"26"}',
452
- estimation: '{"paper_size":"F4","paper_size_width":"215","paper_size_height":"330","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"12","header":"ESTIMASI BIAYA PERBAIKAN","header_font":"0","header_font_size":"18"}',
453
- invoice: '{"paper_size":"A5","paper_size_width":"148","paper_size_height":"210","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"12","header":"INVOICE","header_font":"0","header_font_size":"18"}',
454
- currency: '{"symbol":"Rp","name":"Rupiah","thousand":"."}',
455
- }
461
+ register: '{"paper_size":"F4","paper_size_width":"215","paper_size_height":"330","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"10","header":"SURAT PERINTAH KERJA","header_font":"0","header_font_size":"26"}',
462
+ estimation: '{"paper_size":"F4","paper_size_width":"215","paper_size_height":"330","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"12","header":"ESTIMASI BIAYA PERBAIKAN","header_font":"0","header_font_size":"18"}',
463
+ invoice: '{"paper_size":"A5","paper_size_width":"148","paper_size_height":"210","padding_top":"8","padding_right":"8","padding_bottom":"8","padding_left":"8","border":"1","font":"0","font_size":"12","header":"INVOICE","header_font":"0","header_font_size":"18"}',
464
+ currency: '{"symbol":"Rp","name":"Rupiah","thousand":"."}'
465
+ };
456
466
 
457
467
  Util.isJson = function (text) {
458
- if (text) {
459
- if (
460
- /^[\],:{}\s]*$/.test(
461
- text
462
- .replace(/\\["\\\/bfnrtu]/g, '@')
463
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
464
- .replace(/(?:^|:|,)(?:\s*\[)+/g, '')
465
- )
466
- ) {
467
- //the json is ok
468
- return true
469
- } else {
470
- return false
471
- //the json is not ok
468
+ if(text) {
469
+ if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
470
+ //the json is ok
471
+ return true;
472
+ } else {
473
+ return false;
474
+ //the json is not ok
475
+ }
472
476
  }
473
- }
474
- return false
475
- }
477
+ return false;
478
+ };
476
479
 
477
480
  Util.isEmptyObject = function (obj) {
478
- for (let prop in obj) {
479
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
480
- return false
481
+ for(let prop in obj) {
482
+ if(Object.prototype.hasOwnProperty.call(obj, prop)) {
483
+ return false;
484
+ }
481
485
  }
482
- }
483
486
 
484
- return JSON.stringify(obj) === JSON.stringify({})
485
- }
487
+ return JSON.stringify(obj) === JSON.stringify({});
488
+ };
486
489
 
487
490
  Util.serializeTable = function (table) {
488
- return '`' + table + '`'
489
- }
491
+ return '`' + table + '`';
492
+ };
490
493
 
491
494
  Util.getKey = function (obj, field) {
492
- let t = ''
493
- for (let item in obj) {
494
- if (obj[item] == field) {
495
- return item
495
+ let t = '';
496
+ for (let item in obj) {
497
+ if (obj[item] == field) {
498
+ return item;
499
+ }
496
500
  }
497
- }
498
- return t
499
- }
501
+ return t;
502
+ };
503
+
500
504
 
501
505
  Util.camelize = function (text) {
502
- return text.replace(/^([A-Z])|[\s-_]+(\w)/g, function (match, p1, p2, offset) {
503
- if (p2) return p2.toUpperCase()
504
- return p1.toLowerCase()
505
- })
506
+ return text.replace(/^([A-Z])|[\s-_]+(\w)/g, function (match, p1, p2, offset) {
507
+ if (p2) return p2.toUpperCase();
508
+ return p1.toLowerCase();
509
+ });
506
510
  }
507
511
 
508
512
  Util.decamelize = function (str, separator) {
509
- separator = typeof separator === 'undefined' ? '_' : separator
510
- return str
511
- .replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
512
- .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
513
- .replace('_', separator)
514
- .toLowerCase()
513
+ separator = typeof separator === 'undefined' ? '_' : separator;
514
+ return str
515
+ .replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2')
516
+ .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2')
517
+ .replace("_", separator)
518
+ .toLowerCase();
515
519
  }
516
520
 
517
521
  /*
@@ -520,19 +524,19 @@ Util.decamelize = function (str, separator) {
520
524
  */
521
525
 
522
526
  Util.toName = function (str, separator) {
523
- if (str && str.length) {
524
- separator = separator || '_'
525
- str = str.trim()
526
- //add if first character is number with string character
527
- if (Util.isInteger(str.charAt(0))) {
528
- str = 'a' + str
527
+ if (str && str.length) {
528
+ separator = separator || "_";
529
+ str = str.trim();
530
+ //add if first character is number with string character
531
+ if(Util.isInteger(str.charAt(0))) {
532
+ str = "a"+str;
533
+ }
534
+ let string = str.replace(/\s+/g, separator).toLowerCase();
535
+ string = string.replace("/","");
536
+ string = string.replace("/\/","");
537
+ string = string.replace("__","_");
538
+ return string.replace(/[^A-Za-z0-9/_]/g, "")
529
539
  }
530
- let string = str.replace(/\s+/g, separator).toLowerCase()
531
- string = string.replace('/', '')
532
- string = string.replace('//', '')
533
- string = string.replace('__', '_')
534
- return string.replace(/[^A-Za-z0-9/_]/g, '')
535
- }
536
540
  }
537
541
 
538
542
  /*
@@ -540,651 +544,658 @@ Util.toName = function (str, separator) {
540
544
  to : Order Step
541
545
  */
542
546
  Util.fieldToName = function (str) {
543
- let title = Util.capitalizeFirstLetter(Util.decamelize(str))
544
- title = Util.replaceAll(title, '_', ' ')
545
- title = Util.replaceAll(title, ' id', '')
546
- title = Util.capitalizeAfterSpace(title)
547
-
548
- const lastWords = Util.lastWord(title)
549
- if (title.length > 4 && lastWords == 'Id') {
550
- title = title.replace('Id', '')
551
- }
547
+ let title = Util.capitalizeFirstLetter(Util.decamelize(str));
548
+ title = Util.replaceAll(title, "_", " ");
549
+ title = Util.replaceAll(title, " id", "");
550
+ title = Util.capitalizeAfterSpace(title);
551
+
552
+ const lastWords = Util.lastWord(title);
553
+ if (title.length > 4 && lastWords == "Id") {
554
+ title = title.replace("Id", "");
555
+ }
552
556
 
553
- return title
554
- }
557
+ return title;
558
+ };
555
559
 
556
560
  Util.capitalizeWord = (string) => {
557
- return string
558
- .split(' ')
559
- .map((m) => m[0].toUpperCase() + m.substr(1))
560
- .join(' ')
561
- }
561
+ return string.split(" ").map(m => m[0].toUpperCase() + m.substr(1)).join(" ");
562
+ };
562
563
 
563
564
  Util.capitalizeFirstLetter = (string) => {
564
- return string.charAt(0).toUpperCase() + string.slice(1)
565
- }
565
+ return string.charAt(0).toUpperCase() + string.slice(1);
566
+ };
566
567
 
567
568
  Util.asyncWrap = (fn) => {
568
- return (req, res, next) => {
569
- fn(req, res, next).catch(next)
570
- }
571
- }
569
+ return (req, res, next) => {
570
+ fn(req, res, next).catch(next);
571
+ }
572
+ };
572
573
 
573
574
  Util.capitalizeAfterSpace = function (str) {
574
- str = Util.replaceAll(str, '_', ' ')
575
- return str.replace(/\w\S*/g, function (txt) {
576
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
577
- })
578
- }
575
+ str = Util.replaceAll(str, "_", " ");
576
+ return str.replace(
577
+ /\w\S*/g,
578
+ function (txt) {
579
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
580
+ }
581
+ );
582
+ };
579
583
 
580
584
  Util.capitalizeAfterSpaceTitle = function (str) {
581
- str = Util.replaceAll(str, ' ', '_')
582
- return str.replace(/\w\S*/g, function (txt) {
583
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
584
- })
585
- }
585
+ str = Util.replaceAll(str, " ", "_");
586
+ return str.replace(
587
+ /\w\S*/g,
588
+ function (txt) {
589
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
590
+ }
591
+ );
592
+ };
586
593
 
587
594
  Util.lastWord = function (words) {
588
- let n = words.split(' ')
589
- return n[n.length - 1]
590
- }
595
+ let n = words.split(" ");
596
+ return n[n.length - 1];
597
+ };
591
598
 
592
599
  Util.arrayUnShift = function (arr) {
593
- let obj = {}
594
- obj[arr[0]] = ''
595
- obj[arr[1]] = ''
596
- return obj
597
- }
600
+ let obj = {}
601
+ obj[arr[0]] = '';
602
+ obj[arr[1]] = '';
603
+ return obj;
604
+ };
598
605
 
599
606
  Util.in_array = function (needle, haystack) {
600
- haystack = haystack || []
601
- if (haystack.length && needle) {
602
- return haystack.includes(needle)
603
- } else {
604
- return false
605
- }
606
- }
607
+ haystack = haystack || [];
608
+ if (haystack.length && needle) {
609
+ return haystack.includes(needle);
610
+ } else {
611
+ return false;
612
+ }
613
+ };
607
614
 
608
615
  Util.gridSearch = function (visibles, relations, name, value) {
609
- let index = 0
610
- let elm = 'input'
611
- for (let i = 0; i < visibles.length; i++) {
612
- if (name == visibles[i]) {
613
- index = i
616
+ let index = 0;
617
+ let elm = "input";
618
+ for (let i = 0; i < visibles.length; i++) {
619
+ if (name == visibles[i]) {
620
+ index = i;
621
+ }
614
622
  }
615
- }
616
- if (!Util.isEmptyObject(relations)) {
617
- let arr = Object.keys(relations)
618
- for (let i = 0; i < arr.length; i++) {
619
- if (name == arr[i]) {
620
- elm = 'select'
621
- }
623
+ if (!Util.isEmptyObject(relations)) {
624
+ let arr = Object.keys(relations)
625
+ for (let i = 0; i < arr.length; i++) {
626
+ if (name == arr[i]) {
627
+ elm = "select";
628
+ }
629
+ }
622
630
  }
623
- }
624
- return 'searchValue.eq(' + index + ').find("' + elm + '").val("' + value + '");'
625
- }
631
+ return 'searchValue.eq(' + index + ').find("' + elm + '").val("' + value + '");';
632
+ };
626
633
 
627
634
  Util.toNumber = function (num) {
628
- num = num + ''
629
- return parseFloat(Util.replaceAll(num, '.', ''))
630
- }
631
-
632
- Util.formatNumber = function (num, thousandSeparator = '.') {
633
- num = num || ''
634
- let sep = '$1' + thousandSeparator
635
- let numString = num.toString()
636
- if (numString.indexOf('.') > -1) {
637
- let explode = numString.split('.')
638
- return explode[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, sep) + ',' + explode[1]
639
- } else {
640
- return numString.replace(/(\d)(?=(\d{3})+(?!\d))/g, sep)
641
- }
642
- }
635
+ num = num+"";
636
+ return parseFloat(Util.replaceAll(num,".",""));
637
+ };
638
+
639
+ Util.formatNumber = function (num, thousandSeparator='.') {
640
+ num = num || "";
641
+ let sep = "$1" + thousandSeparator;
642
+ let numString = num.toString();
643
+ if (numString.indexOf(".") > -1) {
644
+ let explode = numString.split(".");
645
+ return explode[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, sep) + "," + explode[1];
646
+ } else {
647
+ return numString.replace(/(\d)(?=(\d{3})+(?!\d))/g, sep);
648
+ }
649
+ };
643
650
 
644
651
  Util.fileAttribute = function (filename) {
645
- filename = filename.toLowerCase() || ''
646
- let ext = filename.split('.').pop()
647
- let obj = {}
648
- obj.ext = ext
649
- if (Util.in_array(ext, Util.fileImage)) {
650
- obj.type = 'image'
651
- } else {
652
- obj.type = 'file'
653
- }
654
- return obj
655
- }
652
+ filename = filename.toLowerCase() || "";
653
+ let ext = filename.split('.').pop();
654
+ let obj = {};
655
+ obj.ext = ext;
656
+ if (Util.in_array(ext, Util.fileImage)) {
657
+ obj.type = 'image';
658
+ } else {
659
+ obj.type = 'file';
660
+ }
661
+ return obj;
662
+ };
656
663
 
657
- Util.fileImage = ['jpg', 'jpeg', 'png', 'webp', 'bmp', 'tif', 'gif', 'png', 'svg']
664
+ Util.fileImage = ['jpg', 'jpeg', 'png', 'webp', 'bmp', 'tif', 'gif', 'png','svg'];
658
665
 
659
666
  Util.fileExtension = (filename) => {
660
- filename = filename.toLowerCase() || ''
661
- let obj = {}
662
- let ext = filename.split('.').pop()
663
- obj.ext = ext
664
- if (Util.in_array(ext, Util.fileImage)) {
665
- obj.type = 'image'
666
- } else {
667
- obj.type = 'file'
668
- }
669
- let file = 'file.png'
670
- if (ext == 'docx' || ext == 'doc') {
671
- file = 'word.png'
672
- } else if (ext == 'xls' || ext == 'xlsx') {
673
- file = 'excel.png'
674
- } else if (ext == 'pdf') {
675
- file = 'pdf.png'
676
- } else if (ext == 'ppt' || ext == 'pptx') {
677
- file = 'ppt.png'
678
- } else if (ext == 'txt') {
679
- file = 'txt.png'
680
- } else if (ext == 'zip') {
681
- file = 'zip.jpg'
682
- } else if (ext == 'rar') {
683
- file = 'rar.jpg'
684
- } else if (ext == 'rar') {
685
- file = 'file.png'
686
- }
687
- obj.file = file
688
- return obj
689
- }
690
-
691
- Util.fileView = function (dir, file, attributes = {}) {
692
- let filename = dir + file
693
- let html = ''
694
- let width = attributes.hasOwnProperty('width') ? attributes.width : '300'
695
- let withIcon = attributes.hasOwnProperty('withIcon') ? true : false
696
- let obj = Util.fileExtension(filename)
697
- let className = attributes.hasOwnProperty('class') ? ` class="${attributes.class}" ` : ''
698
- if (filename.includes('https')) {
699
- html = `<img src="${file}" ${className} class="img-responsive">`
700
- } else {
701
- if (obj.type == 'image') {
702
- html = `<img src="${filename}" ${className} width="${width}px">`
667
+ filename = filename.toLowerCase() || "";
668
+ let obj = {}
669
+ let ext = filename.split('.').pop();
670
+ obj.ext=ext;
671
+ if (Util.in_array(ext, Util.fileImage)) {
672
+ obj.type = 'image';
703
673
  } else {
704
- if (file) {
705
- if (withIcon) {
706
- html = `<img class="mb-3 boxy-small" src="/img/${obj.file}" height="45px" width="45px"><a class="text-success" target="_blank" href="${filename}"> ${file.substring(13)}</a>`
674
+ obj.type = 'file';
675
+ }
676
+ let file = 'file.png';
677
+ if(ext == "docx" || ext == "doc") {
678
+ file = 'word.png'
679
+ } else if(ext == 'xls' || ext == 'xlsx') {
680
+ file = 'excel.png'
681
+ } else if(ext == 'pdf') {
682
+ file = 'pdf.png'
683
+ } else if(ext == 'ppt' || ext == 'pptx'){
684
+ file = 'ppt.png';
685
+ } else if(ext == 'txt') {
686
+ file = 'txt.png';
687
+ } else if(ext == 'zip') {
688
+ file = 'zip.jpg';
689
+ } else if(ext == 'rar') {
690
+ file = 'rar.jpg';
691
+ } else if(ext == 'rar') {
692
+ file = 'file.png';
693
+ }
694
+ obj.file = file;
695
+ return obj;
696
+ };
697
+
698
+ Util.fileView = function (dir, file, attributes={}) {
699
+ let filename = dir + file;
700
+ let html = '';
701
+ let width = attributes.hasOwnProperty('width') ? attributes.width : '300';
702
+ let withIcon = attributes.hasOwnProperty('withIcon') ? true : false;
703
+ let obj = Util.fileExtension(filename);
704
+ let className = attributes.hasOwnProperty('class') ? ` class="${attributes.class}" ` : '';
705
+ if(filename.includes('https')) {
706
+ html = `<img src="${file}" ${className} class="img-responsive">`
707
+ } else {
708
+ if (obj.type == 'image') {
709
+ html = `<img src="${filename}" ${className} width="${width}px">`
707
710
  } else {
708
- html = `<a class="text-success" target="_blank" href="${filename}"> ${file.substring(13)}</a>`
711
+ if (file) {
712
+ if(withIcon) {
713
+ html = `<img class="mb-3 boxy-small" src="/img/${obj.file}" height="45px" width="45px"><a class="text-success" target="_blank" href="${filename}"> ${file.substring(13)}</a>`;
714
+ } else {
715
+ html = `<a class="text-success" target="_blank" href="${filename}"> ${file.substring(13)}</a>`;
716
+ }
717
+ }
709
718
  }
710
- }
711
719
  }
712
- }
713
720
 
714
- return html
715
- }
721
+
722
+ return html;
723
+ };
716
724
  /// end files
717
725
 
718
726
  Util.arrayDelete = function (arr, value) {
719
- return arr.filter((item) => item != value)
720
- }
727
+ return arr.filter((item)=> item != value);
728
+ };
721
729
 
722
730
  Util.arrayDeletes = function (arr, array) {
723
- return arr.filter((item) => !Util.in_array(item, array))
724
- }
731
+ return arr.filter((item)=> !Util.in_array(item,array));
732
+ };
725
733
 
726
734
  Util.arrayToList = function (arr, array, delimiter, isCount) {
727
- delimiter = delimiter || '<br>'
728
- isCount = isCount || 1
729
- let html = ''
730
- if (arr) {
731
- for (var i = 0; i < arr.length; i++) {
732
- html += isCount == 1 ? i + 1 + '. ' + array[arr[i]] + delimiter : ' ' + array[arr[i]] + delimiter
735
+ delimiter = delimiter || "<br>"
736
+ isCount = isCount || 1;
737
+ let html = '';
738
+ if (arr) {
739
+ for (var i = 0; i < arr.length; i++) {
740
+ html += isCount == 1 ? (i + 1) + ". " + array[arr[i]] + delimiter : " " + array[arr[i]] + delimiter;
741
+ }
742
+ html = html.slice(0, (delimiter.length * -1))
733
743
  }
734
- html = html.slice(0, delimiter.length * -1)
735
- }
736
744
 
737
- return html
738
- }
745
+ return html;
746
+ };
739
747
 
740
748
  Util.menuAccess = function (menu, params) {
741
- const roles = require('./role')
742
- const routes = roles.routes
743
- if (Util.in_array(menu, routes)) {
744
- if (Util.in_array(menu, params)) return true
745
- else return false
746
- } else {
747
- return true
748
- }
749
- }
749
+ const roles = require('./role')
750
+ const routes = roles.routes;
751
+ if (Util.in_array(menu, routes)) {
752
+ if (Util.in_array(menu, params))
753
+ return true;
754
+ else return false;
755
+
756
+ } else {
757
+ return true;
758
+ }
759
+ };
750
760
 
751
761
  Util.dropdownHelper = function (data, field, model) {
752
- let fieldsx = field + '[]'
753
- let name = field + '[]'
754
- let myvalue = typeof data[fieldsx] == undefined ? ' ' : typeof data[fieldsx] == 'string' ? '["' + data[fieldsx] + '"]' : JSON.stringify(data[name])
755
- if (myvalue) {
756
- let unique = myvalue.indexOf('[') > -1 ? myvalue : !myvalue ? '' : '[' + myvalue + ']'
757
- unique = JSON.parse(unique)
758
- data[field] = JSON.stringify(unique.filter(Util.arrayUnique))
759
- delete data[name]
760
- }
761
- if (model.fields[field].required) {
762
- if (!data[field]) {
763
- return false
762
+ let fieldsx = field + '[]';
763
+ let name = field + "[]";
764
+ let myvalue = typeof data[fieldsx] == undefined ? " " : typeof data[fieldsx] == "string" ? '["' + data[fieldsx] + '"]' : JSON.stringify(data[name])
765
+ if (myvalue) {
766
+ let unique = myvalue.indexOf("[") > -1 ? myvalue : !myvalue ? "" : '[' + myvalue + ']';
767
+ unique = JSON.parse(unique);
768
+ data[field] = JSON.stringify(unique.filter(Util.arrayUnique));
769
+ delete data[name]
764
770
  }
765
- }
766
- return data
767
- }
771
+ if (model.fields[field].required) {
772
+ if (!data[field]) {
773
+ return false;
774
+ }
775
+ }
776
+ return data;
777
+ };
768
778
 
769
779
  Util.dropdownAdd = function (data, field, model, datas) {
770
- let name = field + '[]'
771
- let myvalue = typeof datas == undefined ? ' ' : typeof datas == 'string' ? '["' + datas + '"]' : JSON.stringify(datas)
772
- if (myvalue) {
773
- let unique = myvalue.indexOf('[') > -1 ? myvalue : !myvalue ? '' : '[' + myvalue + ']'
774
- unique = JSON.parse(unique)
775
- myvalue = JSON.stringify(unique.filter(Util.arrayUnique))
776
- delete data[name]
777
-
778
- data[field] = myvalue
779
- }
780
- if (model.fields[field].required) {
781
- if (!myvalue) {
782
- return false
780
+ let name = field + "[]";
781
+ let myvalue = typeof datas == undefined ? " " : typeof datas == "string" ? '["' + datas + '"]' : JSON.stringify(datas)
782
+ if (myvalue) {
783
+ let unique = myvalue.indexOf("[") > -1 ? myvalue : !myvalue ? "" : '[' + myvalue + ']';
784
+ unique = JSON.parse(unique);
785
+ myvalue = JSON.stringify(unique.filter(Util.arrayUnique));
786
+ delete data[name]
787
+
788
+ data[field] = myvalue;
783
789
  }
784
- }
785
- return data
786
- }
790
+ if (model.fields[field].required) {
791
+ if (!myvalue) {
792
+ return false;
793
+ }
794
+ }
795
+ return data;
796
+ };
787
797
  //array unique
788
798
  // array.filter(Util.arrayUnique);
789
799
  Util.arrayUnique = (value, index, self) => {
790
- return self.indexOf(value) == index
791
- }
800
+ return self.indexOf(value) == index;
801
+ };
792
802
 
793
803
  Util.virtualHelper = function (obj) {
794
- if (Util.isEmptyObject(obj)) return
795
- if (obj == undefined) return
804
+ if (Util.isEmptyObject(obj)) return;
805
+ if (obj == undefined) return;
796
806
 
797
- var str = ''
798
- for (var key in obj) {
799
- str += ', `' + obj[key] + '` AS ' + key
800
- }
807
+ var str = '';
808
+ for (var key in obj) {
809
+ str += ", `" + obj[key] + "` AS " + key;
810
+ }
801
811
 
802
- return str
803
- }
812
+ return str;
813
+ };
804
814
 
805
- Util.nots = ['id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'companyId', 'created_at', 'updated_at', 'updated_by', 'created_by', 'modified_by', 'company_id', 'token', 'version', 'signin_method', 'lastLogin', 'last_login', 'forgotPassword', 'forgot_password', 'no', 'actionColumn']
815
+ Util.nots = ['id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'companyId', 'created_at', 'updated_at','updated_by', 'created_by', 'modified_by', 'company_id', 'token', 'version', 'signin_method', 'lastLogin', 'last_login', 'forgotPassword', 'forgot_password','no', 'actionColumn'];
806
816
 
807
817
  Util.requiredFields = function (obj) {
808
- var nots = Util.nots
809
- var arr = []
810
- for (var key in obj) {
811
- if (!Util.in_array(key, nots)) {
812
- if (obj[key].required == true) {
813
- arr.push(key)
814
- }
818
+ var nots = Util.nots;
819
+ var arr = [];
820
+ for (var key in obj) {
821
+ if (!Util.in_array(key, nots)) {
822
+ if (obj[key].required == true) {
823
+ arr.push(key)
824
+ }
825
+ }
815
826
  }
816
- }
817
- return arr
818
- }
827
+ return arr;
828
+ };
819
829
 
820
830
  Util.extractDetails = function (obj) {
821
- let arr = []
822
- for (let key in obj) {
823
- if (obj[key].length > 0) {
824
- for (var i = 0; i < obj[key].length; i++) {
825
- arr.push(obj[key][i])
826
- }
831
+ let arr = [];
832
+ for (let key in obj) {
833
+ if (obj[key].length > 0) {
834
+ for (var i = 0; i < obj[key].length; i++) {
835
+ arr.push(obj[key][i])
836
+ }
837
+ }
827
838
  }
828
- }
829
- return arr
830
- }
839
+ return arr;
840
+ };
831
841
 
832
842
  Util.arrayToConcat = function (arr) {
833
- let str = 'CONCAT('
834
- for (let i = 0; i < arr.length; i++) {
835
- str += arr[i] + '," - ",'
836
- }
837
- str = str.slice(0, -9)
838
- str += ')'
839
-
840
- return str
841
- }
843
+ let str = 'CONCAT(';
844
+ for (let i = 0; i < arr.length; i++) {
845
+ str += arr[i] + '," - ",'
846
+ }
847
+ str = str.slice(0, -9);
848
+ str += ")"
849
+
850
+ return str;
851
+ };
842
852
 
843
853
  //sequence all fields based on drag drop generator
844
854
  Util.arraySequence = function (arr, left, right) {
845
- left = left || []
846
- right = right || []
847
- let obj = Util.arrayToObject(arr, 'Field')
848
- let temp = [],
849
- stores = []
850
- for (let i = 0; i < arr.length; i++) {
851
- if (arr[i].Field == 'id') {
852
- stores.push(arr[i].Field)
853
- temp.push(arr[i])
855
+ left = left || [];
856
+ right = right || [];
857
+ let obj = Util.arrayToObject(arr, "Field");
858
+ let temp = [], stores = [];
859
+ for (let i = 0; i < arr.length; i++) {
860
+ if (arr[i].Field == "id") {
861
+ stores.push(arr[i].Field)
862
+ temp.push(arr[i])
863
+ }
854
864
  }
855
- }
856
- if (Array.isArray(left)) {
857
- for (let i = 0; i < left.length; i++) {
858
- if (i % 2 == 0) {
859
- temp.push(obj[left[i]])
860
- stores.push(left[i])
861
- }
865
+ if (Array.isArray(left)) {
866
+ for (let i = 0; i < left.length; i++) {
867
+ if (i % 2 == 0) {
868
+ temp.push(obj[left[i]])
869
+ stores.push(left[i])
870
+ }
871
+ }
862
872
  }
863
- }
864
- if (Array.isArray(right)) {
865
- for (let i = 0; i < right.length; i++) {
866
- if (i % 2 == 0) {
867
- temp.push(obj[right[i]])
868
- stores.push(right[i])
869
- }
873
+ if (Array.isArray(right)) {
874
+ for (let i = 0; i < right.length; i++) {
875
+ if (i % 2 == 0) {
876
+ temp.push(obj[right[i]])
877
+ stores.push(right[i])
878
+ }
879
+ }
870
880
  }
871
- }
872
- if (Array.isArray(left)) {
873
- for (let i = 0; i < left.length; i++) {
874
- if (i % 2 == 1) {
875
- temp.push(obj[left[i]])
876
- stores.push(left[i])
877
- }
881
+ if (Array.isArray(left)) {
882
+ for (let i = 0; i < left.length; i++) {
883
+ if (i % 2 == 1) {
884
+ temp.push(obj[left[i]])
885
+ stores.push(left[i])
886
+ }
887
+ }
878
888
  }
879
- }
880
- if (Array.isArray(right)) {
881
- for (let i = 0; i < right.length; i++) {
882
- if (i % 2 == 1) {
883
- temp.push(obj[right[i]])
884
- stores.push(right[i])
885
- }
889
+ if (Array.isArray(right)) {
890
+ for (let i = 0; i < right.length; i++) {
891
+ if (i % 2 == 1) {
892
+ temp.push(obj[right[i]])
893
+ stores.push(right[i])
894
+ }
895
+ }
886
896
  }
887
- }
888
897
 
889
- for (let i = 0; i < arr.length; i++) {
890
- const field = arr[i].Field
891
- if (!Util.in_array(field, stores)) {
892
- temp.push(arr[i])
898
+ for (let i = 0; i < arr.length; i++) {
899
+ const field = arr[i].Field;
900
+ if (!Util.in_array(field, stores)) {
901
+ temp.push(arr[i])
902
+ }
893
903
  }
894
- }
895
904
 
896
- return temp
897
- }
905
+ return temp;
906
+ };
898
907
 
899
908
  Util.isInteger = (value) => {
900
- return (
901
- !isNaN(value) &&
902
- (function (x) {
903
- return (x | 0) === x
909
+ return !isNaN(value) && (function (x) {
910
+ return (x | 0) === x;
904
911
  })(parseFloat(value))
905
- )
906
- }
912
+ };
907
913
 
908
914
  Util.isNumeric = function (value) {
909
- return /^-?\d+$/.test(value)
910
- }
915
+ return /^-?\d+$/.test(value);
916
+ };
911
917
 
912
918
  Util.tags = function (tags) {
913
- let html = ''
914
- tags = tags || ''
915
- if (tags.indexOf(',') > -1) {
916
- let explode = tags.split(',')
917
- for (var i = 0; i < explode.length; i++) {
918
- html += `<a href="#" rel="tag">${explode[i]}</a>`
919
+ let html = '';
920
+ tags = tags || "";
921
+ if (tags.indexOf(",") > -1) {
922
+ let explode = tags.split(",");
923
+ for (var i = 0; i < explode.length; i++) {
924
+ html += `<a href="#" rel="tag">${explode[i]}</a>`
925
+ }
926
+ } else {
927
+ html += `<a href="#" rel="tag">${tags}</a>`;
919
928
  }
920
- } else {
921
- html += `<a href="#" rel="tag">${tags}</a>`
922
- }
923
929
 
924
- return html
925
- }
930
+ return html;
931
+ };
926
932
 
927
933
  /*
928
934
  get extension of filename
929
935
  */
930
936
 
931
937
  Util.getExtensionFile = (str) => {
932
- str = str || ''
933
- let extension = str.split('.').pop()
934
- extension = extension.toLowerCase()
935
- let ret = extension
936
- if (extension == 'jpg') {
937
- ret = 'jpeg'
938
- }
939
- return ret
940
- }
938
+ str = str || "";
939
+ let extension = str.split('.').pop();
940
+ extension = extension.toLowerCase();
941
+ let ret = extension;
942
+ if (extension == "jpg") {
943
+ ret = "jpeg";
944
+ }
945
+ return ret;
946
+ };
941
947
 
942
948
  Util.badgeError = (msg) => {
943
- return `<span class="badge badge-danger">${msg}</span>`
944
- }
949
+ return `<span class="badge badge-danger">${msg}</span>`;
950
+ };
945
951
 
946
952
  Util.badgeSuccess = (msg) => {
947
- return `<span class="badge badge-success">${msg}</span>`
948
- }
953
+ return `<span class="badge badge-success">${msg}</span>`;
954
+ };
949
955
 
950
956
  Util.alertError = function (msg) {
951
- return `<div class="alert alert-danger" role="alert">${msg}</div>`
952
- }
957
+ return `<div class="alert alert-danger" role="alert">${msg}</div>`;
958
+ };
953
959
 
954
960
  Util.alertSuccess = function (msg) {
955
- return `<div class="alert alert-success" role="alert">${msg}</div>`
956
- }
961
+ return `<div class="alert alert-success" role="alert">${msg}</div>`;
962
+ };
957
963
 
958
964
  Util.alertInfo = function (msg) {
959
- return `<div class="alert alert-info" role="alert">${msg}</div>`
960
- }
965
+ return `<div class="alert alert-info" role="alert">${msg}</div>`;
966
+ };
961
967
 
962
968
  Util.regexPassword = (lengthMin, lengthMax) => {
963
- //minimum length
964
- lengthMin = lengthMin || 6
965
- lengthMax = lengthMax || 20
969
+ //minimum length
970
+ lengthMin = lengthMin || 6;
971
+ lengthMax = lengthMax || 20;
966
972
 
967
- return new RegExp('^[a-zA-Z0-9_-]{' + lengthMin + ',' + lengthMax + '}$', 'i')
968
- }
973
+ return new RegExp('^[a-zA-Z0-9_-]{' + lengthMin + ',' + lengthMax + '}$', "i");
974
+ };
969
975
 
970
976
  //huruf dan angka saja
971
977
  Util.regexCode = (lengthMin, lengthMax) => {
972
- lengthMin = lengthMin || 2
973
- lengthMax = lengthMax || 10
978
+ lengthMin = lengthMin || 2;
979
+ lengthMax = lengthMax || 10;
974
980
 
975
- return new RegExp('^[A-Z0-9]{' + lengthMin + ',' + lengthMax + '}$', 'i')
976
- }
981
+ return new RegExp('^[A-Z0-9]{' + lengthMin + ',' + lengthMax + '}$', "i");
982
+ };
977
983
 
978
984
  Util.imageProfile = function (image) {
979
- return image ? (image.indexOf('http') > -1 ? image : '/uploads/user/' + image) : '/img/user.png'
980
- }
985
+ return image ? image.indexOf("http") > -1 ? image : "/uploads/user/" + image : "/img/user.png";
986
+ };
981
987
 
982
988
  /*
983
989
  Files
984
990
  */
985
991
  Util.readFile = function (filename) {
986
- try {
987
- if (Util.fileExist(filename)) {
988
- const data = fs.readFileSync(filename, 'utf8')
989
- return data
992
+ try {
993
+ if(Util.fileExist(filename)) {
994
+ const data = fs.readFileSync(filename, 'utf8');
995
+ return data;
996
+ }
997
+ } catch (err) {
990
998
  }
991
- } catch (err) {}
992
- return ''
993
- }
999
+ return ""
1000
+
1001
+ };
994
1002
  //check directory if not exist create or not return true/false
995
- Util.dirExist = (dir, create = false) => {
996
- try {
997
- if (create) {
998
- fs.ensureDir(dir, (err) => {})
999
- }
1000
- // check if directory exists
1001
- if (fs.existsSync(dir)) {
1002
- return true
1003
+ Util.dirExist = (dir, create = false) =>{
1004
+ try {
1005
+ if(create) {
1006
+ fs.ensureDir(dir, err => {
1007
+ });
1008
+ }
1009
+ // check if directory exists
1010
+ if (fs.existsSync(dir)) {
1011
+ return true;
1012
+ }
1013
+ } catch (e) {
1003
1014
  }
1004
- } catch (e) {}
1005
- return false
1006
- }
1015
+ return false;
1016
+ };
1007
1017
 
1008
1018
  Util.fileExist = (filename) => {
1009
- if (fs.existsSync(filename)) {
1010
- return true
1011
- }
1012
- return false
1013
- }
1019
+ if (fs.existsSync(filename)) {
1020
+ return true;
1021
+ }
1022
+ return false;
1023
+ };
1014
1024
 
1015
1025
  Util.getAllFiles = (dir) => {
1016
- let files = []
1017
- try {
1018
- if (Util.dirExist(dir, true)) {
1019
- files = fs.readdirSync(dir)
1026
+ let files = [];
1027
+ try {
1028
+ if(Util.dirExist(dir, true)) {
1029
+ files = fs.readdirSync(dir);
1030
+ }
1031
+ } catch (e) {
1032
+ return [];
1020
1033
  }
1021
- } catch (e) {
1022
- return []
1023
- }
1024
- return files
1025
- }
1034
+ return files;
1035
+ };
1026
1036
 
1027
1037
  Util.writeFile = (filename, content) => {
1028
- try {
1029
- let dir = require('path').dirname(filename)
1030
- Util.dirExist(dir, true)
1031
- fs.writeFileSync(filename, content)
1032
- return true
1033
- } catch (e) {
1034
- return false
1035
- }
1036
- }
1038
+ try {
1039
+ let dir = require('path').dirname(filename);
1040
+ Util.dirExist(dir,true);
1041
+ fs.writeFileSync(filename, content);
1042
+ return true
1043
+ } catch (e) {
1044
+ return false
1045
+ }
1046
+ };
1037
1047
 
1038
1048
  Util.deleteAllFiles = (dir) => {
1039
- try {
1040
- fs.emptyDirSync(dir)
1041
- return true
1042
- } catch (e) {
1043
- return false
1044
- }
1045
- }
1046
-
1047
- Util.findFilesName = (arr, filename) => {
1048
- arr = arr || []
1049
- return arr.filter((item) => item.includes(filename))
1050
- }
1051
-
1052
- Util.getFiles = function (dir, token = '') {
1053
- let arr = fs.readdirSync(dir)
1054
- let folders = ''
1055
- let files = ''
1056
- arr.forEach(function (item) {
1057
- if (item.indexOf('.') > -1) {
1058
- var explode = dir.split('public/')
1059
- var path = explode[1]
1060
- var url = '/' + path + '/' + item
1061
- var extension = item.split('.').pop()
1062
- files += ` <div class="folder data-file ui-draggable ui-draggable-handle ui-selectee" data-toggle="tooltip" data-type="file" data-url="${url}" data-extension="${extension}" data-name="${item}" filename="${item}" data-original-title="${item}">
1049
+ try {
1050
+ fs.emptyDirSync(dir);
1051
+ return true
1052
+ } catch (e) {
1053
+ return false
1054
+ }
1055
+ };
1056
+
1057
+ Util.findFilesName = (arr,filename) => {
1058
+ arr = arr || [];
1059
+ return arr.filter((item) => item.includes(filename));
1060
+ };
1061
+
1062
+ Util.getFiles = function (dir, token = "") {
1063
+ let arr = fs.readdirSync(dir);
1064
+ let folders = "";
1065
+ let files = "";
1066
+ arr.forEach(function (item) {
1067
+ if (item.indexOf(".") > -1) {
1068
+ var explode = dir.split("public/");
1069
+ var path = explode[1];
1070
+ var url = "/" + path + "/" + item;
1071
+ var extension = item.split('.').pop();
1072
+ files += ` <div class="folder data-file ui-draggable ui-draggable-handle ui-selectee" data-toggle="tooltip" data-type="file" data-url="${url}" data-extension="${extension}" data-name="${item}" filename="${item}" data-original-title="${item}">
1063
1073
  <img src="/assets/images/formats/file.png" class="img-responsive ui-selectee">
1064
1074
  <p class="text-ellipsis ui-selectee">${item}</p>
1065
- </div>`
1066
- } else {
1067
- let explode = dir.split(token)
1068
- let path = explode[1] || ''
1069
- let state = ''
1070
- if (path == '') {
1071
- state = '/' + item
1072
- } else {
1073
- state = path.replace(item, '') + '/' + item
1074
- }
1075
- folders += `<div class="folder data-folder ui-draggable ui-draggable-handle ui-droppable ui-selectee" data-toggle="tooltip" data-type="folder" data-state="${state}" data-name="${item}" data-original-title="${item}">
1075
+ </div>`;
1076
+ } else {
1077
+ let explode = dir.split(token);
1078
+ let path = explode[1] || "";
1079
+ let state = "";
1080
+ if (path == "") {
1081
+ state = "/" + item;
1082
+ } else {
1083
+ state = path.replace(item, "") + "/" + item;
1084
+ }
1085
+ folders += `<div class="folder data-folder ui-draggable ui-draggable-handle ui-droppable ui-selectee" data-toggle="tooltip" data-type="folder" data-state="${state}" data-name="${item}" data-original-title="${item}">
1076
1086
  <img src="/assets/images/folder.png" class="img-responsive ui-selectee">
1077
1087
  <p class="text-ellipsis ui-selectee">${item}</p>
1078
- </div>`
1079
- }
1080
- })
1088
+ </div>`;
1089
+ }
1090
+ });
1081
1091
 
1082
- return folders + files
1083
- }
1092
+ return folders + files;
1093
+ };
1084
1094
 
1085
- Util.ejsOpen = '<%- '
1086
- Util.ejsStart = '<% '
1087
- Util.ejsClose = ' %>'
1095
+ Util.ejsOpen = "<%- ";
1096
+ Util.ejsStart = "<% ";
1097
+ Util.ejsClose = " %>";
1088
1098
  Util.ejsFunction = (yourCode, isStatement = false) => {
1089
- const open = isStatement ? Util.ejsStart : Util.ejsOpen
1090
- return open + yourCode + Util.ejsClose
1091
- }
1099
+ const open = isStatement ? Util.ejsStart : Util.ejsOpen;
1100
+ return open + yourCode + Util.ejsClose;
1101
+ };
1092
1102
 
1093
1103
  Util.attributeOptions = (obj, defaultObj = {}) => {
1094
- let html = ''
1095
- let arr = Object.keys(defaultObj) || []
1096
- for (const key in obj) {
1097
- let value = obj[key]
1098
- if (defaultObj.hasOwnProperty(key)) {
1099
- value = defaultObj[key] + obj[key]
1100
- Util.arrayDelete(arr, key)
1104
+ let html = '';
1105
+ let arr = Object.keys(defaultObj) || [];
1106
+ for (const key in obj) {
1107
+ let value = obj[key];
1108
+ if(defaultObj.hasOwnProperty(key)) {
1109
+ value = defaultObj[key] + obj[key];
1110
+ Util.arrayDelete(arr,key);
1111
+ }
1112
+ html += ` ${key}="${value}" `;
1101
1113
  }
1102
- html += ` ${key}="${value}" `
1103
- }
1104
- if (arr.length) {
1105
- arr.map((item) => (html += ` ${item}="${defaultObj[item]}" `))
1106
- }
1107
- return html
1108
- }
1114
+ if(arr.length){
1115
+ arr.map(item => html += ` ${item}="${defaultObj[item]}" `)
1116
+ }
1117
+ return html;
1118
+ };
1109
1119
 
1110
1120
  Util.userAvatar = (img) => {
1111
- return img ? (img.includes('http') ? img : `/uploads/user/${img}`) : `/img/user.png`
1112
- }
1121
+ return img ? img.includes("http") ? img : `/uploads/user/${img}` : `/img/user.png`;
1122
+ };
1113
1123
 
1114
1124
  /*
1115
1125
  MYSQL HELPER
1116
1126
  */
1117
1127
  Util.selectParser = (fields, MYMODEL) => {
1118
- fields = fields.filter((e) => e !== 'actionColumn')
1119
- let virtuals = []
1120
- for (var key in MYMODEL.widgets) {
1121
- if (MYMODEL.widgets[key].name === 'virtual') {
1122
- virtuals.push(key)
1123
- }
1124
- }
1125
- let arr = []
1126
- fields.forEach((item) => {
1127
- if (virtuals.includes(item)) {
1128
- arr.push(MYMODEL.widgets[item].fields)
1129
- } else if (item === 'no') {
1130
- arr.push('id')
1131
- } else {
1132
- arr.push(item)
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
+ }
1133
1134
  }
1134
- })
1135
-
1136
- return `"${arr.join('","')}"`
1137
- }
1138
-
1139
- Util.selectMysql = (fields, relations = {}) => {
1140
- let obj = {}
1141
- let arr = []
1142
- let virtuals = {}
1143
- let virtualArray = []
1144
- if (relations.hasOwnProperty('zvirtuals')) {
1145
- virtuals = relations.zvirtuals
1146
- delete relations.zvirtuals
1147
- virtualArray = Object.keys(virtuals)
1148
- virtualArray.forEach(function (item) {
1149
- fields = Util.arrayDelete(fields, item)
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
+ }
1150
1144
  })
1151
- }
1152
- let selects = []
1153
- fields = fields || []
1154
- fields.forEach(function (item) {
1155
- if (item != 'actionColumn') {
1156
- if (item == 'no') {
1157
- selects.push('id')
1158
- } else {
1159
- selects.push(item)
1160
- }
1145
+
1146
+ let select = `"${arr.join('","')}"`;
1147
+ return select;
1148
+ }
1149
+
1150
+ Util.selectMysql = (fields,relations={}) => {
1151
+ let obj = {}
1152
+ let arr = [];
1153
+ let virtuals = {};
1154
+ let virtualArray = [];
1155
+ if(relations.hasOwnProperty("zvirtuals")){
1156
+ virtuals = relations.zvirtuals;
1157
+ delete relations.zvirtuals;
1158
+ virtualArray = Object.keys(virtuals);
1159
+ virtualArray.forEach(function (item) {
1160
+ fields = Util.arrayDelete(fields,item);
1161
+ });
1161
1162
  }
1162
- })
1163
- //make sure id
1164
- selects.push('id')
1165
- let select = `"${selects.join('","')}"`
1166
- if (virtualArray.length) {
1167
- for (let key in virtuals) {
1168
- select += `, ${virtuals[key]} `
1163
+ let selects = [];
1164
+ fields = fields || [];
1165
+ fields.forEach(function (item) {
1166
+ if(item != "actionColumn") {
1167
+ if (item == "no") {
1168
+ selects.push("id");
1169
+ } else {
1170
+ selects.push(item);
1171
+ }
1172
+ }
1173
+ })
1174
+ //make sure id
1175
+ selects.push("id")
1176
+ let select =`"${selects.join('","')}"`;
1177
+ if(virtualArray.length) {
1178
+ for(let key in virtuals) {
1179
+ select += `, ${virtuals[key]} `;
1180
+ }
1169
1181
  }
1170
- }
1171
- return select
1172
- }
1182
+ return select;
1183
+ };
1173
1184
 
1174
1185
  /*
1175
1186
  Sorting array object with key name
1176
1187
  */
1177
- Util.sortArray = (arr, key) => {
1178
- function compare(a, b) {
1179
- if (a[key] < b[key]) {
1180
- return -1
1181
- }
1182
- if (a[key] > b[key]) {
1183
- return 1
1188
+ Util.sortArray = (arr,key) => {
1189
+ function compare( a, b ) {
1190
+ if ( a[key] < b[key] ){
1191
+ return -1;
1192
+ }
1193
+ if ( a[key] > b[key] ){
1194
+ return 1;
1195
+ }
1196
+ return 0;
1184
1197
  }
1185
- return 0
1186
- }
1187
- return arr.sort(compare)
1188
- }
1198
+ return arr.sort(compare);
1199
+ };
1189
1200
 
1190
- module.exports = Util
1201
+ module.exports = Util;