forstok-ui-lib 8.4.1 → 8.5.0
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/dist/index.d.ts +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assets/javascripts/function.ts +694 -440
- package/src/components/image/index.tsx +20 -11
|
@@ -1,60 +1,91 @@
|
|
|
1
|
-
import approve from
|
|
2
|
-
import { ReactNode } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import approve from "approvejs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import {
|
|
4
|
+
TMessage,
|
|
5
|
+
TMessageFunction,
|
|
6
|
+
TMessageQuestion,
|
|
7
|
+
} from "../../components/message/typed";
|
|
8
|
+
import { TObject } from "../../typeds/base.typed";
|
|
9
|
+
import { errorTitle } from "./helper";
|
|
10
|
+
import { THeadProps } from "../../typeds";
|
|
11
|
+
|
|
12
|
+
export const getStorage = (
|
|
13
|
+
name: string,
|
|
14
|
+
type: string = "string",
|
|
15
|
+
defaultVal?: any,
|
|
16
|
+
loadName: string = "load",
|
|
17
|
+
) => {
|
|
18
|
+
let result: any;
|
|
10
19
|
if (sessionStorage.getItem(loadName) !== null) {
|
|
11
|
-
result =
|
|
20
|
+
result =
|
|
21
|
+
sessionStorage.getItem(name) !== null
|
|
22
|
+
? sessionStorage.getItem(name)
|
|
23
|
+
: defaultVal;
|
|
12
24
|
} else {
|
|
13
|
-
result =
|
|
14
|
-
|
|
25
|
+
result =
|
|
26
|
+
localStorage.getItem(name) !== null
|
|
27
|
+
? localStorage.getItem(name)
|
|
28
|
+
: defaultVal;
|
|
29
|
+
localStorage.getItem(name) !== null && sessionStorage.setItem(name, result);
|
|
15
30
|
}
|
|
16
31
|
switch (type) {
|
|
17
|
-
case
|
|
18
|
-
result =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
case
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
break
|
|
32
|
+
case "boolean":
|
|
33
|
+
result =
|
|
34
|
+
result !== undefined && result !== "undefined"
|
|
35
|
+
? result === "true"
|
|
36
|
+
: false;
|
|
37
|
+
break;
|
|
38
|
+
case "number":
|
|
39
|
+
case "integer":
|
|
40
|
+
result =
|
|
41
|
+
result !== undefined && result !== "undefined" ? parseInt(result) : 0;
|
|
42
|
+
break;
|
|
43
|
+
case "object":
|
|
44
|
+
case "array":
|
|
45
|
+
result =
|
|
46
|
+
result !== undefined && result !== "undefined"
|
|
47
|
+
? typeof result === "string"
|
|
48
|
+
? result !== ""
|
|
49
|
+
? JSON.parse(result)
|
|
50
|
+
: undefined
|
|
51
|
+
: result
|
|
52
|
+
: undefined;
|
|
53
|
+
break;
|
|
28
54
|
default:
|
|
29
|
-
result =
|
|
30
|
-
break
|
|
55
|
+
result = result === undefined || result === "undefined" ? "" : result;
|
|
56
|
+
break;
|
|
31
57
|
}
|
|
32
|
-
return result
|
|
33
|
-
}
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
34
60
|
|
|
35
61
|
export const setStorage = (name: string, value?: any, only?: string) => {
|
|
36
62
|
if (value === undefined || value === null) {
|
|
37
63
|
return false;
|
|
38
64
|
}
|
|
39
|
-
const _value: string =
|
|
65
|
+
const _value: string =
|
|
66
|
+
typeof value !== "string"
|
|
67
|
+
? typeof value === "object"
|
|
68
|
+
? JSON.stringify(value)
|
|
69
|
+
: value.toString()
|
|
70
|
+
: value;
|
|
40
71
|
switch (only) {
|
|
41
|
-
case
|
|
72
|
+
case "session":
|
|
42
73
|
sessionStorage.setItem(name, _value);
|
|
43
|
-
break
|
|
44
|
-
case
|
|
74
|
+
break;
|
|
75
|
+
case "local":
|
|
45
76
|
localStorage.setItem(name, _value);
|
|
46
|
-
break
|
|
77
|
+
break;
|
|
47
78
|
default:
|
|
48
79
|
sessionStorage.setItem(name, _value);
|
|
49
80
|
localStorage.setItem(name, _value);
|
|
50
81
|
}
|
|
51
|
-
}
|
|
82
|
+
};
|
|
52
83
|
|
|
53
84
|
export const removeStorage = (name: string) => {
|
|
54
85
|
localStorage.removeItem(name);
|
|
55
86
|
sessionStorage.removeItem(name);
|
|
56
87
|
return true;
|
|
57
|
-
}
|
|
88
|
+
};
|
|
58
89
|
|
|
59
90
|
export const debounce = (fn: Function, ms = 300) => {
|
|
60
91
|
let timeoutId: ReturnType<typeof setTimeout>;
|
|
@@ -62,16 +93,16 @@ export const debounce = (fn: Function, ms = 300) => {
|
|
|
62
93
|
clearTimeout(timeoutId);
|
|
63
94
|
timeoutId = setTimeout(() => fn.apply(this, args), ms);
|
|
64
95
|
};
|
|
65
|
-
}
|
|
96
|
+
};
|
|
66
97
|
|
|
67
98
|
export const capitalize = (value?: string) => {
|
|
68
|
-
return value ?
|
|
69
|
-
}
|
|
99
|
+
return value ? value[0].toUpperCase() + value.substring(1) : "";
|
|
100
|
+
};
|
|
70
101
|
|
|
71
102
|
export const formatNumber = (n?: string | number, flag?: boolean) => {
|
|
72
103
|
const _flag = flag === undefined ? true : flag;
|
|
73
|
-
let result:string =
|
|
74
|
-
if (n !==
|
|
104
|
+
let result: string = "";
|
|
105
|
+
if (n !== "" && n !== null && n !== undefined) {
|
|
75
106
|
result = n?.toString().replaceAll(".", "");
|
|
76
107
|
if (result.length === 2 && result.substring(0, 1) === "0") {
|
|
77
108
|
result = parseInt(result).toString();
|
|
@@ -81,71 +112,105 @@ export const formatNumber = (n?: string | number, flag?: boolean) => {
|
|
|
81
112
|
}
|
|
82
113
|
}
|
|
83
114
|
return result;
|
|
84
|
-
}
|
|
115
|
+
};
|
|
85
116
|
|
|
86
117
|
export const IsNumeric = (val?: any) => {
|
|
87
118
|
return Number(parseFloat(val)) === val;
|
|
88
|
-
}
|
|
119
|
+
};
|
|
89
120
|
|
|
90
|
-
export const generateMessage = (
|
|
121
|
+
export const generateMessage = (
|
|
122
|
+
type: string,
|
|
123
|
+
value: string | ReactNode,
|
|
124
|
+
callback?: () => void,
|
|
125
|
+
timer?: number,
|
|
126
|
+
) => {
|
|
91
127
|
let result: TMessage = {
|
|
92
128
|
$type: type,
|
|
93
129
|
message: value,
|
|
94
|
-
timer: timer || (type ===
|
|
130
|
+
timer: timer || (type === "warning" ? 3000 : 2000),
|
|
95
131
|
};
|
|
96
|
-
callback &&
|
|
132
|
+
callback &&
|
|
133
|
+
(result.callback = () => {
|
|
134
|
+
callback();
|
|
135
|
+
});
|
|
97
136
|
return result;
|
|
98
|
-
}
|
|
137
|
+
};
|
|
99
138
|
|
|
100
|
-
export const generateMessageQuestion = (
|
|
139
|
+
export const generateMessageQuestion = (
|
|
140
|
+
type: string,
|
|
141
|
+
title: string,
|
|
142
|
+
subtitle: string,
|
|
143
|
+
callback?: () => void,
|
|
144
|
+
buttonSubmit?: string,
|
|
145
|
+
cancelCallback?: () => void,
|
|
146
|
+
) => {
|
|
101
147
|
let result: TMessageQuestion = {
|
|
102
148
|
$type: type,
|
|
103
149
|
title: title,
|
|
104
150
|
subtitle: subtitle,
|
|
105
151
|
callback: callback,
|
|
106
152
|
buttonSubmit: buttonSubmit,
|
|
107
|
-
cancelCallback: cancelCallback
|
|
153
|
+
cancelCallback: cancelCallback,
|
|
108
154
|
};
|
|
109
155
|
return result;
|
|
110
|
-
}
|
|
156
|
+
};
|
|
111
157
|
|
|
112
158
|
export const currencyNumber = (value?: number | null) => {
|
|
113
|
-
return
|
|
114
|
-
|
|
159
|
+
return value !== undefined && value !== null
|
|
160
|
+
? value.toLocaleString("id-ID", {
|
|
161
|
+
style: "currency",
|
|
162
|
+
currency: "IDR",
|
|
163
|
+
minimumFractionDigits: 0,
|
|
164
|
+
})
|
|
165
|
+
: "-";
|
|
166
|
+
};
|
|
115
167
|
|
|
116
|
-
export const generateSUM = (
|
|
117
|
-
|
|
168
|
+
export const generateSUM = (
|
|
169
|
+
names: string[] | string,
|
|
170
|
+
data: any,
|
|
171
|
+
type?: string,
|
|
172
|
+
) => {
|
|
173
|
+
let result: number = 0;
|
|
118
174
|
if (data && names) {
|
|
119
175
|
result = data.reduce((_sum: any, cur: any) => {
|
|
120
|
-
let _name
|
|
176
|
+
let _name;
|
|
121
177
|
if (Array.isArray(names)) {
|
|
122
|
-
_name = cur
|
|
178
|
+
_name = cur;
|
|
123
179
|
for (const name of names) {
|
|
124
180
|
if (name in _name) {
|
|
125
|
-
_name = _name[name]
|
|
181
|
+
_name = _name[name];
|
|
126
182
|
}
|
|
127
183
|
}
|
|
128
184
|
} else {
|
|
129
|
-
_name = cur[names]
|
|
185
|
+
_name = cur[names];
|
|
130
186
|
}
|
|
131
|
-
return
|
|
132
|
-
|
|
187
|
+
return (
|
|
188
|
+
_sum +
|
|
189
|
+
(type === "currency"
|
|
190
|
+
? parseInt(_name.replace(/,.*|[^0-9]/g, ""))
|
|
191
|
+
: _name)
|
|
192
|
+
);
|
|
193
|
+
}, 0);
|
|
133
194
|
}
|
|
134
|
-
return result
|
|
135
|
-
}
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
136
197
|
|
|
137
|
-
export const evUpdateInputRc = (
|
|
198
|
+
export const evUpdateInputRc = (
|
|
199
|
+
input?: HTMLInputElement,
|
|
200
|
+
value?: string | number,
|
|
201
|
+
) => {
|
|
138
202
|
if (!input) {
|
|
139
203
|
return false;
|
|
140
204
|
}
|
|
141
205
|
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
|
142
206
|
window.HTMLInputElement.prototype,
|
|
143
|
-
"value"
|
|
207
|
+
"value",
|
|
144
208
|
)?.set;
|
|
145
|
-
nativeInputValueSetter &&
|
|
146
|
-
|
|
209
|
+
nativeInputValueSetter &&
|
|
210
|
+
nativeInputValueSetter.call(input, value === undefined ? "" : value);
|
|
211
|
+
const inputEvent = new Event("input", { bubbles: true });
|
|
147
212
|
input.dispatchEvent(inputEvent);
|
|
148
|
-
}
|
|
213
|
+
};
|
|
149
214
|
|
|
150
215
|
export const getSizeContainer = (full?: boolean) => {
|
|
151
216
|
const height = window.innerHeight;
|
|
@@ -157,370 +222,463 @@ export const getSizeContainer = (full?: boolean) => {
|
|
|
157
222
|
result.width = width - 187 - 32;
|
|
158
223
|
}
|
|
159
224
|
return result;
|
|
160
|
-
}
|
|
225
|
+
};
|
|
161
226
|
|
|
162
|
-
export const generateValueTable = (input: string|number, key: string) => {
|
|
227
|
+
export const generateValueTable = (input: string | number, key: string) => {
|
|
163
228
|
let result = input;
|
|
164
|
-
if (key && input !==
|
|
229
|
+
if (key && input !== "") {
|
|
165
230
|
const _key = key.toLowerCase();
|
|
166
|
-
const _input =
|
|
231
|
+
const _input = typeof input === "string" ? parseInt(input) : input;
|
|
167
232
|
if (/price/.test(_key)) {
|
|
168
233
|
result = currencyNumber(_input);
|
|
169
|
-
} else if (
|
|
170
|
-
|
|
234
|
+
} else if (
|
|
235
|
+
/width/.test(_key) ||
|
|
236
|
+
/length/.test(_key) ||
|
|
237
|
+
/height/.test(_key)
|
|
238
|
+
) {
|
|
239
|
+
result = input + " cm";
|
|
171
240
|
} else if (/weight/.test(_key)) {
|
|
172
|
-
result = input +
|
|
173
|
-
} else if(/discount/.test(_key)) {
|
|
174
|
-
result = input +
|
|
241
|
+
result = input + " gr";
|
|
242
|
+
} else if (/discount/.test(_key)) {
|
|
243
|
+
result = input + " %";
|
|
175
244
|
}
|
|
176
245
|
}
|
|
177
246
|
return result;
|
|
178
|
-
}
|
|
247
|
+
};
|
|
179
248
|
|
|
180
249
|
export const generateValue = (type: string, value: any) => {
|
|
181
250
|
let result: any;
|
|
182
251
|
switch (type) {
|
|
183
|
-
case
|
|
184
|
-
result = value ? value.toString().trim() :
|
|
185
|
-
break
|
|
186
|
-
case
|
|
187
|
-
result =
|
|
188
|
-
break
|
|
189
|
-
case
|
|
190
|
-
result =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
252
|
+
case "String":
|
|
253
|
+
result = value ? value.toString().trim() : "";
|
|
254
|
+
break;
|
|
255
|
+
case "Integer":
|
|
256
|
+
result = value !== "" && value !== null ? parseInt(value) : null;
|
|
257
|
+
break;
|
|
258
|
+
case "Currency":
|
|
259
|
+
result =
|
|
260
|
+
value !== "" && value !== null
|
|
261
|
+
? parseInt(formatNumber(value, false))
|
|
262
|
+
: null;
|
|
263
|
+
break;
|
|
264
|
+
case "Boolean":
|
|
265
|
+
case "Array":
|
|
194
266
|
result = value;
|
|
195
|
-
break
|
|
267
|
+
break;
|
|
196
268
|
default:
|
|
197
269
|
result = value.toString().trim();
|
|
198
270
|
}
|
|
199
271
|
return result;
|
|
200
|
-
}
|
|
272
|
+
};
|
|
201
273
|
|
|
202
|
-
export const validateByApproveJs = (
|
|
274
|
+
export const validateByApproveJs = (
|
|
275
|
+
head: TObject,
|
|
276
|
+
value: any,
|
|
277
|
+
title?: string,
|
|
278
|
+
valueMatch?: any,
|
|
279
|
+
) => {
|
|
203
280
|
let result: TObject = { approved: true };
|
|
204
281
|
let _title: string = title || errorTitle(head.name);
|
|
205
|
-
if (head.key.indexOf(
|
|
206
|
-
if (value ===
|
|
207
|
-
result = { approved: false, errors: [_title+
|
|
282
|
+
if (head.key.indexOf("options-option") !== -1) {
|
|
283
|
+
if (value === "") {
|
|
284
|
+
result = { approved: false, errors: [_title + " is required"] };
|
|
208
285
|
}
|
|
209
286
|
}
|
|
210
287
|
if (head?.validations) {
|
|
211
|
-
const typeData: string = head?.typeData ||
|
|
288
|
+
const typeData: string = head?.typeData || "String";
|
|
212
289
|
let rules: TObject = { title: _title };
|
|
213
290
|
if (head.validations?.required) {
|
|
214
291
|
switch (typeData) {
|
|
215
|
-
case
|
|
292
|
+
case "String":
|
|
216
293
|
rules.required = true;
|
|
217
|
-
|
|
218
|
-
case
|
|
219
|
-
|
|
220
|
-
|
|
294
|
+
break;
|
|
295
|
+
case "Boolean":
|
|
296
|
+
const requiredBooleanRule = {
|
|
297
|
+
expects: ["value"],
|
|
298
|
+
message: "{title} is required",
|
|
299
|
+
validate: (value: any, pars: TObject) => {
|
|
300
|
+
return pars.value !== undefined && pars.value !== null;
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
approve.addTest(requiredBooleanRule, "requiredBooleanRule");
|
|
304
|
+
rules.requiredBooleanRule = {
|
|
305
|
+
value: value,
|
|
306
|
+
};
|
|
307
|
+
break;
|
|
308
|
+
case "Integer":
|
|
309
|
+
case "Currency":
|
|
310
|
+
const _value =
|
|
311
|
+
typeof value === "undefined" ? "" : isNaN(value) ? "" : value;
|
|
221
312
|
const requiredIntegerRule = {
|
|
222
|
-
expects: [
|
|
223
|
-
|
|
224
|
-
],
|
|
225
|
-
message: '{title} is required',
|
|
313
|
+
expects: ["value"],
|
|
314
|
+
message: "{title} is required",
|
|
226
315
|
validate: (value: any, pars: TObject) => {
|
|
227
|
-
return pars.value !==
|
|
228
|
-
}
|
|
316
|
+
return pars.value !== "" && pars.value !== null;
|
|
317
|
+
},
|
|
229
318
|
};
|
|
230
|
-
approve.addTest(requiredIntegerRule,
|
|
319
|
+
approve.addTest(requiredIntegerRule, "requiredIntegerRule");
|
|
231
320
|
rules.requiredIntegerRule = {
|
|
232
|
-
value: _value
|
|
321
|
+
value: _value,
|
|
233
322
|
};
|
|
234
|
-
|
|
235
|
-
case
|
|
323
|
+
break;
|
|
324
|
+
case "Array":
|
|
236
325
|
const requiredArrayRule = {
|
|
237
|
-
expects: [
|
|
238
|
-
|
|
239
|
-
],
|
|
240
|
-
message: '{title} is required',
|
|
326
|
+
expects: ["value"],
|
|
327
|
+
message: "{title} is required",
|
|
241
328
|
validate: (value: any, pars: TObject) => {
|
|
242
|
-
return pars.value?.length ||
|
|
243
|
-
|
|
329
|
+
return pars.value?.length ||
|
|
330
|
+
(pars.value && Object.keys(pars.value).length)
|
|
331
|
+
? true
|
|
332
|
+
: false;
|
|
333
|
+
},
|
|
244
334
|
};
|
|
245
|
-
approve.addTest(requiredArrayRule,
|
|
335
|
+
approve.addTest(requiredArrayRule, "requiredArrayRule");
|
|
246
336
|
rules.requiredArrayRule = {
|
|
247
|
-
value: value
|
|
337
|
+
value: value,
|
|
248
338
|
};
|
|
249
|
-
|
|
250
|
-
default:
|
|
339
|
+
break;
|
|
340
|
+
default:
|
|
251
341
|
rules.required = true;
|
|
252
342
|
}
|
|
253
343
|
}
|
|
254
344
|
|
|
255
|
-
if
|
|
345
|
+
if (head.validations?.requiredIf) {
|
|
346
|
+
const requiredIfRule = {
|
|
347
|
+
expects: ["value", "valueMatch"],
|
|
348
|
+
message: "{title} is required",
|
|
349
|
+
validate: (value: any, pars: TObject) => {
|
|
350
|
+
if (pars?.valueMatch) {
|
|
351
|
+
if (IsNumeric(pars?.valueMatch)) {
|
|
352
|
+
return pars?.valueMatch > 0 && value ? true : false;
|
|
353
|
+
} else {
|
|
354
|
+
return pars?.valueMatch && value ? true : false;
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
approve.addTest(requiredIfRule, "requiredIfRule");
|
|
362
|
+
rules.requiredIfRule = {
|
|
363
|
+
value: value,
|
|
364
|
+
valueMatch: valueMatch,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (
|
|
369
|
+
"min" in head.validations &&
|
|
370
|
+
head.validations.min !== null &&
|
|
371
|
+
"max" in head.validations &&
|
|
372
|
+
head.validations.max !== null
|
|
373
|
+
) {
|
|
256
374
|
switch (typeData) {
|
|
257
|
-
case
|
|
258
|
-
case
|
|
375
|
+
case "Integer":
|
|
376
|
+
case "Currency":
|
|
377
|
+
const minMaxMin = head.validations.min;
|
|
378
|
+
const minMaxMax = head.validations.max;
|
|
259
379
|
const minMaxIntegerRule = {
|
|
260
|
-
expects: [
|
|
261
|
-
|
|
262
|
-
],
|
|
263
|
-
message: '{title} min '+head.validations.min+' and max '+head.validations.max,
|
|
380
|
+
expects: ["value"],
|
|
381
|
+
message: "{title} min " + minMaxMin + " and max " + minMaxMax,
|
|
264
382
|
validate: (value: any, pars: TObject) => {
|
|
265
|
-
return (
|
|
266
|
-
|
|
383
|
+
return (
|
|
384
|
+
(pars.value >= minMaxMin && pars.value <= minMaxMax) ||
|
|
385
|
+
pars.value === "" ||
|
|
386
|
+
pars.value === null ||
|
|
387
|
+
typeof pars.value === "undefined"
|
|
388
|
+
);
|
|
389
|
+
},
|
|
267
390
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
391
|
+
const minMaxIntegerRuleName = "minMaxIntegerRule_" + head.key;
|
|
392
|
+
approve.addTest(minMaxIntegerRule, minMaxIntegerRuleName);
|
|
393
|
+
rules[minMaxIntegerRuleName] = {
|
|
394
|
+
value: value,
|
|
271
395
|
};
|
|
272
|
-
|
|
273
|
-
case
|
|
396
|
+
break;
|
|
397
|
+
case "Array":
|
|
398
|
+
const minMaxArrayMin = head.validations.min;
|
|
399
|
+
const minMaxArrayMax = head.validations.max;
|
|
274
400
|
const minMaxArrayRule = {
|
|
275
|
-
expects: [
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
401
|
+
expects: ["value"],
|
|
402
|
+
message:
|
|
403
|
+
"{title} must be a minimum of " +
|
|
404
|
+
minMaxArrayMin +
|
|
405
|
+
" and a maximum of " +
|
|
406
|
+
minMaxArrayMax,
|
|
279
407
|
validate: (value: any, pars: TObject) => {
|
|
280
|
-
return pars.value
|
|
281
|
-
|
|
408
|
+
return pars.value
|
|
409
|
+
? pars.value.length >= minMaxArrayMin &&
|
|
410
|
+
pars.value.length <= minMaxArrayMax
|
|
411
|
+
: minMaxArrayMin === 0
|
|
412
|
+
? true
|
|
413
|
+
: false;
|
|
414
|
+
},
|
|
282
415
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
416
|
+
const minMaxArrayRuleName = "minMaxArrayRule_" + head.key;
|
|
417
|
+
approve.addTest(minMaxArrayRule, minMaxArrayRuleName);
|
|
418
|
+
rules[minMaxArrayRuleName] = {
|
|
419
|
+
value: value,
|
|
286
420
|
};
|
|
287
|
-
|
|
288
|
-
default:
|
|
421
|
+
break;
|
|
422
|
+
default:
|
|
289
423
|
rules.min = head.validations.min;
|
|
290
424
|
rules.max = head.validations.max;
|
|
291
425
|
}
|
|
292
|
-
}
|
|
293
|
-
else if('min' in head.validations && head.validations.min !== null) {
|
|
426
|
+
} else if ("min" in head.validations && head.validations.min !== null) {
|
|
294
427
|
switch (typeData) {
|
|
295
|
-
case
|
|
296
|
-
case
|
|
428
|
+
case "Integer":
|
|
429
|
+
case "Currency":
|
|
430
|
+
const minValue = head.validations.min;
|
|
297
431
|
const minIntegerRule = {
|
|
298
|
-
expects: [
|
|
299
|
-
|
|
300
|
-
],
|
|
301
|
-
message: '{title} min '+head.validations.min,
|
|
432
|
+
expects: ["value"],
|
|
433
|
+
message: "{title} min " + minValue,
|
|
302
434
|
validate: (value: any, pars: TObject) => {
|
|
303
|
-
return
|
|
304
|
-
|
|
435
|
+
return (
|
|
436
|
+
pars.value >= minValue ||
|
|
437
|
+
pars.value === "" ||
|
|
438
|
+
pars.value === null ||
|
|
439
|
+
typeof pars.value === "undefined"
|
|
440
|
+
);
|
|
441
|
+
},
|
|
305
442
|
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
443
|
+
const minIntegerRuleName = "minIntegerRule_" + head.key;
|
|
444
|
+
approve.addTest(minIntegerRule, minIntegerRuleName);
|
|
445
|
+
rules[minIntegerRuleName] = {
|
|
446
|
+
value: value,
|
|
309
447
|
};
|
|
310
|
-
|
|
311
|
-
case
|
|
448
|
+
break;
|
|
449
|
+
case "Array":
|
|
450
|
+
const minArrayMin = head.validations.min;
|
|
312
451
|
const minArrayRule = {
|
|
313
|
-
expects: [
|
|
314
|
-
|
|
315
|
-
],
|
|
316
|
-
message: '{title} must be a minimum of '+head.validations.min,
|
|
452
|
+
expects: ["value"],
|
|
453
|
+
message: "{title} must be a minimum of " + minArrayMin,
|
|
317
454
|
validate: (value: any, pars: TObject) => {
|
|
318
|
-
return pars.value
|
|
319
|
-
|
|
455
|
+
return pars.value
|
|
456
|
+
? pars.value.length >= minArrayMin
|
|
457
|
+
: minArrayMin === 0
|
|
458
|
+
? true
|
|
459
|
+
: false;
|
|
460
|
+
},
|
|
320
461
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
462
|
+
const minArrayRuleName = "minArrayRule_" + head.key;
|
|
463
|
+
approve.addTest(minArrayRule, minArrayRuleName);
|
|
464
|
+
rules[minArrayRuleName] = {
|
|
465
|
+
value: value,
|
|
324
466
|
};
|
|
325
|
-
|
|
326
|
-
default:
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
327
469
|
rules.min = head.validations.min;
|
|
328
470
|
}
|
|
329
|
-
}
|
|
330
|
-
else if('max' in head.validations && head.validations.max !== null) {
|
|
471
|
+
} else if ("max" in head.validations && head.validations.max !== null) {
|
|
331
472
|
switch (typeData) {
|
|
332
|
-
case
|
|
333
|
-
case
|
|
473
|
+
case "Integer":
|
|
474
|
+
case "Currency":
|
|
475
|
+
const maxValue = head.validations.max;
|
|
334
476
|
const maxIntegerRule = {
|
|
335
|
-
expects: [
|
|
336
|
-
|
|
337
|
-
],
|
|
338
|
-
message: '{title} max '+head.validations.max,
|
|
477
|
+
expects: ["value"],
|
|
478
|
+
message: "{title} max " + maxValue,
|
|
339
479
|
validate: (value: any, pars: TObject) => {
|
|
340
|
-
return
|
|
341
|
-
|
|
480
|
+
return (
|
|
481
|
+
pars.value <= maxValue ||
|
|
482
|
+
pars.value === "" ||
|
|
483
|
+
pars.value === null ||
|
|
484
|
+
typeof pars.value === "undefined"
|
|
485
|
+
);
|
|
486
|
+
},
|
|
342
487
|
};
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
488
|
+
const maxIntegerRuleName = "maxIntegerRule_" + head.key;
|
|
489
|
+
approve.addTest(maxIntegerRule, maxIntegerRuleName);
|
|
490
|
+
rules[maxIntegerRuleName] = {
|
|
491
|
+
value: value,
|
|
346
492
|
};
|
|
347
|
-
|
|
348
|
-
case
|
|
493
|
+
break;
|
|
494
|
+
case "Array":
|
|
495
|
+
const maxArrayMax = head.validations.max;
|
|
349
496
|
const maxArrayRule = {
|
|
350
|
-
expects: [
|
|
351
|
-
|
|
352
|
-
],
|
|
353
|
-
message: '{title} must be a maximum of '+head.validations.max,
|
|
497
|
+
expects: ["value"],
|
|
498
|
+
message: "{title} must be a maximum of " + maxArrayMax,
|
|
354
499
|
validate: (value: any, pars: TObject) => {
|
|
355
|
-
return pars?.value?.length <=
|
|
356
|
-
}
|
|
500
|
+
return pars?.value?.length <= maxArrayMax;
|
|
501
|
+
},
|
|
357
502
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
503
|
+
const maxArrayRuleName = "maxArrayRule_" + head.key;
|
|
504
|
+
approve.addTest(maxArrayRule, maxArrayRuleName);
|
|
505
|
+
rules[maxArrayRuleName] = {
|
|
506
|
+
value: value,
|
|
361
507
|
};
|
|
362
|
-
|
|
363
|
-
default:
|
|
508
|
+
break;
|
|
509
|
+
default:
|
|
364
510
|
rules.max = head.validations.max;
|
|
365
511
|
}
|
|
366
512
|
}
|
|
367
513
|
|
|
368
|
-
if(
|
|
514
|
+
if ("lessEqual" in head.validations) {
|
|
369
515
|
const lessEqualRule = {
|
|
370
|
-
expects: [
|
|
371
|
-
|
|
372
|
-
'valueMatch',
|
|
373
|
-
],
|
|
374
|
-
message: '{title} is less than or equal {valueMatch}',
|
|
516
|
+
expects: ["value", "valueMatch"],
|
|
517
|
+
message: "{title} is less than or equal {valueMatch}",
|
|
375
518
|
validate: (value: any, pars: TObject) => {
|
|
376
|
-
return
|
|
377
|
-
|
|
519
|
+
return IsNumeric(value) && IsNumeric(pars?.valueMatch)
|
|
520
|
+
? value <= pars.valueMatch
|
|
521
|
+
: true;
|
|
522
|
+
},
|
|
378
523
|
};
|
|
379
|
-
approve.addTest(lessEqualRule,
|
|
524
|
+
approve.addTest(lessEqualRule, "lessEqualRule");
|
|
380
525
|
rules.lessEqualRule = {
|
|
381
526
|
value: value,
|
|
382
|
-
valueMatch: valueMatch
|
|
527
|
+
valueMatch: valueMatch,
|
|
383
528
|
};
|
|
384
529
|
}
|
|
385
530
|
|
|
386
|
-
if(
|
|
531
|
+
if ("less" in head.validations) {
|
|
387
532
|
const lessRule = {
|
|
388
|
-
expects: [
|
|
389
|
-
|
|
390
|
-
'valueMatch',
|
|
391
|
-
],
|
|
392
|
-
message: '{title} is less than {valueMatch}',
|
|
533
|
+
expects: ["value", "valueMatch"],
|
|
534
|
+
message: "{title} is less than {valueMatch}",
|
|
393
535
|
validate: (value: any, pars: TObject) => {
|
|
394
|
-
return
|
|
395
|
-
|
|
536
|
+
return IsNumeric(value) && IsNumeric(pars?.valueMatch)
|
|
537
|
+
? value < pars.valueMatch
|
|
538
|
+
: true;
|
|
539
|
+
},
|
|
396
540
|
};
|
|
397
|
-
approve.addTest(lessRule,
|
|
541
|
+
approve.addTest(lessRule, "lessRule");
|
|
398
542
|
rules.lessRule = {
|
|
399
543
|
value: value,
|
|
400
|
-
valueMatch: valueMatch
|
|
544
|
+
valueMatch: valueMatch,
|
|
401
545
|
};
|
|
402
546
|
}
|
|
403
547
|
|
|
404
|
-
if(head.validations?.greaterEqual) {
|
|
548
|
+
if (head.validations?.greaterEqual) {
|
|
405
549
|
const greaterEqualRule = {
|
|
406
|
-
expects: [
|
|
407
|
-
|
|
408
|
-
'valueMatch',
|
|
409
|
-
],
|
|
410
|
-
message: '{title} is greater than or equal {valueMatch}',
|
|
550
|
+
expects: ["value", "valueMatch"],
|
|
551
|
+
message: "{title} is greater than or equal {valueMatch}",
|
|
411
552
|
validate: (value: any, pars: TObject) => {
|
|
412
|
-
return
|
|
413
|
-
|
|
553
|
+
return IsNumeric(value) && IsNumeric(pars?.valueMatch)
|
|
554
|
+
? value >= pars.valueMatch
|
|
555
|
+
: true;
|
|
556
|
+
},
|
|
414
557
|
};
|
|
415
|
-
approve.addTest(greaterEqualRule,
|
|
558
|
+
approve.addTest(greaterEqualRule, "greaterEqualRule");
|
|
416
559
|
rules.greaterEqualRule = {
|
|
417
560
|
value: value,
|
|
418
|
-
valueMatch: valueMatch
|
|
561
|
+
valueMatch: valueMatch,
|
|
419
562
|
};
|
|
420
563
|
}
|
|
421
564
|
|
|
422
|
-
if(head.validations?.greater) {
|
|
565
|
+
if (head.validations?.greater) {
|
|
423
566
|
const greaterRule = {
|
|
424
|
-
expects: [
|
|
425
|
-
|
|
426
|
-
'valueMatch',
|
|
427
|
-
],
|
|
428
|
-
message: '{title} is greater than {valueMatch}',
|
|
567
|
+
expects: ["value", "valueMatch"],
|
|
568
|
+
message: "{title} is greater than {valueMatch}",
|
|
429
569
|
validate: (value: any, pars: TObject) => {
|
|
430
|
-
return
|
|
431
|
-
|
|
570
|
+
return IsNumeric(value) && IsNumeric(pars?.valueMatch)
|
|
571
|
+
? value > pars.valueMatch
|
|
572
|
+
: true;
|
|
573
|
+
},
|
|
432
574
|
};
|
|
433
|
-
approve.addTest(greaterRule,
|
|
575
|
+
approve.addTest(greaterRule, "greaterRule");
|
|
434
576
|
rules.greaterRule = {
|
|
435
577
|
value: value,
|
|
436
|
-
valueMatch: valueMatch
|
|
578
|
+
valueMatch: valueMatch,
|
|
437
579
|
};
|
|
438
580
|
}
|
|
439
581
|
|
|
440
582
|
result = approve.value(value, rules);
|
|
441
583
|
}
|
|
442
|
-
return result
|
|
443
|
-
}
|
|
584
|
+
return result;
|
|
585
|
+
};
|
|
444
586
|
|
|
445
587
|
export const evGenerateValueMatch = (validation?: TObject, data?: any) => {
|
|
446
588
|
let result = undefined;
|
|
447
589
|
if (validation && Object.keys(validation).length) {
|
|
448
|
-
const keyArr = [
|
|
590
|
+
const keyArr = ["lessEqual", "greaterEqual", "less", "greater"];
|
|
449
591
|
const key = keyArr.find((_key) => _key in validation);
|
|
450
592
|
if (data && key) {
|
|
451
593
|
const obj = validation[key];
|
|
452
|
-
if(obj && obj in data) result = data[obj];
|
|
594
|
+
if (obj && obj in data) result = data[obj];
|
|
453
595
|
}
|
|
454
596
|
}
|
|
455
597
|
return result;
|
|
456
|
-
}
|
|
598
|
+
};
|
|
457
599
|
|
|
458
600
|
export const unescapeHTML = (value?: string) => {
|
|
459
|
-
return value
|
|
460
|
-
|
|
601
|
+
return value
|
|
602
|
+
? value.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")
|
|
603
|
+
: (value as string);
|
|
604
|
+
};
|
|
461
605
|
|
|
462
606
|
export const evScrollTo = (el?: HTMLElement, range?: number) => {
|
|
463
607
|
const _range = range || 140;
|
|
464
608
|
if (el) {
|
|
465
609
|
setTimeout(() => {
|
|
466
|
-
const viewportEl = document.querySelector(
|
|
610
|
+
const viewportEl = document.querySelector(
|
|
611
|
+
"._refMasterTableViewport",
|
|
612
|
+
) as HTMLElement;
|
|
467
613
|
if (!viewportEl) {
|
|
468
614
|
return;
|
|
469
615
|
}
|
|
470
616
|
const bodyRect = viewportEl.getBoundingClientRect();
|
|
471
617
|
const elemRect = el.getBoundingClientRect();
|
|
472
618
|
if (elemRect) {
|
|
473
|
-
const offsetTop =
|
|
474
|
-
|
|
475
|
-
|
|
619
|
+
const offsetTop =
|
|
620
|
+
elemRect.top - bodyRect.top - _range + viewportEl.scrollTop;
|
|
621
|
+
const offsetLeft =
|
|
622
|
+
elemRect.left - bodyRect.left + viewportEl.scrollLeft;
|
|
623
|
+
viewportEl.scrollTo(offsetLeft, offsetTop);
|
|
476
624
|
}
|
|
477
625
|
}, 20);
|
|
478
626
|
}
|
|
479
|
-
}
|
|
627
|
+
};
|
|
480
628
|
|
|
481
|
-
export const evHighlight = (ids?: string[]|number[]) => {
|
|
629
|
+
export const evHighlight = (ids?: string[] | number[]) => {
|
|
482
630
|
if (!ids?.length) {
|
|
483
|
-
return false
|
|
631
|
+
return false;
|
|
484
632
|
}
|
|
485
|
-
const timer: number =
|
|
633
|
+
const timer: number =
|
|
634
|
+
Math.ceil(ids.length / 10) * 10 <= 10
|
|
635
|
+
? 30
|
|
636
|
+
: Math.ceil(ids.length / 10) * 10 >= 200
|
|
637
|
+
? 200
|
|
638
|
+
: Math.ceil(ids.length / 10) * 10;
|
|
486
639
|
setTimeout(() => {
|
|
487
|
-
const contentHightlightedEls = document.querySelectorAll(
|
|
640
|
+
const contentHightlightedEls = document.querySelectorAll(
|
|
641
|
+
"._refMasterTableBodyContent.is-highlighted",
|
|
642
|
+
) as NodeListOf<HTMLElement>;
|
|
488
643
|
if (contentHightlightedEls?.length) {
|
|
489
644
|
for (const contentHightlightedEl of contentHightlightedEls) {
|
|
490
|
-
contentHightlightedEl.classList.remove(
|
|
645
|
+
contentHightlightedEl.classList.remove("is-highlighted");
|
|
491
646
|
}
|
|
492
647
|
}
|
|
493
648
|
for (let i = 0; i < ids.length; i++) {
|
|
494
|
-
const id = ids[i]
|
|
495
|
-
const el = document.querySelector(`#row-${id}`) as HTMLElement
|
|
649
|
+
const id = ids[i];
|
|
650
|
+
const el = document.querySelector(`#row-${id}`) as HTMLElement;
|
|
496
651
|
if (el) {
|
|
497
|
-
el.classList.add(
|
|
652
|
+
el.classList.add("is-highlighted");
|
|
498
653
|
setTimeout(() => {
|
|
499
|
-
el.classList.remove(
|
|
500
|
-
}, 1888)
|
|
654
|
+
el.classList.remove("is-highlighted");
|
|
655
|
+
}, 1888);
|
|
501
656
|
}
|
|
502
|
-
if (i ===
|
|
503
|
-
const firstEl = document.querySelector(`#row-${ids[0]}`) as HTMLElement
|
|
504
|
-
|
|
657
|
+
if (i === ids.length - 1) {
|
|
658
|
+
const firstEl = document.querySelector(`#row-${ids[0]}`) as HTMLElement;
|
|
659
|
+
firstEl && evScrollTo(firstEl, 140);
|
|
505
660
|
}
|
|
506
661
|
}
|
|
507
|
-
}, timer)
|
|
508
|
-
}
|
|
662
|
+
}, timer);
|
|
663
|
+
};
|
|
509
664
|
|
|
510
665
|
export const evKeyMapperScanner = (oEvent: any) => {
|
|
511
666
|
var iCode = oEvent.which;
|
|
512
667
|
switch (true) {
|
|
513
668
|
case iCode >= 48 && iCode <= 90:
|
|
514
|
-
case (iCode >= 106 && iCode <= 111) ||
|
|
515
|
-
|
|
669
|
+
case (iCode >= 106 && iCode <= 111) ||
|
|
670
|
+
iCode === 45 ||
|
|
671
|
+
iCode === 173 ||
|
|
672
|
+
iCode === 189:
|
|
673
|
+
if (oEvent.key !== undefined && oEvent.key !== "") {
|
|
516
674
|
return oEvent.key;
|
|
517
675
|
}
|
|
518
676
|
var sDecoded = String.fromCharCode(iCode);
|
|
519
677
|
switch (oEvent.shiftKey) {
|
|
520
|
-
case false:
|
|
678
|
+
case false:
|
|
521
679
|
sDecoded = sDecoded.toLowerCase();
|
|
522
680
|
break;
|
|
523
|
-
case true:
|
|
681
|
+
case true:
|
|
524
682
|
sDecoded = sDecoded.toUpperCase();
|
|
525
683
|
break;
|
|
526
684
|
default:
|
|
@@ -528,40 +686,45 @@ export const evKeyMapperScanner = (oEvent: any) => {
|
|
|
528
686
|
}
|
|
529
687
|
return sDecoded;
|
|
530
688
|
case iCode >= 96 && iCode <= 105:
|
|
531
|
-
return 0+(iCode-96);
|
|
689
|
+
return 0 + (iCode - 96);
|
|
532
690
|
default:
|
|
533
691
|
break;
|
|
534
692
|
}
|
|
535
|
-
return
|
|
536
|
-
}
|
|
693
|
+
return "";
|
|
694
|
+
};
|
|
537
695
|
|
|
538
696
|
export const evExecuteError = (evCreateMessage?: TMessageFunction) => {
|
|
539
|
-
const msg: TMessage = generateMessage(
|
|
697
|
+
const msg: TMessage = generateMessage(
|
|
698
|
+
"failed",
|
|
699
|
+
"Validation Errors found, Please fix it!",
|
|
700
|
+
);
|
|
540
701
|
evCreateMessage && evCreateMessage(msg);
|
|
541
|
-
const errorEl = document.querySelectorAll(
|
|
702
|
+
const errorEl = document.querySelectorAll(
|
|
703
|
+
".cell-error",
|
|
704
|
+
) as NodeListOf<HTMLDivElement>;
|
|
542
705
|
if (errorEl.length) {
|
|
543
706
|
evScrollTo(errorEl[0]);
|
|
544
707
|
}
|
|
545
|
-
}
|
|
708
|
+
};
|
|
546
709
|
|
|
547
710
|
export const evCheckAllValidation = (data: any[]) => {
|
|
548
711
|
let isError = false;
|
|
549
|
-
for(let x=0; x<data.length; x++) {
|
|
712
|
+
for (let x = 0; x < data.length; x++) {
|
|
550
713
|
const _data = data[x];
|
|
551
714
|
const keys = Object.keys(_data);
|
|
552
715
|
|
|
553
|
-
for(let key of keys) {
|
|
716
|
+
for (let key of keys) {
|
|
554
717
|
if (Array.isArray(_data[key])) {
|
|
555
|
-
for(let i = 0; i < _data[key].length; i++){
|
|
718
|
+
for (let i = 0; i < _data[key].length; i++) {
|
|
556
719
|
const _dataArr = _data[key][i];
|
|
557
720
|
const keysArr = Object.keys(_dataArr);
|
|
558
|
-
for(let keyArr of keysArr) {
|
|
721
|
+
for (let keyArr of keysArr) {
|
|
559
722
|
if (Array.isArray(_dataArr[keyArr])) {
|
|
560
|
-
for(let z = 0; z < _dataArr[keyArr].length; z++){
|
|
723
|
+
for (let z = 0; z < _dataArr[keyArr].length; z++) {
|
|
561
724
|
const _dataArrArr = _dataArr[keyArr][z];
|
|
562
725
|
const keysArrArr = Object.keys(_dataArrArr);
|
|
563
|
-
for(let keyArrArr of keysArrArr) {
|
|
564
|
-
if (keyArrArr.indexOf(
|
|
726
|
+
for (let keyArrArr of keysArrArr) {
|
|
727
|
+
if (keyArrArr.indexOf("_error") !== -1 && !isError) {
|
|
565
728
|
isError = true;
|
|
566
729
|
}
|
|
567
730
|
if (isError) {
|
|
@@ -573,7 +736,7 @@ export const evCheckAllValidation = (data: any[]) => {
|
|
|
573
736
|
}
|
|
574
737
|
}
|
|
575
738
|
} else {
|
|
576
|
-
if (keyArr.indexOf(
|
|
739
|
+
if (keyArr.indexOf("_error") !== -1 && !isError) {
|
|
577
740
|
isError = true;
|
|
578
741
|
}
|
|
579
742
|
if (isError) {
|
|
@@ -589,8 +752,8 @@ export const evCheckAllValidation = (data: any[]) => {
|
|
|
589
752
|
}
|
|
590
753
|
}
|
|
591
754
|
} else {
|
|
592
|
-
if (key.indexOf(
|
|
593
|
-
isError = true
|
|
755
|
+
if (key.indexOf("_error") !== -1 && !isError) {
|
|
756
|
+
isError = true;
|
|
594
757
|
}
|
|
595
758
|
if (isError) {
|
|
596
759
|
break;
|
|
@@ -602,277 +765,368 @@ export const evCheckAllValidation = (data: any[]) => {
|
|
|
602
765
|
}
|
|
603
766
|
}
|
|
604
767
|
return isError;
|
|
605
|
-
}
|
|
768
|
+
};
|
|
606
769
|
|
|
607
|
-
export const unCamelCaseKeys = (object: TObject) => {
|
|
770
|
+
export const unCamelCaseKeys = (object: TObject) => {
|
|
608
771
|
const unCamelCase = (value: string) => {
|
|
609
|
-
return value.replace(/([a-z][A-Z])/g, function (g) {
|
|
772
|
+
return value.replace(/([a-z][A-Z])/g, function (g) {
|
|
773
|
+
return g[0] + "_" + g[1].toLowerCase();
|
|
774
|
+
});
|
|
610
775
|
};
|
|
611
|
-
return Object
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}, {});
|
|
617
|
-
}
|
|
776
|
+
return Object.entries(object).reduce((carry: any, [key, value]) => {
|
|
777
|
+
carry[unCamelCase(key)] = value;
|
|
778
|
+
return carry;
|
|
779
|
+
}, {});
|
|
780
|
+
};
|
|
618
781
|
|
|
619
782
|
export const abbreviateNumber = (value?: number) => {
|
|
620
|
-
let result: string =
|
|
783
|
+
let result: string = "";
|
|
621
784
|
if (value !== undefined) {
|
|
622
|
-
result = value.toString()
|
|
785
|
+
result = value.toString();
|
|
623
786
|
if (value >= 1000) {
|
|
624
|
-
const suffixes = ["", "k", "m", "b","t"]
|
|
625
|
-
const suffixNum = Math.floor((""+value).length/3)
|
|
626
|
-
let shortValue
|
|
787
|
+
const suffixes = ["", "k", "m", "b", "t"];
|
|
788
|
+
const suffixNum = Math.floor(("" + value).length / 3);
|
|
789
|
+
let shortValue;
|
|
627
790
|
for (let precision = 2; precision >= 1; precision--) {
|
|
628
|
-
shortValue = parseFloat(
|
|
629
|
-
|
|
791
|
+
shortValue = parseFloat(
|
|
792
|
+
(suffixNum !== 0
|
|
793
|
+
? value / Math.pow(1000, suffixNum)
|
|
794
|
+
: value
|
|
795
|
+
).toPrecision(precision),
|
|
796
|
+
);
|
|
797
|
+
const dotLessShortValue = (shortValue + "").replace(
|
|
798
|
+
/[^a-zA-Z 0-9]+/g,
|
|
799
|
+
"",
|
|
800
|
+
);
|
|
630
801
|
if (dotLessShortValue.length <= 2) {
|
|
631
|
-
break
|
|
802
|
+
break;
|
|
632
803
|
}
|
|
633
804
|
}
|
|
634
|
-
result = shortValue+suffixes[suffixNum]
|
|
805
|
+
result = shortValue + suffixes[suffixNum];
|
|
635
806
|
}
|
|
636
807
|
}
|
|
637
|
-
return result
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
export const pasteIntoInput = (
|
|
641
|
-
el
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
808
|
+
return result;
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
export const pasteIntoInput = (
|
|
812
|
+
el: HTMLInputElement | HTMLTextAreaElement,
|
|
813
|
+
text: string,
|
|
814
|
+
) => {
|
|
815
|
+
el.focus();
|
|
816
|
+
if (
|
|
817
|
+
typeof el.selectionStart == "number" &&
|
|
818
|
+
typeof el.selectionEnd == "number"
|
|
819
|
+
) {
|
|
820
|
+
var val = el.value;
|
|
821
|
+
var selStart = el.selectionStart;
|
|
822
|
+
el.value = val.slice(0, selStart) + text + val.slice(el.selectionEnd);
|
|
823
|
+
el.selectionEnd = el.selectionStart = selStart + text.length;
|
|
824
|
+
} else if (typeof (document as any).selection != "undefined") {
|
|
825
|
+
var textRange = (document as any).selection.createRange();
|
|
826
|
+
textRange.text = text;
|
|
827
|
+
textRange.collapse(false);
|
|
828
|
+
textRange.select();
|
|
652
829
|
}
|
|
653
|
-
}
|
|
830
|
+
};
|
|
654
831
|
|
|
655
832
|
export const isDesktop = () => {
|
|
656
833
|
return document.body.clientWidth >= 1024 ? true : false;
|
|
657
|
-
}
|
|
834
|
+
};
|
|
658
835
|
|
|
659
836
|
export const isTablet = () => {
|
|
660
|
-
return
|
|
661
|
-
|
|
837
|
+
return document.body.clientWidth >= 768 && document.body.clientWidth < 1024
|
|
838
|
+
? true
|
|
839
|
+
: false;
|
|
840
|
+
};
|
|
662
841
|
|
|
663
842
|
export const isMobile = () => {
|
|
664
843
|
return document.body.clientWidth < 768 ? true : false;
|
|
665
|
-
}
|
|
844
|
+
};
|
|
666
845
|
|
|
667
846
|
export const evCloseDropdown = (currentTarget: EventTarget & HTMLElement) => {
|
|
668
|
-
const containerEl =
|
|
669
|
-
|
|
847
|
+
const containerEl =
|
|
848
|
+
(currentTarget.closest("._refContainer") as HTMLElement) ||
|
|
849
|
+
(currentTarget.closest("._refDropdownPortal") as HTMLDivElement);
|
|
850
|
+
const isOpen = containerEl
|
|
851
|
+
? containerEl.classList.contains("is-shown")
|
|
852
|
+
: false;
|
|
670
853
|
if (isOpen) {
|
|
671
|
-
const containerRefs = document.getElementsByClassName(
|
|
672
|
-
|
|
854
|
+
const containerRefs = document.getElementsByClassName(
|
|
855
|
+
"_refContainer is-shown",
|
|
856
|
+
) as HTMLCollectionOf<HTMLElement>;
|
|
857
|
+
const dropdownContainerRefs = document.getElementsByClassName(
|
|
858
|
+
"_refDropdownPortal is-shown",
|
|
859
|
+
) as HTMLCollectionOf<HTMLDivElement>;
|
|
673
860
|
if (containerRefs?.length) {
|
|
674
861
|
for (let i = 0; i < containerRefs.length; i++) {
|
|
675
|
-
const overlay = containerRefs[i].querySelector(
|
|
676
|
-
|
|
677
|
-
|
|
862
|
+
const overlay = containerRefs[i].querySelector(
|
|
863
|
+
`._refDropdownOverlay`,
|
|
864
|
+
) as HTMLElement;
|
|
865
|
+
overlay && (overlay.style.display = "none");
|
|
866
|
+
containerRefs[i].classList.remove("is-shown");
|
|
678
867
|
}
|
|
679
868
|
}
|
|
680
869
|
if (dropdownContainerRefs?.length) {
|
|
681
870
|
for (let i = 0; i < dropdownContainerRefs.length; i++) {
|
|
682
|
-
const overlay = dropdownContainerRefs[i].querySelector(
|
|
683
|
-
|
|
684
|
-
|
|
871
|
+
const overlay = dropdownContainerRefs[i].querySelector(
|
|
872
|
+
`._refDropdownOverlay`,
|
|
873
|
+
) as HTMLElement;
|
|
874
|
+
overlay && (overlay.style.display = "none");
|
|
875
|
+
dropdownContainerRefs[i].classList.remove("is-shown");
|
|
685
876
|
}
|
|
686
877
|
}
|
|
687
|
-
const refScrollContainerEl = document.querySelector(
|
|
688
|
-
|
|
689
|
-
|
|
878
|
+
const refScrollContainerEl = document.querySelector(
|
|
879
|
+
"._refScrollContainer",
|
|
880
|
+
) as HTMLElement;
|
|
881
|
+
const bodyEl = document.getElementsByTagName("BODY")[0] as HTMLBodyElement;
|
|
882
|
+
bodyEl.classList.remove("is-immuned");
|
|
690
883
|
if (refScrollContainerEl) {
|
|
691
|
-
refScrollContainerEl.style.overflow =
|
|
692
|
-
const child = refScrollContainerEl.firstChild as HTMLElement
|
|
693
|
-
child.style.overflowY =
|
|
884
|
+
refScrollContainerEl.style.overflow = "auto";
|
|
885
|
+
const child = refScrollContainerEl.firstChild as HTMLElement;
|
|
886
|
+
child.style.overflowY = "unset";
|
|
694
887
|
}
|
|
695
888
|
}
|
|
696
|
-
}
|
|
889
|
+
};
|
|
697
890
|
|
|
698
891
|
export const evForceCloseDropdown = () => {
|
|
699
|
-
const containerRefs = document.getElementsByClassName(
|
|
892
|
+
const containerRefs = document.getElementsByClassName(
|
|
893
|
+
"_refContainer is-shown",
|
|
894
|
+
) as HTMLCollectionOf<HTMLElement>;
|
|
700
895
|
if (containerRefs?.length) {
|
|
701
896
|
for (let i = 0; i < containerRefs.length; i++) {
|
|
702
|
-
containerRefs[i].classList.remove(
|
|
897
|
+
containerRefs[i].classList.remove("is-shown");
|
|
703
898
|
}
|
|
704
|
-
const refScrollContainerEl = document.querySelector(
|
|
705
|
-
|
|
706
|
-
|
|
899
|
+
const refScrollContainerEl = document.querySelector(
|
|
900
|
+
"._refScrollContainer",
|
|
901
|
+
) as HTMLElement;
|
|
902
|
+
const bodyEl = document.getElementsByTagName("BODY")[0] as HTMLBodyElement;
|
|
903
|
+
bodyEl.classList.remove("is-immuned");
|
|
707
904
|
if (refScrollContainerEl) {
|
|
708
|
-
refScrollContainerEl.style.overflow =
|
|
709
|
-
const child = refScrollContainerEl.firstChild as HTMLElement
|
|
710
|
-
child.style.overflowY =
|
|
905
|
+
refScrollContainerEl.style.overflow = "auto";
|
|
906
|
+
const child = refScrollContainerEl.firstChild as HTMLElement;
|
|
907
|
+
child.style.overflowY = "unset";
|
|
711
908
|
}
|
|
712
|
-
const overlayEls = document.querySelectorAll(
|
|
713
|
-
|
|
909
|
+
const overlayEls = document.querySelectorAll(
|
|
910
|
+
`._refDropdownOverlay`,
|
|
911
|
+
) as NodeListOf<HTMLDivElement>;
|
|
912
|
+
overlayEls?.length &&
|
|
913
|
+
overlayEls.forEach((overlayEl) => (overlayEl.style.display = "none"));
|
|
714
914
|
}
|
|
715
|
-
return
|
|
716
|
-
}
|
|
915
|
+
return;
|
|
916
|
+
};
|
|
717
917
|
|
|
718
|
-
export const evSetTotal = (
|
|
918
|
+
export const evSetTotal = (
|
|
919
|
+
totalCount: number,
|
|
920
|
+
totalEl: HTMLSpanElement,
|
|
921
|
+
callback?: () => void,
|
|
922
|
+
) => {
|
|
719
923
|
if (totalCount && totalEl) {
|
|
720
|
-
totalEl.innerText
|
|
721
|
-
totalEl.removeAttribute(
|
|
924
|
+
totalEl.innerText = `(${totalCount})`;
|
|
925
|
+
totalEl.removeAttribute("hidden");
|
|
722
926
|
}
|
|
723
|
-
if (callback && typeof
|
|
724
|
-
callback()
|
|
927
|
+
if (callback && typeof callback == "function") {
|
|
928
|
+
callback();
|
|
725
929
|
}
|
|
726
|
-
}
|
|
930
|
+
};
|
|
727
931
|
|
|
728
932
|
export const humanise = (value?: string) => {
|
|
729
|
-
const underscoreMatch = /_/g,
|
|
730
|
-
|
|
731
|
-
|
|
933
|
+
const underscoreMatch = /_/g,
|
|
934
|
+
underscoreMatch2 = /-/g;
|
|
935
|
+
return value
|
|
936
|
+
? value.replace(underscoreMatch, " ").replace(underscoreMatch2, " ")
|
|
937
|
+
: "";
|
|
938
|
+
};
|
|
732
939
|
|
|
733
940
|
export const generateAddress = (address?: TObject | null) => {
|
|
734
|
-
let result: string =
|
|
941
|
+
let result: string = "-";
|
|
735
942
|
if (address) {
|
|
736
|
-
const firstLine =
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
943
|
+
const firstLine =
|
|
944
|
+
!address.address1 && !address.address2
|
|
945
|
+
? ""
|
|
946
|
+
: (address.address1 ? address.address1 + ", " : "") +
|
|
947
|
+
(address.address2 || "") +
|
|
948
|
+
"<br/>",
|
|
949
|
+
secondLine =
|
|
950
|
+
!address.subDistrict && !address.district && !address.city
|
|
951
|
+
? ""
|
|
952
|
+
: (address.subDistrict ? address.subDistrict + ", " : "") +
|
|
953
|
+
(address.district ? address.district + ", " : "") +
|
|
954
|
+
(address.city || "") +
|
|
955
|
+
"<br/>",
|
|
956
|
+
thirdLine = address.postalCode ? address.postalCode + "<br/>" : "",
|
|
957
|
+
lastLine = address.phone || "";
|
|
958
|
+
result = firstLine + secondLine + thirdLine + lastLine;
|
|
741
959
|
}
|
|
742
|
-
return result
|
|
743
|
-
}
|
|
960
|
+
return result;
|
|
961
|
+
};
|
|
744
962
|
|
|
745
963
|
export const evRemoveActiveButton = () => {
|
|
746
|
-
const nextButtonEl = document.querySelector(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
964
|
+
const nextButtonEl = document.querySelector(
|
|
965
|
+
"#btn-active-red",
|
|
966
|
+
) as HTMLButtonElement;
|
|
967
|
+
nextButtonEl && nextButtonEl.removeAttribute("id");
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
export const evCheckAllValidationByHeader = (
|
|
971
|
+
data: any[],
|
|
972
|
+
headerColumns: THeadProps[],
|
|
973
|
+
) => {
|
|
974
|
+
let isError = false;
|
|
975
|
+
const validByHeader = (
|
|
976
|
+
key: string,
|
|
977
|
+
valuex: any,
|
|
978
|
+
idx?: number,
|
|
979
|
+
title = null,
|
|
980
|
+
) => {
|
|
981
|
+
const __idx = idx || 0;
|
|
982
|
+
const validHeaderKeyFilter = headerColumns.filter(
|
|
983
|
+
(header) => header.key === key && header.validations,
|
|
984
|
+
);
|
|
755
985
|
if (validHeaderKeyFilter.length) {
|
|
756
|
-
const head = validHeaderKeyFilter[__idx]
|
|
757
|
-
const type = head.typeData ||
|
|
758
|
-
const _value = generateValue(type, valuex)
|
|
759
|
-
const valid = validateByApproveJs(head, _value, title ||
|
|
760
|
-
return valid
|
|
986
|
+
const head = validHeaderKeyFilter[__idx];
|
|
987
|
+
const type = head.typeData || "String";
|
|
988
|
+
const _value = generateValue(type, valuex);
|
|
989
|
+
const valid = validateByApproveJs(head, _value, title || "");
|
|
990
|
+
return valid;
|
|
761
991
|
}
|
|
762
|
-
return { approved: true }
|
|
763
|
-
}
|
|
992
|
+
return { approved: true };
|
|
993
|
+
};
|
|
764
994
|
|
|
765
|
-
const newData = []
|
|
766
|
-
for (let x=0; x<data.length; x++) {
|
|
767
|
-
const _data = data[x]
|
|
768
|
-
const keys = Object.keys(_data)
|
|
995
|
+
const newData = [];
|
|
996
|
+
for (let x = 0; x < data.length; x++) {
|
|
997
|
+
const _data = data[x];
|
|
998
|
+
const keys = Object.keys(_data);
|
|
769
999
|
|
|
770
1000
|
for (const key of keys) {
|
|
771
|
-
let _valid: TObject = { approved: true }
|
|
1001
|
+
let _valid: TObject = { approved: true };
|
|
772
1002
|
if (Array.isArray(_data[key])) {
|
|
773
1003
|
for (let i = 0; i < _data[key].length; i++) {
|
|
774
|
-
const _dataArr = _data[key][i]
|
|
775
|
-
const keysArr = Object.keys(_dataArr)
|
|
1004
|
+
const _dataArr = _data[key][i];
|
|
1005
|
+
const keysArr = Object.keys(_dataArr);
|
|
776
1006
|
for (const keyArr of keysArr) {
|
|
777
1007
|
if (Array.isArray(_dataArr[keyArr])) {
|
|
778
1008
|
for (let z = 0; z < _dataArr[keyArr].length; z++) {
|
|
779
|
-
const _dataArrArr = _dataArr[keyArr][z]
|
|
780
|
-
const keysArrArr = Object.keys(_dataArrArr)
|
|
1009
|
+
const _dataArrArr = _dataArr[keyArr][z];
|
|
1010
|
+
const keysArrArr = Object.keys(_dataArrArr);
|
|
781
1011
|
for (const keyArrArr of keysArrArr) {
|
|
782
|
-
_valid = validByHeader(keyArrArr, _dataArrArr[keyArrArr])
|
|
1012
|
+
_valid = validByHeader(keyArrArr, _dataArrArr[keyArrArr]);
|
|
783
1013
|
if (!_valid.approved) {
|
|
784
|
-
_dataArrArr[`${keyArr}_error`] = _valid.errors[0]
|
|
1014
|
+
_dataArrArr[`${keyArr}_error`] = _valid.errors[0];
|
|
785
1015
|
if (!isError) {
|
|
786
|
-
isError = true
|
|
1016
|
+
isError = true;
|
|
787
1017
|
}
|
|
788
1018
|
}
|
|
789
|
-
if (keyArrArr.indexOf(
|
|
790
|
-
isError = true
|
|
1019
|
+
if (keyArrArr.indexOf("_error") !== -1 && !isError) {
|
|
1020
|
+
isError = true;
|
|
791
1021
|
}
|
|
792
1022
|
}
|
|
793
1023
|
}
|
|
794
1024
|
} else {
|
|
795
|
-
_valid = validByHeader(keyArr, _dataArr[keyArr])
|
|
1025
|
+
_valid = validByHeader(keyArr, _dataArr[keyArr]);
|
|
796
1026
|
if (!_valid.approved) {
|
|
797
|
-
_dataArr[`${keyArr}_error`] = _valid.errors[0]
|
|
1027
|
+
_dataArr[`${keyArr}_error`] = _valid.errors[0];
|
|
798
1028
|
if (!isError) {
|
|
799
|
-
isError = true
|
|
1029
|
+
isError = true;
|
|
800
1030
|
}
|
|
801
1031
|
}
|
|
802
|
-
if (keyArr.indexOf(
|
|
803
|
-
isError = true
|
|
1032
|
+
if (keyArr.indexOf("_error") !== -1 && !isError) {
|
|
1033
|
+
isError = true;
|
|
804
1034
|
}
|
|
805
1035
|
}
|
|
806
1036
|
}
|
|
807
1037
|
}
|
|
808
1038
|
} else {
|
|
809
|
-
_valid = validByHeader(key, _data[key])
|
|
1039
|
+
_valid = validByHeader(key, _data[key]);
|
|
810
1040
|
if (!_valid.approved) {
|
|
811
|
-
_data[`${key}_error`] = _valid.errors[0]
|
|
1041
|
+
_data[`${key}_error`] = _valid.errors[0];
|
|
812
1042
|
if (!isError) {
|
|
813
|
-
isError = true
|
|
1043
|
+
isError = true;
|
|
814
1044
|
}
|
|
815
1045
|
}
|
|
816
|
-
if (key.indexOf(
|
|
817
|
-
isError = true
|
|
1046
|
+
if (key.indexOf("_error") !== -1 && !isError) {
|
|
1047
|
+
isError = true;
|
|
818
1048
|
}
|
|
819
1049
|
}
|
|
820
1050
|
}
|
|
821
|
-
newData.push(_data)
|
|
1051
|
+
newData.push(_data);
|
|
822
1052
|
}
|
|
823
|
-
return { error: isError, data: newData }
|
|
824
|
-
}
|
|
1053
|
+
return { error: isError, data: newData };
|
|
1054
|
+
};
|
|
825
1055
|
|
|
826
|
-
export const evCheckAllValidationByHeaderWithVariant = (
|
|
827
|
-
|
|
1056
|
+
export const evCheckAllValidationByHeaderWithVariant = (
|
|
1057
|
+
newData: any[],
|
|
1058
|
+
headerColumns: THeadProps[],
|
|
1059
|
+
) => {
|
|
1060
|
+
let isError = false;
|
|
828
1061
|
|
|
829
|
-
const validByHeader = (
|
|
830
|
-
|
|
831
|
-
|
|
1062
|
+
const validByHeader = (
|
|
1063
|
+
key: string,
|
|
1064
|
+
valuex: any,
|
|
1065
|
+
idx?: number,
|
|
1066
|
+
content?: any,
|
|
1067
|
+
) => {
|
|
1068
|
+
const __idx = idx || 0;
|
|
1069
|
+
const validHeaderKeyFilter = headerColumns.filter(
|
|
1070
|
+
(header) => header.key === key && header.validations,
|
|
1071
|
+
);
|
|
832
1072
|
if (validHeaderKeyFilter.length) {
|
|
833
|
-
const head = validHeaderKeyFilter[__idx]
|
|
834
|
-
const type = head.typeData ||
|
|
835
|
-
const _value = generateValue(type, valuex)
|
|
836
|
-
const valid = validateByApproveJs(
|
|
837
|
-
|
|
1073
|
+
const head = validHeaderKeyFilter[__idx];
|
|
1074
|
+
const type = head.typeData || "String";
|
|
1075
|
+
const _value = generateValue(type, valuex);
|
|
1076
|
+
const valid = validateByApproveJs(
|
|
1077
|
+
head,
|
|
1078
|
+
_value,
|
|
1079
|
+
undefined,
|
|
1080
|
+
evGenerateValueMatch(head.validations, content),
|
|
1081
|
+
);
|
|
1082
|
+
return valid;
|
|
838
1083
|
}
|
|
839
|
-
return { approved: true }
|
|
840
|
-
}
|
|
1084
|
+
return { approved: true };
|
|
1085
|
+
};
|
|
841
1086
|
|
|
842
|
-
let _newData = [...newData]
|
|
843
|
-
for (let x=0; x<_newData.length; x++) {
|
|
844
|
-
let _data = _newData[x]
|
|
845
|
-
let keys = Object.keys(_data)
|
|
1087
|
+
let _newData = [...newData];
|
|
1088
|
+
for (let x = 0; x < _newData.length; x++) {
|
|
1089
|
+
let _data = _newData[x];
|
|
1090
|
+
let keys = Object.keys(_data);
|
|
846
1091
|
|
|
847
1092
|
for (const key of keys) {
|
|
848
|
-
if (
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
1093
|
+
if (
|
|
1094
|
+
Array.isArray(_data[key]) &&
|
|
1095
|
+
_data[key].length &&
|
|
1096
|
+
typeof _data[key][0] === "object"
|
|
1097
|
+
) {
|
|
1098
|
+
for (let i = 0; i < _data[key].length; i++) {
|
|
1099
|
+
const _dataArr = _data[key][i];
|
|
1100
|
+
const keysArr = Object.keys(_dataArr);
|
|
852
1101
|
for (const keyArr of keysArr) {
|
|
853
1102
|
if (!Array.isArray(_dataArr[keyArr])) {
|
|
854
1103
|
const _key = `${key}-${keyArr}`,
|
|
855
|
-
|
|
1104
|
+
valid = validByHeader(
|
|
1105
|
+
_key,
|
|
1106
|
+
_dataArr[keyArr],
|
|
1107
|
+
undefined,
|
|
1108
|
+
_dataArr,
|
|
1109
|
+
);
|
|
856
1110
|
if (!valid.approved) {
|
|
857
|
-
_dataArr[`${keyArr}_error`] = valid.errors[0]
|
|
1111
|
+
_dataArr[`${keyArr}_error`] = valid.errors[0];
|
|
858
1112
|
if (!isError) {
|
|
859
|
-
isError = true
|
|
1113
|
+
isError = true;
|
|
860
1114
|
}
|
|
861
1115
|
}
|
|
862
1116
|
}
|
|
863
1117
|
}
|
|
864
1118
|
}
|
|
865
1119
|
} else {
|
|
866
|
-
const valid = validByHeader(key, _data[key], undefined, _data)
|
|
1120
|
+
const valid = validByHeader(key, _data[key], undefined, _data);
|
|
867
1121
|
if (!valid.approved) {
|
|
868
|
-
_data[`${key}_error`] = valid.errors[0]
|
|
1122
|
+
_data[`${key}_error`] = valid.errors[0];
|
|
869
1123
|
if (!isError) {
|
|
870
|
-
isError = true
|
|
1124
|
+
isError = true;
|
|
871
1125
|
}
|
|
872
1126
|
}
|
|
873
1127
|
}
|
|
874
|
-
}
|
|
875
|
-
_newData.splice(x, 1, _data)
|
|
1128
|
+
}
|
|
1129
|
+
_newData.splice(x, 1, _data);
|
|
876
1130
|
}
|
|
877
|
-
return { error: isError, data: _newData }
|
|
878
|
-
}
|
|
1131
|
+
return { error: isError, data: _newData };
|
|
1132
|
+
};
|