@outliant/sunrise-utils 1.0.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/.eslintignore +5 -0
- package/.eslintrc +53 -0
- package/.github/workflows/pr-dev-workflow.yml +16 -0
- package/.nvmrc +1 -0
- package/.release-it.js +26 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +7 -0
- package/CHANGELOG.md +12 -0
- package/README.md +19 -0
- package/changelog.hbs +13 -0
- package/helpers/es.js +6 -0
- package/helpers/projectFilter/projectFieldFilter.js +587 -0
- package/helpers/searchFilter.js +86 -0
- package/helpers/taskFilter/criticalPathFilter.js +144 -0
- package/helpers/taskFilter/index.js +228 -0
- package/helpers/taskFilter/onHoldFilter.js +101 -0
- package/helpers/taskFilter/ownerFilter.js +148 -0
- package/helpers/taskFilter/pathAgeFilter.js +18 -0
- package/helpers/taskFilter/regionFilter.js +82 -0
- package/helpers/taskFilter/statusFilter.js +177 -0
- package/helpers/taskFilter/taskFieldFilter.js +309 -0
- package/helpers/taskSortScript.js +356 -0
- package/index.d.ts +11 -0
- package/index.js +9 -0
- package/lib/fieldConditions.js +166 -0
- package/lib/logger.js +48 -0
- package/lib/taskPipeline.js +137 -0
- package/package.json +73 -0
- package/test/helpers/projectFilter/projectFieldFilter.spec.js +881 -0
- package/test/helpers/taskFilter/criticalPathFilter.spec.js +174 -0
- package/test/helpers/taskFilter/index.spec.js +339 -0
- package/test/helpers/taskFilter/onHoldFilter.spec.js +112 -0
- package/test/helpers/taskFilter/ownerFilter.spec.js +226 -0
- package/test/helpers/taskFilter/pathAgeFilter.spec.js +47 -0
- package/test/helpers/taskFilter/regionFilter.spec.js +131 -0
- package/test/helpers/taskFilter/statusFilter.spec.js +197 -0
- package/test/helpers/taskFilter/taskFieldFilter.spec.js +355 -0
- package/test/lib/fieldConditions.spec.js +17 -0
- package/test/lib/logger.spec.js +117 -0
- package/test/lib/taskPipeline.spec.js +162 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'is_empty':
|
|
4
|
+
return module.exports.isEmpty();
|
|
5
|
+
case 'is_not_empty':
|
|
6
|
+
return module.exports.isNotEmpty();
|
|
7
|
+
case 'is_equal':
|
|
8
|
+
return module.exports.isEqual(filter);
|
|
9
|
+
case 'not_equal':
|
|
10
|
+
return module.exports.isNotEqual(filter);
|
|
11
|
+
case 'is_any_of':
|
|
12
|
+
return module.exports.isAnyOf(filter);
|
|
13
|
+
default:
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports.isEmpty = () => {
|
|
19
|
+
return {
|
|
20
|
+
bool: {
|
|
21
|
+
must_not: [
|
|
22
|
+
{
|
|
23
|
+
exists: {
|
|
24
|
+
field: 'is_complete'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
exists: {
|
|
29
|
+
field: 'is_ready'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
exists: {
|
|
34
|
+
field: 'on_hold'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports.isNotEmpty = () => {
|
|
43
|
+
const isEmptyFilter = module.exports.isEmpty();
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
bool: {
|
|
47
|
+
must_not: isEmptyFilter
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports.isEqual = (filter) => {
|
|
53
|
+
switch (filter.value) {
|
|
54
|
+
case 'new':
|
|
55
|
+
return {
|
|
56
|
+
bool: {
|
|
57
|
+
must: [
|
|
58
|
+
{
|
|
59
|
+
term: {
|
|
60
|
+
is_ready: false
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
term: {
|
|
65
|
+
is_complete: false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
case 'pending':
|
|
72
|
+
return {
|
|
73
|
+
bool: {
|
|
74
|
+
must: [
|
|
75
|
+
{
|
|
76
|
+
term: {
|
|
77
|
+
is_ready: true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
term: {
|
|
82
|
+
is_complete: false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
case 'completed':
|
|
89
|
+
return {
|
|
90
|
+
bool: {
|
|
91
|
+
must: [
|
|
92
|
+
{
|
|
93
|
+
term: {
|
|
94
|
+
is_complete: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
case 'on_hold':
|
|
101
|
+
return {
|
|
102
|
+
bool: {
|
|
103
|
+
must: [
|
|
104
|
+
{
|
|
105
|
+
term: {
|
|
106
|
+
on_hold: true
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
case 'overdue':
|
|
113
|
+
return {
|
|
114
|
+
bool: {
|
|
115
|
+
must: [
|
|
116
|
+
{
|
|
117
|
+
term: {
|
|
118
|
+
is_complete: false
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
exists: {
|
|
123
|
+
field: 'due_date'
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
range: {
|
|
128
|
+
due_date: {
|
|
129
|
+
lte: Date.now()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
default:
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
module.exports.isAnyOf = (filter) => {
|
|
142
|
+
let value = filter.value;
|
|
143
|
+
|
|
144
|
+
if (typeof value === 'string') {
|
|
145
|
+
value = value.split(';');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const should = [];
|
|
149
|
+
value.forEach((x) => {
|
|
150
|
+
const condition = module.exports.isEqual({
|
|
151
|
+
value: x
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (condition) {
|
|
155
|
+
should.push(condition);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
bool: {
|
|
160
|
+
should
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
module.exports.isNotEqual = (filter) => {
|
|
166
|
+
const equalFilter = module.exports.isEqual(filter);
|
|
167
|
+
|
|
168
|
+
if (equalFilter) {
|
|
169
|
+
return {
|
|
170
|
+
bool: {
|
|
171
|
+
must_not: equalFilter
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
const moment = require('moment');
|
|
2
|
+
|
|
3
|
+
module.exports = (filter) => {
|
|
4
|
+
switch (filter.condition) {
|
|
5
|
+
case 'is_empty':
|
|
6
|
+
return module.exports.isEmpty(filter);
|
|
7
|
+
case 'is_any_of':
|
|
8
|
+
return module.exports.isAnyOf(filter);
|
|
9
|
+
case 'is_not_empty':
|
|
10
|
+
return module.exports.isNotEmpty(filter);
|
|
11
|
+
case 'is_equal':
|
|
12
|
+
return module.exports.isEqual(filter);
|
|
13
|
+
case 'not_equal':
|
|
14
|
+
return module.exports.isNotEqual(filter);
|
|
15
|
+
case 'before':
|
|
16
|
+
case 'less_than':
|
|
17
|
+
return module.exports.isBefore(filter);
|
|
18
|
+
case 'after':
|
|
19
|
+
case 'greater_than':
|
|
20
|
+
return module.exports.isAfter(filter);
|
|
21
|
+
case 'less_than_or_equal':
|
|
22
|
+
return module.exports.isBeforeIncludeParam(filter);
|
|
23
|
+
case 'greater_than_or_equal':
|
|
24
|
+
return module.exports.isAfterIncludeParam(filter);
|
|
25
|
+
case 'between':
|
|
26
|
+
return module.exports.isBetween(filter);
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports.isAnyOf = (filter) => {
|
|
33
|
+
let value = filter.value;
|
|
34
|
+
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
value = value.split(';');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
terms: {
|
|
41
|
+
[filter.type]: value
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports.isEmpty = (filter) => {
|
|
47
|
+
if (filter.field_type === 'text' || filter.field_type === 'textarea') {
|
|
48
|
+
return {
|
|
49
|
+
bool: {
|
|
50
|
+
should: [
|
|
51
|
+
{
|
|
52
|
+
bool: {
|
|
53
|
+
must_not: [
|
|
54
|
+
{
|
|
55
|
+
exists: {
|
|
56
|
+
field: filter.type
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
bool: {
|
|
64
|
+
must_not: [
|
|
65
|
+
{
|
|
66
|
+
wildcard: {
|
|
67
|
+
[filter.type]: {
|
|
68
|
+
value: '?*'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
term: {
|
|
77
|
+
[filter.type]: {
|
|
78
|
+
value: ''
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
bool: {
|
|
88
|
+
should: [
|
|
89
|
+
{
|
|
90
|
+
bool: {
|
|
91
|
+
must_not: [
|
|
92
|
+
{
|
|
93
|
+
exists: {
|
|
94
|
+
field: filter.type
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
module.exports.isNotEmpty = (filter) => {
|
|
106
|
+
if (filter.field_type === 'text' || filter.field_type === 'textarea') {
|
|
107
|
+
return {
|
|
108
|
+
bool: {
|
|
109
|
+
must: [
|
|
110
|
+
{
|
|
111
|
+
exists: {
|
|
112
|
+
field: filter.type
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
wildcard: {
|
|
117
|
+
[filter.type]: {
|
|
118
|
+
value: '?*'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
bool: {
|
|
124
|
+
must_not: [
|
|
125
|
+
{
|
|
126
|
+
term: {
|
|
127
|
+
[filter.type]: {
|
|
128
|
+
value: ''
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
bool: {
|
|
142
|
+
must: [
|
|
143
|
+
{
|
|
144
|
+
exists: {
|
|
145
|
+
field: filter.type
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
module.exports.isEqual = (filter) => {
|
|
154
|
+
if (filter.field_type === 'date') {
|
|
155
|
+
const startOfDay = moment(filter.value).startOf('day').valueOf();
|
|
156
|
+
const endOfDay = moment(filter.value).endOf('day').valueOf();
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
range: {
|
|
160
|
+
[filter.type]: {
|
|
161
|
+
gte: startOfDay,
|
|
162
|
+
lte: endOfDay
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
} else if (filter.field_type === 'textarea') {
|
|
167
|
+
return {
|
|
168
|
+
query_string: {
|
|
169
|
+
fields: [filter.type],
|
|
170
|
+
query: `*${filter.value}*`
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
bool: {
|
|
177
|
+
must: [
|
|
178
|
+
{
|
|
179
|
+
term: {
|
|
180
|
+
[filter.type]: {
|
|
181
|
+
value:
|
|
182
|
+
filter.field_type === 'number'
|
|
183
|
+
? parseInt(filter.value)
|
|
184
|
+
: filter.value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
module.exports.isBefore = (filter) => {
|
|
194
|
+
let param;
|
|
195
|
+
|
|
196
|
+
if (filter.field_type === 'date') {
|
|
197
|
+
param = moment(filter.value).startOf('day').valueOf();
|
|
198
|
+
} else if (filter.field_type === 'number') {
|
|
199
|
+
param = parseInt(filter.value);
|
|
200
|
+
} else {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
range: {
|
|
206
|
+
[filter.type]: {
|
|
207
|
+
lt: param
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
module.exports.isAfter = (filter) => {
|
|
214
|
+
let param;
|
|
215
|
+
|
|
216
|
+
if (filter.field_type === 'date') {
|
|
217
|
+
param = moment(filter.value).endOf('day').valueOf();
|
|
218
|
+
} else if (filter.field_type === 'number') {
|
|
219
|
+
param = parseInt(filter.value);
|
|
220
|
+
} else {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
range: {
|
|
226
|
+
[filter.type]: {
|
|
227
|
+
gt: param
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
module.exports.isBeforeIncludeParam = (filter) => {
|
|
234
|
+
let param;
|
|
235
|
+
|
|
236
|
+
if (filter.field_type === 'date') {
|
|
237
|
+
param = moment(filter.value).endOf('day').valueOf();
|
|
238
|
+
} else if (filter.field_type === 'number') {
|
|
239
|
+
param = parseInt(filter.value);
|
|
240
|
+
} else {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
range: {
|
|
246
|
+
[filter.type]: {
|
|
247
|
+
lte: param
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
module.exports.isAfterIncludeParam = (filter) => {
|
|
254
|
+
let param;
|
|
255
|
+
|
|
256
|
+
if (filter.field_type === 'date') {
|
|
257
|
+
param = moment(filter.value).endOf('day').valueOf();
|
|
258
|
+
} else if (filter.field_type === 'number') {
|
|
259
|
+
param = parseInt(filter.value);
|
|
260
|
+
} else {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
range: {
|
|
266
|
+
[filter.type]: {
|
|
267
|
+
gte: param
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
module.exports.isBetween = (filter) => {
|
|
274
|
+
let firstParam;
|
|
275
|
+
let secondParam;
|
|
276
|
+
|
|
277
|
+
if (filter.field_type === 'date') {
|
|
278
|
+
firstParam = moment(filter.value).startOf('day').valueOf();
|
|
279
|
+
secondParam = moment(filter.second_value).endOf('day').valueOf();
|
|
280
|
+
} else if (filter.field_type === 'number') {
|
|
281
|
+
firstParam = parseInt(filter.value);
|
|
282
|
+
secondParam = parseInt(filter.second_value);
|
|
283
|
+
} else {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
range: {
|
|
289
|
+
[filter.type]: {
|
|
290
|
+
gte: firstParam,
|
|
291
|
+
lte: secondParam
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
module.exports.isNotEqual = (filter) => {
|
|
298
|
+
const equalFilter = module.exports.isEqual(filter);
|
|
299
|
+
|
|
300
|
+
if (equalFilter) {
|
|
301
|
+
return {
|
|
302
|
+
bool: {
|
|
303
|
+
must_not: equalFilter
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return null;
|
|
309
|
+
};
|