dtable-utils 0.0.3-beta.1 → 0.0.4-beta.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 +12 -3
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +82 -60
- package/es/cell-value-get/collaborator.js +9 -2
- package/es/cell-value-get/duration.js +3 -3
- package/es/cell-value-get/geolocation.js +23 -25
- package/es/cell-value-get/number.js +19 -11
- package/es/cell-value-get/option.js +18 -4
- package/es/cell-value-get/rate.js +5 -0
- package/es/cell-value-set/date.js +9 -3
- package/es/{column/color.js → color/column-color.js} +25 -3
- package/es/{row/color.js → color/row-color.js} +12 -1
- package/es/column/option.js +37 -7
- package/es/common.js +23 -2
- package/es/constants/formula.js +2 -1
- package/es/filter/core.js +61 -26
- package/es/filter/filter-column/array.js +35 -30
- package/es/filter/filter-column/checkbox.js +9 -3
- package/es/filter/filter-column/collaborator.js +20 -15
- package/es/filter/filter-column/creator.js +22 -13
- package/es/filter/filter-column/date.js +57 -14
- package/es/filter/filter-column/digital-sign.js +11 -8
- package/es/filter/filter-column/file.js +9 -6
- package/es/filter/filter-column/formula.js +16 -8
- package/es/filter/filter-column/geolocation.js +12 -7
- package/es/filter/filter-column/link.js +10 -2
- package/es/filter/filter-column/long-text.js +10 -7
- package/es/filter/filter-column/multiple-select.js +17 -13
- package/es/filter/filter-column/number.js +25 -21
- package/es/filter/filter-column/single-select.js +14 -10
- package/es/filter/filter-column/text.js +18 -13
- package/es/filter/filter-row.js +35 -0
- package/es/group/core.js +15 -6
- package/es/group/group-row.js +39 -3
- package/es/index.js +10 -10
- package/es/link/core.js +14 -14
- package/es/number.js +11 -3
- package/es/row/core.js +20 -1
- package/es/sort/core.js +66 -7
- package/es/sort/sort-column/array.js +39 -30
- package/es/sort/sort-column/checkbox.js +12 -5
- package/es/sort/sort-column/collaborator.js +11 -4
- package/es/sort/sort-column/date.js +12 -12
- package/es/sort/sort-column/formula.js +21 -12
- package/es/sort/sort-column/link.js +18 -9
- package/es/sort/sort-column/multiple-select.js +26 -26
- package/es/sort/sort-column/number.js +15 -8
- package/es/sort/sort-column/single-select.js +16 -8
- package/es/sort/sort-column/text.js +24 -10
- package/es/sort/sort-row.js +22 -38
- package/es/table/column.js +2 -2
- package/es/table/core.js +2 -2
- package/es/table/row.js +4 -4
- package/es/view/core.js +20 -21
- package/es/view/formula.js +35 -31
- package/es/view/group.js +4 -4
- package/es/view/summaries.js +17 -29
- package/lib/cell-value-get/cell-value.js +82 -60
- package/lib/cell-value-get/collaborator.js +9 -2
- package/lib/cell-value-get/duration.js +4 -2
- package/lib/cell-value-get/geolocation.js +23 -25
- package/lib/cell-value-get/number.js +19 -11
- package/lib/cell-value-get/option.js +18 -4
- package/lib/cell-value-get/rate.js +5 -0
- package/lib/cell-value-set/date.js +9 -3
- package/lib/{column/color.js → color/column-color.js} +31 -9
- package/lib/{row/color.js → color/row-color.js} +12 -1
- package/lib/column/option.js +37 -7
- package/lib/common.js +23 -1
- package/lib/constants/formula.js +2 -0
- package/lib/filter/core.js +61 -26
- package/lib/filter/filter-column/array.js +35 -30
- package/lib/filter/filter-column/checkbox.js +9 -3
- package/lib/filter/filter-column/collaborator.js +20 -15
- package/lib/filter/filter-column/creator.js +22 -13
- package/lib/filter/filter-column/date.js +57 -14
- package/lib/filter/filter-column/digital-sign.js +11 -8
- package/lib/filter/filter-column/file.js +9 -6
- package/lib/filter/filter-column/formula.js +16 -8
- package/lib/filter/filter-column/geolocation.js +12 -7
- package/lib/filter/filter-column/link.js +10 -2
- package/lib/filter/filter-column/long-text.js +10 -7
- package/lib/filter/filter-column/multiple-select.js +17 -13
- package/lib/filter/filter-column/number.js +25 -21
- package/lib/filter/filter-column/single-select.js +14 -10
- package/lib/filter/filter-column/text.js +18 -13
- package/lib/filter/filter-row.js +35 -0
- package/lib/group/core.js +15 -6
- package/lib/group/group-row.js +39 -3
- package/lib/index.js +47 -45
- package/lib/link/core.js +14 -14
- package/lib/number.js +11 -3
- package/lib/row/core.js +20 -1
- package/lib/sort/core.js +71 -6
- package/lib/sort/sort-column/array.js +39 -30
- package/lib/sort/sort-column/checkbox.js +12 -5
- package/lib/sort/sort-column/collaborator.js +11 -4
- package/lib/sort/sort-column/date.js +12 -12
- package/lib/sort/sort-column/formula.js +21 -12
- package/lib/sort/sort-column/link.js +18 -9
- package/lib/sort/sort-column/multiple-select.js +25 -26
- package/lib/sort/sort-column/number.js +15 -8
- package/lib/sort/sort-column/single-select.js +16 -8
- package/lib/sort/sort-column/text.js +24 -10
- package/lib/sort/sort-row.js +21 -42
- package/lib/table/column.js +2 -2
- package/lib/table/core.js +2 -2
- package/lib/table/row.js +4 -4
- package/lib/view/core.js +20 -21
- package/lib/view/formula.js +35 -31
- package/lib/view/group.js +4 -4
- package/lib/view/summaries.js +17 -29
- package/package.json +1 -1
- package/es/table/index.js +0 -14
- package/lib/table/index.js +0 -18
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import '../../constants/filter/filter-column-options.js';
|
|
2
|
-
import '../../constants/filter/filter-modifier.js';
|
|
3
1
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
4
|
-
import '../../constants/filter/filter-is-within.js';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter digital signature
|
|
5
|
+
* @param {object} digitalSignature e.g. { username, sign_time, sign_image_url, ... }
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @returns bool
|
|
8
|
+
*/
|
|
9
|
+
var digitalSignFilter = function digitalSignFilter(digitalSignature, _ref) {
|
|
7
10
|
var filter_predicate = _ref.filter_predicate;
|
|
8
11
|
switch (filter_predicate) {
|
|
9
12
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
10
13
|
{
|
|
11
|
-
if (!
|
|
12
|
-
return !
|
|
14
|
+
if (!digitalSignature) return true;
|
|
15
|
+
return !digitalSignature.username || !digitalSignature.sign_time || !digitalSignature.sign_image_url;
|
|
13
16
|
}
|
|
14
17
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
15
18
|
{
|
|
16
|
-
if (!
|
|
17
|
-
return
|
|
19
|
+
if (!digitalSignature) return false;
|
|
20
|
+
return !!(digitalSignature.username && digitalSignature.sign_time && digitalSignature.sign_image_url);
|
|
18
21
|
}
|
|
19
22
|
default:
|
|
20
23
|
{
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import '../../constants/filter/filter-column-options.js';
|
|
2
|
-
import '../../constants/filter/filter-modifier.js';
|
|
3
1
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
4
|
-
import '../../constants/filter/filter-is-within.js';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter file
|
|
5
|
+
* @param {array} files e.g. [{ name, type, url, ... }] | [ url1, ... ]
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @returns bool
|
|
8
|
+
*/
|
|
9
|
+
var fileFilter = function fileFilter(files, _ref) {
|
|
7
10
|
var filter_predicate = _ref.filter_predicate;
|
|
8
11
|
switch (filter_predicate) {
|
|
9
12
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
10
13
|
{
|
|
11
|
-
return
|
|
14
|
+
return !(files && files.length > 0);
|
|
12
15
|
}
|
|
13
16
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
14
17
|
{
|
|
15
|
-
return
|
|
18
|
+
return !!(files && files.length > 0);
|
|
16
19
|
}
|
|
17
20
|
default:
|
|
18
21
|
{
|
|
@@ -6,7 +6,15 @@ import { filterByArrayType } from './array.js';
|
|
|
6
6
|
import { getFormulaDisplayString } from '../../cell-value-get/cell-value.js';
|
|
7
7
|
import { FORMULA_RESULT_TYPE } from '../../constants/formula.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Filter formula
|
|
11
|
+
* @param {any} computedValue cell value from formulaRow
|
|
12
|
+
* @param {object} filter e.g. { filter_predicate, column, ... }
|
|
13
|
+
* @param {string} username
|
|
14
|
+
* @param {string} userId
|
|
15
|
+
* @returns bool
|
|
16
|
+
*/
|
|
17
|
+
var formulaFilter = function formulaFilter(computedValue, filter, _ref) {
|
|
10
18
|
var username = _ref.username,
|
|
11
19
|
userId = _ref.userId;
|
|
12
20
|
var data = filter.column.data;
|
|
@@ -15,25 +23,25 @@ var formulaFilter = function formulaFilter(cellValue, filter, _ref) {
|
|
|
15
23
|
switch (result_type) {
|
|
16
24
|
case FORMULA_RESULT_TYPE.NUMBER:
|
|
17
25
|
{
|
|
18
|
-
return numberFilter(
|
|
26
|
+
return numberFilter(computedValue, filter);
|
|
19
27
|
}
|
|
20
28
|
case FORMULA_RESULT_TYPE.DATE:
|
|
21
29
|
{
|
|
22
|
-
return dateFilter(
|
|
30
|
+
return dateFilter(computedValue, filter);
|
|
23
31
|
}
|
|
24
32
|
case FORMULA_RESULT_TYPE.BOOL:
|
|
25
33
|
{
|
|
26
|
-
var normalizedCellValue =
|
|
27
|
-
if (
|
|
34
|
+
var normalizedCellValue = computedValue;
|
|
35
|
+
if (computedValue === 'true') {
|
|
28
36
|
normalizedCellValue = true;
|
|
29
|
-
} else if (
|
|
37
|
+
} else if (computedValue === 'false') {
|
|
30
38
|
normalizedCellValue = false;
|
|
31
39
|
}
|
|
32
40
|
return checkboxFilter(normalizedCellValue, filter);
|
|
33
41
|
}
|
|
34
42
|
case FORMULA_RESULT_TYPE.ARRAY:
|
|
35
43
|
{
|
|
36
|
-
return filterByArrayType(
|
|
44
|
+
return filterByArrayType(computedValue, filter, {
|
|
37
45
|
username: username,
|
|
38
46
|
userId: userId
|
|
39
47
|
});
|
|
@@ -41,7 +49,7 @@ var formulaFilter = function formulaFilter(cellValue, filter, _ref) {
|
|
|
41
49
|
default:
|
|
42
50
|
{
|
|
43
51
|
// FORMULA_RESULT_TYPE.STRING
|
|
44
|
-
return textFilter(getFormulaDisplayString(
|
|
52
|
+
return textFilter(getFormulaDisplayString(computedValue, data) || '', filter, userId);
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
};
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { getGeolocationDisplayString } from '../../cell-value-get/geolocation.js';
|
|
2
|
-
import '../../constants/filter/filter-column-options.js';
|
|
3
|
-
import '../../constants/filter/filter-modifier.js';
|
|
4
2
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
5
|
-
import '../../constants/filter/filter-is-within.js';
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Filter geolocation
|
|
6
|
+
* @param {object} location e.g. { province, ... }
|
|
7
|
+
* @param {string} filter_predicate
|
|
8
|
+
* @param {string} filter_term
|
|
9
|
+
* @param {object} column e.g. { type, data: { geo_format, ... }, ... }
|
|
10
|
+
* @returns bool
|
|
11
|
+
*/
|
|
12
|
+
var geolocationFilter = function geolocationFilter(location, _ref) {
|
|
8
13
|
var filter_predicate = _ref.filter_predicate,
|
|
9
14
|
filter_term = _ref.filter_term,
|
|
10
15
|
column = _ref.column;
|
|
11
|
-
var geolocation = getGeolocationDisplayString(
|
|
16
|
+
var geolocation = getGeolocationDisplayString(location, column.data);
|
|
12
17
|
switch (filter_predicate) {
|
|
13
18
|
case FILTER_PREDICATE_TYPE.CONTAINS:
|
|
14
19
|
{
|
|
@@ -37,11 +42,11 @@ var geolocationFilter = function geolocationFilter(cellValue, _ref) {
|
|
|
37
42
|
}
|
|
38
43
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
39
44
|
{
|
|
40
|
-
return geolocation
|
|
45
|
+
return !geolocation;
|
|
41
46
|
}
|
|
42
47
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
43
48
|
{
|
|
44
|
-
return geolocation
|
|
49
|
+
return !!geolocation;
|
|
45
50
|
}
|
|
46
51
|
default:
|
|
47
52
|
{
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { filterByArrayType } from './array.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter link
|
|
5
|
+
* @param {array} linkedCellValues e.g. [ displayCellValue, ... ]
|
|
6
|
+
* @param {object} filter e.g. { filter_predicate, column, ... }
|
|
7
|
+
* @param {string} username
|
|
8
|
+
* @param {string} userId
|
|
9
|
+
* @returns bool
|
|
10
|
+
*/
|
|
11
|
+
var linkFilter = function linkFilter(linkedCellValues, filter, _ref) {
|
|
4
12
|
var username = _ref.username,
|
|
5
13
|
userId = _ref.userId;
|
|
6
|
-
return filterByArrayType(
|
|
14
|
+
return filterByArrayType(linkedCellValues, filter, {
|
|
7
15
|
username: username,
|
|
8
16
|
userId: userId
|
|
9
17
|
});
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import '../../constants/filter/filter-column-options.js';
|
|
2
|
-
import '../../constants/filter/filter-modifier.js';
|
|
3
1
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
4
|
-
import '../../constants/filter/filter-is-within.js';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter long-text
|
|
5
|
+
* @param {object} longText e.g. { text, ... }
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @returns bool
|
|
8
|
+
*/
|
|
9
|
+
var longTextFilter = function longTextFilter(longText, _ref) {
|
|
7
10
|
var filter_predicate = _ref.filter_predicate;
|
|
8
|
-
var text =
|
|
11
|
+
var text = longText ? longText.text : null;
|
|
9
12
|
switch (filter_predicate) {
|
|
10
13
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
11
14
|
{
|
|
12
|
-
return text
|
|
15
|
+
return !text;
|
|
13
16
|
}
|
|
14
17
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
15
18
|
{
|
|
16
|
-
return text
|
|
19
|
+
return !!text;
|
|
17
20
|
}
|
|
18
21
|
default:
|
|
19
22
|
{
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
-
import '../../constants/filter/filter-column-options.js';
|
|
3
|
-
import '../../constants/filter/filter-modifier.js';
|
|
4
2
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
5
|
-
import '../../constants/filter/filter-is-within.js';
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Filter multiple-select
|
|
6
|
+
* @param {array} optionIds e.g. [ option.id, ... ]
|
|
7
|
+
* @param {string} filter_predicate
|
|
8
|
+
* @param {array} filter_term option ids
|
|
9
|
+
* @returns bool
|
|
10
|
+
*/
|
|
11
|
+
var multipleSelectFilter = function multipleSelectFilter(optionIds, _ref) {
|
|
8
12
|
var filter_predicate = _ref.filter_predicate,
|
|
9
13
|
filter_term = _ref.filter_term;
|
|
10
14
|
switch (filter_predicate) {
|
|
11
15
|
case FILTER_PREDICATE_TYPE.HAS_ANY_OF:
|
|
12
16
|
{
|
|
13
|
-
return filter_term.length === 0 || Array.isArray(
|
|
17
|
+
return filter_term.length === 0 || Array.isArray(optionIds) && optionIds.some(function (optionId) {
|
|
14
18
|
return filter_term.includes(optionId);
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
21
|
case FILTER_PREDICATE_TYPE.HAS_ALL_OF:
|
|
18
22
|
{
|
|
19
|
-
return filter_term.length === 0 || Array.isArray(
|
|
20
|
-
return
|
|
23
|
+
return filter_term.length === 0 || Array.isArray(optionIds) && filter_term.every(function (optionId) {
|
|
24
|
+
return optionIds.includes(optionId);
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
27
|
case FILTER_PREDICATE_TYPE.HAS_NONE_OF:
|
|
24
28
|
{
|
|
25
|
-
if (filter_term.length === 0 || !Array.isArray(
|
|
29
|
+
if (filter_term.length === 0 || !Array.isArray(optionIds) || optionIds.length === 0) {
|
|
26
30
|
return true;
|
|
27
31
|
}
|
|
28
32
|
return filter_term.every(function (optionId) {
|
|
29
|
-
return
|
|
33
|
+
return optionIds.indexOf(optionId) < 0;
|
|
30
34
|
});
|
|
31
35
|
}
|
|
32
36
|
case FILTER_PREDICATE_TYPE.IS_EXACTLY:
|
|
@@ -34,21 +38,21 @@ var multipleSelectFilter = function multipleSelectFilter(cellValue, _ref) {
|
|
|
34
38
|
if (filter_term.length === 0) {
|
|
35
39
|
return true;
|
|
36
40
|
}
|
|
37
|
-
if (!Array.isArray(
|
|
41
|
+
if (!Array.isArray(optionIds)) {
|
|
38
42
|
return false;
|
|
39
43
|
}
|
|
40
44
|
var uniqueArr = function uniqueArr(arr) {
|
|
41
45
|
return _toConsumableArray(new Set(arr)).sort();
|
|
42
46
|
};
|
|
43
|
-
return uniqueArr(
|
|
47
|
+
return uniqueArr(optionIds).toString() === uniqueArr(filter_term).toString();
|
|
44
48
|
}
|
|
45
49
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
46
50
|
{
|
|
47
|
-
return !Array.isArray(
|
|
51
|
+
return !Array.isArray(optionIds) || optionIds.length === 0;
|
|
48
52
|
}
|
|
49
53
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
50
54
|
{
|
|
51
|
-
return Array.isArray(
|
|
55
|
+
return Array.isArray(optionIds) && optionIds.length > 0;
|
|
52
56
|
}
|
|
53
57
|
default:
|
|
54
58
|
{
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { isNumberEqual } from '../../number.js';
|
|
2
|
-
import '../../constants/filter/filter-column-options.js';
|
|
3
|
-
import '../../constants/filter/filter-modifier.js';
|
|
4
2
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
5
|
-
import '../../constants/filter/filter-is-within.js';
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Filter number
|
|
6
|
+
* @param {number} number
|
|
7
|
+
* @param {string} filter_predicate
|
|
8
|
+
* @param {number} filter_term
|
|
9
|
+
* @returns bool
|
|
10
|
+
*/
|
|
11
|
+
var numberFilter = function numberFilter(number, _ref) {
|
|
8
12
|
var filter_predicate = _ref.filter_predicate,
|
|
9
13
|
filter_term = _ref.filter_term;
|
|
10
14
|
switch (filter_predicate) {
|
|
@@ -13,75 +17,75 @@ var numberFilter = function numberFilter(cellValue, _ref) {
|
|
|
13
17
|
if (!filter_term && filter_term !== 0) {
|
|
14
18
|
return true;
|
|
15
19
|
}
|
|
16
|
-
if (!
|
|
20
|
+
if (!number && number !== 0) {
|
|
17
21
|
return false;
|
|
18
22
|
}
|
|
19
|
-
return isNumberEqual(filter_term,
|
|
23
|
+
return isNumberEqual(filter_term, number);
|
|
20
24
|
}
|
|
21
25
|
case FILTER_PREDICATE_TYPE.NOT_EQUAL:
|
|
22
26
|
{
|
|
23
|
-
if (!filter_term && filter_term !== 0 || !
|
|
27
|
+
if (!filter_term && filter_term !== 0 || !number && number !== 0) {
|
|
24
28
|
return true;
|
|
25
29
|
}
|
|
26
|
-
return !isNumberEqual(filter_term,
|
|
30
|
+
return !isNumberEqual(filter_term, number);
|
|
27
31
|
}
|
|
28
32
|
case FILTER_PREDICATE_TYPE.LESS:
|
|
29
33
|
{
|
|
30
34
|
if (!filter_term && filter_term !== 0) {
|
|
31
35
|
return true;
|
|
32
36
|
}
|
|
33
|
-
if (!
|
|
37
|
+
if (!number && number !== 0 || isNumberEqual(number, filter_term)) {
|
|
34
38
|
return false;
|
|
35
39
|
}
|
|
36
|
-
return
|
|
40
|
+
return number < filter_term;
|
|
37
41
|
}
|
|
38
42
|
case FILTER_PREDICATE_TYPE.GREATER:
|
|
39
43
|
{
|
|
40
44
|
if (!filter_term && filter_term !== 0) {
|
|
41
45
|
return true;
|
|
42
46
|
}
|
|
43
|
-
if (!
|
|
47
|
+
if (!number && number !== 0 || isNumberEqual(number, filter_term)) {
|
|
44
48
|
return false;
|
|
45
49
|
}
|
|
46
|
-
return
|
|
50
|
+
return number > filter_term;
|
|
47
51
|
}
|
|
48
52
|
case FILTER_PREDICATE_TYPE.LESS_OR_EQUAL:
|
|
49
53
|
{
|
|
50
54
|
if (!filter_term && filter_term !== 0) {
|
|
51
55
|
return true;
|
|
52
56
|
}
|
|
53
|
-
if (!
|
|
57
|
+
if (!number && number !== 0) {
|
|
54
58
|
return false;
|
|
55
59
|
}
|
|
56
|
-
if (isNumberEqual(
|
|
60
|
+
if (isNumberEqual(number, filter_term)) {
|
|
57
61
|
return true;
|
|
58
62
|
}
|
|
59
|
-
return
|
|
63
|
+
return number < filter_term;
|
|
60
64
|
}
|
|
61
65
|
case FILTER_PREDICATE_TYPE.GREATER_OR_EQUAL:
|
|
62
66
|
{
|
|
63
67
|
if (!filter_term && filter_term !== 0) {
|
|
64
68
|
return true;
|
|
65
69
|
}
|
|
66
|
-
if (!
|
|
70
|
+
if (!number && number !== 0) {
|
|
67
71
|
return false;
|
|
68
72
|
}
|
|
69
|
-
return isNumberEqual(
|
|
73
|
+
return isNumberEqual(number, filter_term) || number > filter_term;
|
|
70
74
|
}
|
|
71
75
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
72
76
|
{
|
|
73
|
-
if (
|
|
77
|
+
if (number === 0) {
|
|
74
78
|
return false;
|
|
75
79
|
}
|
|
76
|
-
return !
|
|
80
|
+
return !number || typeof number !== 'number';
|
|
77
81
|
}
|
|
78
82
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
79
83
|
{
|
|
80
84
|
// must be a number
|
|
81
|
-
if (
|
|
85
|
+
if (number === 0) {
|
|
82
86
|
return true;
|
|
83
87
|
}
|
|
84
|
-
return
|
|
88
|
+
return !!(number && typeof number === 'number');
|
|
85
89
|
}
|
|
86
90
|
default:
|
|
87
91
|
{
|
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import '../../constants/filter/filter-column-options.js';
|
|
2
|
-
import '../../constants/filter/filter-modifier.js';
|
|
3
1
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
4
|
-
import '../../constants/filter/filter-is-within.js';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter single-select
|
|
5
|
+
* @param {string} optionId
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @param {string|array} filter_term option id or option ids
|
|
8
|
+
* @returns bool
|
|
9
|
+
*/
|
|
10
|
+
var singleSelectFilter = function singleSelectFilter(optionId, _ref) {
|
|
7
11
|
var filter_predicate = _ref.filter_predicate,
|
|
8
12
|
filter_term = _ref.filter_term;
|
|
9
13
|
switch (filter_predicate) {
|
|
10
14
|
case FILTER_PREDICATE_TYPE.IS:
|
|
11
15
|
{
|
|
12
|
-
return !filter_term ||
|
|
16
|
+
return !filter_term || optionId === filter_term;
|
|
13
17
|
}
|
|
14
18
|
case FILTER_PREDICATE_TYPE.IS_NOT:
|
|
15
19
|
{
|
|
16
|
-
return !filter_term ||
|
|
20
|
+
return !filter_term || optionId !== filter_term;
|
|
17
21
|
}
|
|
18
22
|
case FILTER_PREDICATE_TYPE.IS_ANY_OF:
|
|
19
23
|
{
|
|
20
|
-
return filter_term.length === 0 || filter_term.includes(
|
|
24
|
+
return filter_term.length === 0 || filter_term.includes(optionId);
|
|
21
25
|
}
|
|
22
26
|
case FILTER_PREDICATE_TYPE.IS_NONE_OF:
|
|
23
27
|
{
|
|
24
|
-
return filter_term.length === 0 || filter_term.indexOf(
|
|
28
|
+
return filter_term.length === 0 || filter_term.indexOf(optionId) < 0;
|
|
25
29
|
}
|
|
26
30
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
27
31
|
{
|
|
28
|
-
return
|
|
32
|
+
return !optionId;
|
|
29
33
|
}
|
|
30
34
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
31
35
|
{
|
|
32
|
-
return
|
|
36
|
+
return !!optionId;
|
|
33
37
|
}
|
|
34
38
|
default:
|
|
35
39
|
{
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import '../../constants/filter/filter-column-options.js';
|
|
2
|
-
import '../../constants/filter/filter-modifier.js';
|
|
3
1
|
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
4
|
-
import '../../constants/filter/filter-is-within.js';
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Filter text
|
|
5
|
+
* @param {string} text
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @param {string} filter_term
|
|
8
|
+
* @param {string} userId
|
|
9
|
+
* @returns bool
|
|
10
|
+
*/
|
|
11
|
+
var textFilter = function textFilter(text, _ref, userId) {
|
|
7
12
|
var filter_predicate = _ref.filter_predicate,
|
|
8
13
|
filter_term = _ref.filter_term;
|
|
9
14
|
switch (filter_predicate) {
|
|
@@ -12,38 +17,38 @@ var textFilter = function textFilter(cellValue, _ref, userId) {
|
|
|
12
17
|
if (!filter_term) {
|
|
13
18
|
return true;
|
|
14
19
|
}
|
|
15
|
-
if (!
|
|
20
|
+
if (!text) {
|
|
16
21
|
return false;
|
|
17
22
|
}
|
|
18
|
-
return
|
|
23
|
+
return text.toString().toLowerCase().indexOf(filter_term.toLowerCase()) > -1;
|
|
19
24
|
}
|
|
20
25
|
case FILTER_PREDICATE_TYPE.NOT_CONTAIN:
|
|
21
26
|
{
|
|
22
|
-
if (!filter_term || !
|
|
27
|
+
if (!filter_term || !text) {
|
|
23
28
|
return true;
|
|
24
29
|
}
|
|
25
|
-
return
|
|
30
|
+
return text.toString().toLowerCase().indexOf(filter_term.toLowerCase()) < 0;
|
|
26
31
|
}
|
|
27
32
|
case FILTER_PREDICATE_TYPE.IS:
|
|
28
33
|
{
|
|
29
|
-
return !filter_term ||
|
|
34
|
+
return !filter_term || text === filter_term;
|
|
30
35
|
}
|
|
31
36
|
case FILTER_PREDICATE_TYPE.IS_NOT:
|
|
32
37
|
{
|
|
33
|
-
return !filter_term ||
|
|
38
|
+
return !filter_term || text !== filter_term;
|
|
34
39
|
}
|
|
35
40
|
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
36
41
|
{
|
|
37
|
-
return
|
|
42
|
+
return !text;
|
|
38
43
|
}
|
|
39
44
|
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
40
45
|
{
|
|
41
|
-
return
|
|
46
|
+
return !!text;
|
|
42
47
|
}
|
|
43
48
|
case FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID:
|
|
44
49
|
{
|
|
45
50
|
if (!userId) return false;
|
|
46
|
-
return
|
|
51
|
+
return text === userId;
|
|
47
52
|
}
|
|
48
53
|
default:
|
|
49
54
|
{
|
package/es/filter/filter-row.js
CHANGED
|
@@ -113,6 +113,17 @@ var getFilterResult = function getFilterResult(row, filter, _ref) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Filter row
|
|
119
|
+
* @param {object} row e.g. { _id, .... }
|
|
120
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
121
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
122
|
+
* @param {object} formulaRow
|
|
123
|
+
* @param {string} username
|
|
124
|
+
* @param {string} userId
|
|
125
|
+
* @returns filter result, bool
|
|
126
|
+
*/
|
|
116
127
|
var filterRow = function filterRow(row, filterConjunction, filters) {
|
|
117
128
|
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
118
129
|
_ref2$formulaRow = _ref2.formulaRow,
|
|
@@ -140,6 +151,17 @@ var filterRow = function filterRow(row, filterConjunction, filters) {
|
|
|
140
151
|
}
|
|
141
152
|
return false;
|
|
142
153
|
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Filter rows
|
|
157
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
158
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
159
|
+
* @param {array} rows e.g. [{ _id, .... }, ...]
|
|
160
|
+
* @param {object} formulaRows
|
|
161
|
+
* @param {string} username
|
|
162
|
+
* @param {userId} username
|
|
163
|
+
* @returns filtered rows ids, array
|
|
164
|
+
*/
|
|
143
165
|
var filterRows = function filterRows(filterConjunction, filters, rows, _ref3) {
|
|
144
166
|
var formulaRows = _ref3.formulaRows,
|
|
145
167
|
username = _ref3.username,
|
|
@@ -159,6 +181,19 @@ var filterRows = function filterRows(filterConjunction, filters, rows, _ref3) {
|
|
|
159
181
|
});
|
|
160
182
|
return filteredRows;
|
|
161
183
|
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Filter rows without formula calculation
|
|
187
|
+
* The "formulaRows" need to be provided if you want to filter formula, link columns etc.
|
|
188
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
189
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
190
|
+
* @param {array} rows e.g. [{ _id, .... }, ...]
|
|
191
|
+
* @param {object} table e.g. { columns, ... }
|
|
192
|
+
* @param {object} formulaRows
|
|
193
|
+
* @param {string} username
|
|
194
|
+
* @param {userId} username
|
|
195
|
+
* @returns filtered rows: row_ids and error message: error_message, object
|
|
196
|
+
*/
|
|
162
197
|
var getFilteredRowsWithoutFormulaCalculation = function getFilteredRowsWithoutFormulaCalculation(filterConjunction, filters, rows, table) {
|
|
163
198
|
var _ref4 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
164
199
|
_ref4$formulaRows = _ref4.formulaRows,
|
package/es/group/core.js
CHANGED
|
@@ -10,10 +10,10 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
10
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {object} groupby { column_key
|
|
13
|
+
* Check is valid groupby
|
|
14
|
+
* @param {object} groupby e.g. { column_key, count_type, sort_type, ... }
|
|
15
15
|
* @param {array} columns
|
|
16
|
-
* @returns
|
|
16
|
+
* @returns bool
|
|
17
17
|
*/
|
|
18
18
|
var isValidGroupby = function isValidGroupby(groupby, columns) {
|
|
19
19
|
if (!groupby || !Array.isArray(columns)) return false;
|
|
@@ -28,10 +28,10 @@ var isValidGroupby = function isValidGroupby(groupby, columns) {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param {array} groupbys
|
|
31
|
+
* Get valid groupbys
|
|
32
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, ... }, ...]
|
|
33
33
|
* @param {array} columns
|
|
34
|
-
* @returns array
|
|
34
|
+
* @returns valid groupbys, array
|
|
35
35
|
*/
|
|
36
36
|
var getValidGroupbys = function getValidGroupbys(groupbys, columns) {
|
|
37
37
|
if (!Array.isArray(groupbys) || !Array.isArray(columns)) {
|
|
@@ -41,6 +41,15 @@ var getValidGroupbys = function getValidGroupbys(groupbys, columns) {
|
|
|
41
41
|
return isValidGroupby(groupby, columns);
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get valid and formatted groupbys
|
|
47
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, ... }, ...]
|
|
48
|
+
* @param {array} columns
|
|
49
|
+
* @param {object} currentTable e.g. { _id, ... }
|
|
50
|
+
* @param {object} value e.g. { tables, collaborators }
|
|
51
|
+
* @returns valid and formatted groupbys
|
|
52
|
+
*/
|
|
44
53
|
var deleteInvalidGroupby = function deleteInvalidGroupby(groupbys, columns, currentTable, value) {
|
|
45
54
|
var validGroupbys = getValidGroupbys(groupbys, columns);
|
|
46
55
|
var cleanGroupbys = [];
|
package/es/group/group-row.js
CHANGED
|
@@ -311,6 +311,17 @@ var groupRowsWithMultipleGroupbys = function groupRowsWithMultipleGroupbys(group
|
|
|
311
311
|
groups = getSortedGroups(groups, validGroupbys, value, 0);
|
|
312
312
|
return groups;
|
|
313
313
|
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Group table rows
|
|
317
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, column, ... }, ...]
|
|
318
|
+
* @param {array} rows e.g. [{ _id, ... }, ...]
|
|
319
|
+
* @param {object} formulaRows computed value of formula, link-formula, link etc.
|
|
320
|
+
* @param {object} value e.g. { collaborators, ... }
|
|
321
|
+
* @returns groups: [{
|
|
322
|
+
* cell_value, original_cell_value, column_key,
|
|
323
|
+
row_ids, subgroups, summaries, ...}, ...], array
|
|
324
|
+
*/
|
|
314
325
|
var groupTableRows = function groupTableRows(groupbys, rows, formulaRows, value) {
|
|
315
326
|
if (groupbys.length === 0) {
|
|
316
327
|
return [];
|
|
@@ -347,13 +358,38 @@ var groupTableRows = function groupTableRows(groupbys, rows, formulaRows, value)
|
|
|
347
358
|
groups = getSortedGroups(groups, groupbys, value, 0);
|
|
348
359
|
return groups;
|
|
349
360
|
};
|
|
350
|
-
|
|
351
|
-
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Group view rows
|
|
364
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, column, ... }, ...]
|
|
365
|
+
* @param {object} table e.g. { id_row_map, ... }
|
|
366
|
+
* @param {array} rowsIds e.g. [ row._id, ...]
|
|
367
|
+
* @param {object} formulaRows computed value of formula, link-formula, link etc.
|
|
368
|
+
* @param {object} value e.g. { collaborators, ... }
|
|
369
|
+
* @returns groups: [{
|
|
370
|
+
* cell_value, original_cell_value, column_key,
|
|
371
|
+
row_ids, subgroups, summaries, ...}, ...], array
|
|
372
|
+
*/
|
|
373
|
+
var groupViewRows = function groupViewRows(groupbys, table, rowsIds, formulaRows, value) {
|
|
374
|
+
if (rowsIds.length === 0) {
|
|
352
375
|
return [];
|
|
353
376
|
}
|
|
354
|
-
var rowsData = getRowsByIds(table,
|
|
377
|
+
var rowsData = getRowsByIds(table, rowsIds);
|
|
355
378
|
return groupTableRows(groupbys, rowsData, formulaRows, value);
|
|
356
379
|
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Group rows
|
|
383
|
+
* The "formulaRows" must be supplied if you want group rows by formula/link-formula/link columns
|
|
384
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, ... }, ...]
|
|
385
|
+
* @param {array} rows e.g. table rows: [{ _id, ... }, ...] | view rows: [ row._id, ...]
|
|
386
|
+
* @param {object} table e.g. { id_row_map, columns, ... }
|
|
387
|
+
* @param {object} value e.g. { collaborators, ... }
|
|
388
|
+
* @param {object} formulaRows computed value of formula, link-formula, link etc.
|
|
389
|
+
* @returns groups: [{
|
|
390
|
+
* cell_value, original_cell_value, column_key,
|
|
391
|
+
row_ids, subgroups, summaries, ...}, ...], array
|
|
392
|
+
*/
|
|
357
393
|
var getGroupedRowsWithoutFormulaCalculation = function getGroupedRowsWithoutFormulaCalculation(groupbys, rows, table, value) {
|
|
358
394
|
var _ref3 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
359
395
|
_ref3$formulaRows = _ref3.formulaRows,
|