zet-lib 1.3.42 → 1.3.43
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 +959 -772
- package/package.json +1 -1
package/lib/Util.js
CHANGED
|
@@ -1,69 +1,96 @@
|
|
|
1
|
-
const moment = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const randomstring = require(
|
|
4
|
-
const fs = require(
|
|
5
|
-
const { v4: uuidv4 } = require(
|
|
6
|
-
const sha256 = require(
|
|
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
|
-
const Util = {}
|
|
8
|
+
const Util = {};
|
|
9
9
|
|
|
10
|
-
Util.tab =
|
|
10
|
+
Util.tab = "\t";
|
|
11
11
|
Util.tabs = (n) => {
|
|
12
|
-
let ret =
|
|
12
|
+
let ret = "";
|
|
13
13
|
for (var i = 0; i < n; i++) {
|
|
14
|
-
ret += Util.tab
|
|
14
|
+
ret += Util.tab;
|
|
15
15
|
}
|
|
16
|
-
return ret
|
|
17
|
-
}
|
|
16
|
+
return ret;
|
|
17
|
+
};
|
|
18
18
|
|
|
19
|
-
Util.NEW_LINE =
|
|
20
|
-
Util.newLine =
|
|
19
|
+
Util.NEW_LINE = "\n";
|
|
20
|
+
Util.newLine = "\r\n";
|
|
21
21
|
Util.newLines = (n) => {
|
|
22
|
-
let ret =
|
|
22
|
+
let ret = "";
|
|
23
23
|
for (var i = 0; i < n; i++) {
|
|
24
|
-
ret += Util.newLine
|
|
24
|
+
ret += Util.newLine;
|
|
25
25
|
}
|
|
26
|
-
return ret
|
|
27
|
-
}
|
|
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 = [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
let abjads = [
|
|
40
|
+
"A",
|
|
41
|
+
"B",
|
|
42
|
+
"C",
|
|
43
|
+
"D",
|
|
44
|
+
"E",
|
|
45
|
+
"F",
|
|
46
|
+
"G",
|
|
47
|
+
"H",
|
|
48
|
+
"I",
|
|
49
|
+
"J",
|
|
50
|
+
"K",
|
|
51
|
+
"L",
|
|
52
|
+
"M",
|
|
53
|
+
"N",
|
|
54
|
+
"O",
|
|
55
|
+
"P",
|
|
56
|
+
"Q",
|
|
57
|
+
"R",
|
|
58
|
+
"S",
|
|
59
|
+
"T",
|
|
60
|
+
"U",
|
|
61
|
+
"V",
|
|
62
|
+
"W",
|
|
63
|
+
"X",
|
|
64
|
+
"Y",
|
|
65
|
+
"Z",
|
|
66
|
+
];
|
|
67
|
+
let arr = abjads;
|
|
68
|
+
let char = 0;
|
|
69
|
+
let num = 26;
|
|
43
70
|
for (let x = 2; x < 15; x++) {
|
|
44
|
-
let idx = 0
|
|
71
|
+
let idx = 0;
|
|
45
72
|
for (let i = 1; i <= 26; i++) {
|
|
46
|
-
arr[num] = abjads[char] + abjads[idx]
|
|
47
|
-
idx
|
|
48
|
-
num
|
|
73
|
+
arr[num] = abjads[char] + abjads[idx];
|
|
74
|
+
idx++;
|
|
75
|
+
num++;
|
|
49
76
|
}
|
|
50
|
-
char
|
|
77
|
+
char++;
|
|
51
78
|
}
|
|
52
79
|
|
|
53
|
-
return arr
|
|
54
|
-
}
|
|
80
|
+
return arr;
|
|
81
|
+
};
|
|
55
82
|
|
|
56
83
|
Util.now = function () {
|
|
57
|
-
return moment(new Date()).format(
|
|
58
|
-
}
|
|
84
|
+
return moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
|
|
85
|
+
};
|
|
59
86
|
|
|
60
87
|
Util.nowShort = function () {
|
|
61
|
-
return moment(new Date()).format(
|
|
62
|
-
}
|
|
88
|
+
return moment(new Date()).format("YYYY-MM-DD");
|
|
89
|
+
};
|
|
63
90
|
|
|
64
91
|
Util.ago = (data) => {
|
|
65
|
-
return moment(data).fromNow()
|
|
66
|
-
}
|
|
92
|
+
return moment(data).fromNow();
|
|
93
|
+
};
|
|
67
94
|
/*
|
|
68
95
|
moment get one month ago from current
|
|
69
96
|
var monthago = moment().subtract(1, 'months').format('YYYY-MM-DD');
|
|
@@ -71,269 +98,300 @@ Util.ago = (data) => {
|
|
|
71
98
|
*/
|
|
72
99
|
|
|
73
100
|
Util.dateSql = function (date, format) {
|
|
74
|
-
format = format ||
|
|
75
|
-
if (date && date !=
|
|
76
|
-
else return
|
|
77
|
-
}
|
|
101
|
+
format = format || "YYYY-MM-DD";
|
|
102
|
+
if (date && date != "0000-00-00") return moment(date).format(format);
|
|
103
|
+
else return "";
|
|
104
|
+
};
|
|
78
105
|
|
|
79
106
|
Util.dateOriginal = function (date) {
|
|
80
|
-
if (date && date !=
|
|
81
|
-
let value = moment(date).utc(false)
|
|
82
|
-
return value
|
|
107
|
+
if (date && date != "0000-00-00") {
|
|
108
|
+
let value = moment(date).utc(false);
|
|
109
|
+
return value;
|
|
83
110
|
} else {
|
|
84
|
-
return
|
|
111
|
+
return "";
|
|
85
112
|
}
|
|
86
|
-
}
|
|
113
|
+
};
|
|
87
114
|
|
|
88
115
|
Util.dateFormat = function (date, format) {
|
|
89
|
-
format = format ||
|
|
90
|
-
if (date && date !=
|
|
91
|
-
else return
|
|
92
|
-
}
|
|
116
|
+
format = format || "YYYY-MM-DD";
|
|
117
|
+
if (date && date != "0000-00-00") return moment(date).format(format);
|
|
118
|
+
else return "";
|
|
119
|
+
};
|
|
93
120
|
|
|
94
121
|
Util.timePublic = function (date) {
|
|
95
|
-
if (date) return moment(date).format(
|
|
96
|
-
else return
|
|
97
|
-
}
|
|
122
|
+
if (date) return moment(date).format("DD MMM YYYY");
|
|
123
|
+
else return "";
|
|
124
|
+
};
|
|
98
125
|
|
|
99
126
|
Util.timeSql = function (date, format) {
|
|
100
|
-
if (date && date !=
|
|
101
|
-
format = format ||
|
|
102
|
-
return moment(date).format(format)
|
|
103
|
-
} else return
|
|
104
|
-
}
|
|
127
|
+
if (date && date != "0000-00-00 00:00:00") {
|
|
128
|
+
format = format || "YYYY-MM-DD HH:mm:ss";
|
|
129
|
+
return moment(date).format(format);
|
|
130
|
+
} else return "";
|
|
131
|
+
};
|
|
105
132
|
|
|
106
133
|
//moment('2017-11-30T15:00:00-07:00').diff(moment('2017-05-31T15:00:00-07:00'), 'months')
|
|
107
|
-
Util.dateDiff = (start, end, format =
|
|
108
|
-
let count = 0
|
|
134
|
+
Util.dateDiff = (start, end, format = "months") => {
|
|
135
|
+
let count = 0;
|
|
109
136
|
if (start && end) {
|
|
110
|
-
count = moment(end).diff(moment(start), format, true)
|
|
137
|
+
count = moment(end).diff(moment(start), format, true);
|
|
111
138
|
}
|
|
112
|
-
return count
|
|
113
|
-
}
|
|
139
|
+
return count;
|
|
140
|
+
};
|
|
114
141
|
|
|
115
142
|
Util.getDate = function (date) {
|
|
116
|
-
date = date +
|
|
117
|
-
if (date !=
|
|
118
|
-
let explode = date.split(
|
|
143
|
+
date = date + "" || "";
|
|
144
|
+
if (date != "") {
|
|
145
|
+
let explode = date.split("-");
|
|
119
146
|
return {
|
|
120
147
|
year: parseInt(explode[0]),
|
|
121
148
|
month: parseInt(explode[1]),
|
|
122
149
|
date: parseInt(explode[2]),
|
|
123
|
-
}
|
|
150
|
+
};
|
|
124
151
|
} else {
|
|
125
152
|
return {
|
|
126
153
|
year: 0,
|
|
127
154
|
month: 0,
|
|
128
155
|
date: 0,
|
|
129
|
-
}
|
|
156
|
+
};
|
|
130
157
|
}
|
|
131
|
-
}
|
|
158
|
+
};
|
|
132
159
|
|
|
133
160
|
Util.dateIsBetween = (compare, start, end) => {
|
|
134
|
-
if (compare ==
|
|
135
|
-
return false
|
|
161
|
+
if (compare == "" || compare == "0000-00-00") {
|
|
162
|
+
return false;
|
|
136
163
|
}
|
|
137
|
-
compare = moment(compare).format(
|
|
138
|
-
start = moment(start).format(
|
|
139
|
-
end = moment(end).format(
|
|
140
|
-
let today = moment(compare)
|
|
141
|
-
let startDate = moment(start)
|
|
142
|
-
let endDate = moment(end)
|
|
164
|
+
compare = moment(compare).format("YYYY-MM-DD");
|
|
165
|
+
start = moment(start).format("YYYY-MM-DD");
|
|
166
|
+
end = moment(end).format("YYYY-MM-DD");
|
|
167
|
+
let today = moment(compare);
|
|
168
|
+
let startDate = moment(start);
|
|
169
|
+
let endDate = moment(end);
|
|
143
170
|
|
|
144
171
|
if (compare == start) {
|
|
145
|
-
return true
|
|
172
|
+
return true;
|
|
146
173
|
} else if (compare == end) {
|
|
147
|
-
return true
|
|
174
|
+
return true;
|
|
148
175
|
} else {
|
|
149
|
-
return today.isBetween(startDate, endDate)
|
|
176
|
+
return today.isBetween(startDate, endDate);
|
|
150
177
|
}
|
|
151
|
-
}
|
|
178
|
+
};
|
|
152
179
|
|
|
153
180
|
Util.getMonth = function (date) {
|
|
154
181
|
if (date.length > 5) {
|
|
155
|
-
let n = new Date(date)
|
|
156
|
-
let m = n.getMonth()
|
|
157
|
-
return parseInt(m) + 1
|
|
182
|
+
let n = new Date(date);
|
|
183
|
+
let m = n.getMonth();
|
|
184
|
+
return parseInt(m) + 1;
|
|
158
185
|
}
|
|
159
|
-
return 0
|
|
160
|
-
}
|
|
186
|
+
return 0;
|
|
187
|
+
};
|
|
161
188
|
|
|
162
189
|
Util.getYear = function (date) {
|
|
163
|
-
date = Util.dateSql(date) ||
|
|
164
|
-
return date.slice(0, 4)
|
|
165
|
-
}
|
|
190
|
+
date = Util.dateSql(date) || "";
|
|
191
|
+
return date.slice(0, 4);
|
|
192
|
+
};
|
|
166
193
|
|
|
167
194
|
//first is smaller than second
|
|
168
195
|
Util.calculateDay = function (from, to, holidayInWeek = 0) {
|
|
169
|
-
holidayInWeek = parseInt(holidayInWeek) || 0
|
|
170
|
-
let count = 0
|
|
196
|
+
holidayInWeek = parseInt(holidayInWeek) || 0;
|
|
197
|
+
let count = 0;
|
|
171
198
|
if (holidayInWeek == 1) {
|
|
172
|
-
let days = Util.enumerateDaysBetweenDates(
|
|
173
|
-
|
|
174
|
-
|
|
199
|
+
let days = Util.enumerateDaysBetweenDates(
|
|
200
|
+
moment(from).format("YYYY-MM-DD"),
|
|
201
|
+
moment(to).format("YYYY-MM-DD")
|
|
202
|
+
);
|
|
203
|
+
let countdays = days.filter(
|
|
204
|
+
(item) => parseInt(moment(item).format("d")) != 0
|
|
205
|
+
);
|
|
206
|
+
count = countdays.length;
|
|
175
207
|
} else if (holidayInWeek == 2) {
|
|
176
|
-
let days = Util.enumerateDaysBetweenDates(
|
|
177
|
-
|
|
178
|
-
|
|
208
|
+
let days = Util.enumerateDaysBetweenDates(
|
|
209
|
+
moment(from).format("YYYY-MM-DD"),
|
|
210
|
+
moment(to).format("YYYY-MM-DD")
|
|
211
|
+
);
|
|
212
|
+
let countdays = days.filter(
|
|
213
|
+
(item) =>
|
|
214
|
+
parseInt(moment(item).format("d")) != 0 &&
|
|
215
|
+
parseInt(moment(item).format("d")) != 6
|
|
216
|
+
);
|
|
217
|
+
count = countdays.length;
|
|
179
218
|
} else {
|
|
180
|
-
let a = moment(from)
|
|
181
|
-
let b = moment(to)
|
|
182
|
-
count = b.diff(a,
|
|
219
|
+
let a = moment(from);
|
|
220
|
+
let b = moment(to);
|
|
221
|
+
count = b.diff(a, "days") + 1;
|
|
183
222
|
}
|
|
184
223
|
|
|
185
|
-
return count
|
|
186
|
-
}
|
|
224
|
+
return count;
|
|
225
|
+
};
|
|
187
226
|
|
|
188
227
|
var getDaysBetweenDates = function (startDate, endDate) {
|
|
189
228
|
let now = startDate.clone(),
|
|
190
|
-
dates = []
|
|
229
|
+
dates = [];
|
|
191
230
|
while (now.isSameOrBefore(endDate)) {
|
|
192
|
-
dates.push(now.format(
|
|
193
|
-
now.add(1,
|
|
231
|
+
dates.push(now.format("MM/DD/YYYY"));
|
|
232
|
+
now.add(1, "days");
|
|
194
233
|
}
|
|
195
|
-
return dates
|
|
196
|
-
}
|
|
234
|
+
return dates;
|
|
235
|
+
};
|
|
197
236
|
|
|
198
237
|
//itterate days in array
|
|
199
238
|
Util.enumerateDaysBetweenDates = function (startDate, endDate) {
|
|
200
239
|
let now = moment(startDate).clone(),
|
|
201
|
-
dates = []
|
|
240
|
+
dates = [];
|
|
202
241
|
while (now.isSameOrBefore(endDate)) {
|
|
203
|
-
dates.push(now.format(
|
|
204
|
-
now.add(1,
|
|
242
|
+
dates.push(now.format("MM/DD/YYYY"));
|
|
243
|
+
now.add(1, "days");
|
|
205
244
|
}
|
|
206
|
-
return dates
|
|
207
|
-
}
|
|
245
|
+
return dates;
|
|
246
|
+
};
|
|
208
247
|
|
|
209
248
|
Util.tableArray = function (arr = []) {
|
|
210
|
-
let r = []
|
|
211
|
-
let tables = arr[0]
|
|
249
|
+
let r = [];
|
|
250
|
+
let tables = arr[0];
|
|
212
251
|
for (let i = 0; i < tables.length; i++) {
|
|
213
252
|
for (let obj in tables[i]) {
|
|
214
|
-
r.push(tables[i][obj])
|
|
253
|
+
r.push(tables[i][obj]);
|
|
215
254
|
}
|
|
216
255
|
}
|
|
217
|
-
return r
|
|
218
|
-
}
|
|
256
|
+
return r;
|
|
257
|
+
};
|
|
219
258
|
|
|
220
259
|
/*
|
|
221
260
|
table array in sql to arr table name
|
|
222
261
|
only for generator
|
|
223
262
|
*/
|
|
224
263
|
Util.tableArrayToObj = (arr = []) => {
|
|
225
|
-
return arr.map((m) => Object.values(m)[0])
|
|
226
|
-
}
|
|
264
|
+
return arr.map((m) => Object.values(m)[0]);
|
|
265
|
+
};
|
|
227
266
|
|
|
228
|
-
Util.escapeRegExp = function (str =
|
|
229
|
-
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,
|
|
230
|
-
}
|
|
267
|
+
Util.escapeRegExp = function (str = "") {
|
|
268
|
+
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
|
269
|
+
};
|
|
231
270
|
|
|
232
271
|
Util.validateEmail = function (email) {
|
|
233
|
-
let re =
|
|
234
|
-
|
|
235
|
-
|
|
272
|
+
let re =
|
|
273
|
+
/^(([^<>()[\]\\.,;:\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,}))$/;
|
|
274
|
+
return re.test(email);
|
|
275
|
+
};
|
|
236
276
|
|
|
237
277
|
/*
|
|
238
278
|
Replace All like str_replace in PHP
|
|
239
279
|
example : Util.replaceAll("abd","a","")
|
|
240
280
|
*/
|
|
241
281
|
|
|
242
|
-
Util.replaceAll = function (str =
|
|
243
|
-
let t =
|
|
282
|
+
Util.replaceAll = function (str = "", find, replace) {
|
|
283
|
+
let t = "";
|
|
244
284
|
if (Array.isArray(find)) {
|
|
245
|
-
t = str
|
|
285
|
+
t = str;
|
|
246
286
|
for (let i = 0; i < find.length; i++) {
|
|
247
287
|
if (str.indexOf(find[i]) > -1) {
|
|
248
|
-
t = str.replace(new RegExp(Util.escapeRegExp(find[i]),
|
|
288
|
+
t = str.replace(new RegExp(Util.escapeRegExp(find[i]), "g"), replace);
|
|
249
289
|
}
|
|
250
290
|
}
|
|
251
291
|
} else {
|
|
252
|
-
if (typeof str ==
|
|
253
|
-
t = str.replace(new RegExp(Util.escapeRegExp(find),
|
|
292
|
+
if (typeof str == "string") {
|
|
293
|
+
t = str.replace(new RegExp(Util.escapeRegExp(find), "g"), replace);
|
|
254
294
|
}
|
|
255
295
|
}
|
|
256
|
-
return t
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
Util.phoneFixed = function (str =
|
|
260
|
-
let ret =
|
|
261
|
-
str = Util.replaceAll(str,
|
|
262
|
-
let phone = str.trim()
|
|
263
|
-
phone = Util.replaceAll(phone,
|
|
264
|
-
let first = phone.charAt(0)
|
|
265
|
-
if (first ==
|
|
266
|
-
ret =
|
|
267
|
-
} else if (first ==
|
|
268
|
-
ret = phone
|
|
269
|
-
} else if (first ==
|
|
270
|
-
ret =
|
|
296
|
+
return t;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
Util.phoneFixed = function (str = "") {
|
|
300
|
+
let ret = "";
|
|
301
|
+
str = Util.replaceAll(str, " ", "");
|
|
302
|
+
let phone = str.trim();
|
|
303
|
+
phone = Util.replaceAll(phone, "-", "");
|
|
304
|
+
let first = phone.charAt(0);
|
|
305
|
+
if (first == "") {
|
|
306
|
+
ret = "";
|
|
307
|
+
} else if (first == "+") {
|
|
308
|
+
ret = phone;
|
|
309
|
+
} else if (first == "0") {
|
|
310
|
+
ret = "+62" + phone.replace("0", "");
|
|
271
311
|
} else {
|
|
272
|
-
ret =
|
|
312
|
+
ret = "+" + phone;
|
|
273
313
|
}
|
|
274
314
|
|
|
275
|
-
return ret
|
|
276
|
-
}
|
|
315
|
+
return ret;
|
|
316
|
+
};
|
|
277
317
|
|
|
278
|
-
Util.jsonSuccess = function (message =
|
|
279
|
-
message = message || LANGUAGE.data_saved
|
|
280
|
-
let json = {
|
|
318
|
+
Util.jsonSuccess = function (message = "") {
|
|
319
|
+
message = message || LANGUAGE.data_saved;
|
|
320
|
+
let json = {
|
|
321
|
+
type: "success",
|
|
322
|
+
status: 1,
|
|
323
|
+
title: LANGUAGE.success,
|
|
324
|
+
message: message,
|
|
325
|
+
};
|
|
281
326
|
|
|
282
|
-
return json
|
|
283
|
-
}
|
|
327
|
+
return json;
|
|
328
|
+
};
|
|
284
329
|
|
|
285
|
-
Util.flashError = function (message =
|
|
286
|
-
message = message || LANGUAGE.data_not_found
|
|
287
|
-
let json = {
|
|
330
|
+
Util.flashError = function (message = "", errors = []) {
|
|
331
|
+
message = message || LANGUAGE.data_not_found;
|
|
332
|
+
let json = {
|
|
333
|
+
type: "error",
|
|
334
|
+
status: 0,
|
|
335
|
+
title: "Error",
|
|
336
|
+
message: message,
|
|
337
|
+
errors: errors,
|
|
338
|
+
};
|
|
288
339
|
|
|
289
|
-
return json
|
|
290
|
-
}
|
|
340
|
+
return json;
|
|
341
|
+
};
|
|
291
342
|
|
|
292
343
|
Util.jsonError = function (path, message) {
|
|
293
|
-
let json = {}
|
|
294
|
-
json.errorLog = 1
|
|
295
|
-
json.type =
|
|
296
|
-
json.status = 0
|
|
297
|
-
json.title = path +
|
|
298
|
-
json.message = message
|
|
299
|
-
json.errors = [{ path: path, message: message }]
|
|
344
|
+
let json = {};
|
|
345
|
+
json.errorLog = 1;
|
|
346
|
+
json.type = "error";
|
|
347
|
+
json.status = 0;
|
|
348
|
+
json.title = path + " Error!";
|
|
349
|
+
json.message = message;
|
|
350
|
+
json.errors = [{ path: path, message: message }];
|
|
300
351
|
|
|
301
|
-
return json
|
|
302
|
-
}
|
|
352
|
+
return json;
|
|
353
|
+
};
|
|
303
354
|
|
|
304
355
|
Util.arrayToObject = (array = [], keyField, isInteger = false) => {
|
|
305
|
-
let obj = {}
|
|
356
|
+
let obj = {};
|
|
306
357
|
if (array.length) {
|
|
307
358
|
array.forEach(function (item) {
|
|
308
|
-
var name =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
359
|
+
var name =
|
|
360
|
+
item[keyField] == null
|
|
361
|
+
? "xxxxxx"
|
|
362
|
+
: item[keyField] == "null"
|
|
363
|
+
? "xxxxxx"
|
|
364
|
+
: isInteger
|
|
365
|
+
? item[keyField]
|
|
366
|
+
: item[keyField] + "";
|
|
367
|
+
obj[name] = item;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
return obj;
|
|
371
|
+
};
|
|
314
372
|
|
|
315
373
|
//chase id:1,name:'test' t0 {1:'test'}
|
|
316
374
|
Util.modulesSwitch = (arr = []) => {
|
|
317
|
-
let stores = []
|
|
318
|
-
stores.push({ id:
|
|
375
|
+
let stores = [];
|
|
376
|
+
stores.push({ id: "", name: "" });
|
|
319
377
|
arr.forEach((ar, index) => {
|
|
320
|
-
stores.push({ id: index, name: ar })
|
|
321
|
-
})
|
|
322
|
-
return stores
|
|
323
|
-
}
|
|
378
|
+
stores.push({ id: index, name: ar });
|
|
379
|
+
});
|
|
380
|
+
return stores;
|
|
381
|
+
};
|
|
324
382
|
|
|
325
383
|
Util.buildArrayObjectPrefix = function (arr = []) {
|
|
326
|
-
return Util.modulesSwitch(arr)
|
|
327
|
-
}
|
|
384
|
+
return Util.modulesSwitch(arr);
|
|
385
|
+
};
|
|
328
386
|
|
|
329
387
|
Util.arrayWithObject = (array = [], key, field) => {
|
|
330
388
|
if (array.length) {
|
|
331
389
|
return array.reduce((obj, item) => {
|
|
332
|
-
obj[item[key]] = item[field]
|
|
333
|
-
return obj
|
|
334
|
-
}, {})
|
|
390
|
+
obj[item[key]] = item[field];
|
|
391
|
+
return obj;
|
|
392
|
+
}, {});
|
|
335
393
|
}
|
|
336
|
-
}
|
|
394
|
+
};
|
|
337
395
|
|
|
338
396
|
/*
|
|
339
397
|
for movedupload file using single file
|
|
@@ -342,925 +400,1018 @@ Util.moveFile = function (buffer, filename) {
|
|
|
342
400
|
return new Promise(function (resolve, reject) {
|
|
343
401
|
buffer.mv(filename, function (err) {
|
|
344
402
|
if (err) {
|
|
345
|
-
reject(err)
|
|
403
|
+
reject(err);
|
|
346
404
|
} else {
|
|
347
|
-
resolve(filename)
|
|
405
|
+
resolve(filename);
|
|
348
406
|
}
|
|
349
|
-
})
|
|
350
|
-
})
|
|
351
|
-
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
};
|
|
352
410
|
|
|
353
411
|
Util.generateUnique = function (length, charset) {
|
|
354
|
-
let random = Util.generate(length, charset)
|
|
355
|
-
let uid = new Date().valueOf().toString(36)
|
|
412
|
+
let random = Util.generate(length, charset);
|
|
413
|
+
let uid = new Date().valueOf().toString(36);
|
|
356
414
|
|
|
357
|
-
return uid + random
|
|
358
|
-
}
|
|
415
|
+
return uid + random;
|
|
416
|
+
};
|
|
359
417
|
|
|
360
418
|
Util.generate = function (length, charset) {
|
|
361
|
-
length = length || 50
|
|
419
|
+
length = length || 50;
|
|
362
420
|
//alphanumeric - [0-9 a-z A-Z] alphabetic - [a-z A-Z] numeric - [0-9] hex - [0-9 a-f] custom - any given characters
|
|
363
|
-
charset = charset ||
|
|
421
|
+
charset = charset || "alphanumeric";
|
|
364
422
|
return randomstring.generate({
|
|
365
423
|
length: length,
|
|
366
424
|
charset: charset,
|
|
367
|
-
})
|
|
368
|
-
}
|
|
425
|
+
});
|
|
426
|
+
};
|
|
369
427
|
|
|
370
428
|
Util.uuid = () => {
|
|
371
|
-
return uuidv4()
|
|
372
|
-
}
|
|
429
|
+
return uuidv4();
|
|
430
|
+
};
|
|
373
431
|
/*
|
|
374
432
|
generate random string 8
|
|
375
433
|
*/
|
|
376
434
|
Util.random = function (length) {
|
|
377
|
-
length = length || 5
|
|
378
|
-
let text =
|
|
379
|
-
const possible =
|
|
380
|
-
|
|
435
|
+
length = length || 5;
|
|
436
|
+
let text = "";
|
|
437
|
+
const possible =
|
|
438
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
439
|
+
for (let i = 0; i < length; i++)
|
|
440
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
381
441
|
|
|
382
|
-
return text
|
|
383
|
-
}
|
|
442
|
+
return text;
|
|
443
|
+
};
|
|
384
444
|
|
|
385
445
|
Util.whitelist = function () {
|
|
386
|
-
return [
|
|
387
|
-
}
|
|
446
|
+
return ["www", "app", "my", "sintret", "https", "https"];
|
|
447
|
+
};
|
|
388
448
|
|
|
389
449
|
Util.convertDate = function (d) {
|
|
390
|
-
d = d.trim()
|
|
391
|
-
let myarr = d.split(
|
|
392
|
-
return myarr[2] +
|
|
393
|
-
}
|
|
450
|
+
d = d.trim();
|
|
451
|
+
let myarr = d.split(" ");
|
|
452
|
+
return myarr[2] + "-" + Util.monthConvert(myarr[1]) + "-" + myarr[0];
|
|
453
|
+
};
|
|
394
454
|
|
|
395
455
|
// get string start from to
|
|
396
456
|
Util.cut = function (text, start, end) {
|
|
397
|
-
return text.substr(start, end)
|
|
398
|
-
}
|
|
457
|
+
return text.substr(start, end);
|
|
458
|
+
};
|
|
399
459
|
|
|
400
460
|
Util.getFormattedDate = function (date) {
|
|
401
|
-
let year = date.getFullYear()
|
|
402
|
-
let month = (1 + date.getMonth()).toString()
|
|
403
|
-
month = month.length > 1 ? month :
|
|
404
|
-
let day = date.getDate().toString()
|
|
405
|
-
day = day.length > 1 ? day :
|
|
406
|
-
let time =
|
|
407
|
-
|
|
408
|
-
|
|
461
|
+
let year = date.getFullYear();
|
|
462
|
+
let month = (1 + date.getMonth()).toString();
|
|
463
|
+
month = month.length > 1 ? month : "0" + month;
|
|
464
|
+
let day = date.getDate().toString();
|
|
465
|
+
day = day.length > 1 ? day : "0" + day;
|
|
466
|
+
let time =
|
|
467
|
+
date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
|
|
468
|
+
return year + "-" + month + "-" + day + " " + time;
|
|
469
|
+
};
|
|
409
470
|
|
|
410
471
|
Util.uniqueId = function () {
|
|
411
|
-
return (
|
|
412
|
-
|
|
472
|
+
return (
|
|
473
|
+
Date.now().toString(36) + Math.random().toString(36).substr(2, 5)
|
|
474
|
+
).toUpperCase();
|
|
475
|
+
};
|
|
413
476
|
|
|
414
477
|
Util.typePaperSize = [
|
|
415
|
-
{ title:
|
|
416
|
-
{ title:
|
|
417
|
-
{ title:
|
|
418
|
-
{ title:
|
|
419
|
-
{ title:
|
|
420
|
-
{ title:
|
|
421
|
-
{ title:
|
|
422
|
-
{ title:
|
|
423
|
-
{ title:
|
|
424
|
-
{ title:
|
|
425
|
-
{ title:
|
|
426
|
-
]
|
|
478
|
+
{ title: "F4", description: "FOLIO", width: 215, height: 330 },
|
|
479
|
+
{ title: "LEGAL", description: "LEGAL", width: 216, height: 356 },
|
|
480
|
+
{ title: "LETTER", description: "LETTER", width: 216, height: 279 },
|
|
481
|
+
{ title: "A3", description: "A3", width: 297, height: 420 },
|
|
482
|
+
{ title: "A4", description: "A4", width: 210, height: 297 },
|
|
483
|
+
{ title: "A5", description: "A5", width: 148, height: 210 },
|
|
484
|
+
{ title: "A6", description: "A6", width: 105, height: 148 },
|
|
485
|
+
{ title: "A7", description: "A7", width: 74, height: 105 },
|
|
486
|
+
{ title: "A8", description: "A8", width: 52, height: 74 },
|
|
487
|
+
{ title: "A9", description: "A9", width: 37, height: 52 },
|
|
488
|
+
{ title: "CUSTOM", description: "CUSTOM", width: 105, height: 148 },
|
|
489
|
+
];
|
|
427
490
|
|
|
428
491
|
Util.typeFont = [
|
|
429
|
-
|
|
492
|
+
"Verdana, Geneva, sans-serif",
|
|
430
493
|
'"Times New Roman", Times, serif',
|
|
431
|
-
|
|
494
|
+
"Georgia, serif",
|
|
432
495
|
'"Palatino Linotype", "Book Antiqua", Palatino, serif',
|
|
433
|
-
|
|
496
|
+
"Arial, Helvetica, sans-serif",
|
|
434
497
|
'"Arial Black", Gadget, sans-serif',
|
|
435
498
|
'"Comic Sans MS", cursive, sans-serif',
|
|
436
|
-
|
|
499
|
+
"Impact, Charcoal, sans-serif",
|
|
437
500
|
'"Lucida Sans Unicode", "Lucida Grande", sans-serif',
|
|
438
|
-
|
|
501
|
+
"Tahoma, Geneva, sans-serif",
|
|
439
502
|
'"Trebuchet MS", Helvetica, sans-serif',
|
|
440
503
|
'"Courier New", Courier, monospace',
|
|
441
504
|
'"Lucida Console", Monaco, monospace',
|
|
442
|
-
]
|
|
505
|
+
];
|
|
443
506
|
|
|
444
507
|
Util.objectToGridFormat = function (obj = {}, isInteger = false) {
|
|
445
|
-
isInteger = isInteger || false
|
|
446
|
-
let arr = []
|
|
447
|
-
arr.push({ id:
|
|
508
|
+
isInteger = isInteger || false;
|
|
509
|
+
let arr = [];
|
|
510
|
+
arr.push({ id: "", name: "" });
|
|
448
511
|
for (let keys in obj) {
|
|
449
512
|
if (isInteger) {
|
|
450
|
-
arr.push({ id: parseInt(keys), name: obj[keys] })
|
|
513
|
+
arr.push({ id: parseInt(keys), name: obj[keys] });
|
|
451
514
|
} else {
|
|
452
|
-
arr.push({ id: keys, name: obj[keys] })
|
|
515
|
+
arr.push({ id: keys, name: obj[keys] });
|
|
453
516
|
}
|
|
454
517
|
}
|
|
455
|
-
return arr
|
|
456
|
-
}
|
|
518
|
+
return arr;
|
|
519
|
+
};
|
|
457
520
|
|
|
458
521
|
Util.random = function (length = 5) {
|
|
459
|
-
let text =
|
|
460
|
-
const possible =
|
|
461
|
-
|
|
522
|
+
let text = "";
|
|
523
|
+
const possible =
|
|
524
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
525
|
+
for (let i = 0; i < length; i++)
|
|
526
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
462
527
|
|
|
463
|
-
return text
|
|
464
|
-
}
|
|
528
|
+
return text;
|
|
529
|
+
};
|
|
465
530
|
|
|
466
531
|
Util.typePrint = {
|
|
467
|
-
register:
|
|
468
|
-
|
|
469
|
-
|
|
532
|
+
register:
|
|
533
|
+
'{"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"}',
|
|
534
|
+
estimation:
|
|
535
|
+
'{"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"}',
|
|
536
|
+
invoice:
|
|
537
|
+
'{"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"}',
|
|
470
538
|
currency: '{"symbol":"Rp","name":"Rupiah","thousand":"."}',
|
|
471
|
-
}
|
|
539
|
+
};
|
|
472
540
|
|
|
473
541
|
Util.isJson = function (text) {
|
|
474
542
|
if (text) {
|
|
475
543
|
if (
|
|
476
544
|
/^[\],:{}\s]*$/.test(
|
|
477
545
|
text
|
|
478
|
-
.replace(/\\["\\\/bfnrtu]/g,
|
|
479
|
-
.replace(
|
|
480
|
-
|
|
546
|
+
.replace(/\\["\\\/bfnrtu]/g, "@")
|
|
547
|
+
.replace(
|
|
548
|
+
/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
|
|
549
|
+
"]"
|
|
550
|
+
)
|
|
551
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, "")
|
|
481
552
|
)
|
|
482
553
|
) {
|
|
483
554
|
//the json is ok
|
|
484
|
-
return true
|
|
555
|
+
return true;
|
|
485
556
|
} else {
|
|
486
|
-
return false
|
|
557
|
+
return false;
|
|
487
558
|
//the json is not ok
|
|
488
559
|
}
|
|
489
560
|
}
|
|
490
|
-
return false
|
|
491
|
-
}
|
|
561
|
+
return false;
|
|
562
|
+
};
|
|
492
563
|
|
|
493
564
|
Util.isEmptyObject = function (obj = {}) {
|
|
494
565
|
for (let prop in obj) {
|
|
495
566
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
496
|
-
return false
|
|
567
|
+
return false;
|
|
497
568
|
}
|
|
498
569
|
}
|
|
499
570
|
|
|
500
|
-
return JSON.stringify(obj) === JSON.stringify({})
|
|
501
|
-
}
|
|
571
|
+
return JSON.stringify(obj) === JSON.stringify({});
|
|
572
|
+
};
|
|
502
573
|
|
|
503
|
-
Util.serializeTable = function (table =
|
|
504
|
-
return
|
|
505
|
-
}
|
|
574
|
+
Util.serializeTable = function (table = "") {
|
|
575
|
+
return "`" + table + "`";
|
|
576
|
+
};
|
|
506
577
|
|
|
507
|
-
Util.getKey = function (obj = {}, field =
|
|
508
|
-
let t =
|
|
578
|
+
Util.getKey = function (obj = {}, field = "") {
|
|
579
|
+
let t = "";
|
|
509
580
|
for (let item in obj) {
|
|
510
581
|
if (obj[item] == field) {
|
|
511
|
-
return item
|
|
582
|
+
return item;
|
|
512
583
|
}
|
|
513
584
|
}
|
|
514
|
-
return t
|
|
515
|
-
}
|
|
585
|
+
return t;
|
|
586
|
+
};
|
|
516
587
|
|
|
517
|
-
Util.camelize = function (text =
|
|
518
|
-
return text.replace(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
588
|
+
Util.camelize = function (text = "") {
|
|
589
|
+
return text.replace(
|
|
590
|
+
/^([A-Z])|[\s-_]+(\w)/g,
|
|
591
|
+
function (match, p1, p2, offset) {
|
|
592
|
+
if (p2) return p2.toUpperCase();
|
|
593
|
+
return p1.toLowerCase();
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
};
|
|
523
597
|
|
|
524
|
-
Util.decamelize = function (str =
|
|
598
|
+
Util.decamelize = function (str = "", separator = "_") {
|
|
525
599
|
return str
|
|
526
|
-
.replace(/([a-z\d])([A-Z])/g,
|
|
527
|
-
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g,
|
|
528
|
-
.replace(
|
|
529
|
-
.toLowerCase()
|
|
530
|
-
}
|
|
600
|
+
.replace(/([a-z\d])([A-Z])/g, "$1" + separator + "$2")
|
|
601
|
+
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + separator + "$2")
|
|
602
|
+
.replace("_", separator)
|
|
603
|
+
.toLowerCase();
|
|
604
|
+
};
|
|
531
605
|
|
|
532
606
|
/*
|
|
533
607
|
change : Order Step
|
|
534
608
|
to : order_tep
|
|
535
609
|
*/
|
|
536
610
|
|
|
537
|
-
Util.toName = function (str =
|
|
611
|
+
Util.toName = function (str = "", separator = "_") {
|
|
538
612
|
if (str && str.length) {
|
|
539
|
-
str = str.trim()
|
|
613
|
+
str = str.trim();
|
|
540
614
|
//add if first character is number with string character
|
|
541
615
|
if (Util.isInteger(str.charAt(0))) {
|
|
542
|
-
str =
|
|
616
|
+
str = "a" + str;
|
|
543
617
|
}
|
|
544
|
-
let string = str.replace(/\s+/g, separator).toLowerCase()
|
|
545
|
-
string = string.replace(
|
|
546
|
-
string = string.replace(
|
|
547
|
-
string = string.replace(
|
|
548
|
-
return string.replace(/[^A-Za-z0-9/_]/g,
|
|
618
|
+
let string = str.replace(/\s+/g, separator).toLowerCase();
|
|
619
|
+
string = string.replace("/", "");
|
|
620
|
+
string = string.replace("//", "");
|
|
621
|
+
string = string.replace("__", "_");
|
|
622
|
+
return string.replace(/[^A-Za-z0-9/_]/g, "");
|
|
549
623
|
}
|
|
550
|
-
}
|
|
624
|
+
};
|
|
551
625
|
|
|
552
626
|
/*
|
|
553
627
|
change : orderStep
|
|
554
628
|
to : Order Step
|
|
555
629
|
*/
|
|
556
|
-
Util.fieldToName = function (str =
|
|
557
|
-
let title = Util.capitalizeFirstLetter(Util.decamelize(str))
|
|
558
|
-
title = Util.replaceAll(title,
|
|
559
|
-
title = Util.replaceAll(title,
|
|
560
|
-
title = Util.capitalizeAfterSpace(title)
|
|
630
|
+
Util.fieldToName = function (str = "") {
|
|
631
|
+
let title = Util.capitalizeFirstLetter(Util.decamelize(str));
|
|
632
|
+
title = Util.replaceAll(title, "_", " ");
|
|
633
|
+
title = Util.replaceAll(title, " id", "");
|
|
634
|
+
title = Util.capitalizeAfterSpace(title);
|
|
561
635
|
|
|
562
|
-
const lastWords = Util.lastWord(title)
|
|
563
|
-
if (title.length > 4 && lastWords ==
|
|
564
|
-
title = title.replace(
|
|
636
|
+
const lastWords = Util.lastWord(title);
|
|
637
|
+
if (title.length > 4 && lastWords == "Id") {
|
|
638
|
+
title = title.replace("Id", "");
|
|
565
639
|
}
|
|
566
640
|
|
|
567
|
-
return title
|
|
568
|
-
}
|
|
641
|
+
return title;
|
|
642
|
+
};
|
|
569
643
|
|
|
570
|
-
Util.capitalizeWord = (string =
|
|
644
|
+
Util.capitalizeWord = (string = "") => {
|
|
571
645
|
return string
|
|
572
|
-
.split(
|
|
646
|
+
.split(" ")
|
|
573
647
|
.map((m) => m[0].toUpperCase() + m.substr(1))
|
|
574
|
-
.join(
|
|
575
|
-
}
|
|
648
|
+
.join(" ");
|
|
649
|
+
};
|
|
576
650
|
|
|
577
|
-
Util.capitalizeFirstLetter = (string =
|
|
578
|
-
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
579
|
-
}
|
|
651
|
+
Util.capitalizeFirstLetter = (string = "") => {
|
|
652
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
653
|
+
};
|
|
580
654
|
|
|
581
655
|
Util.asyncWrap = (fn) => {
|
|
582
656
|
return (req, res, next) => {
|
|
583
|
-
fn(req, res, next).catch(next)
|
|
584
|
-
}
|
|
585
|
-
}
|
|
657
|
+
fn(req, res, next).catch(next);
|
|
658
|
+
};
|
|
659
|
+
};
|
|
586
660
|
|
|
587
|
-
Util.capitalizeAfterSpace = function (str =
|
|
588
|
-
str = Util.replaceAll(str,
|
|
661
|
+
Util.capitalizeAfterSpace = function (str = "") {
|
|
662
|
+
str = Util.replaceAll(str, "_", " ");
|
|
589
663
|
return str.replace(/\w\S*/g, function (txt) {
|
|
590
|
-
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
|
|
591
|
-
})
|
|
592
|
-
}
|
|
664
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
665
|
+
});
|
|
666
|
+
};
|
|
593
667
|
|
|
594
|
-
Util.capitalizeAfterSpaceTitle = function (str =
|
|
595
|
-
str = Util.replaceAll(str,
|
|
668
|
+
Util.capitalizeAfterSpaceTitle = function (str = "") {
|
|
669
|
+
str = Util.replaceAll(str, " ", "_");
|
|
596
670
|
return str.replace(/\w\S*/g, function (txt) {
|
|
597
|
-
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
|
|
598
|
-
})
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
Util.lastWord = function (words =
|
|
602
|
-
let n = words.split(
|
|
603
|
-
return n[n.length - 1]
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
Util.arrayUnShift = function (arr = [], val =
|
|
607
|
-
let obj = {}
|
|
608
|
-
obj[arr[0]] =
|
|
609
|
-
obj[arr[1]] =
|
|
610
|
-
return obj
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
Util.in_array = function (needle =
|
|
671
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
Util.lastWord = function (words = "") {
|
|
676
|
+
let n = words.split(" ");
|
|
677
|
+
return n[n.length - 1];
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
Util.arrayUnShift = function (arr = [], val = "") {
|
|
681
|
+
let obj = {};
|
|
682
|
+
obj[arr[0]] = "";
|
|
683
|
+
obj[arr[1]] = "";
|
|
684
|
+
return obj;
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
Util.in_array = function (needle = "", haystack = []) {
|
|
614
688
|
if (haystack.length && needle) {
|
|
615
|
-
return haystack.includes(needle)
|
|
689
|
+
return haystack.includes(needle);
|
|
616
690
|
} else {
|
|
617
|
-
return false
|
|
691
|
+
return false;
|
|
618
692
|
}
|
|
619
|
-
}
|
|
693
|
+
};
|
|
620
694
|
|
|
621
695
|
Util.gridSearch = function (visibles, relations, name, value) {
|
|
622
|
-
let index = 0
|
|
623
|
-
let elm =
|
|
696
|
+
let index = 0;
|
|
697
|
+
let elm = "input";
|
|
624
698
|
for (let i = 0; i < visibles.length; i++) {
|
|
625
699
|
if (name == visibles[i]) {
|
|
626
|
-
index = i
|
|
700
|
+
index = i;
|
|
627
701
|
}
|
|
628
702
|
}
|
|
629
703
|
if (!Util.isEmptyObject(relations)) {
|
|
630
|
-
let arr = Object.keys(relations)
|
|
704
|
+
let arr = Object.keys(relations);
|
|
631
705
|
for (let i = 0; i < arr.length; i++) {
|
|
632
706
|
if (name == arr[i]) {
|
|
633
|
-
elm =
|
|
707
|
+
elm = "select";
|
|
634
708
|
}
|
|
635
709
|
}
|
|
636
710
|
}
|
|
637
|
-
return
|
|
638
|
-
|
|
711
|
+
return (
|
|
712
|
+
"searchValue.eq(" + index + ').find("' + elm + '").val("' + value + '");'
|
|
713
|
+
);
|
|
714
|
+
};
|
|
639
715
|
|
|
640
716
|
Util.toNumber = function (num) {
|
|
641
|
-
num = num +
|
|
642
|
-
return parseFloat(Util.replaceAll(num,
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
Util.formatNumber = function (num, thousandSeparator =
|
|
646
|
-
num = num ||
|
|
647
|
-
let sep =
|
|
648
|
-
let numString = num.toString()
|
|
649
|
-
if (numString.indexOf(
|
|
650
|
-
let explode = numString.split(
|
|
651
|
-
return
|
|
717
|
+
num = num + "";
|
|
718
|
+
return parseFloat(Util.replaceAll(num, ".", ""));
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
Util.formatNumber = function (num, thousandSeparator = ".") {
|
|
722
|
+
num = num || "";
|
|
723
|
+
let sep = "$1" + thousandSeparator;
|
|
724
|
+
let numString = num.toString();
|
|
725
|
+
if (numString.indexOf(".") > -1) {
|
|
726
|
+
let explode = numString.split(".");
|
|
727
|
+
return (
|
|
728
|
+
explode[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, sep) + "," + explode[1]
|
|
729
|
+
);
|
|
652
730
|
} else {
|
|
653
|
-
return numString.replace(/(\d)(?=(\d{3})+(?!\d))/g, sep)
|
|
731
|
+
return numString.replace(/(\d)(?=(\d{3})+(?!\d))/g, sep);
|
|
654
732
|
}
|
|
655
|
-
}
|
|
733
|
+
};
|
|
656
734
|
|
|
657
735
|
//usage Util.round(12345.6789, 2) // 12345.68
|
|
658
736
|
Util.round = (value, precision = 0) => {
|
|
659
|
-
value = +value || 0
|
|
660
|
-
var multiplier = Math.pow(10, precision)
|
|
661
|
-
return Math.round(value * multiplier) / multiplier
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
Util.fileAttribute = function (filename =
|
|
665
|
-
filename = filename.toLowerCase() ||
|
|
666
|
-
let ext = filename.split(
|
|
667
|
-
let obj = {}
|
|
668
|
-
obj.ext = ext
|
|
737
|
+
value = +value || 0;
|
|
738
|
+
var multiplier = Math.pow(10, precision);
|
|
739
|
+
return Math.round(value * multiplier) / multiplier;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
Util.fileAttribute = function (filename = "") {
|
|
743
|
+
filename = filename.toLowerCase() || "";
|
|
744
|
+
let ext = filename.split(".").pop();
|
|
745
|
+
let obj = {};
|
|
746
|
+
obj.ext = ext;
|
|
669
747
|
if (Util.in_array(ext, Util.fileImage)) {
|
|
670
|
-
obj.type =
|
|
748
|
+
obj.type = "image";
|
|
671
749
|
} else {
|
|
672
|
-
obj.type =
|
|
673
|
-
}
|
|
674
|
-
return obj
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
Util.fileImage = [
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
750
|
+
obj.type = "file";
|
|
751
|
+
}
|
|
752
|
+
return obj;
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
Util.fileImage = [
|
|
756
|
+
"jpg",
|
|
757
|
+
"jpeg",
|
|
758
|
+
"png",
|
|
759
|
+
"webp",
|
|
760
|
+
"bmp",
|
|
761
|
+
"tif",
|
|
762
|
+
"gif",
|
|
763
|
+
"png",
|
|
764
|
+
"svg",
|
|
765
|
+
"avif",
|
|
766
|
+
];
|
|
767
|
+
|
|
768
|
+
Util.fileExtension = (filename = "") => {
|
|
769
|
+
filename = filename.toLowerCase() || "";
|
|
770
|
+
let obj = {};
|
|
771
|
+
let ext = filename.split(".").pop();
|
|
772
|
+
obj.ext = ext;
|
|
684
773
|
if (Util.in_array(ext, Util.fileImage)) {
|
|
685
|
-
obj.type =
|
|
774
|
+
obj.type = "image";
|
|
686
775
|
} else {
|
|
687
|
-
obj.type =
|
|
688
|
-
}
|
|
689
|
-
let file =
|
|
690
|
-
if (ext ==
|
|
691
|
-
file =
|
|
692
|
-
} else if (ext ==
|
|
693
|
-
file =
|
|
694
|
-
} else if (ext ==
|
|
695
|
-
file =
|
|
696
|
-
} else if (ext ==
|
|
697
|
-
file =
|
|
698
|
-
} else if (ext ==
|
|
699
|
-
file =
|
|
700
|
-
} else if (ext ==
|
|
701
|
-
file =
|
|
702
|
-
} else if (ext ==
|
|
703
|
-
file =
|
|
704
|
-
} else if (ext ==
|
|
705
|
-
file =
|
|
706
|
-
}
|
|
707
|
-
obj.file = file
|
|
708
|
-
return obj
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
Util.fileView = function (dir =
|
|
712
|
-
let filename = dir + file
|
|
713
|
-
let html =
|
|
714
|
-
let width = attributes.hasOwnProperty(
|
|
715
|
-
let withIcon = attributes.hasOwnProperty(
|
|
716
|
-
let obj = Util.fileExtension(filename)
|
|
717
|
-
let className = attributes.hasOwnProperty(
|
|
718
|
-
|
|
719
|
-
|
|
776
|
+
obj.type = "file";
|
|
777
|
+
}
|
|
778
|
+
let file = "file.png";
|
|
779
|
+
if (ext == "docx" || ext == "doc") {
|
|
780
|
+
file = "word.png";
|
|
781
|
+
} else if (ext == "xls" || ext == "xlsx") {
|
|
782
|
+
file = "excel.png";
|
|
783
|
+
} else if (ext == "pdf") {
|
|
784
|
+
file = "pdf.png";
|
|
785
|
+
} else if (ext == "ppt" || ext == "pptx") {
|
|
786
|
+
file = "ppt.png";
|
|
787
|
+
} else if (ext == "txt") {
|
|
788
|
+
file = "txt.png";
|
|
789
|
+
} else if (ext == "zip") {
|
|
790
|
+
file = "zip.jpg";
|
|
791
|
+
} else if (ext == "rar") {
|
|
792
|
+
file = "rar.jpg";
|
|
793
|
+
} else if (ext == "rar") {
|
|
794
|
+
file = "file.png";
|
|
795
|
+
}
|
|
796
|
+
obj.file = file;
|
|
797
|
+
return obj;
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
Util.fileView = function (dir = "", file = "", attributes = {}) {
|
|
801
|
+
let filename = dir + file;
|
|
802
|
+
let html = "";
|
|
803
|
+
let width = attributes.hasOwnProperty("width") ? attributes.width : "300";
|
|
804
|
+
let withIcon = attributes.hasOwnProperty("withIcon") ? true : false;
|
|
805
|
+
let obj = Util.fileExtension(filename);
|
|
806
|
+
let className = attributes.hasOwnProperty("class")
|
|
807
|
+
? ` class="${attributes.class}" `
|
|
808
|
+
: "";
|
|
809
|
+
if (filename.includes("https")) {
|
|
810
|
+
html = `<img src="${file}" ${className} class="img-responsive">`;
|
|
720
811
|
} else {
|
|
721
|
-
if (obj.type ==
|
|
722
|
-
html = `<img src="${filename}" ${className} width="${width}px"
|
|
812
|
+
if (obj.type == "image") {
|
|
813
|
+
html = `<img src="${filename}" ${className} width="${width}px">`;
|
|
723
814
|
} else {
|
|
724
815
|
if (file) {
|
|
725
816
|
if (withIcon) {
|
|
726
|
-
html = `<img class="mb-3 boxy-small" src="/img/${
|
|
817
|
+
html = `<img class="mb-3 boxy-small" src="/img/${
|
|
818
|
+
obj.file
|
|
819
|
+
}" height="45px" width="45px"><a class="text-success" target="_blank" href="${filename}"> ${file.substring(
|
|
820
|
+
13
|
|
821
|
+
)}</a>`;
|
|
727
822
|
} else {
|
|
728
|
-
html = `<a class="text-success" target="_blank" href="${filename}"> ${file.substring(
|
|
823
|
+
html = `<a class="text-success" target="_blank" href="${filename}"> ${file.substring(
|
|
824
|
+
13
|
|
825
|
+
)}</a>`;
|
|
729
826
|
}
|
|
730
827
|
}
|
|
731
828
|
}
|
|
732
829
|
}
|
|
733
830
|
|
|
734
|
-
return html
|
|
735
|
-
}
|
|
831
|
+
return html;
|
|
832
|
+
};
|
|
736
833
|
/// end files
|
|
737
834
|
|
|
738
835
|
Util.arrayDelete = function (arr, value) {
|
|
739
|
-
return arr.filter((item) => item != value)
|
|
740
|
-
}
|
|
836
|
+
return arr.filter((item) => item != value);
|
|
837
|
+
};
|
|
741
838
|
|
|
742
839
|
Util.arrayDeletes = function (arr = [], array = []) {
|
|
743
|
-
return arr.filter((item) => !Util.in_array(item, array))
|
|
744
|
-
}
|
|
840
|
+
return arr.filter((item) => !Util.in_array(item, array));
|
|
841
|
+
};
|
|
745
842
|
|
|
746
843
|
Util.arrayToList = function (arr, array, delimiter, isCount) {
|
|
747
|
-
delimiter = delimiter ||
|
|
748
|
-
isCount = isCount || 1
|
|
749
|
-
let html =
|
|
844
|
+
delimiter = delimiter || "<br>";
|
|
845
|
+
isCount = isCount || 1;
|
|
846
|
+
let html = "";
|
|
750
847
|
if (arr) {
|
|
751
848
|
for (var i = 0; i < arr.length; i++) {
|
|
752
|
-
html +=
|
|
849
|
+
html +=
|
|
850
|
+
isCount == 1
|
|
851
|
+
? i + 1 + ". " + array[arr[i]] + delimiter
|
|
852
|
+
: " " + array[arr[i]] + delimiter;
|
|
753
853
|
}
|
|
754
|
-
html = html.slice(0, delimiter.length * -1)
|
|
854
|
+
html = html.slice(0, delimiter.length * -1);
|
|
755
855
|
}
|
|
756
856
|
|
|
757
|
-
return html
|
|
758
|
-
}
|
|
857
|
+
return html;
|
|
858
|
+
};
|
|
759
859
|
|
|
760
860
|
Util.menuAccess = function (menu, params) {
|
|
761
|
-
const roles = require(
|
|
762
|
-
const routes = roles.routes
|
|
861
|
+
const roles = require("./role");
|
|
862
|
+
const routes = roles.routes;
|
|
763
863
|
if (Util.in_array(menu, routes)) {
|
|
764
|
-
if (Util.in_array(menu, params)) return true
|
|
765
|
-
else return false
|
|
864
|
+
if (Util.in_array(menu, params)) return true;
|
|
865
|
+
else return false;
|
|
766
866
|
} else {
|
|
767
|
-
return true
|
|
867
|
+
return true;
|
|
768
868
|
}
|
|
769
|
-
}
|
|
869
|
+
};
|
|
770
870
|
|
|
771
871
|
Util.dropdownHelper = function (data, field, model) {
|
|
772
|
-
let fieldsx = field +
|
|
773
|
-
let name = field +
|
|
774
|
-
let myvalue =
|
|
872
|
+
let fieldsx = field + "[]";
|
|
873
|
+
let name = field + "[]";
|
|
874
|
+
let myvalue =
|
|
875
|
+
typeof data[fieldsx] == undefined
|
|
876
|
+
? " "
|
|
877
|
+
: typeof data[fieldsx] == "string"
|
|
878
|
+
? '["' + data[fieldsx] + '"]'
|
|
879
|
+
: JSON.stringify(data[name]);
|
|
775
880
|
if (myvalue) {
|
|
776
|
-
let unique =
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
881
|
+
let unique =
|
|
882
|
+
myvalue.indexOf("[") > -1 ? myvalue : !myvalue ? "" : "[" + myvalue + "]";
|
|
883
|
+
unique = JSON.parse(unique);
|
|
884
|
+
data[field] = JSON.stringify(unique.filter(Util.arrayUnique));
|
|
885
|
+
delete data[name];
|
|
780
886
|
}
|
|
781
887
|
if (model.fields[field].required) {
|
|
782
888
|
if (!data[field]) {
|
|
783
|
-
return false
|
|
889
|
+
return false;
|
|
784
890
|
}
|
|
785
891
|
}
|
|
786
|
-
return data
|
|
787
|
-
}
|
|
892
|
+
return data;
|
|
893
|
+
};
|
|
788
894
|
|
|
789
895
|
Util.dropdownAdd = function (data, field, model, datas) {
|
|
790
|
-
let name = field +
|
|
791
|
-
let myvalue =
|
|
896
|
+
let name = field + "[]";
|
|
897
|
+
let myvalue =
|
|
898
|
+
typeof datas == undefined
|
|
899
|
+
? " "
|
|
900
|
+
: typeof datas == "string"
|
|
901
|
+
? '["' + datas + '"]'
|
|
902
|
+
: JSON.stringify(datas);
|
|
792
903
|
if (myvalue) {
|
|
793
|
-
let unique =
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
904
|
+
let unique =
|
|
905
|
+
myvalue.indexOf("[") > -1 ? myvalue : !myvalue ? "" : "[" + myvalue + "]";
|
|
906
|
+
unique = JSON.parse(unique);
|
|
907
|
+
myvalue = JSON.stringify(unique.filter(Util.arrayUnique));
|
|
908
|
+
delete data[name];
|
|
797
909
|
|
|
798
|
-
data[field] = myvalue
|
|
910
|
+
data[field] = myvalue;
|
|
799
911
|
}
|
|
800
912
|
if (model.fields[field].required) {
|
|
801
913
|
if (!myvalue) {
|
|
802
|
-
return false
|
|
914
|
+
return false;
|
|
803
915
|
}
|
|
804
916
|
}
|
|
805
|
-
return data
|
|
806
|
-
}
|
|
917
|
+
return data;
|
|
918
|
+
};
|
|
807
919
|
//array unique
|
|
808
920
|
// array.filter(Util.arrayUnique);
|
|
809
921
|
Util.arrayUnique = (value, index, self) => {
|
|
810
|
-
return self.indexOf(value) == index
|
|
811
|
-
}
|
|
922
|
+
return self.indexOf(value) == index;
|
|
923
|
+
};
|
|
812
924
|
|
|
813
925
|
Util.virtualHelper = function (obj) {
|
|
814
|
-
if (Util.isEmptyObject(obj)) return
|
|
815
|
-
if (obj == undefined) return
|
|
926
|
+
if (Util.isEmptyObject(obj)) return;
|
|
927
|
+
if (obj == undefined) return;
|
|
816
928
|
|
|
817
|
-
var str =
|
|
929
|
+
var str = "";
|
|
818
930
|
for (var key in obj) {
|
|
819
|
-
str +=
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
return str
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
Util.nots = [
|
|
931
|
+
str += ", `" + obj[key] + "` AS " + key;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
return str;
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
Util.nots = [
|
|
938
|
+
"id",
|
|
939
|
+
"createdAt",
|
|
940
|
+
"updatedAt",
|
|
941
|
+
"createdBy",
|
|
942
|
+
"updatedBy",
|
|
943
|
+
"companyId",
|
|
944
|
+
"created_at",
|
|
945
|
+
"updated_at",
|
|
946
|
+
"updated_by",
|
|
947
|
+
"created_by",
|
|
948
|
+
"modified_by",
|
|
949
|
+
"company_id",
|
|
950
|
+
"token",
|
|
951
|
+
"version",
|
|
952
|
+
"signin_method",
|
|
953
|
+
"lastLogin",
|
|
954
|
+
"last_login",
|
|
955
|
+
"forgotPassword",
|
|
956
|
+
"forgot_password",
|
|
957
|
+
"no",
|
|
958
|
+
"actionColumn",
|
|
959
|
+
"lock",
|
|
960
|
+
"approval_status",
|
|
961
|
+
"approval_history",
|
|
962
|
+
];
|
|
826
963
|
|
|
827
964
|
Util.requiredFields = function (obj = {}) {
|
|
828
|
-
var nots = Util.nots
|
|
829
|
-
var arr = []
|
|
965
|
+
var nots = Util.nots;
|
|
966
|
+
var arr = [];
|
|
830
967
|
for (var key in obj) {
|
|
831
968
|
if (!Util.in_array(key, nots)) {
|
|
832
969
|
if (obj[key].required == true) {
|
|
833
|
-
arr.push(key)
|
|
970
|
+
arr.push(key);
|
|
834
971
|
}
|
|
835
972
|
}
|
|
836
973
|
}
|
|
837
|
-
return arr
|
|
838
|
-
}
|
|
974
|
+
return arr;
|
|
975
|
+
};
|
|
839
976
|
|
|
840
977
|
Util.extractDetails = function (obj = {}) {
|
|
841
|
-
let arr = []
|
|
978
|
+
let arr = [];
|
|
842
979
|
for (let key in obj) {
|
|
843
980
|
if (obj[key].length > 0) {
|
|
844
981
|
for (var i = 0; i < obj[key].length; i++) {
|
|
845
|
-
arr.push(obj[key][i])
|
|
982
|
+
arr.push(obj[key][i]);
|
|
846
983
|
}
|
|
847
984
|
}
|
|
848
985
|
}
|
|
849
|
-
return arr
|
|
850
|
-
}
|
|
986
|
+
return arr;
|
|
987
|
+
};
|
|
851
988
|
|
|
852
989
|
Util.arrayToConcat = function (arr = []) {
|
|
853
|
-
let str =
|
|
990
|
+
let str = "CONCAT(";
|
|
854
991
|
for (let i = 0; i < arr.length; i++) {
|
|
855
|
-
str += arr[i] + '," - ",'
|
|
992
|
+
str += arr[i] + '," - ",';
|
|
856
993
|
}
|
|
857
|
-
str = str.slice(0, -9)
|
|
858
|
-
str +=
|
|
994
|
+
str = str.slice(0, -9);
|
|
995
|
+
str += ")";
|
|
859
996
|
|
|
860
|
-
return str
|
|
861
|
-
}
|
|
997
|
+
return str;
|
|
998
|
+
};
|
|
862
999
|
|
|
863
1000
|
//sequence all fields based on drag drop generator
|
|
864
1001
|
Util.arraySequence = function (arr = [], left = [], right = []) {
|
|
865
|
-
let obj = Util.arrayToObject(arr,
|
|
1002
|
+
let obj = Util.arrayToObject(arr, "Field");
|
|
866
1003
|
let temp = [],
|
|
867
|
-
stores = []
|
|
1004
|
+
stores = [];
|
|
868
1005
|
for (let i = 0; i < arr.length; i++) {
|
|
869
|
-
if (arr[i].Field ==
|
|
870
|
-
stores.push(arr[i].Field)
|
|
871
|
-
temp.push(arr[i])
|
|
1006
|
+
if (arr[i].Field == "id") {
|
|
1007
|
+
stores.push(arr[i].Field);
|
|
1008
|
+
temp.push(arr[i]);
|
|
872
1009
|
}
|
|
873
1010
|
}
|
|
874
1011
|
if (Array.isArray(left)) {
|
|
875
1012
|
for (let i = 0; i < left.length; i++) {
|
|
876
1013
|
if (i % 2 == 0) {
|
|
877
|
-
temp.push(obj[left[i]])
|
|
878
|
-
stores.push(left[i])
|
|
1014
|
+
temp.push(obj[left[i]]);
|
|
1015
|
+
stores.push(left[i]);
|
|
879
1016
|
}
|
|
880
1017
|
}
|
|
881
1018
|
}
|
|
882
1019
|
if (Array.isArray(right)) {
|
|
883
1020
|
for (let i = 0; i < right.length; i++) {
|
|
884
1021
|
if (i % 2 == 0) {
|
|
885
|
-
temp.push(obj[right[i]])
|
|
886
|
-
stores.push(right[i])
|
|
1022
|
+
temp.push(obj[right[i]]);
|
|
1023
|
+
stores.push(right[i]);
|
|
887
1024
|
}
|
|
888
1025
|
}
|
|
889
1026
|
}
|
|
890
1027
|
if (Array.isArray(left)) {
|
|
891
1028
|
for (let i = 0; i < left.length; i++) {
|
|
892
1029
|
if (i % 2 == 1) {
|
|
893
|
-
temp.push(obj[left[i]])
|
|
894
|
-
stores.push(left[i])
|
|
1030
|
+
temp.push(obj[left[i]]);
|
|
1031
|
+
stores.push(left[i]);
|
|
895
1032
|
}
|
|
896
1033
|
}
|
|
897
1034
|
}
|
|
898
1035
|
if (Array.isArray(right)) {
|
|
899
1036
|
for (let i = 0; i < right.length; i++) {
|
|
900
1037
|
if (i % 2 == 1) {
|
|
901
|
-
temp.push(obj[right[i]])
|
|
902
|
-
stores.push(right[i])
|
|
1038
|
+
temp.push(obj[right[i]]);
|
|
1039
|
+
stores.push(right[i]);
|
|
903
1040
|
}
|
|
904
1041
|
}
|
|
905
1042
|
}
|
|
906
1043
|
|
|
907
1044
|
for (let i = 0; i < arr.length; i++) {
|
|
908
|
-
const field = arr[i].Field
|
|
1045
|
+
const field = arr[i].Field;
|
|
909
1046
|
if (!Util.in_array(field, stores)) {
|
|
910
|
-
temp.push(arr[i])
|
|
1047
|
+
temp.push(arr[i]);
|
|
911
1048
|
}
|
|
912
1049
|
}
|
|
913
1050
|
|
|
914
|
-
return temp
|
|
915
|
-
}
|
|
1051
|
+
return temp;
|
|
1052
|
+
};
|
|
916
1053
|
|
|
917
1054
|
Util.isInteger = (value) => {
|
|
918
1055
|
return (
|
|
919
1056
|
!isNaN(value) &&
|
|
920
1057
|
(function (x) {
|
|
921
|
-
return (x | 0) === x
|
|
1058
|
+
return (x | 0) === x;
|
|
922
1059
|
})(parseFloat(value))
|
|
923
|
-
)
|
|
924
|
-
}
|
|
1060
|
+
);
|
|
1061
|
+
};
|
|
925
1062
|
|
|
926
1063
|
Util.isEmptyArray = (arr = []) => {
|
|
927
|
-
let isArr = false
|
|
1064
|
+
let isArr = false;
|
|
928
1065
|
if (Array.isArray(arr)) {
|
|
929
1066
|
if (arr.length === 0) {
|
|
930
|
-
isArr = true
|
|
1067
|
+
isArr = true;
|
|
931
1068
|
} else {
|
|
932
|
-
isArr = arr.reduce((a, b) => (b === null ? a + 0 : a + 1), 0) === 0
|
|
1069
|
+
isArr = arr.reduce((a, b) => (b === null ? a + 0 : a + 1), 0) === 0;
|
|
933
1070
|
}
|
|
934
1071
|
} else {
|
|
935
|
-
isArr = true
|
|
1072
|
+
isArr = true;
|
|
936
1073
|
}
|
|
937
|
-
return isArr
|
|
938
|
-
}
|
|
1074
|
+
return isArr;
|
|
1075
|
+
};
|
|
939
1076
|
|
|
940
1077
|
Util.isNumeric = function (value) {
|
|
941
|
-
return /^-?\d+$/.test(value)
|
|
942
|
-
}
|
|
1078
|
+
return /^-?\d+$/.test(value);
|
|
1079
|
+
};
|
|
943
1080
|
|
|
944
|
-
Util.tags = function (tags =
|
|
945
|
-
let html =
|
|
946
|
-
if (tags.indexOf(
|
|
947
|
-
let explode = tags.split(
|
|
1081
|
+
Util.tags = function (tags = "") {
|
|
1082
|
+
let html = "";
|
|
1083
|
+
if (tags.indexOf(",") > -1) {
|
|
1084
|
+
let explode = tags.split(",");
|
|
948
1085
|
for (var i = 0; i < explode.length; i++) {
|
|
949
|
-
html += `<a href="#" rel="tag">${explode[i]}</a
|
|
1086
|
+
html += `<a href="#" rel="tag">${explode[i]}</a>`;
|
|
950
1087
|
}
|
|
951
1088
|
} else {
|
|
952
|
-
html += `<a href="#" rel="tag">${tags}</a
|
|
1089
|
+
html += `<a href="#" rel="tag">${tags}</a>`;
|
|
953
1090
|
}
|
|
954
1091
|
|
|
955
|
-
return html
|
|
956
|
-
}
|
|
1092
|
+
return html;
|
|
1093
|
+
};
|
|
957
1094
|
|
|
958
1095
|
/*
|
|
959
1096
|
get extension of filename
|
|
960
1097
|
*/
|
|
961
1098
|
|
|
962
|
-
Util.getExtensionFile = (str =
|
|
963
|
-
str = str ||
|
|
964
|
-
let extension = str.split(
|
|
965
|
-
extension = extension.toLowerCase()
|
|
966
|
-
let ret = extension
|
|
967
|
-
if (extension ==
|
|
968
|
-
ret =
|
|
1099
|
+
Util.getExtensionFile = (str = "") => {
|
|
1100
|
+
str = str || "";
|
|
1101
|
+
let extension = str.split(".").pop();
|
|
1102
|
+
extension = extension.toLowerCase();
|
|
1103
|
+
let ret = extension;
|
|
1104
|
+
if (extension == "jpg") {
|
|
1105
|
+
ret = "jpeg";
|
|
969
1106
|
}
|
|
970
|
-
return ret
|
|
971
|
-
}
|
|
1107
|
+
return ret;
|
|
1108
|
+
};
|
|
972
1109
|
|
|
973
|
-
Util.badgeError = (msg =
|
|
974
|
-
return `<span class="badge badge-danger">${msg}</span
|
|
975
|
-
}
|
|
1110
|
+
Util.badgeError = (msg = "") => {
|
|
1111
|
+
return `<span class="badge badge-danger">${msg}</span>`;
|
|
1112
|
+
};
|
|
976
1113
|
|
|
977
|
-
Util.badgeSuccess = (msg =
|
|
978
|
-
return `<span class="badge badge-success">${msg}</span
|
|
979
|
-
}
|
|
1114
|
+
Util.badgeSuccess = (msg = "") => {
|
|
1115
|
+
return `<span class="badge badge-success">${msg}</span>`;
|
|
1116
|
+
};
|
|
980
1117
|
|
|
981
|
-
Util.alertError = function (msg =
|
|
982
|
-
return `<div class="alert alert-danger" role="alert">${msg}</div
|
|
983
|
-
}
|
|
1118
|
+
Util.alertError = function (msg = "") {
|
|
1119
|
+
return `<div class="alert alert-danger" role="alert">${msg}</div>`;
|
|
1120
|
+
};
|
|
984
1121
|
|
|
985
|
-
Util.alertSuccess = function (msg =
|
|
986
|
-
return `<div class="alert alert-success" role="alert">${msg}</div
|
|
987
|
-
}
|
|
1122
|
+
Util.alertSuccess = function (msg = "") {
|
|
1123
|
+
return `<div class="alert alert-success" role="alert">${msg}</div>`;
|
|
1124
|
+
};
|
|
988
1125
|
|
|
989
|
-
Util.alertInfo = function (msg =
|
|
990
|
-
return `<div class="alert alert-info" role="alert">${msg}</div
|
|
991
|
-
}
|
|
1126
|
+
Util.alertInfo = function (msg = "") {
|
|
1127
|
+
return `<div class="alert alert-info" role="alert">${msg}</div>`;
|
|
1128
|
+
};
|
|
992
1129
|
|
|
993
1130
|
Util.regexPassword = (lengthMin, lengthMax) => {
|
|
994
1131
|
//minimum length
|
|
995
|
-
lengthMin = lengthMin || 6
|
|
996
|
-
lengthMax = lengthMax || 20
|
|
1132
|
+
lengthMin = lengthMin || 6;
|
|
1133
|
+
lengthMax = lengthMax || 20;
|
|
997
1134
|
|
|
998
|
-
return new RegExp(
|
|
999
|
-
}
|
|
1135
|
+
return new RegExp(
|
|
1136
|
+
"^[a-zA-Z0-9_-]{" + lengthMin + "," + lengthMax + "}$",
|
|
1137
|
+
"i"
|
|
1138
|
+
);
|
|
1139
|
+
};
|
|
1000
1140
|
|
|
1001
1141
|
//huruf dan angka saja
|
|
1002
1142
|
Util.regexCode = (lengthMin, lengthMax) => {
|
|
1003
|
-
lengthMin = lengthMin || 2
|
|
1004
|
-
lengthMax = lengthMax || 10
|
|
1143
|
+
lengthMin = lengthMin || 2;
|
|
1144
|
+
lengthMax = lengthMax || 10;
|
|
1005
1145
|
|
|
1006
|
-
return new RegExp(
|
|
1007
|
-
}
|
|
1146
|
+
return new RegExp("^[A-Z0-9]{" + lengthMin + "," + lengthMax + "}$", "i");
|
|
1147
|
+
};
|
|
1008
1148
|
|
|
1009
|
-
Util.imageProfile = function (image =
|
|
1010
|
-
return image
|
|
1011
|
-
|
|
1149
|
+
Util.imageProfile = function (image = "") {
|
|
1150
|
+
return image
|
|
1151
|
+
? image.indexOf("http") > -1
|
|
1152
|
+
? image
|
|
1153
|
+
: "/uploads/zuser/" + image
|
|
1154
|
+
: "/img/user.png";
|
|
1155
|
+
};
|
|
1012
1156
|
|
|
1013
1157
|
/*
|
|
1014
1158
|
Files
|
|
1015
1159
|
*/
|
|
1016
|
-
Util.readFile = function (filename =
|
|
1160
|
+
Util.readFile = function (filename = "") {
|
|
1017
1161
|
try {
|
|
1018
1162
|
if (Util.fileExist(filename)) {
|
|
1019
|
-
const data = fs.readFileSync(filename,
|
|
1020
|
-
return data
|
|
1163
|
+
const data = fs.readFileSync(filename, "utf8");
|
|
1164
|
+
return data;
|
|
1021
1165
|
}
|
|
1022
1166
|
} catch (err) {}
|
|
1023
|
-
return
|
|
1024
|
-
}
|
|
1167
|
+
return "";
|
|
1168
|
+
};
|
|
1025
1169
|
//check directory if not exist create or not return true/false
|
|
1026
|
-
Util.dirExist = (dir =
|
|
1170
|
+
Util.dirExist = (dir = "", create = false) => {
|
|
1027
1171
|
try {
|
|
1028
1172
|
if (create) {
|
|
1029
|
-
fs.ensureDir(dir, (err) => {})
|
|
1173
|
+
fs.ensureDir(dir, (err) => {});
|
|
1030
1174
|
}
|
|
1031
1175
|
// check if directory exists
|
|
1032
1176
|
if (fs.existsSync(dir)) {
|
|
1033
|
-
return true
|
|
1177
|
+
return true;
|
|
1034
1178
|
}
|
|
1035
1179
|
} catch (e) {}
|
|
1036
|
-
return false
|
|
1037
|
-
}
|
|
1180
|
+
return false;
|
|
1181
|
+
};
|
|
1038
1182
|
|
|
1039
|
-
Util.fileExist = (filename =
|
|
1183
|
+
Util.fileExist = (filename = "") => {
|
|
1040
1184
|
if (fs.existsSync(filename)) {
|
|
1041
|
-
return true
|
|
1185
|
+
return true;
|
|
1042
1186
|
}
|
|
1043
|
-
return false
|
|
1044
|
-
}
|
|
1187
|
+
return false;
|
|
1188
|
+
};
|
|
1045
1189
|
|
|
1046
|
-
Util.getAllFiles = (dir =
|
|
1047
|
-
let files = []
|
|
1190
|
+
Util.getAllFiles = (dir = "") => {
|
|
1191
|
+
let files = [];
|
|
1048
1192
|
try {
|
|
1049
1193
|
if (Util.dirExist(dir, true)) {
|
|
1050
|
-
files = fs.readdirSync(dir)
|
|
1194
|
+
files = fs.readdirSync(dir);
|
|
1051
1195
|
}
|
|
1052
1196
|
} catch (e) {
|
|
1053
|
-
return []
|
|
1197
|
+
return [];
|
|
1054
1198
|
}
|
|
1055
|
-
return files
|
|
1056
|
-
}
|
|
1199
|
+
return files;
|
|
1200
|
+
};
|
|
1057
1201
|
|
|
1058
|
-
Util.writeFile = (filename =
|
|
1202
|
+
Util.writeFile = (filename = "", content = "") => {
|
|
1059
1203
|
try {
|
|
1060
|
-
let dir = require(
|
|
1061
|
-
Util.dirExist(dir, true)
|
|
1062
|
-
fs.writeFileSync(filename, content)
|
|
1063
|
-
return true
|
|
1204
|
+
let dir = require("path").dirname(filename);
|
|
1205
|
+
Util.dirExist(dir, true);
|
|
1206
|
+
fs.writeFileSync(filename, content);
|
|
1207
|
+
return true;
|
|
1064
1208
|
} catch (e) {
|
|
1065
|
-
return false
|
|
1209
|
+
return false;
|
|
1066
1210
|
}
|
|
1067
|
-
}
|
|
1211
|
+
};
|
|
1068
1212
|
|
|
1069
|
-
Util.deleteAllFiles = (dir =
|
|
1213
|
+
Util.deleteAllFiles = (dir = "") => {
|
|
1070
1214
|
try {
|
|
1071
|
-
fs.emptyDirSync(dir)
|
|
1072
|
-
return true
|
|
1215
|
+
fs.emptyDirSync(dir);
|
|
1216
|
+
return true;
|
|
1073
1217
|
} catch (e) {
|
|
1074
|
-
return false
|
|
1218
|
+
return false;
|
|
1075
1219
|
}
|
|
1076
|
-
}
|
|
1220
|
+
};
|
|
1077
1221
|
|
|
1078
|
-
Util.findFilesName = (arr = [], filename =
|
|
1079
|
-
return arr.filter((item) => item.includes(filename))
|
|
1080
|
-
}
|
|
1222
|
+
Util.findFilesName = (arr = [], filename = "") => {
|
|
1223
|
+
return arr.filter((item) => item.includes(filename));
|
|
1224
|
+
};
|
|
1081
1225
|
|
|
1082
1226
|
//convert image file to base64
|
|
1083
1227
|
Util.imageFiletoBase64 = (imgPath) => {
|
|
1084
1228
|
// read image file
|
|
1085
|
-
const base64Image = fs.readFileSync(imgPath,
|
|
1086
|
-
const extensionName = path.extname(imgPath)
|
|
1087
|
-
return `data:image/${extensionName.split(
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
Util.getFiles = function (dir, token =
|
|
1091
|
-
let arr = fs.readdirSync(dir)
|
|
1092
|
-
let folders =
|
|
1093
|
-
let files =
|
|
1229
|
+
const base64Image = fs.readFileSync(imgPath, "base64");
|
|
1230
|
+
const extensionName = path.extname(imgPath);
|
|
1231
|
+
return `data:image/${extensionName.split(".").pop()};base64,${base64Image}`;
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
Util.getFiles = function (dir, token = "") {
|
|
1235
|
+
let arr = fs.readdirSync(dir);
|
|
1236
|
+
let folders = "";
|
|
1237
|
+
let files = "";
|
|
1094
1238
|
arr.forEach(function (item) {
|
|
1095
|
-
if (item.indexOf(
|
|
1096
|
-
var explode = dir.split(
|
|
1097
|
-
var path = explode[1]
|
|
1098
|
-
var url =
|
|
1099
|
-
var extension = item.split(
|
|
1239
|
+
if (item.indexOf(".") > -1) {
|
|
1240
|
+
var explode = dir.split("public/");
|
|
1241
|
+
var path = explode[1];
|
|
1242
|
+
var url = "/" + path + "/" + item;
|
|
1243
|
+
var extension = item.split(".").pop();
|
|
1100
1244
|
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}">
|
|
1101
1245
|
<img src="/assets/images/formats/file.png" class="img-responsive ui-selectee">
|
|
1102
1246
|
<p class="text-ellipsis ui-selectee">${item}</p>
|
|
1103
|
-
</div
|
|
1247
|
+
</div>`;
|
|
1104
1248
|
} else {
|
|
1105
|
-
let explode = dir.split(token)
|
|
1106
|
-
let path = explode[1] ||
|
|
1107
|
-
let state =
|
|
1108
|
-
if (path ==
|
|
1109
|
-
state =
|
|
1249
|
+
let explode = dir.split(token);
|
|
1250
|
+
let path = explode[1] || "";
|
|
1251
|
+
let state = "";
|
|
1252
|
+
if (path == "") {
|
|
1253
|
+
state = "/" + item;
|
|
1110
1254
|
} else {
|
|
1111
|
-
state = path.replace(item,
|
|
1255
|
+
state = path.replace(item, "") + "/" + item;
|
|
1112
1256
|
}
|
|
1113
1257
|
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}">
|
|
1114
1258
|
<img src="/assets/images/folder.png" class="img-responsive ui-selectee">
|
|
1115
1259
|
<p class="text-ellipsis ui-selectee">${item}</p>
|
|
1116
|
-
</div
|
|
1260
|
+
</div>`;
|
|
1117
1261
|
}
|
|
1118
|
-
})
|
|
1262
|
+
});
|
|
1119
1263
|
|
|
1120
|
-
return folders + files
|
|
1121
|
-
}
|
|
1264
|
+
return folders + files;
|
|
1265
|
+
};
|
|
1122
1266
|
|
|
1123
|
-
Util.ejsOpen =
|
|
1124
|
-
Util.ejsStart =
|
|
1125
|
-
Util.ejsClose =
|
|
1267
|
+
Util.ejsOpen = "<%- ";
|
|
1268
|
+
Util.ejsStart = "<% ";
|
|
1269
|
+
Util.ejsClose = " %>";
|
|
1126
1270
|
Util.ejsFunction = (yourCode, isStatement = false) => {
|
|
1127
|
-
const open = isStatement ? Util.ejsStart : Util.ejsOpen
|
|
1128
|
-
return open + yourCode + Util.ejsClose
|
|
1129
|
-
}
|
|
1271
|
+
const open = isStatement ? Util.ejsStart : Util.ejsOpen;
|
|
1272
|
+
return open + yourCode + Util.ejsClose;
|
|
1273
|
+
};
|
|
1130
1274
|
|
|
1131
1275
|
Util.attributeOptions = (obj = {}, defaultObj = {}) => {
|
|
1132
|
-
let html =
|
|
1133
|
-
let arr = Object.keys(defaultObj) || []
|
|
1276
|
+
let html = "";
|
|
1277
|
+
let arr = Object.keys(defaultObj) || [];
|
|
1134
1278
|
for (const key in obj) {
|
|
1135
|
-
let value = obj[key]
|
|
1279
|
+
let value = obj[key];
|
|
1136
1280
|
if (defaultObj.hasOwnProperty(key)) {
|
|
1137
|
-
value = defaultObj[key] + obj[key]
|
|
1138
|
-
Util.arrayDelete(arr, key)
|
|
1281
|
+
value = defaultObj[key] + obj[key];
|
|
1282
|
+
Util.arrayDelete(arr, key);
|
|
1139
1283
|
}
|
|
1140
|
-
html += ` ${key}="${value}"
|
|
1284
|
+
html += ` ${key}="${value}" `;
|
|
1141
1285
|
}
|
|
1142
1286
|
if (arr.length) {
|
|
1143
|
-
arr.map((item) => (html += ` ${item}="${defaultObj[item]}" `))
|
|
1287
|
+
arr.map((item) => (html += ` ${item}="${defaultObj[item]}" `));
|
|
1144
1288
|
}
|
|
1145
|
-
return html
|
|
1146
|
-
}
|
|
1289
|
+
return html;
|
|
1290
|
+
};
|
|
1147
1291
|
|
|
1148
1292
|
/*
|
|
1149
1293
|
array to update json array at postgresql
|
|
1150
1294
|
*/
|
|
1151
1295
|
Util.array_to_jsonb = (arr = []) => {
|
|
1152
|
-
let value =
|
|
1153
|
-
let myarr = []
|
|
1296
|
+
let value = "";
|
|
1297
|
+
let myarr = [];
|
|
1154
1298
|
if (arr.length > 0) {
|
|
1155
1299
|
arr.map((item) => {
|
|
1156
|
-
myarr.push(JSON.stringify(item))
|
|
1157
|
-
})
|
|
1300
|
+
myarr.push(JSON.stringify(item));
|
|
1301
|
+
});
|
|
1158
1302
|
}
|
|
1159
|
-
value = JSON.stringify(myarr).replace(
|
|
1160
|
-
return value
|
|
1161
|
-
}
|
|
1303
|
+
value = JSON.stringify(myarr).replace("[", "{").replaceAll("]", "}");
|
|
1304
|
+
return value;
|
|
1305
|
+
};
|
|
1162
1306
|
|
|
1163
1307
|
/*
|
|
1164
1308
|
array to update array at postgresql
|
|
1165
1309
|
*/
|
|
1166
1310
|
Util.array_to_arraypg = (arr = []) => {
|
|
1167
|
-
let value = null
|
|
1311
|
+
let value = null;
|
|
1168
1312
|
if (arr.length > 0) {
|
|
1169
|
-
value = JSON.stringify(arr).replace(
|
|
1313
|
+
value = JSON.stringify(arr).replace("[", "{").replaceAll("]", "}");
|
|
1170
1314
|
}
|
|
1171
|
-
return value
|
|
1172
|
-
}
|
|
1315
|
+
return value;
|
|
1316
|
+
};
|
|
1173
1317
|
|
|
1174
|
-
Util.userAvatar = (img =
|
|
1175
|
-
return img
|
|
1176
|
-
|
|
1318
|
+
Util.userAvatar = (img = "") => {
|
|
1319
|
+
return img
|
|
1320
|
+
? img.includes("http")
|
|
1321
|
+
? img
|
|
1322
|
+
: `/uploads/user/${img}`
|
|
1323
|
+
: `/img/user.png`;
|
|
1324
|
+
};
|
|
1177
1325
|
|
|
1178
1326
|
/*
|
|
1179
1327
|
SQL HELPER
|
|
1180
1328
|
*/
|
|
1181
1329
|
Util.selectParser = (fields = [], MYMODEL = {}) => {
|
|
1182
|
-
let table = MYMODEL.table
|
|
1183
|
-
let virtuals = []
|
|
1184
|
-
let select =
|
|
1330
|
+
let table = MYMODEL.table;
|
|
1331
|
+
let virtuals = [];
|
|
1332
|
+
let select = "";
|
|
1185
1333
|
for (var key in MYMODEL.widgets) {
|
|
1186
|
-
if (MYMODEL.widgets[key].name ===
|
|
1187
|
-
virtuals.push(key)
|
|
1334
|
+
if (MYMODEL.widgets[key].name === "virtual") {
|
|
1335
|
+
virtuals.push(key);
|
|
1188
1336
|
}
|
|
1189
1337
|
}
|
|
1190
|
-
let arr = []
|
|
1338
|
+
let arr = [];
|
|
1191
1339
|
fields.forEach((item) => {
|
|
1192
1340
|
if (virtuals.includes(item)) {
|
|
1193
|
-
select += `${MYMODEL.widgets[item].fields}
|
|
1194
|
-
} else if (item ===
|
|
1195
|
-
arr.push(`${table}.id`)
|
|
1196
|
-
} else if (item ===
|
|
1197
|
-
arr.push(`${table}.lock`)
|
|
1341
|
+
select += `${MYMODEL.widgets[item].fields},`;
|
|
1342
|
+
} else if (item === "no") {
|
|
1343
|
+
arr.push(`${table}.id`);
|
|
1344
|
+
} else if (item === "actionColumn") {
|
|
1345
|
+
arr.push(`${table}.lock`);
|
|
1198
1346
|
} else {
|
|
1199
|
-
arr.push(Util.fieldWithTable(item, MYMODEL))
|
|
1347
|
+
arr.push(Util.fieldWithTable(item, MYMODEL));
|
|
1200
1348
|
}
|
|
1201
|
-
})
|
|
1349
|
+
});
|
|
1202
1350
|
//select += `"${arr.join('","')}"`
|
|
1203
|
-
select += arr.join(
|
|
1204
|
-
return select
|
|
1205
|
-
}
|
|
1351
|
+
select += arr.join(",");
|
|
1352
|
+
return select;
|
|
1353
|
+
};
|
|
1206
1354
|
|
|
1207
1355
|
Util.fieldWithTable = (field, MYMODEL, isWhere = false) => {
|
|
1208
|
-
let name =
|
|
1209
|
-
let joinList =
|
|
1356
|
+
let name = "";
|
|
1357
|
+
let joinList =
|
|
1358
|
+
MYMODEL.joins && MYMODEL.joins.list.length > 0 ? MYMODEL.joins.list : [];
|
|
1210
1359
|
if (joinList.length > 0) {
|
|
1211
1360
|
if (joinList.includes(field)) {
|
|
1212
|
-
let split = field.split(
|
|
1361
|
+
let split = field.split("___");
|
|
1213
1362
|
if (isWhere) {
|
|
1214
|
-
name = `${split[0]}.${split[1]}
|
|
1363
|
+
name = `${split[0]}.${split[1]}`;
|
|
1215
1364
|
} else {
|
|
1216
|
-
name = `${split[0]}.${split[1]} as ${field}
|
|
1365
|
+
name = `${split[0]}.${split[1]} as ${field}`;
|
|
1217
1366
|
}
|
|
1218
1367
|
} else {
|
|
1219
|
-
name = `${MYMODEL.table}.${field}
|
|
1368
|
+
name = `${MYMODEL.table}.${field}`;
|
|
1220
1369
|
}
|
|
1221
1370
|
} else {
|
|
1222
|
-
name = `${MYMODEL.table}.${field}
|
|
1371
|
+
name = `${MYMODEL.table}.${field}`;
|
|
1223
1372
|
}
|
|
1224
|
-
return name
|
|
1225
|
-
}
|
|
1373
|
+
return name;
|
|
1374
|
+
};
|
|
1226
1375
|
|
|
1227
1376
|
Util.tableWithJoin = (MYMODEL) => {
|
|
1228
|
-
return MYMODEL.joins && MYMODEL.joins.list.length > 0
|
|
1229
|
-
|
|
1377
|
+
return MYMODEL.joins && MYMODEL.joins.list.length > 0
|
|
1378
|
+
? MYMODEL.joins.sql
|
|
1379
|
+
: [];
|
|
1380
|
+
};
|
|
1230
1381
|
|
|
1231
1382
|
Util.selectMysql = (fields = [], relations = {}) => {
|
|
1232
|
-
let obj = {}
|
|
1233
|
-
let arr = []
|
|
1234
|
-
let virtuals = {}
|
|
1235
|
-
let virtualArray = []
|
|
1236
|
-
if (relations.hasOwnProperty(
|
|
1237
|
-
virtuals = relations.zvirtuals
|
|
1238
|
-
delete relations.zvirtuals
|
|
1239
|
-
virtualArray = Object.keys(virtuals)
|
|
1383
|
+
let obj = {};
|
|
1384
|
+
let arr = [];
|
|
1385
|
+
let virtuals = {};
|
|
1386
|
+
let virtualArray = [];
|
|
1387
|
+
if (relations.hasOwnProperty("zvirtuals")) {
|
|
1388
|
+
virtuals = relations.zvirtuals;
|
|
1389
|
+
delete relations.zvirtuals;
|
|
1390
|
+
virtualArray = Object.keys(virtuals);
|
|
1240
1391
|
virtualArray.forEach(function (item) {
|
|
1241
|
-
fields = Util.arrayDelete(fields, item)
|
|
1242
|
-
})
|
|
1392
|
+
fields = Util.arrayDelete(fields, item);
|
|
1393
|
+
});
|
|
1243
1394
|
}
|
|
1244
|
-
let selects = []
|
|
1395
|
+
let selects = [];
|
|
1245
1396
|
fields.forEach(function (item) {
|
|
1246
|
-
if (item !=
|
|
1247
|
-
if (item ==
|
|
1248
|
-
selects.push(
|
|
1397
|
+
if (item != "actionColumn") {
|
|
1398
|
+
if (item == "no") {
|
|
1399
|
+
selects.push("id");
|
|
1249
1400
|
} else {
|
|
1250
|
-
selects.push(item)
|
|
1401
|
+
selects.push(item);
|
|
1251
1402
|
}
|
|
1252
1403
|
}
|
|
1253
|
-
})
|
|
1404
|
+
});
|
|
1254
1405
|
//make sure id
|
|
1255
|
-
selects.push(
|
|
1256
|
-
let select = `"${selects.join('","')}"
|
|
1406
|
+
selects.push("id");
|
|
1407
|
+
let select = `"${selects.join('","')}"`;
|
|
1257
1408
|
if (virtualArray.length) {
|
|
1258
1409
|
for (let key in virtuals) {
|
|
1259
|
-
select += `, ${virtuals[key]}
|
|
1410
|
+
select += `, ${virtuals[key]} `;
|
|
1260
1411
|
}
|
|
1261
1412
|
}
|
|
1262
|
-
return select
|
|
1263
|
-
}
|
|
1413
|
+
return select;
|
|
1414
|
+
};
|
|
1264
1415
|
|
|
1265
1416
|
/*
|
|
1266
1417
|
Sorting array object with key name
|
|
@@ -1268,117 +1419,153 @@ Sorting array object with key name
|
|
|
1268
1419
|
Util.sortArray = (arr, key) => {
|
|
1269
1420
|
function compare(a, b) {
|
|
1270
1421
|
if (a[key] < b[key]) {
|
|
1271
|
-
return -1
|
|
1422
|
+
return -1;
|
|
1272
1423
|
}
|
|
1273
1424
|
if (a[key] > b[key]) {
|
|
1274
|
-
return 1
|
|
1425
|
+
return 1;
|
|
1275
1426
|
}
|
|
1276
|
-
return 0
|
|
1427
|
+
return 0;
|
|
1277
1428
|
}
|
|
1278
1429
|
|
|
1279
|
-
return arr.sort(compare)
|
|
1280
|
-
}
|
|
1430
|
+
return arr.sort(compare);
|
|
1431
|
+
};
|
|
1281
1432
|
|
|
1282
|
-
Util.cleanString = (str =
|
|
1283
|
-
return str
|
|
1284
|
-
|
|
1433
|
+
Util.cleanString = (str = "") => {
|
|
1434
|
+
return str
|
|
1435
|
+
.replaceAll("(", "")
|
|
1436
|
+
.replaceAll(")", "")
|
|
1437
|
+
.replaceAll("%", "")
|
|
1438
|
+
.replaceAll("-", "");
|
|
1439
|
+
};
|
|
1285
1440
|
|
|
1286
1441
|
Util.encrypt = (str, key) => {
|
|
1287
|
-
const crypto = require(
|
|
1288
|
-
var encrypt = crypto.createCipheriv(
|
|
1289
|
-
var theCipher = encrypt.update(str,
|
|
1290
|
-
theCipher += encrypt.final(
|
|
1291
|
-
theCipher = theCipher.replaceAll(
|
|
1292
|
-
return theCipher
|
|
1293
|
-
}
|
|
1442
|
+
const crypto = require("crypto");
|
|
1443
|
+
var encrypt = crypto.createCipheriv("des-ede3", key, "");
|
|
1444
|
+
var theCipher = encrypt.update(str, "utf8", "base64");
|
|
1445
|
+
theCipher += encrypt.final("base64");
|
|
1446
|
+
theCipher = theCipher.replaceAll("/", "55ter55");
|
|
1447
|
+
return theCipher;
|
|
1448
|
+
};
|
|
1294
1449
|
|
|
1295
1450
|
Util.decrypt = (str, key) => {
|
|
1296
|
-
const crypto = require(
|
|
1297
|
-
str = str.replaceAll(
|
|
1298
|
-
var decrypt = crypto.createDecipheriv(
|
|
1299
|
-
var s = decrypt.update(str,
|
|
1300
|
-
return s + decrypt.final(
|
|
1301
|
-
}
|
|
1451
|
+
const crypto = require("crypto");
|
|
1452
|
+
str = str.replaceAll("55ter55", "/");
|
|
1453
|
+
var decrypt = crypto.createDecipheriv("des-ede3", key, "");
|
|
1454
|
+
var s = decrypt.update(str, "base64", "utf8");
|
|
1455
|
+
return s + decrypt.final("utf8");
|
|
1456
|
+
};
|
|
1302
1457
|
|
|
1303
1458
|
Util.terbilang = (nilai) => {
|
|
1304
|
-
nilai = Math.floor(Math.abs(nilai))
|
|
1305
|
-
let huruf = [
|
|
1306
|
-
|
|
1307
|
-
|
|
1459
|
+
nilai = Math.floor(Math.abs(nilai));
|
|
1460
|
+
let huruf = [
|
|
1461
|
+
"",
|
|
1462
|
+
"Satu",
|
|
1463
|
+
"Dua",
|
|
1464
|
+
"Tiga",
|
|
1465
|
+
"Empat",
|
|
1466
|
+
"Lima",
|
|
1467
|
+
"Enam",
|
|
1468
|
+
"Tujuh",
|
|
1469
|
+
"Delapan",
|
|
1470
|
+
"Sembilan",
|
|
1471
|
+
"Sepuluh",
|
|
1472
|
+
"Sebelas",
|
|
1473
|
+
];
|
|
1474
|
+
let bagi = 0;
|
|
1475
|
+
let penyimpanan = "";
|
|
1308
1476
|
if (nilai < 12) {
|
|
1309
|
-
penyimpanan =
|
|
1477
|
+
penyimpanan = " " + huruf[nilai];
|
|
1310
1478
|
} else if (nilai < 20) {
|
|
1311
|
-
penyimpanan = Util.terbilang(Math.floor(nilai - 10)) +
|
|
1479
|
+
penyimpanan = Util.terbilang(Math.floor(nilai - 10)) + " Belas";
|
|
1312
1480
|
} else if (nilai < 100) {
|
|
1313
|
-
bagi = Math.floor(nilai / 10)
|
|
1314
|
-
penyimpanan = Util.terbilang(bagi) +
|
|
1481
|
+
bagi = Math.floor(nilai / 10);
|
|
1482
|
+
penyimpanan = Util.terbilang(bagi) + " Puluh" + Util.terbilang(nilai % 10);
|
|
1315
1483
|
} else if (nilai < 200) {
|
|
1316
|
-
penyimpanan =
|
|
1484
|
+
penyimpanan = " Seratus" + Util.terbilang(nilai - 100);
|
|
1317
1485
|
} else if (nilai < 1000) {
|
|
1318
|
-
bagi = Math.floor(nilai / 100)
|
|
1319
|
-
penyimpanan = Util.terbilang(bagi) +
|
|
1486
|
+
bagi = Math.floor(nilai / 100);
|
|
1487
|
+
penyimpanan = Util.terbilang(bagi) + " Ratus" + Util.terbilang(nilai % 100);
|
|
1320
1488
|
} else if (nilai < 2000) {
|
|
1321
|
-
penyimpanan =
|
|
1489
|
+
penyimpanan = " Seribu" + Util.terbilang(nilai - 1000);
|
|
1322
1490
|
} else if (nilai < 1000000) {
|
|
1323
|
-
bagi = Math.floor(nilai / 1000)
|
|
1324
|
-
penyimpanan = Util.terbilang(bagi) +
|
|
1491
|
+
bagi = Math.floor(nilai / 1000);
|
|
1492
|
+
penyimpanan = Util.terbilang(bagi) + " Ribu" + Util.terbilang(nilai % 1000);
|
|
1325
1493
|
} else if (nilai < 1000000000) {
|
|
1326
|
-
bagi = Math.floor(nilai / 1000000)
|
|
1327
|
-
penyimpanan =
|
|
1494
|
+
bagi = Math.floor(nilai / 1000000);
|
|
1495
|
+
penyimpanan =
|
|
1496
|
+
Util.terbilang(bagi) + " Juta" + Util.terbilang(nilai % 1000000);
|
|
1328
1497
|
} else if (nilai < 1000000000000) {
|
|
1329
|
-
bagi = Math.floor(nilai / 1000000000)
|
|
1330
|
-
penyimpanan =
|
|
1498
|
+
bagi = Math.floor(nilai / 1000000000);
|
|
1499
|
+
penyimpanan =
|
|
1500
|
+
Util.terbilang(bagi) + " Miliar" + Util.terbilang(nilai % 1000000000);
|
|
1331
1501
|
} else if (nilai < 1000000000000000) {
|
|
1332
|
-
bagi = Math.floor(nilai / 1000000000000)
|
|
1333
|
-
penyimpanan =
|
|
1502
|
+
bagi = Math.floor(nilai / 1000000000000);
|
|
1503
|
+
penyimpanan =
|
|
1504
|
+
Util.terbilang(nilai / 1000000000000) +
|
|
1505
|
+
" Triliun" +
|
|
1506
|
+
Util.terbilang(nilai % 1000000000000);
|
|
1334
1507
|
}
|
|
1335
|
-
return penyimpanan
|
|
1336
|
-
}
|
|
1508
|
+
return penyimpanan;
|
|
1509
|
+
};
|
|
1337
1510
|
|
|
1338
1511
|
Util.array_id_to_zname = (arr) => {
|
|
1339
|
-
let r = {}
|
|
1512
|
+
let r = {};
|
|
1340
1513
|
arr.map((item) => {
|
|
1341
1514
|
r[item.id] = item.zname;
|
|
1342
|
-
})
|
|
1515
|
+
});
|
|
1516
|
+
return r;
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
Util.array_zname_to_id = (arr) => {
|
|
1520
|
+
let r = {};
|
|
1521
|
+
arr.map((item) => {
|
|
1522
|
+
r[item.zname] = item.id;
|
|
1523
|
+
});
|
|
1343
1524
|
return r;
|
|
1344
|
-
}
|
|
1525
|
+
};
|
|
1345
1526
|
|
|
1346
1527
|
Util.tableShowInGrid = (arr, qey, MYMODEL, myCache, companyId) => {
|
|
1347
1528
|
try {
|
|
1348
|
-
if (typeof arr !=
|
|
1349
|
-
arr = []
|
|
1529
|
+
if (typeof arr != "object") {
|
|
1530
|
+
arr = [];
|
|
1350
1531
|
}
|
|
1351
|
-
arr = arr || []
|
|
1352
|
-
let html =
|
|
1353
|
-
let MYMODELS = myCache.get(
|
|
1354
|
-
let mywidget = MYMODELS[MYMODEL.widgets[qey].table].widgets
|
|
1532
|
+
arr = arr || [];
|
|
1533
|
+
let html = "";
|
|
1534
|
+
let MYMODELS = myCache.get("MYMODELS");
|
|
1535
|
+
let mywidget = MYMODELS[MYMODEL.widgets[qey].table].widgets;
|
|
1355
1536
|
if (arr.length > 0) {
|
|
1356
|
-
html += `<table class="table table-sm table-striped table-bordered table-hover"
|
|
1357
|
-
let json = arr[0]
|
|
1537
|
+
html += `<table class="table table-sm table-striped table-bordered table-hover">`;
|
|
1538
|
+
let json = arr[0];
|
|
1358
1539
|
arr.map((item) => {
|
|
1359
|
-
html += `<tr
|
|
1540
|
+
html += `<tr>`;
|
|
1360
1541
|
for (let key in item) {
|
|
1361
|
-
var keyFields = key +
|
|
1362
|
-
var keyObject = key +
|
|
1363
|
-
let value = item[key]
|
|
1364
|
-
if(mywidget[key].name == "relation"){
|
|
1365
|
-
value = value
|
|
1542
|
+
var keyFields = key + "Fields";
|
|
1543
|
+
var keyObject = key + "Object";
|
|
1544
|
+
let value = item[key];
|
|
1545
|
+
if (mywidget[key].name == "relation") {
|
|
1546
|
+
value = value
|
|
1547
|
+
? Util.array_id_to_zname(
|
|
1548
|
+
myCache.get(
|
|
1549
|
+
`${mywidget[key].table}_${MYMODEL.widgets[qey].table}___${key}_${companyId}`
|
|
1550
|
+
)
|
|
1551
|
+
)[value]
|
|
1552
|
+
: "";
|
|
1366
1553
|
} else {
|
|
1367
1554
|
if (Util.isNumeric(value)) {
|
|
1368
|
-
value = Util.formatNumber(value,
|
|
1555
|
+
value = Util.formatNumber(value, ".");
|
|
1369
1556
|
}
|
|
1370
1557
|
}
|
|
1371
1558
|
|
|
1372
|
-
html += `<td>${value}</td
|
|
1559
|
+
html += `<td>${value}</td>`;
|
|
1373
1560
|
}
|
|
1374
|
-
html += `</tr
|
|
1375
|
-
})
|
|
1376
|
-
html += `</table
|
|
1561
|
+
html += `</tr>`;
|
|
1562
|
+
});
|
|
1563
|
+
html += `</table>`;
|
|
1377
1564
|
}
|
|
1378
|
-
return html
|
|
1565
|
+
return html;
|
|
1379
1566
|
} catch (e) {
|
|
1380
|
-
return e +
|
|
1567
|
+
return e + "";
|
|
1381
1568
|
}
|
|
1382
|
-
}
|
|
1569
|
+
};
|
|
1383
1570
|
|
|
1384
|
-
module.exports = Util
|
|
1571
|
+
module.exports = Util;
|