@mixd-id/web-scaffold 0.1.230406315 → 0.1.230406317
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/package.json +1 -1
- package/src/components/List.vue +36 -11
- package/src/components/VirtualTable.vue +2 -0
- package/src/utils/preset-selector.js +396 -113
package/package.json
CHANGED
package/src/components/List.vue
CHANGED
|
@@ -610,17 +610,42 @@ export default{
|
|
|
610
610
|
filters.push({
|
|
611
611
|
key,
|
|
612
612
|
value: [{
|
|
613
|
-
operator: '
|
|
614
|
-
value: value[0]
|
|
613
|
+
operator: '=',
|
|
614
|
+
value: value[0].split(':')[0],
|
|
615
615
|
fn: 'format_hour'
|
|
616
616
|
}]
|
|
617
617
|
})
|
|
618
|
+
break
|
|
619
|
+
|
|
620
|
+
case 'date':
|
|
618
621
|
filters.push({
|
|
619
622
|
key,
|
|
620
623
|
value: [{
|
|
621
|
-
operator: '
|
|
622
|
-
value: value
|
|
623
|
-
fn: '
|
|
624
|
+
operator: '=',
|
|
625
|
+
value: value,
|
|
626
|
+
fn: 'format_date'
|
|
627
|
+
}]
|
|
628
|
+
})
|
|
629
|
+
break
|
|
630
|
+
|
|
631
|
+
case 'month':
|
|
632
|
+
filters.push({
|
|
633
|
+
key,
|
|
634
|
+
value: [{
|
|
635
|
+
operator: '=',
|
|
636
|
+
value: value,
|
|
637
|
+
fn: 'format_month'
|
|
638
|
+
}]
|
|
639
|
+
})
|
|
640
|
+
break
|
|
641
|
+
|
|
642
|
+
case 'year':
|
|
643
|
+
filters.push({
|
|
644
|
+
key,
|
|
645
|
+
value: [{
|
|
646
|
+
operator: '=',
|
|
647
|
+
value: value,
|
|
648
|
+
fn: 'format_year'
|
|
624
649
|
}]
|
|
625
650
|
})
|
|
626
651
|
break
|
|
@@ -933,7 +958,7 @@ export default{
|
|
|
933
958
|
}
|
|
934
959
|
|
|
935
960
|
.pv-green1, .pv-green2, .pv-green3, .pv-green4, .pv-green5{
|
|
936
|
-
@apply rounded-lg text-
|
|
961
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
937
962
|
}
|
|
938
963
|
.pv-green1{
|
|
939
964
|
background-color: #d3f3df;
|
|
@@ -972,7 +997,7 @@ html[data-theme="dark"] .pv-green5{
|
|
|
972
997
|
}
|
|
973
998
|
|
|
974
999
|
.pv-red1, .pv-red2, .pv-red3, .pv-red4, .pv-red5{
|
|
975
|
-
@apply rounded-lg text-
|
|
1000
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
976
1001
|
}
|
|
977
1002
|
.pv-red1{
|
|
978
1003
|
background-color: #fce9e9;
|
|
@@ -1011,7 +1036,7 @@ html[data-theme="dark"] .pv-red5{
|
|
|
1011
1036
|
}
|
|
1012
1037
|
|
|
1013
1038
|
.pv-blue1, .pv-blue2, .pv-blue3, .pv-blue4, .pv-blue5{
|
|
1014
|
-
@apply rounded-lg text-
|
|
1039
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
1015
1040
|
}
|
|
1016
1041
|
.pv-blue1{
|
|
1017
1042
|
background-color: #e9effd;
|
|
@@ -1050,7 +1075,7 @@ html[data-theme="dark"] .pv-blue5{
|
|
|
1050
1075
|
}
|
|
1051
1076
|
|
|
1052
1077
|
.pv-yellow1, .pv-yellow2, .pv-yellow3, .pv-yellow4, .pv-yellow5{
|
|
1053
|
-
@apply rounded-lg text-
|
|
1078
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
1054
1079
|
}
|
|
1055
1080
|
.pv-yellow1{
|
|
1056
1081
|
background-color: #fdf7e6;
|
|
@@ -1089,7 +1114,7 @@ html[data-theme="dark"] .pv-yellow5{
|
|
|
1089
1114
|
}
|
|
1090
1115
|
|
|
1091
1116
|
.pv-fuchsia1, .pv-fuchsia2, .pv-fuchsia3, .pv-fuchsia4, .pv-fuchsia5{
|
|
1092
|
-
@apply rounded-lg text-
|
|
1117
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
1093
1118
|
}
|
|
1094
1119
|
.pv-fuchsia1{
|
|
1095
1120
|
background-color: #f6e8f7;
|
|
@@ -1128,7 +1153,7 @@ html[data-theme="dark"] .pv-fuchsia5{
|
|
|
1128
1153
|
}
|
|
1129
1154
|
|
|
1130
1155
|
.pv-gradient1, .pv-gradient2, .pv-gradient3, .pv-gradient4, .pv-gradient5, .pv-default{
|
|
1131
|
-
@apply rounded-lg text-
|
|
1156
|
+
@apply rounded-lg text-right text-text cursor-pointer;
|
|
1132
1157
|
}
|
|
1133
1158
|
.pv-gradient1{
|
|
1134
1159
|
@apply bg-gradient-to-r from-cyan-500 to-blue-500;
|
|
@@ -346,6 +346,7 @@ export default{
|
|
|
346
346
|
if(!column.align){
|
|
347
347
|
switch(column.type){
|
|
348
348
|
case 'currency':
|
|
349
|
+
case 'number':
|
|
349
350
|
align = 'right'
|
|
350
351
|
break
|
|
351
352
|
|
|
@@ -481,6 +482,7 @@ export default{
|
|
|
481
482
|
if(!column.align){
|
|
482
483
|
switch(column.type){
|
|
483
484
|
case 'currency':
|
|
485
|
+
case 'number':
|
|
484
486
|
align = 'right'
|
|
485
487
|
break
|
|
486
488
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const groupBy = require("lodash/groupBy");
|
|
2
2
|
const dayjs = require("dayjs");
|
|
3
|
-
const {Op, literal, fn, DataTypes} = require("sequelize");
|
|
3
|
+
const {Op, literal, fn, col, where, DataTypes} = require("sequelize");
|
|
4
4
|
const {ftWildcard} = require("./helpers");
|
|
5
5
|
const util = require("util");
|
|
6
6
|
|
|
7
7
|
const getValue = (filter, opt) => {
|
|
8
8
|
|
|
9
9
|
const { columns, withoutKey = false } = opt
|
|
10
|
-
const { key, operator
|
|
10
|
+
const { key, operator } = filter
|
|
11
11
|
const keyColumns = groupBy(columns, 'key')
|
|
12
12
|
const type = ((keyColumns[key] ?? [])[0] ?? {}).type
|
|
13
13
|
|
|
@@ -20,39 +20,17 @@ const getValue = (filter, opt) => {
|
|
|
20
20
|
break
|
|
21
21
|
|
|
22
22
|
case 'number':
|
|
23
|
-
case 'currency':
|
|
24
23
|
switch(operator) {
|
|
25
24
|
case '=':
|
|
26
25
|
withoutKey ? whereObj = { [Op.eq]:filter.value } : whereObj[key] = filter.value
|
|
27
26
|
break
|
|
28
27
|
|
|
29
28
|
case '>':
|
|
30
|
-
withoutKey ?
|
|
31
|
-
whereObj = { [Op.gt]:filter.value } :
|
|
32
|
-
whereObj[key] = {
|
|
33
|
-
[Op[operator]]: filter.value
|
|
34
|
-
}
|
|
35
|
-
break
|
|
36
|
-
|
|
37
29
|
case '>=':
|
|
38
|
-
withoutKey ?
|
|
39
|
-
whereObj = { [Op.gte]:filter.value } :
|
|
40
|
-
whereObj[key] = {
|
|
41
|
-
[Op[operator]]: filter.value
|
|
42
|
-
}
|
|
43
|
-
break
|
|
44
|
-
|
|
45
30
|
case '<':
|
|
46
|
-
withoutKey ?
|
|
47
|
-
whereObj = { [Op.lt]:filter.value } :
|
|
48
|
-
whereObj[key] = {
|
|
49
|
-
[Op[operator]]: filter.value
|
|
50
|
-
}
|
|
51
|
-
break
|
|
52
|
-
|
|
53
31
|
case '<=':
|
|
54
32
|
withoutKey ?
|
|
55
|
-
whereObj = { [Op
|
|
33
|
+
whereObj = { [Op[operator]]:filter.value } :
|
|
56
34
|
whereObj[key] = {
|
|
57
35
|
[Op[operator]]: filter.value
|
|
58
36
|
}
|
|
@@ -60,11 +38,11 @@ const getValue = (filter, opt) => {
|
|
|
60
38
|
|
|
61
39
|
case 'in':
|
|
62
40
|
withoutKey ?
|
|
63
|
-
whereObj = { [Op.in]:
|
|
41
|
+
whereObj = { [Op.in]: filter.value.split(',')
|
|
64
42
|
.map(_ => parseInt(_))
|
|
65
43
|
.filter(_ => !isNaN(_)) } :
|
|
66
44
|
whereObj[key] = {
|
|
67
|
-
[Op.in]:
|
|
45
|
+
[Op.in]: filter.value.split(',')
|
|
68
46
|
.map(_ => parseInt(_))
|
|
69
47
|
.filter(_ => !isNaN(_))
|
|
70
48
|
}
|
|
@@ -119,22 +97,6 @@ const getValue = (filter, opt) => {
|
|
|
119
97
|
}
|
|
120
98
|
break
|
|
121
99
|
|
|
122
|
-
case 'lastMonth':
|
|
123
|
-
withoutKey ?
|
|
124
|
-
whereObj = {
|
|
125
|
-
[Op.between]: [
|
|
126
|
-
dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
127
|
-
dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
128
|
-
]
|
|
129
|
-
} :
|
|
130
|
-
whereObj[key] = {
|
|
131
|
-
[Op.between]: [
|
|
132
|
-
dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
133
|
-
dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
134
|
-
]
|
|
135
|
-
}
|
|
136
|
-
break
|
|
137
|
-
|
|
138
100
|
case 'thisYear':
|
|
139
101
|
withoutKey ?
|
|
140
102
|
whereObj = {
|
|
@@ -214,26 +176,17 @@ const getValue = (filter, opt) => {
|
|
|
214
176
|
break
|
|
215
177
|
|
|
216
178
|
case '<=':
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
]
|
|
229
|
-
} :
|
|
230
|
-
whereObj[key] = {
|
|
231
|
-
[Op.lte]: [
|
|
232
|
-
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
233
|
-
]
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
179
|
+
withoutKey ?
|
|
180
|
+
whereObj = {
|
|
181
|
+
[Op.lte]: [
|
|
182
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
183
|
+
]
|
|
184
|
+
} :
|
|
185
|
+
whereObj[key] = {
|
|
186
|
+
[Op.lte]: [
|
|
187
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
188
|
+
]
|
|
189
|
+
}
|
|
237
190
|
break
|
|
238
191
|
|
|
239
192
|
case '=':
|
|
@@ -267,25 +220,17 @@ const getValue = (filter, opt) => {
|
|
|
267
220
|
break
|
|
268
221
|
|
|
269
222
|
case '>=':
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
]
|
|
282
|
-
} :
|
|
283
|
-
whereObj[key] = {
|
|
284
|
-
[Op.gte]: [
|
|
285
|
-
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
286
|
-
]
|
|
287
|
-
}
|
|
288
|
-
}
|
|
223
|
+
withoutKey ?
|
|
224
|
+
whereObj = {
|
|
225
|
+
[Op.gte]: [
|
|
226
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
227
|
+
]
|
|
228
|
+
} :
|
|
229
|
+
whereObj[key] = {
|
|
230
|
+
[Op.gte]: [
|
|
231
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
232
|
+
]
|
|
233
|
+
}
|
|
289
234
|
break
|
|
290
235
|
|
|
291
236
|
}
|
|
@@ -358,11 +303,13 @@ const getValue = (filter, opt) => {
|
|
|
358
303
|
withoutKey ?
|
|
359
304
|
whereObj = {
|
|
360
305
|
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
361
|
-
.
|
|
306
|
+
.map(_ => parseInt(_))
|
|
307
|
+
.filter(_ => !isNaN(_))
|
|
362
308
|
} :
|
|
363
309
|
whereObj[key] = {
|
|
364
310
|
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
365
|
-
.
|
|
311
|
+
.map(_ => parseInt(_))
|
|
312
|
+
.filter(_ => !isNaN(_))
|
|
366
313
|
}
|
|
367
314
|
break
|
|
368
315
|
|
|
@@ -393,12 +340,9 @@ const getValue = (filter, opt) => {
|
|
|
393
340
|
break
|
|
394
341
|
}
|
|
395
342
|
|
|
396
|
-
//console.log('getValue', type, util.inspect({ filter, whereObj }, false, null, true /* enable colors */))
|
|
397
|
-
|
|
398
343
|
return whereObj
|
|
399
344
|
}
|
|
400
345
|
|
|
401
|
-
|
|
402
346
|
const filtersToSequelizeWhere = async(filters, opt) => {
|
|
403
347
|
if(!Array.isArray(filters) || filters.length < 1){
|
|
404
348
|
return {
|
|
@@ -407,52 +351,388 @@ const filtersToSequelizeWhere = async(filters, opt) => {
|
|
|
407
351
|
}
|
|
408
352
|
}
|
|
409
353
|
|
|
410
|
-
let whereObj = {}
|
|
411
354
|
let whereArr = []
|
|
412
355
|
let replacements = []
|
|
413
356
|
|
|
357
|
+
const getValue = (filter, opt) => {
|
|
358
|
+
|
|
359
|
+
const { columns } = opt.config
|
|
360
|
+
let { key, operator, value, fn:filterFn } = filter
|
|
361
|
+
const keyColumns = groupBy(columns, 'key')
|
|
362
|
+
const type = ((keyColumns[key] ?? [])[0] ?? {}).type
|
|
363
|
+
|
|
364
|
+
let whereObj = {}
|
|
365
|
+
const modelAttributes = opt.model.getAttributes()
|
|
366
|
+
const {Model, field} = modelAttributes[key]
|
|
367
|
+
|
|
368
|
+
switch(type){
|
|
369
|
+
|
|
370
|
+
case 'boolean':
|
|
371
|
+
value = !!value
|
|
372
|
+
whereObj = { [key]: value }
|
|
373
|
+
break
|
|
374
|
+
|
|
375
|
+
case 'number':
|
|
376
|
+
case 'currency':
|
|
377
|
+
value = parseFloat(value)
|
|
378
|
+
|
|
379
|
+
switch(operator) {
|
|
380
|
+
case '=':
|
|
381
|
+
whereObj = { [key]:value }
|
|
382
|
+
break
|
|
383
|
+
|
|
384
|
+
case '>':
|
|
385
|
+
whereObj = { [key]:{ [Op.gt]:value } }
|
|
386
|
+
break
|
|
387
|
+
|
|
388
|
+
case '>=':
|
|
389
|
+
whereObj = { [key]:{ [Op.gte]:value } }
|
|
390
|
+
break
|
|
391
|
+
|
|
392
|
+
case '<':
|
|
393
|
+
whereObj = { [key]:{ [Op.lt]:value } }
|
|
394
|
+
break
|
|
395
|
+
|
|
396
|
+
case '<=':
|
|
397
|
+
whereObj = { [key]:{ [Op.lte]:value } }
|
|
398
|
+
break
|
|
399
|
+
|
|
400
|
+
case 'in':
|
|
401
|
+
whereObj = {
|
|
402
|
+
[key]:{
|
|
403
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
404
|
+
.map(_ => parseInt(_))
|
|
405
|
+
.filter(_ => !isNaN(_))
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
break
|
|
409
|
+
|
|
410
|
+
case 'notIn':
|
|
411
|
+
whereObj = {
|
|
412
|
+
[key]:{
|
|
413
|
+
[Op.notIn]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
414
|
+
.map(_ => parseInt(_))
|
|
415
|
+
.filter(_ => !isNaN(_))
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
break
|
|
419
|
+
}
|
|
420
|
+
break
|
|
421
|
+
|
|
422
|
+
case 'date':
|
|
423
|
+
switch(operator) {
|
|
424
|
+
|
|
425
|
+
case 'thisWeek':
|
|
426
|
+
whereObj = {
|
|
427
|
+
[key]:{
|
|
428
|
+
[Op.between]: [
|
|
429
|
+
dayjs().startOf('week').format('YYYY-MM-DD 00:00:00'),
|
|
430
|
+
dayjs().endOf('week').format('YYYY-MM-DD 23:59:59'),
|
|
431
|
+
]
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
break
|
|
435
|
+
|
|
436
|
+
case 'thisMonth':
|
|
437
|
+
whereObj = {
|
|
438
|
+
[key]:{
|
|
439
|
+
[Op.between]: [
|
|
440
|
+
dayjs().startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
441
|
+
dayjs().endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
break
|
|
446
|
+
|
|
447
|
+
case 'lastMonth':
|
|
448
|
+
whereObj = {
|
|
449
|
+
[key]:{
|
|
450
|
+
[Op.between]: [
|
|
451
|
+
dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
452
|
+
dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
453
|
+
]
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
break
|
|
457
|
+
|
|
458
|
+
case 'thisYear':
|
|
459
|
+
whereObj = {
|
|
460
|
+
[key]:{
|
|
461
|
+
[Op.between]: [
|
|
462
|
+
dayjs().startOf('year').format('YYYY-MM-DD 00:00:00'),
|
|
463
|
+
dayjs().endOf('year').format('YYYY-MM-DD 23:59:59'),
|
|
464
|
+
]
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
break
|
|
468
|
+
|
|
469
|
+
case 'between':
|
|
470
|
+
whereObj = {
|
|
471
|
+
[key]:{
|
|
472
|
+
[Op.between]: [
|
|
473
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
474
|
+
dayjs(filter.value2).format('YYYY-MM-DD 23:59:59'),
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
break
|
|
479
|
+
|
|
480
|
+
case 'yesterday':
|
|
481
|
+
whereObj = {
|
|
482
|
+
[key]:{
|
|
483
|
+
[Op.between]: [
|
|
484
|
+
dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
485
|
+
dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
486
|
+
]
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
break
|
|
490
|
+
|
|
491
|
+
case 'today':
|
|
492
|
+
whereObj = {
|
|
493
|
+
[key]:{
|
|
494
|
+
[Op.between]: [
|
|
495
|
+
dayjs().startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
496
|
+
dayjs().endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
497
|
+
]
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
break
|
|
501
|
+
|
|
502
|
+
case '<':
|
|
503
|
+
switch(filterFn) {
|
|
504
|
+
|
|
505
|
+
case 'format_hour':
|
|
506
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") < "${filter.value}"`)
|
|
507
|
+
break
|
|
508
|
+
|
|
509
|
+
default:
|
|
510
|
+
whereObj = {
|
|
511
|
+
[key]: {
|
|
512
|
+
[Op.lt]: [
|
|
513
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
514
|
+
]
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
break
|
|
519
|
+
|
|
520
|
+
case '<=':
|
|
521
|
+
switch(filterFn) {
|
|
522
|
+
|
|
523
|
+
case 'format_hour':
|
|
524
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") <= "${filter.value}"`)
|
|
525
|
+
break
|
|
526
|
+
|
|
527
|
+
default:
|
|
528
|
+
whereObj = {
|
|
529
|
+
[key]: {
|
|
530
|
+
[Op.lte]: [
|
|
531
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
break
|
|
537
|
+
|
|
538
|
+
case '=':
|
|
539
|
+
switch(filterFn) {
|
|
540
|
+
|
|
541
|
+
case 'format_date':
|
|
542
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%Y-%m-%d") = "${filter.value}"`)
|
|
543
|
+
break
|
|
544
|
+
|
|
545
|
+
case 'format_hour':
|
|
546
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") = "${filter.value}"`)
|
|
547
|
+
break
|
|
548
|
+
|
|
549
|
+
case 'format_month':
|
|
550
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%m") = "${filter.value.split('-')[1]}"`)
|
|
551
|
+
break
|
|
552
|
+
|
|
553
|
+
case 'format_year':
|
|
554
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%Y") = "${filter.value}"`)
|
|
555
|
+
break
|
|
556
|
+
|
|
557
|
+
default:
|
|
558
|
+
whereObj = {
|
|
559
|
+
[key]: {
|
|
560
|
+
[Op.between]: [
|
|
561
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
562
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
563
|
+
]
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
break
|
|
568
|
+
|
|
569
|
+
case '>':
|
|
570
|
+
switch(filterFn) {
|
|
571
|
+
|
|
572
|
+
case 'format_hour':
|
|
573
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") > "${filter.value}"`)
|
|
574
|
+
break
|
|
575
|
+
|
|
576
|
+
default:
|
|
577
|
+
whereObj = {
|
|
578
|
+
[key]: {
|
|
579
|
+
[Op.gt]: [
|
|
580
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
break
|
|
586
|
+
|
|
587
|
+
case '>=':
|
|
588
|
+
switch(filterFn) {
|
|
589
|
+
|
|
590
|
+
case 'format_hour':
|
|
591
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") >= "${filter.value}"`)
|
|
592
|
+
break
|
|
593
|
+
|
|
594
|
+
default:
|
|
595
|
+
whereObj = {
|
|
596
|
+
[key]: {
|
|
597
|
+
[Op.gte]: [
|
|
598
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
599
|
+
]
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
break
|
|
604
|
+
|
|
605
|
+
}
|
|
606
|
+
break
|
|
607
|
+
|
|
608
|
+
default:
|
|
609
|
+
switch(operator) {
|
|
610
|
+
case '=':
|
|
611
|
+
whereObj = {
|
|
612
|
+
[key]:{
|
|
613
|
+
[Op.eq]: filter.value
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
break
|
|
617
|
+
|
|
618
|
+
case 'eq':
|
|
619
|
+
case 'not':
|
|
620
|
+
whereObj = {
|
|
621
|
+
[key]:{
|
|
622
|
+
[Op[operator]]: filter.value
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
break
|
|
626
|
+
|
|
627
|
+
case 'startsWith':
|
|
628
|
+
whereObj = {
|
|
629
|
+
[key]:{
|
|
630
|
+
[Op.like]: `${filter.value}%`
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
break
|
|
634
|
+
|
|
635
|
+
case 'endsWith':
|
|
636
|
+
whereObj = {
|
|
637
|
+
[key]:{
|
|
638
|
+
[Op.like]: `%${filter.value}`
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
break
|
|
642
|
+
|
|
643
|
+
case 'contains':
|
|
644
|
+
whereObj = {
|
|
645
|
+
[key]:{
|
|
646
|
+
[Op.like]: `%${filter.value}%`
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
break
|
|
650
|
+
|
|
651
|
+
case 'notContains':
|
|
652
|
+
whereObj = {
|
|
653
|
+
[key]:{
|
|
654
|
+
[Op.notLike]: `%${filter.value}%`
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
break
|
|
658
|
+
|
|
659
|
+
case 'in':
|
|
660
|
+
whereObj = {
|
|
661
|
+
[key]:{
|
|
662
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
663
|
+
.filter(_ => _)
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
break
|
|
667
|
+
|
|
668
|
+
case 'notIn':
|
|
669
|
+
whereObj = {
|
|
670
|
+
[key]:{
|
|
671
|
+
[Op.notIn]: filter.value.split(',')
|
|
672
|
+
.map(_ => parseInt(_))
|
|
673
|
+
.filter(_ => !isNaN(_))
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
break
|
|
677
|
+
|
|
678
|
+
case 'regex':
|
|
679
|
+
whereObj = {
|
|
680
|
+
[key]:{
|
|
681
|
+
[Op.regexp]: filter.value
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
break
|
|
685
|
+
}
|
|
686
|
+
break
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return whereObj
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
//console.log(util.inspect(filters, false, null, true))
|
|
693
|
+
|
|
414
694
|
for(let filter of filters) {
|
|
415
695
|
if (filter.enabled === false) continue
|
|
416
696
|
|
|
417
|
-
const { key, value,
|
|
697
|
+
const { key, value, modifier = 'and' } = filter
|
|
418
698
|
|
|
419
699
|
if(key.indexOf('.') >= 0) continue
|
|
420
700
|
|
|
421
|
-
if(Array.isArray(value)
|
|
422
|
-
const { modifier = 'and' } = filter
|
|
701
|
+
if(Array.isArray(value)){
|
|
423
702
|
|
|
424
|
-
|
|
703
|
+
const modifierValue = []
|
|
425
704
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}))
|
|
705
|
+
for(let _value of value){
|
|
706
|
+
modifierValue.push(getValue({
|
|
707
|
+
..._value,
|
|
708
|
+
key
|
|
709
|
+
}, opt))
|
|
432
710
|
}
|
|
433
711
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
712
|
+
switch(modifier){
|
|
713
|
+
case 'or':
|
|
714
|
+
whereArr.push({
|
|
715
|
+
[Op.or]: modifierValue
|
|
716
|
+
})
|
|
717
|
+
break
|
|
440
718
|
|
|
719
|
+
default:
|
|
720
|
+
whereArr.push({
|
|
721
|
+
[Op.and]: modifierValue
|
|
722
|
+
})
|
|
723
|
+
break
|
|
724
|
+
}
|
|
441
725
|
}
|
|
442
726
|
else{
|
|
443
|
-
|
|
444
|
-
...whereObj,
|
|
445
|
-
...getValue(filter, opt)
|
|
446
|
-
}
|
|
727
|
+
whereArr.push(getValue(filter, opt))
|
|
447
728
|
}
|
|
448
729
|
}
|
|
449
730
|
|
|
731
|
+
//console.log(util.inspect(whereArr, false, null, true))
|
|
732
|
+
|
|
450
733
|
return {
|
|
451
734
|
where: {
|
|
452
|
-
[Op.and]:
|
|
453
|
-
whereObj,
|
|
454
|
-
...whereArr
|
|
455
|
-
]
|
|
735
|
+
[Op.and]: whereArr
|
|
456
736
|
},
|
|
457
737
|
replacements
|
|
458
738
|
}
|
|
@@ -1008,7 +1288,10 @@ const presetToSequelizeList = async(preset, {
|
|
|
1008
1288
|
}
|
|
1009
1289
|
}
|
|
1010
1290
|
|
|
1011
|
-
const { where:filterWhere, replacements:filterReplacements } = await filtersToSequelizeWhere(filters,
|
|
1291
|
+
const { where:filterWhere, replacements:filterReplacements } = await filtersToSequelizeWhere(filters, {
|
|
1292
|
+
config,
|
|
1293
|
+
model
|
|
1294
|
+
})
|
|
1012
1295
|
|
|
1013
1296
|
let searchWhere = {}, searchReplacements = []
|
|
1014
1297
|
if(search){
|