@mixd-id/web-scaffold 0.1.230406314 → 0.1.230406316
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 +293 -349
- package/src/widgets/PresetBar.vue +1 -1
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,458 +1,399 @@
|
|
|
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
|
-
const
|
|
7
|
+
const filtersToSequelizeWhere = async(filters, opt) => {
|
|
8
|
+
if(!Array.isArray(filters) || filters.length < 1){
|
|
9
|
+
return {
|
|
10
|
+
where: {},
|
|
11
|
+
replacements: []
|
|
12
|
+
}
|
|
13
|
+
}
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const keyColumns = groupBy(columns, 'key')
|
|
12
|
-
const type = ((keyColumns[key] ?? [])[0] ?? {}).type
|
|
15
|
+
let whereArr = []
|
|
16
|
+
let replacements = []
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
const getValue = (filter, opt) => {
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
const { columns } = opt.config
|
|
21
|
+
let { key, operator, value, fn:filterFn } = filter
|
|
22
|
+
const keyColumns = groupBy(columns, 'key')
|
|
23
|
+
const type = ((keyColumns[key] ?? [])[0] ?? {}).type
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
let whereObj = {}
|
|
26
|
+
const modelAttributes = opt.model.getAttributes()
|
|
27
|
+
const {Model, field} = modelAttributes[key]
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
case 'currency':
|
|
24
|
-
switch(operator) {
|
|
25
|
-
case '=':
|
|
26
|
-
withoutKey ? whereObj = { [Op.eq]:filter.value } : whereObj[key] = filter.value
|
|
27
|
-
break
|
|
29
|
+
switch(type){
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[Op[operator]]: filter.value
|
|
34
|
-
}
|
|
35
|
-
break
|
|
31
|
+
case 'boolean':
|
|
32
|
+
value = !!value
|
|
33
|
+
whereObj = { [key]: value }
|
|
34
|
+
break
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
whereObj[key] = {
|
|
41
|
-
[Op[operator]]: filter.value
|
|
42
|
-
}
|
|
43
|
-
break
|
|
36
|
+
case 'number':
|
|
37
|
+
case 'currency':
|
|
38
|
+
value = parseFloat(value)
|
|
44
39
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
whereObj = { [
|
|
48
|
-
|
|
49
|
-
[Op[operator]]: filter.value
|
|
50
|
-
}
|
|
51
|
-
break
|
|
40
|
+
switch(operator) {
|
|
41
|
+
case '=':
|
|
42
|
+
whereObj = { [key]:value }
|
|
43
|
+
break
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
whereObj[key] = {
|
|
57
|
-
[Op[operator]]: filter.value
|
|
58
|
-
}
|
|
59
|
-
break
|
|
45
|
+
case '>':
|
|
46
|
+
whereObj = { [key]:{ [Op.gt]:value } }
|
|
47
|
+
break
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
whereObj[key]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
case '>=':
|
|
50
|
+
whereObj = { [key]:{ [Op.gte]:value } }
|
|
51
|
+
break
|
|
52
|
+
|
|
53
|
+
case '<':
|
|
54
|
+
whereObj = { [key]:{ [Op.lt]:value } }
|
|
55
|
+
break
|
|
56
|
+
|
|
57
|
+
case '<=':
|
|
58
|
+
whereObj = { [key]:{ [Op.lte]:value } }
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
case 'in':
|
|
62
|
+
whereObj = {
|
|
63
|
+
[key]:{
|
|
64
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
65
|
+
.map(_ => parseInt(_))
|
|
66
|
+
.filter(_ => !isNaN(_))
|
|
67
|
+
}
|
|
70
68
|
}
|
|
71
|
-
|
|
69
|
+
break
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.map(_ => parseInt(_))
|
|
81
|
-
.filter(_ => !isNaN(_))
|
|
71
|
+
case 'notIn':
|
|
72
|
+
whereObj = {
|
|
73
|
+
[key]:{
|
|
74
|
+
[Op.notIn]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
75
|
+
.map(_ => parseInt(_))
|
|
76
|
+
.filter(_ => !isNaN(_))
|
|
77
|
+
}
|
|
82
78
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
break
|
|
86
82
|
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
case 'date':
|
|
84
|
+
switch(operator) {
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
withoutKey ?
|
|
86
|
+
case 'thisWeek':
|
|
92
87
|
whereObj = {
|
|
93
|
-
[
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[Op.between]: [
|
|
100
|
-
dayjs().startOf('week').format('YYYY-MM-DD 00:00:00'),
|
|
101
|
-
dayjs().endOf('week').format('YYYY-MM-DD 23:59:59'),
|
|
102
|
-
]
|
|
88
|
+
[key]:{
|
|
89
|
+
[Op.between]: [
|
|
90
|
+
dayjs().startOf('week').format('YYYY-MM-DD 00:00:00'),
|
|
91
|
+
dayjs().endOf('week').format('YYYY-MM-DD 23:59:59'),
|
|
92
|
+
]
|
|
93
|
+
}
|
|
103
94
|
}
|
|
104
|
-
|
|
95
|
+
break
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
withoutKey ?
|
|
97
|
+
case 'thisMonth':
|
|
108
98
|
whereObj = {
|
|
109
|
-
[
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
[Op.between]: [
|
|
116
|
-
dayjs().startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
117
|
-
dayjs().endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
118
|
-
]
|
|
99
|
+
[key]:{
|
|
100
|
+
[Op.between]: [
|
|
101
|
+
dayjs().startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
102
|
+
dayjs().endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
103
|
+
]
|
|
104
|
+
}
|
|
119
105
|
}
|
|
120
|
-
|
|
106
|
+
break
|
|
121
107
|
|
|
122
|
-
|
|
123
|
-
withoutKey ?
|
|
108
|
+
case 'lastMonth':
|
|
124
109
|
whereObj = {
|
|
125
|
-
[
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
]
|
|
110
|
+
[key]:{
|
|
111
|
+
[Op.between]: [
|
|
112
|
+
dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
113
|
+
dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
114
|
+
]
|
|
115
|
+
}
|
|
135
116
|
}
|
|
136
|
-
|
|
117
|
+
break
|
|
137
118
|
|
|
138
|
-
|
|
139
|
-
withoutKey ?
|
|
119
|
+
case 'thisYear':
|
|
140
120
|
whereObj = {
|
|
141
|
-
[
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
[Op.between]: [
|
|
148
|
-
dayjs().startOf('year').format('YYYY-MM-DD 00:00:00'),
|
|
149
|
-
dayjs().endOf('year').format('YYYY-MM-DD 23:59:59'),
|
|
150
|
-
]
|
|
121
|
+
[key]:{
|
|
122
|
+
[Op.between]: [
|
|
123
|
+
dayjs().startOf('year').format('YYYY-MM-DD 00:00:00'),
|
|
124
|
+
dayjs().endOf('year').format('YYYY-MM-DD 23:59:59'),
|
|
125
|
+
]
|
|
126
|
+
}
|
|
151
127
|
}
|
|
152
|
-
|
|
128
|
+
break
|
|
153
129
|
|
|
154
|
-
|
|
155
|
-
withoutKey ?
|
|
130
|
+
case 'between':
|
|
156
131
|
whereObj = {
|
|
157
|
-
[
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
[Op.between]: [
|
|
164
|
-
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
165
|
-
dayjs(filter.value2).format('YYYY-MM-DD 23:59:59'),
|
|
166
|
-
]
|
|
132
|
+
[key]:{
|
|
133
|
+
[Op.between]: [
|
|
134
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
135
|
+
dayjs(filter.value2).format('YYYY-MM-DD 23:59:59'),
|
|
136
|
+
]
|
|
137
|
+
}
|
|
167
138
|
}
|
|
168
|
-
|
|
139
|
+
break
|
|
169
140
|
|
|
170
|
-
|
|
171
|
-
withoutKey ?
|
|
141
|
+
case 'yesterday':
|
|
172
142
|
whereObj = {
|
|
173
|
-
[
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
[Op.between]: [
|
|
180
|
-
dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
181
|
-
dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
182
|
-
]
|
|
143
|
+
[key]:{
|
|
144
|
+
[Op.between]: [
|
|
145
|
+
dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
146
|
+
dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
147
|
+
]
|
|
148
|
+
}
|
|
183
149
|
}
|
|
184
|
-
|
|
150
|
+
break
|
|
185
151
|
|
|
186
|
-
|
|
187
|
-
withoutKey ?
|
|
152
|
+
case 'today':
|
|
188
153
|
whereObj = {
|
|
189
|
-
[
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
[Op.between]: [
|
|
196
|
-
dayjs().startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
197
|
-
dayjs().endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
198
|
-
]
|
|
154
|
+
[key]:{
|
|
155
|
+
[Op.between]: [
|
|
156
|
+
dayjs().startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
157
|
+
dayjs().endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
158
|
+
]
|
|
159
|
+
}
|
|
199
160
|
}
|
|
200
|
-
|
|
161
|
+
break
|
|
201
162
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
163
|
+
case '<':
|
|
164
|
+
switch(filterFn) {
|
|
165
|
+
|
|
166
|
+
case 'format_hour':
|
|
167
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") < "${filter.value}"`)
|
|
168
|
+
break
|
|
169
|
+
|
|
170
|
+
default:
|
|
171
|
+
whereObj = {
|
|
172
|
+
[key]: {
|
|
173
|
+
[Op.lt]: [
|
|
174
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
}
|
|
213
178
|
}
|
|
214
|
-
|
|
179
|
+
break
|
|
215
180
|
|
|
216
|
-
|
|
217
|
-
|
|
181
|
+
case '<=':
|
|
182
|
+
switch(filterFn) {
|
|
218
183
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
184
|
+
case 'format_hour':
|
|
185
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") <= "${filter.value}"`)
|
|
186
|
+
break
|
|
222
187
|
|
|
223
|
-
|
|
224
|
-
withoutKey ?
|
|
188
|
+
default:
|
|
225
189
|
whereObj = {
|
|
226
|
-
[
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
[Op.lte]: [
|
|
232
|
-
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
233
|
-
]
|
|
190
|
+
[key]: {
|
|
191
|
+
[Op.lte]: [
|
|
192
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
193
|
+
]
|
|
194
|
+
}
|
|
234
195
|
}
|
|
235
|
-
|
|
196
|
+
}
|
|
197
|
+
break
|
|
236
198
|
|
|
237
|
-
|
|
199
|
+
case '=':
|
|
200
|
+
switch(filterFn) {
|
|
238
201
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
202
|
+
case 'format_date':
|
|
203
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%Y-%m-%d") = "${filter.value}"`)
|
|
204
|
+
break
|
|
205
|
+
|
|
206
|
+
case 'format_hour':
|
|
207
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") = "${filter.value}"`)
|
|
208
|
+
break
|
|
209
|
+
|
|
210
|
+
case 'format_month':
|
|
211
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%m") = "${filter.value.split('-')[1]}"`)
|
|
212
|
+
break
|
|
213
|
+
|
|
214
|
+
case 'format_year':
|
|
215
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%Y") = "${filter.value}"`)
|
|
216
|
+
break
|
|
217
|
+
|
|
218
|
+
default:
|
|
219
|
+
whereObj = {
|
|
220
|
+
[key]: {
|
|
221
|
+
[Op.between]: [
|
|
222
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
223
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
}
|
|
252
227
|
}
|
|
253
|
-
|
|
228
|
+
break
|
|
254
229
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
230
|
+
case '>':
|
|
231
|
+
switch(filterFn) {
|
|
232
|
+
|
|
233
|
+
case 'format_hour':
|
|
234
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") > "${filter.value}"`)
|
|
235
|
+
break
|
|
236
|
+
|
|
237
|
+
default:
|
|
238
|
+
whereObj = {
|
|
239
|
+
[key]: {
|
|
240
|
+
[Op.gt]: [
|
|
241
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
266
245
|
}
|
|
267
|
-
|
|
246
|
+
break
|
|
268
247
|
|
|
269
|
-
|
|
270
|
-
|
|
248
|
+
case '>=':
|
|
249
|
+
switch(filterFn) {
|
|
271
250
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
251
|
+
case 'format_hour':
|
|
252
|
+
whereObj = literal(`DATE_FORMAT(${Model.name}.${field}, "%H") >= "${filter.value}"`)
|
|
253
|
+
break
|
|
275
254
|
|
|
276
|
-
|
|
277
|
-
withoutKey ?
|
|
255
|
+
default:
|
|
278
256
|
whereObj = {
|
|
279
|
-
[
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
[Op.gte]: [
|
|
285
|
-
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
286
|
-
]
|
|
257
|
+
[key]: {
|
|
258
|
+
[Op.gte]: [
|
|
259
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
260
|
+
]
|
|
261
|
+
}
|
|
287
262
|
}
|
|
288
|
-
|
|
289
|
-
|
|
263
|
+
}
|
|
264
|
+
break
|
|
290
265
|
|
|
291
|
-
|
|
292
|
-
|
|
266
|
+
}
|
|
267
|
+
break
|
|
293
268
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
withoutKey ?
|
|
269
|
+
default:
|
|
270
|
+
switch(operator) {
|
|
271
|
+
case '=':
|
|
298
272
|
whereObj = {
|
|
299
|
-
[
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
[Op.eq]: filter.value
|
|
273
|
+
[key]:{
|
|
274
|
+
[Op.eq]: filter.value
|
|
275
|
+
}
|
|
303
276
|
}
|
|
304
|
-
|
|
277
|
+
break
|
|
305
278
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
withoutKey ?
|
|
279
|
+
case 'eq':
|
|
280
|
+
case 'not':
|
|
309
281
|
whereObj = {
|
|
310
|
-
[
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
[Op[operator]]: filter.value
|
|
282
|
+
[key]:{
|
|
283
|
+
[Op[operator]]: filter.value
|
|
284
|
+
}
|
|
314
285
|
}
|
|
315
|
-
|
|
286
|
+
break
|
|
316
287
|
|
|
317
|
-
|
|
318
|
-
withoutKey ?
|
|
288
|
+
case 'startsWith':
|
|
319
289
|
whereObj = {
|
|
320
|
-
[
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
[Op.like]: `${filter.value}%`
|
|
290
|
+
[key]:{
|
|
291
|
+
[Op.like]: `${filter.value}%`
|
|
292
|
+
}
|
|
324
293
|
}
|
|
325
|
-
|
|
294
|
+
break
|
|
326
295
|
|
|
327
|
-
|
|
328
|
-
withoutKey ?
|
|
296
|
+
case 'endsWith':
|
|
329
297
|
whereObj = {
|
|
330
|
-
[
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
[Op.like]: `%${filter.value}`
|
|
298
|
+
[key]:{
|
|
299
|
+
[Op.like]: `%${filter.value}`
|
|
300
|
+
}
|
|
334
301
|
}
|
|
335
|
-
|
|
302
|
+
break
|
|
336
303
|
|
|
337
|
-
|
|
338
|
-
withoutKey ?
|
|
304
|
+
case 'contains':
|
|
339
305
|
whereObj = {
|
|
340
|
-
[
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
[Op.like]: `%${filter.value}%`
|
|
306
|
+
[key]:{
|
|
307
|
+
[Op.like]: `%${filter.value}%`
|
|
308
|
+
}
|
|
344
309
|
}
|
|
345
|
-
|
|
310
|
+
break
|
|
346
311
|
|
|
347
|
-
|
|
348
|
-
withoutKey ?
|
|
312
|
+
case 'notContains':
|
|
349
313
|
whereObj = {
|
|
350
|
-
[
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
[Op.notLike]: `%${filter.value}%`
|
|
314
|
+
[key]:{
|
|
315
|
+
[Op.notLike]: `%${filter.value}%`
|
|
316
|
+
}
|
|
354
317
|
}
|
|
355
|
-
|
|
318
|
+
break
|
|
356
319
|
|
|
357
|
-
|
|
358
|
-
withoutKey ?
|
|
320
|
+
case 'in':
|
|
359
321
|
whereObj = {
|
|
360
|
-
[
|
|
361
|
-
.filter(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
365
|
-
.filter(_ => _)
|
|
322
|
+
[key]:{
|
|
323
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
324
|
+
.filter(_ => _)
|
|
325
|
+
}
|
|
366
326
|
}
|
|
367
|
-
|
|
327
|
+
break
|
|
368
328
|
|
|
369
|
-
|
|
370
|
-
withoutKey ?
|
|
329
|
+
case 'notIn':
|
|
371
330
|
whereObj = {
|
|
372
|
-
[
|
|
373
|
-
.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
[Op.notIn]: filter.value.split(',')
|
|
378
|
-
.map(_ => parseInt(_))
|
|
379
|
-
.filter(_ => !isNaN(_))
|
|
331
|
+
[key]:{
|
|
332
|
+
[Op.notIn]: filter.value.split(',')
|
|
333
|
+
.map(_ => parseInt(_))
|
|
334
|
+
.filter(_ => !isNaN(_))
|
|
335
|
+
}
|
|
380
336
|
}
|
|
381
|
-
|
|
337
|
+
break
|
|
382
338
|
|
|
383
|
-
|
|
384
|
-
withoutKey ?
|
|
339
|
+
case 'regex':
|
|
385
340
|
whereObj = {
|
|
386
|
-
[
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
[Op.regexp]: filter.value
|
|
341
|
+
[key]:{
|
|
342
|
+
[Op.regexp]: filter.value
|
|
343
|
+
}
|
|
390
344
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
//console.log('getValue', type, util.inspect({ filter, whereObj }, false, null, true /* enable colors */))
|
|
397
|
-
|
|
398
|
-
return whereObj
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const filtersToSequelizeWhere = async(filters, opt) => {
|
|
403
|
-
if(!Array.isArray(filters) || filters.length < 1){
|
|
404
|
-
return {
|
|
405
|
-
where: {},
|
|
406
|
-
replacements: []
|
|
345
|
+
break
|
|
346
|
+
}
|
|
347
|
+
break
|
|
407
348
|
}
|
|
349
|
+
|
|
350
|
+
return whereObj
|
|
408
351
|
}
|
|
409
352
|
|
|
410
|
-
|
|
411
|
-
let whereArr = []
|
|
412
|
-
let replacements = []
|
|
353
|
+
//console.log(util.inspect(filters, false, null, true))
|
|
413
354
|
|
|
414
355
|
for(let filter of filters) {
|
|
415
356
|
if (filter.enabled === false) continue
|
|
416
357
|
|
|
417
|
-
const { key, value,
|
|
358
|
+
const { key, value, modifier = 'and' } = filter
|
|
418
359
|
|
|
419
360
|
if(key.indexOf('.') >= 0) continue
|
|
420
361
|
|
|
421
|
-
if(Array.isArray(value)
|
|
422
|
-
const { modifier = 'and' } = filter
|
|
362
|
+
if(Array.isArray(value)){
|
|
423
363
|
|
|
424
|
-
|
|
364
|
+
const modifierValue = []
|
|
425
365
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}))
|
|
366
|
+
for(let _value of value){
|
|
367
|
+
modifierValue.push(getValue({
|
|
368
|
+
..._value,
|
|
369
|
+
key
|
|
370
|
+
}, opt))
|
|
432
371
|
}
|
|
433
372
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
373
|
+
switch(modifier){
|
|
374
|
+
case 'or':
|
|
375
|
+
whereArr.push({
|
|
376
|
+
[Op.or]: modifierValue
|
|
377
|
+
})
|
|
378
|
+
break
|
|
440
379
|
|
|
380
|
+
default:
|
|
381
|
+
whereArr.push({
|
|
382
|
+
[Op.and]: modifierValue
|
|
383
|
+
})
|
|
384
|
+
break
|
|
385
|
+
}
|
|
441
386
|
}
|
|
442
387
|
else{
|
|
443
|
-
|
|
444
|
-
...whereObj,
|
|
445
|
-
...getValue(filter, opt)
|
|
446
|
-
}
|
|
388
|
+
whereArr.push(getValue(filter, opt))
|
|
447
389
|
}
|
|
448
390
|
}
|
|
449
391
|
|
|
392
|
+
//console.log(util.inspect(whereArr, false, null, true))
|
|
393
|
+
|
|
450
394
|
return {
|
|
451
395
|
where: {
|
|
452
|
-
[Op.and]:
|
|
453
|
-
whereObj,
|
|
454
|
-
...whereArr
|
|
455
|
-
]
|
|
396
|
+
[Op.and]: whereArr
|
|
456
397
|
},
|
|
457
398
|
replacements
|
|
458
399
|
}
|
|
@@ -1008,7 +949,10 @@ const presetToSequelizeList = async(preset, {
|
|
|
1008
949
|
}
|
|
1009
950
|
}
|
|
1010
951
|
|
|
1011
|
-
const { where:filterWhere, replacements:filterReplacements } = await filtersToSequelizeWhere(filters,
|
|
952
|
+
const { where:filterWhere, replacements:filterReplacements } = await filtersToSequelizeWhere(filters, {
|
|
953
|
+
config,
|
|
954
|
+
model
|
|
955
|
+
})
|
|
1012
956
|
|
|
1013
957
|
let searchWhere = {}, searchReplacements = []
|
|
1014
958
|
if(search){
|