dtable-utils 0.0.1
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/README.md +20 -0
- package/dist/index.js +1 -0
- package/es/cell-value-get/cell-value.js +165 -0
- package/es/cell-value-get/collaborator.js +33 -0
- package/es/cell-value-get/date.js +53 -0
- package/es/cell-value-get/digital-sign.js +10 -0
- package/es/cell-value-get/duration.js +86 -0
- package/es/cell-value-get/geolocation.js +74 -0
- package/es/cell-value-get/long-text.js +11 -0
- package/es/cell-value-get/number.js +222 -0
- package/es/cell-value-get/option.js +32 -0
- package/es/cell-value-set/number.js +53 -0
- package/es/column/common.js +41 -0
- package/es/column/date.js +17 -0
- package/es/column/number.js +31 -0
- package/es/common.js +16 -0
- package/es/constants/cell-type.js +33 -0
- package/es/constants/column.js +45 -0
- package/es/constants/filter/filter-column-options.js +65 -0
- package/es/constants/filter/filter-is-within.js +6 -0
- package/es/constants/filter/filter-modifier.js +29 -0
- package/es/constants/filter/filter-predicate.js +33 -0
- package/es/constants/filter/index.js +16 -0
- package/es/constants/formula.js +14 -0
- package/es/constants/select-option.js +129 -0
- package/es/date.js +226 -0
- package/es/helper/number-precision/index.js +64 -0
- package/es/index.js +26 -0
- package/es/validate/email.js +10 -0
- package/es/validate/filter.js +447 -0
- package/lib/cell-value-get/cell-value.js +170 -0
- package/lib/cell-value-get/collaborator.js +38 -0
- package/lib/cell-value-get/date.js +61 -0
- package/lib/cell-value-get/digital-sign.js +14 -0
- package/lib/cell-value-get/duration.js +90 -0
- package/lib/cell-value-get/geolocation.js +78 -0
- package/lib/cell-value-get/long-text.js +15 -0
- package/lib/cell-value-get/number.js +227 -0
- package/lib/cell-value-get/option.js +37 -0
- package/lib/cell-value-set/number.js +58 -0
- package/lib/column/common.js +46 -0
- package/lib/column/date.js +21 -0
- package/lib/column/number.js +36 -0
- package/lib/common.js +20 -0
- package/lib/constants/cell-type.js +37 -0
- package/lib/constants/column.js +63 -0
- package/lib/constants/filter/filter-column-options.js +73 -0
- package/lib/constants/filter/filter-is-within.js +11 -0
- package/lib/constants/filter/filter-modifier.js +38 -0
- package/lib/constants/filter/filter-predicate.js +42 -0
- package/lib/constants/filter/index.js +27 -0
- package/lib/constants/formula.js +23 -0
- package/lib/constants/select-option.js +134 -0
- package/lib/date.js +235 -0
- package/lib/helper/number-precision/index.js +69 -0
- package/lib/index.js +79 -0
- package/lib/validate/email.js +14 -0
- package/lib/validate/filter.js +458 -0
- package/package.json +44 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import { CellType } from '../constants/cell-type.js';
|
|
5
|
+
import { COLLABORATOR_COLUMN_TYPES } from '../constants/column.js';
|
|
6
|
+
import { FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from '../constants/formula.js';
|
|
7
|
+
import { FILTER_ERR_MSG } from '../constants/filter/index.js';
|
|
8
|
+
import { getColumnOptions } from '../column/common.js';
|
|
9
|
+
import { isDateColumn } from '../column/date.js';
|
|
10
|
+
import { FILTER_PREDICATE_TYPE } from '../constants/filter/filter-predicate.js';
|
|
11
|
+
import { FILTER_TERM_MODIFIER_TYPE } from '../constants/filter/filter-modifier.js';
|
|
12
|
+
import { FILTER_COLUMN_OPTIONS } from '../constants/filter/filter-column-options.js';
|
|
13
|
+
import { filterTermModifierIsWithin, filterTermModifierNotWithin } from '../constants/filter/filter-is-within.js';
|
|
14
|
+
|
|
15
|
+
var TERM_TYPE_MAP = {
|
|
16
|
+
NUMBER: 'number',
|
|
17
|
+
STRING: 'string',
|
|
18
|
+
BOOLEAN: 'boolean',
|
|
19
|
+
ARRAY: 'array'
|
|
20
|
+
};
|
|
21
|
+
var TEXT_COLUMN_TYPES = [CellType.TEXT, CellType.STRING];
|
|
22
|
+
var CHECK_EMPTY_PREDICATES = [FILTER_PREDICATE_TYPE.EMPTY, FILTER_PREDICATE_TYPE.NOT_EMPTY];
|
|
23
|
+
var PREDICATES_REQUIRE_ARRAY_TERM = [FILTER_PREDICATE_TYPE.IS_ANY_OF, FILTER_PREDICATE_TYPE.IS_NONE_OF];
|
|
24
|
+
var DATE_MODIFIERS_REQUIRE_TERM = [FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS, FILTER_TERM_MODIFIER_TYPE.EXACT_DATE];
|
|
25
|
+
var MODIFIERS_REQUIRE_NUMERIC_TERM = [FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS];
|
|
26
|
+
var ValidateFilter = /*#__PURE__*/function () {
|
|
27
|
+
function ValidateFilter() {
|
|
28
|
+
_classCallCheck(this, ValidateFilter);
|
|
29
|
+
}
|
|
30
|
+
_createClass(ValidateFilter, null, [{
|
|
31
|
+
key: "validate",
|
|
32
|
+
value:
|
|
33
|
+
/**
|
|
34
|
+
* Check filter is valid. The error_message from returns will be null if the filter is valid.
|
|
35
|
+
* 1.incomplete filter which should be ignored
|
|
36
|
+
* - column_key: required
|
|
37
|
+
* - filter_predicate: required
|
|
38
|
+
* - filter_term_modifier: determined by the column to filter with
|
|
39
|
+
* - filter_term: determined by filter_predicate / the column to filter with
|
|
40
|
+
* 2.illegal filter
|
|
41
|
+
* - column missing: cannot find the column to filter
|
|
42
|
+
* - column not support: the column to filter is not support
|
|
43
|
+
* - mismatch: filter_predicate, filter_term_modifier mismatch
|
|
44
|
+
* - wrong data type: filter_term with wrong data type
|
|
45
|
+
* @param {object} filter e.g. { column_key, filter_term, ... }
|
|
46
|
+
* @param {array} columns e.g. [{ key, name, ... }, ...]
|
|
47
|
+
* @param {bool} isValidTerm No longer to validate filter term if false. default as false
|
|
48
|
+
* @returns { error_message }, object
|
|
49
|
+
*/
|
|
50
|
+
function validate(filter, columns) {
|
|
51
|
+
var isValidTerm = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
52
|
+
var column_key = filter.column_key,
|
|
53
|
+
filter_predicate = filter.filter_predicate,
|
|
54
|
+
filter_term_modifier = filter.filter_term_modifier,
|
|
55
|
+
filter_term = filter.filter_term;
|
|
56
|
+
var _this$validateColumn = this.validateColumn(column_key, columns),
|
|
57
|
+
column_error_message = _this$validateColumn.error_message;
|
|
58
|
+
if (column_error_message) {
|
|
59
|
+
return {
|
|
60
|
+
error_message: column_error_message
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var filterColumn = columns.find(function (column) {
|
|
64
|
+
return column.key === column_key;
|
|
65
|
+
});
|
|
66
|
+
var _this$validatePredica = this.validatePredicate(filter_predicate, filterColumn),
|
|
67
|
+
predicate_error_message = _this$validatePredica.error_message;
|
|
68
|
+
if (predicate_error_message) {
|
|
69
|
+
return {
|
|
70
|
+
error_message: predicate_error_message
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (this.isFilterOnlyWithPredicate(filter_predicate, filterColumn)) {
|
|
74
|
+
return {
|
|
75
|
+
error_message: null
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
var _this$validateModifie = this.validateModifier(filter_term_modifier, filter_predicate, filterColumn),
|
|
79
|
+
modifier_error_message = _this$validateModifie.error_message;
|
|
80
|
+
if (modifier_error_message) {
|
|
81
|
+
return {
|
|
82
|
+
error_message: modifier_error_message
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (this.isFilterOnlyWithModifier(filter_term_modifier, filterColumn)) {
|
|
86
|
+
return {
|
|
87
|
+
error_message: null
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (isValidTerm) {
|
|
91
|
+
var _this$validateTerm = this.validateTerm(filter_term, filter_predicate, filter_term_modifier, filterColumn),
|
|
92
|
+
term_error_message = _this$validateTerm.error_message;
|
|
93
|
+
if (term_error_message) {
|
|
94
|
+
return {
|
|
95
|
+
error_message: term_error_message
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
error_message: null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "validateColumn",
|
|
105
|
+
value: function validateColumn(column_key, columns) {
|
|
106
|
+
if (!column_key) {
|
|
107
|
+
return {
|
|
108
|
+
error_message: FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
var filterColumn = columns.find(function (column) {
|
|
112
|
+
return column.key === column_key;
|
|
113
|
+
});
|
|
114
|
+
if (!filterColumn) {
|
|
115
|
+
return {
|
|
116
|
+
error_message: FILTER_ERR_MSG.COLUMN_MISSING
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (!this.isValidColumnType(filterColumn)) {
|
|
120
|
+
return {
|
|
121
|
+
error_message: FILTER_ERR_MSG.COLUMN_NOT_SUPPORTED
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
error_message: null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* the column to filter must be available
|
|
131
|
+
*/
|
|
132
|
+
}, {
|
|
133
|
+
key: "validatePredicate",
|
|
134
|
+
value: function validatePredicate(predicate, filterColumn) {
|
|
135
|
+
if (!predicate) {
|
|
136
|
+
return {
|
|
137
|
+
error_message: FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
var columnType = filterColumn.type,
|
|
141
|
+
data = filterColumn.data;
|
|
142
|
+
var filterConfigs = FILTER_COLUMN_OPTIONS[columnType];
|
|
143
|
+
var predicateList = filterConfigs.filterPredicateList;
|
|
144
|
+
if (FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === CellType.LINK) {
|
|
145
|
+
var result_type = data.result_type;
|
|
146
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
147
|
+
return this.validatePredicateWithArrayType(predicate, filterColumn);
|
|
148
|
+
}
|
|
149
|
+
return this.validatePredicate(predicate, {
|
|
150
|
+
type: result_type
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (!predicateList.includes(predicate)) {
|
|
154
|
+
return {
|
|
155
|
+
error_message: FILTER_ERR_MSG.UNMATCHED_PREDICATE
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
error_message: null
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "validatePredicateWithArrayType",
|
|
164
|
+
value: function validatePredicateWithArrayType(predicate, filterColumn) {
|
|
165
|
+
var data = filterColumn.data;
|
|
166
|
+
var array_type = data.array_type;
|
|
167
|
+
if (array_type === CellType.SINGLE_SELECT) {
|
|
168
|
+
return this.validatePredicate(predicate, {
|
|
169
|
+
type: CellType.MULTIPLE_SELECT
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
173
|
+
return this.validatePredicate(predicate, {
|
|
174
|
+
type: CellType.COLLABORATOR
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return this.validatePredicate(predicate, {
|
|
178
|
+
type: array_type
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* filter predicate must be available.
|
|
184
|
+
* filterColumn the column to filter must be available
|
|
185
|
+
*/
|
|
186
|
+
}, {
|
|
187
|
+
key: "isFilterOnlyWithPredicate",
|
|
188
|
+
value: function isFilterOnlyWithPredicate(predicate, filterColumn) {
|
|
189
|
+
if (CHECK_EMPTY_PREDICATES.includes(predicate)) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
var columnType = filterColumn.type,
|
|
193
|
+
data = filterColumn.data;
|
|
194
|
+
if (FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === CellType.LINK) {
|
|
195
|
+
var result_type = data.result_type,
|
|
196
|
+
array_type = data.array_type;
|
|
197
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
198
|
+
return this.isFilterOnlyWithPredicate(predicate, {
|
|
199
|
+
type: array_type
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return this.isFilterOnlyWithPredicate(predicate, {
|
|
203
|
+
type: result_type
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
var IS_CURRENT_USER_ID = FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID,
|
|
207
|
+
INCLUDE_ME = FILTER_PREDICATE_TYPE.INCLUDE_ME;
|
|
208
|
+
if (predicate === IS_CURRENT_USER_ID && TEXT_COLUMN_TYPES.includes(columnType)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
if (predicate === INCLUDE_ME && COLLABORATOR_COLUMN_TYPES.includes(columnType)) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* filter predicate must be available.
|
|
219
|
+
* the column to filter must be available
|
|
220
|
+
*/
|
|
221
|
+
}, {
|
|
222
|
+
key: "validateModifier",
|
|
223
|
+
value: function validateModifier(modifier, predicate, filterColumn) {
|
|
224
|
+
if (!isDateColumn(filterColumn)) {
|
|
225
|
+
return {
|
|
226
|
+
error_message: null
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (!modifier) {
|
|
230
|
+
return {
|
|
231
|
+
error_message: FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (predicate === FILTER_PREDICATE_TYPE.IS_WITHIN) {
|
|
235
|
+
if (filterTermModifierIsWithin.includes(modifier)) {
|
|
236
|
+
return {
|
|
237
|
+
error_message: null
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
} else if (filterTermModifierNotWithin.includes(modifier)) {
|
|
241
|
+
return {
|
|
242
|
+
error_message: null
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
error_message: FILTER_ERR_MSG.UNMATCHED_MODIFIER
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* filter predicate must be available.
|
|
252
|
+
* filter modifier must be available.
|
|
253
|
+
* the column to filter must be available
|
|
254
|
+
*/
|
|
255
|
+
}, {
|
|
256
|
+
key: "isFilterOnlyWithModifier",
|
|
257
|
+
value: function isFilterOnlyWithModifier(modifier, filterColumn) {
|
|
258
|
+
if (isDateColumn(filterColumn)) {
|
|
259
|
+
return !DATE_MODIFIERS_REQUIRE_TERM.includes(modifier);
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "validateTerm",
|
|
265
|
+
value: function validateTerm(term, predicate, modifier, filterColumn) {
|
|
266
|
+
if (this.isTermMissing(term)) {
|
|
267
|
+
return {
|
|
268
|
+
error_message: FILTER_ERR_MSG.INCOMPLETE_FILTER
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (!this.isValidTerm(term, predicate, modifier, filterColumn)) {
|
|
272
|
+
return {
|
|
273
|
+
error_message: FILTER_ERR_MSG.INVALID_TERM
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
error_message: null
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
key: "isTermMissing",
|
|
282
|
+
value: function isTermMissing(term) {
|
|
283
|
+
return !term && term !== 0 && term !== false || Array.isArray(term) && term.length === 0;
|
|
284
|
+
}
|
|
285
|
+
}, {
|
|
286
|
+
key: "isValidTerm",
|
|
287
|
+
value: function isValidTerm(term, predicate, modifier, filterColumn) {
|
|
288
|
+
switch (filterColumn.type) {
|
|
289
|
+
case CellType.TEXT:
|
|
290
|
+
case CellType.GEOLOCATION:
|
|
291
|
+
case CellType.AUTO_NUMBER:
|
|
292
|
+
case CellType.EMAIL:
|
|
293
|
+
case CellType.URL:
|
|
294
|
+
case CellType.STRING:
|
|
295
|
+
{
|
|
296
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.STRING);
|
|
297
|
+
}
|
|
298
|
+
case CellType.SINGLE_SELECT:
|
|
299
|
+
{
|
|
300
|
+
var options = getColumnOptions(filterColumn);
|
|
301
|
+
if (PREDICATES_REQUIRE_ARRAY_TERM.includes(predicate)) {
|
|
302
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// contains deleted option(s)
|
|
307
|
+
return this.isValidSelectedOptions(term, options);
|
|
308
|
+
}
|
|
309
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.STRING)) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// invalid filter_term if selected option is deleted
|
|
314
|
+
return !!options.find(function (option) {
|
|
315
|
+
return term === option.id;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
case CellType.NUMBER:
|
|
319
|
+
case CellType.DURATION:
|
|
320
|
+
case CellType.RATE:
|
|
321
|
+
{
|
|
322
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.NUMBER);
|
|
323
|
+
}
|
|
324
|
+
case CellType.CHECKBOX:
|
|
325
|
+
case CellType.BOOL:
|
|
326
|
+
{
|
|
327
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.BOOLEAN);
|
|
328
|
+
}
|
|
329
|
+
case CellType.COLLABORATOR:
|
|
330
|
+
case CellType.CREATOR:
|
|
331
|
+
case CellType.LAST_MODIFIER:
|
|
332
|
+
{
|
|
333
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.ARRAY);
|
|
334
|
+
}
|
|
335
|
+
case CellType.MULTIPLE_SELECT:
|
|
336
|
+
{
|
|
337
|
+
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// contains deleted option(s)
|
|
342
|
+
var _options = getColumnOptions(filterColumn);
|
|
343
|
+
return this.isValidSelectedOptions(term, _options);
|
|
344
|
+
}
|
|
345
|
+
case CellType.DATE:
|
|
346
|
+
case CellType.CTIME:
|
|
347
|
+
case CellType.MTIME:
|
|
348
|
+
{
|
|
349
|
+
if (MODIFIERS_REQUIRE_NUMERIC_TERM.includes(modifier)) {
|
|
350
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.NUMBER);
|
|
351
|
+
}
|
|
352
|
+
return this.isValidTermType(term, TERM_TYPE_MAP.STRING);
|
|
353
|
+
}
|
|
354
|
+
case CellType.FORMULA:
|
|
355
|
+
case CellType.LINK_FORMULA:
|
|
356
|
+
{
|
|
357
|
+
var data = filterColumn.data;
|
|
358
|
+
var result_type = data.result_type;
|
|
359
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
360
|
+
return this.isValidTermWithArrayType(term, predicate, modifier, filterColumn);
|
|
361
|
+
}
|
|
362
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
363
|
+
type: result_type
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
case CellType.LINK:
|
|
367
|
+
{
|
|
368
|
+
return this.isValidTermWithArrayType(term, predicate, modifier, filterColumn);
|
|
369
|
+
}
|
|
370
|
+
default:
|
|
371
|
+
{
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "isValidTermType",
|
|
378
|
+
value: function isValidTermType(term, type) {
|
|
379
|
+
if (type === TERM_TYPE_MAP.ARRAY) {
|
|
380
|
+
return Array.isArray(term) && term.length > 0;
|
|
381
|
+
}
|
|
382
|
+
if (type === CellType.NUMBER) {
|
|
383
|
+
// is a number or a number string
|
|
384
|
+
// eslint-disable-next-line
|
|
385
|
+
return _typeof(term) === type || !isNaN(Number(term));
|
|
386
|
+
}
|
|
387
|
+
// eslint-disable-next-line
|
|
388
|
+
return _typeof(term) === type;
|
|
389
|
+
}
|
|
390
|
+
}, {
|
|
391
|
+
key: "isValidTermWithArrayType",
|
|
392
|
+
value: function isValidTermWithArrayType(term, predicate, modifier, filterColumn) {
|
|
393
|
+
var data = filterColumn.data;
|
|
394
|
+
var array_type = data.array_type,
|
|
395
|
+
array_data = data.array_data;
|
|
396
|
+
if (array_type === CellType.SINGLE_SELECT) {
|
|
397
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
398
|
+
type: CellType.MULTIPLE_SELECT,
|
|
399
|
+
data: array_data
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
403
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
404
|
+
type: CellType.COLLABORATOR
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return this.isValidTerm(term, predicate, modifier, {
|
|
408
|
+
type: array_type,
|
|
409
|
+
data: array_data
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}, {
|
|
413
|
+
key: "isValidColumnType",
|
|
414
|
+
value: function isValidColumnType(filterColumn) {
|
|
415
|
+
var columnType = filterColumn.type,
|
|
416
|
+
data = filterColumn.data;
|
|
417
|
+
if (FORMULA_COLUMN_TYPES_MAP[columnType] || columnType === CellType.LINK) {
|
|
418
|
+
if (!data) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
var result_type = data.result_type,
|
|
422
|
+
array_type = data.array_type;
|
|
423
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
424
|
+
return this.isValidColumnType({
|
|
425
|
+
type: array_type
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return this.isValidColumnType({
|
|
429
|
+
type: result_type
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
// eslint-disable-next-line
|
|
433
|
+
return FILTER_COLUMN_OPTIONS.hasOwnProperty(columnType);
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
key: "isValidSelectedOptions",
|
|
437
|
+
value: function isValidSelectedOptions(selectedOptionIds, options) {
|
|
438
|
+
var validSelectedOptions = options.filter(function (option) {
|
|
439
|
+
return selectedOptionIds.includes(option.id);
|
|
440
|
+
});
|
|
441
|
+
return selectedOptionIds.length === validSelectedOptions.length;
|
|
442
|
+
}
|
|
443
|
+
}]);
|
|
444
|
+
return ValidateFilter;
|
|
445
|
+
}();
|
|
446
|
+
|
|
447
|
+
export { DATE_MODIFIERS_REQUIRE_TERM, ValidateFilter };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var cellType = require('../constants/cell-type.js');
|
|
6
|
+
var column = require('../constants/column.js');
|
|
7
|
+
var formula = require('../constants/formula.js');
|
|
8
|
+
var date$1 = require('../date.js');
|
|
9
|
+
var collaborator = require('./collaborator.js');
|
|
10
|
+
var date = require('./date.js');
|
|
11
|
+
var digitalSign = require('./digital-sign.js');
|
|
12
|
+
var duration = require('./duration.js');
|
|
13
|
+
var geolocation = require('./geolocation.js');
|
|
14
|
+
var longText = require('./long-text.js');
|
|
15
|
+
var number = require('./number.js');
|
|
16
|
+
var option = require('./option.js');
|
|
17
|
+
|
|
18
|
+
var ARRAY_VALUE_COLUMN_TYPES = [cellType.CellType.IMAGE, cellType.CellType.FILE, cellType.CellType.MULTIPLE_SELECT, cellType.CellType.COLLABORATOR];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get formatted formula result to display. It will not be formatted
|
|
22
|
+
* if formula result_type is array and array_type is collaborator, creator or last-modifier etc.
|
|
23
|
+
* @param {any} cellValue
|
|
24
|
+
* @param {object} columnData the data from column
|
|
25
|
+
* @returns formatted formula result, string|array
|
|
26
|
+
*/
|
|
27
|
+
var getFormulaDisplayString = function getFormulaDisplayString(cellValue, columnData) {
|
|
28
|
+
if (!columnData) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
var result_type = columnData.result_type;
|
|
32
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.NUMBER) {
|
|
33
|
+
return number.getNumberDisplayString(cellValue, columnData);
|
|
34
|
+
}
|
|
35
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.DATE) {
|
|
36
|
+
var format = columnData.format;
|
|
37
|
+
return date.getDateDisplayString(cellValue, format);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// rollup result_type is an array, cellValue may not be an array
|
|
41
|
+
if (result_type === formula.FORMULA_RESULT_TYPE.ARRAY) {
|
|
42
|
+
var array_type = columnData.array_type,
|
|
43
|
+
array_data = columnData.array_data;
|
|
44
|
+
if (!array_type) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
if (column.COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
48
|
+
return cellValue;
|
|
49
|
+
}
|
|
50
|
+
if (!ARRAY_VALUE_COLUMN_TYPES.includes(array_type) && Array.isArray(cellValue)) {
|
|
51
|
+
return cellValue.map(function (val) {
|
|
52
|
+
return getCellValueDisplayString({
|
|
53
|
+
FORMULA_ARRAY: val
|
|
54
|
+
}, array_type, 'FORMULA_ARRAY', {
|
|
55
|
+
data: array_data
|
|
56
|
+
});
|
|
57
|
+
}).join(', ');
|
|
58
|
+
}
|
|
59
|
+
return getCellValueDisplayString({
|
|
60
|
+
FORMULA_ARRAY: cellValue
|
|
61
|
+
}, array_type, 'FORMULA_ARRAY', {
|
|
62
|
+
data: array_data
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (Object.prototype.toString.call(cellValue) === '[object Boolean]') {
|
|
66
|
+
return String(cellValue);
|
|
67
|
+
}
|
|
68
|
+
return cellValue;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get formatted cell value to display.
|
|
73
|
+
* @param {object} row e.g. { [column.key]: 'xxx' }
|
|
74
|
+
* @param {string} type column type
|
|
75
|
+
* @param {string} key column key
|
|
76
|
+
* @param {object} data column data
|
|
77
|
+
* @param {object} formulaRows formula results of rows. Default as "{}"
|
|
78
|
+
* @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]. Default as "[]"
|
|
79
|
+
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
80
|
+
* @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
81
|
+
* @returns formatted cell value, string|array
|
|
82
|
+
*/
|
|
83
|
+
var getCellValueDisplayString = function getCellValueDisplayString(row, type, key) {
|
|
84
|
+
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
85
|
+
data = _ref.data,
|
|
86
|
+
_ref$formulaRows = _ref.formulaRows,
|
|
87
|
+
formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
|
|
88
|
+
_ref$collaborators = _ref.collaborators,
|
|
89
|
+
collaborators = _ref$collaborators === void 0 ? [] : _ref$collaborators,
|
|
90
|
+
_ref$isBaiduMap = _ref.isBaiduMap,
|
|
91
|
+
isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
|
|
92
|
+
_ref$geolocationHyphe = _ref.geolocationHyphen,
|
|
93
|
+
geolocationHyphen = _ref$geolocationHyphe === void 0 ? '' : _ref$geolocationHyphe;
|
|
94
|
+
if (!row) return '';
|
|
95
|
+
var cellValue = row[key];
|
|
96
|
+
switch (type) {
|
|
97
|
+
case cellType.CellType.LONG_TEXT:
|
|
98
|
+
{
|
|
99
|
+
return longText.getLongtextDisplayString(cellValue);
|
|
100
|
+
}
|
|
101
|
+
case cellType.CellType.NUMBER:
|
|
102
|
+
{
|
|
103
|
+
return number.getNumberDisplayString(cellValue, data);
|
|
104
|
+
}
|
|
105
|
+
case cellType.CellType.DURATION:
|
|
106
|
+
{
|
|
107
|
+
return duration.getDurationDisplayString(cellValue, data);
|
|
108
|
+
}
|
|
109
|
+
case cellType.CellType.GEOLOCATION:
|
|
110
|
+
{
|
|
111
|
+
return geolocation.getGeolocationDisplayString(cellValue, data, {
|
|
112
|
+
isBaiduMap: isBaiduMap,
|
|
113
|
+
hyphen: geolocationHyphen
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
case cellType.CellType.SINGLE_SELECT:
|
|
117
|
+
{
|
|
118
|
+
if (!data) return '';
|
|
119
|
+
var options = data.options;
|
|
120
|
+
return option.getOptionName(options, cellValue);
|
|
121
|
+
}
|
|
122
|
+
case cellType.CellType.MULTIPLE_SELECT:
|
|
123
|
+
{
|
|
124
|
+
if (!data) return '';
|
|
125
|
+
var _options = data.options;
|
|
126
|
+
return option.getMultipleOptionName(_options, cellValue);
|
|
127
|
+
}
|
|
128
|
+
case cellType.CellType.DATE:
|
|
129
|
+
{
|
|
130
|
+
var _ref2 = data || {},
|
|
131
|
+
_ref2$format = _ref2.format,
|
|
132
|
+
format = _ref2$format === void 0 ? column.DEFAULT_DATE_FORMAT : _ref2$format;
|
|
133
|
+
return date.getDateDisplayString(cellValue, format);
|
|
134
|
+
}
|
|
135
|
+
case cellType.CellType.CTIME:
|
|
136
|
+
case cellType.CellType.MTIME:
|
|
137
|
+
{
|
|
138
|
+
return date$1.DateUtils.format(cellValue, 'YYYY-MM-DD HH:MM:SS');
|
|
139
|
+
}
|
|
140
|
+
case cellType.CellType.COLLABORATOR:
|
|
141
|
+
{
|
|
142
|
+
return collaborator.getCollaboratorsName(collaborators, cellValue);
|
|
143
|
+
}
|
|
144
|
+
case cellType.CellType.CREATOR:
|
|
145
|
+
case cellType.CellType.LAST_MODIFIER:
|
|
146
|
+
{
|
|
147
|
+
return cellValue === 'anonymous' ? cellValue : collaborator.getCollaboratorsName(collaborators, [cellValue]);
|
|
148
|
+
}
|
|
149
|
+
case cellType.CellType.FORMULA:
|
|
150
|
+
case cellType.CellType.LINK_FORMULA:
|
|
151
|
+
{
|
|
152
|
+
var formulaRow = formulaRows[row._id] || {};
|
|
153
|
+
return getFormulaDisplayString(formulaRow[key], data);
|
|
154
|
+
}
|
|
155
|
+
case cellType.CellType.DIGITAL_SIGN:
|
|
156
|
+
{
|
|
157
|
+
return digitalSign.getDigitalSignImageUrl(cellValue);
|
|
158
|
+
}
|
|
159
|
+
default:
|
|
160
|
+
{
|
|
161
|
+
if (cellValue || typeof cellValue === 'boolean') {
|
|
162
|
+
return String(cellValue);
|
|
163
|
+
}
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
exports.getCellValueDisplayString = getCellValueDisplayString;
|
|
170
|
+
exports.getFormulaDisplayString = getFormulaDisplayString;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get collaborators name list of given emails
|
|
7
|
+
* @param {array} emails e.g. ['email', ...]
|
|
8
|
+
* @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
|
|
9
|
+
* @returns name list, array. e.g. ['name1', 'name2']
|
|
10
|
+
*/
|
|
11
|
+
var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
|
|
12
|
+
if (!Array.isArray(emails) || !Array.isArray(collaborators)) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
var emailCollaboratorMap = {};
|
|
16
|
+
collaborators.forEach(function (collaborator) {
|
|
17
|
+
emailCollaboratorMap[collaborator.email] = collaborator;
|
|
18
|
+
});
|
|
19
|
+
return emails.map(function (email) {
|
|
20
|
+
var collaborator = emailCollaboratorMap[email];
|
|
21
|
+
return collaborator && collaborator.name;
|
|
22
|
+
}).filter(Boolean);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get concatenated collaborators names of given emails.
|
|
27
|
+
* @param {array} collaborators e.g. [{ email: 'xxx', name: 'xxx' }, ...]
|
|
28
|
+
* @param {array} emails e.g. ['email', ...]
|
|
29
|
+
* @returns concatenated collaborators names, string. e.g. 'name1, name2'
|
|
30
|
+
*/
|
|
31
|
+
var getCollaboratorsName = function getCollaboratorsName(collaborators, emails) {
|
|
32
|
+
var collaboratorsNames = getCollaboratorsNames(emails, collaborators);
|
|
33
|
+
if (!Array.isArray(collaboratorsNames) || collaboratorsNames.length === 0) return '';
|
|
34
|
+
return collaboratorsNames.join(', ');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.getCollaboratorsName = getCollaboratorsName;
|
|
38
|
+
exports.getCollaboratorsNames = getCollaboratorsNames;
|