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,15 +1,22 @@
|
|
|
1
1
|
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Sort number
|
|
5
|
+
* @param {number} leftNumber
|
|
6
|
+
* @param {number} rightNumber
|
|
7
|
+
* @param {string} sortType e.g. 'up' | 'down'
|
|
8
|
+
* @returns number
|
|
9
|
+
*/
|
|
10
|
+
var sortNumber = function sortNumber(leftNumber, rightNumber, sortType) {
|
|
11
|
+
var emptyLeftNumber = !leftNumber && leftNumber !== 0;
|
|
12
|
+
var emptyRightNumber = !rightNumber && rightNumber !== 0;
|
|
13
|
+
if (emptyLeftNumber && emptyRightNumber) return 0;
|
|
14
|
+
if (emptyLeftNumber) return 1;
|
|
15
|
+
if (emptyRightNumber) return -1;
|
|
16
|
+
if (leftNumber > rightNumber) {
|
|
10
17
|
return sortType === SORT_TYPE.UP ? 1 : -1;
|
|
11
18
|
}
|
|
12
|
-
if (
|
|
19
|
+
if (leftNumber < rightNumber) {
|
|
13
20
|
return sortType === SORT_TYPE.UP ? -1 : 1;
|
|
14
21
|
}
|
|
15
22
|
return 0;
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Sort single-select
|
|
5
|
+
* @param {string} leftOptionId the id of option
|
|
6
|
+
* @param {string} rightOptionId
|
|
7
|
+
* @param {string} sort_type e.g. 'up' | 'down'
|
|
8
|
+
* @param {object} option_id_index_map e.g. { [option.id]: 0, ... }
|
|
9
|
+
* @returns number
|
|
10
|
+
*/
|
|
11
|
+
var sortSingleSelect = function sortSingleSelect(leftOptionId, rightOptionId, _ref) {
|
|
4
12
|
var sort_type = _ref.sort_type,
|
|
5
13
|
option_id_index_map = _ref.option_id_index_map;
|
|
6
|
-
var currentOptionIdIndex = option_id_index_map[
|
|
7
|
-
var nextOptionIdIndex = option_id_index_map[
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
if (
|
|
11
|
-
if (
|
|
12
|
-
if (
|
|
14
|
+
var currentOptionIdIndex = option_id_index_map[leftOptionId];
|
|
15
|
+
var nextOptionIdIndex = option_id_index_map[rightOptionId];
|
|
16
|
+
var emptyLeftOptionId = !currentOptionIdIndex && currentOptionIdIndex !== 0;
|
|
17
|
+
var emptyRightOptionId = !nextOptionIdIndex && nextOptionIdIndex !== 0;
|
|
18
|
+
if (emptyLeftOptionId && emptyRightOptionId) return 0;
|
|
19
|
+
if (emptyLeftOptionId) return 1;
|
|
20
|
+
if (emptyRightOptionId) return -1;
|
|
13
21
|
if (currentOptionIdIndex > nextOptionIdIndex) {
|
|
14
22
|
return sort_type === SORT_TYPE.UP ? 1 : -1;
|
|
15
23
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { REG_STRING_NUMBER_PARTS, REG_NUMBER_DIGIT } from '../../constants/reg.js';
|
|
2
2
|
import { SORT_TYPE } from '../../constants/sort.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Compare strings
|
|
6
|
+
* @param {string} leftString
|
|
7
|
+
* @param {string} rightString
|
|
8
|
+
* @returns number
|
|
9
|
+
*/
|
|
4
10
|
var compareString = function compareString(leftString, rightString) {
|
|
5
11
|
if (!leftString && !rightString) return 0;
|
|
6
12
|
if (!leftString) return -1;
|
|
@@ -19,8 +25,8 @@ var compareString = function compareString(leftString, rightString) {
|
|
|
19
25
|
rightStringPart = rightStringParts[i];
|
|
20
26
|
isDigitPart = REG_NUMBER_DIGIT.test(leftStringPart) && REG_NUMBER_DIGIT.test(rightStringPart);
|
|
21
27
|
if (isDigitPart) {
|
|
22
|
-
leftStringPart = parseInt(leftStringPart
|
|
23
|
-
rightStringPart = parseInt(rightStringPart
|
|
28
|
+
leftStringPart = parseInt(leftStringPart);
|
|
29
|
+
rightStringPart = parseInt(rightStringPart);
|
|
24
30
|
if (leftStringPart > rightStringPart) {
|
|
25
31
|
return 1;
|
|
26
32
|
}
|
|
@@ -34,14 +40,22 @@ var compareString = function compareString(leftString, rightString) {
|
|
|
34
40
|
}
|
|
35
41
|
return leftString.localeCompare(rightString);
|
|
36
42
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sort text
|
|
46
|
+
* @param {string} leftText
|
|
47
|
+
* @param {string} rightText
|
|
48
|
+
* @param {string} sortType e.g. 'up' | 'down
|
|
49
|
+
* @returns number
|
|
50
|
+
*/
|
|
51
|
+
var sortText = function sortText(leftText, rightText, sortType) {
|
|
52
|
+
var emptyLeftText = !leftText;
|
|
53
|
+
var emptyRightText = !rightText;
|
|
54
|
+
if (emptyLeftText && emptyRightText) return 0;
|
|
55
|
+
if (emptyLeftText) return 1;
|
|
56
|
+
if (emptyRightText) return -1;
|
|
57
|
+
if (rightText === leftText) return 0;
|
|
58
|
+
return sortType === SORT_TYPE.UP ? compareString(leftText, rightText) : -1 * compareString(leftText, rightText);
|
|
45
59
|
};
|
|
46
60
|
|
|
47
61
|
export { compareString, sortText };
|
package/es/sort/sort-row.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getValidSorts } from './core.js';
|
|
1
|
+
import { deleteInvalidSort } from './core.js';
|
|
3
2
|
import { sortCheckbox } from './sort-column/checkbox.js';
|
|
4
3
|
import { sortCollaborator } from './sort-column/collaborator.js';
|
|
5
4
|
import { sortDate } from './sort-column/date.js';
|
|
@@ -14,45 +13,20 @@ import { sortFormula } from './sort-column/formula.js';
|
|
|
14
13
|
import { sortLink } from './sort-column/link.js';
|
|
15
14
|
import { sortMultipleSelect } from './sort-column/multiple-select.js';
|
|
16
15
|
import { sortSingleSelect } from './sort-column/single-select.js';
|
|
17
|
-
import { getColumnOptions } from '../column/option.js';
|
|
18
16
|
import { NUMBER_SORTER_COLUMN_TYPES } from '../constants/sort.js';
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return column.key === column_key;
|
|
29
|
-
});
|
|
30
|
-
var columnType = sortColumn.type;
|
|
31
|
-
var newSort = _objectSpread(_objectSpread({}, sort), {}, {
|
|
32
|
-
column: sortColumn
|
|
33
|
-
});
|
|
34
|
-
switch (columnType) {
|
|
35
|
-
case CellType.SINGLE_SELECT:
|
|
36
|
-
case CellType.MULTIPLE_SELECT:
|
|
37
|
-
{
|
|
38
|
-
var options = getColumnOptions(sortColumn);
|
|
39
|
-
var option_id_index_map = {};
|
|
40
|
-
options.forEach(function (option, index) {
|
|
41
|
-
option_id_index_map[option.id] = index;
|
|
42
|
-
});
|
|
43
|
-
newSort.option_id_index_map = option_id_index_map;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
cleanSorts.push(newSort);
|
|
48
|
-
});
|
|
49
|
-
return cleanSorts;
|
|
50
|
-
};
|
|
51
|
-
var sortRowsWithMultiSorts = function sortRowsWithMultiSorts(sortRows, sorts, _ref) {
|
|
18
|
+
/**
|
|
19
|
+
* Sort rows with multiple sorts
|
|
20
|
+
* @param {array} tableRows e.g. [{ _id, [column.key]: '', ...}, ...]
|
|
21
|
+
* @param {array} sorts e.g. [{ column_key, sort_type, column, ... }, ...]
|
|
22
|
+
* @param {object} formulaRows computed value of formula, link-formula, link etc.
|
|
23
|
+
* @param {object} value e.g. { collaborators, ... }
|
|
24
|
+
*/
|
|
25
|
+
var sortRowsWithMultiSorts = function sortRowsWithMultiSorts(tableRows, sorts, _ref) {
|
|
52
26
|
var _ref$formulaRows = _ref.formulaRows,
|
|
53
27
|
formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
|
|
54
28
|
value = _ref.value;
|
|
55
|
-
|
|
29
|
+
tableRows.sort(function (currentRow, nextRow) {
|
|
56
30
|
var initValue = 0;
|
|
57
31
|
sorts.forEach(function (sort) {
|
|
58
32
|
var column_key = sort.column_key,
|
|
@@ -106,11 +80,21 @@ var sortRowsWithMultiSorts = function sortRowsWithMultiSorts(sortRows, sorts, _r
|
|
|
106
80
|
return initValue;
|
|
107
81
|
});
|
|
108
82
|
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get sorted rows ids from table rows with multiple sorts
|
|
86
|
+
* @param {array} sorts e.g. [{ column_key, sort_type, column, ... }, ...]
|
|
87
|
+
* @param {array} rows e.g. [{ _id, [column.key]: '', ...}, ...]
|
|
88
|
+
* @param {array} columns e.g. [{ key, type, ... }, ...]
|
|
89
|
+
* @param {object} formulaRows computed value of formula, link-formula, link etc.
|
|
90
|
+
* @param {object} value e.g. { collaborators, ... }
|
|
91
|
+
* @returns sorted rows ids, array
|
|
92
|
+
*/
|
|
109
93
|
var sortTableRows = function sortTableRows(sorts, rows, columns) {
|
|
110
94
|
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
111
95
|
formulaRows = _ref2.formulaRows,
|
|
112
96
|
value = _ref2.value;
|
|
113
|
-
if (!Array.isArray(rows)) return [];
|
|
97
|
+
if (!Array.isArray(rows) || rows.length === 0) return [];
|
|
114
98
|
var sortRows = rows.slice(0);
|
|
115
99
|
var validSorts = deleteInvalidSort(sorts, columns);
|
|
116
100
|
var normalizedFormulaRows = formulaRows || {};
|
|
@@ -123,4 +107,4 @@ var sortTableRows = function sortTableRows(sorts, rows, columns) {
|
|
|
123
107
|
});
|
|
124
108
|
};
|
|
125
109
|
|
|
126
|
-
export {
|
|
110
|
+
export { sortRowsWithMultiSorts, sortTableRows };
|
package/es/table/column.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get column by key from table
|
|
3
3
|
* @param {object} table
|
|
4
4
|
* @param {string} columnKey
|
|
5
5
|
* @returns column, object
|
|
@@ -12,7 +12,7 @@ var getTableColumnByKey = function getTableColumnByKey(table, columnKey) {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get table column by name
|
|
16
16
|
* @param {object} table
|
|
17
17
|
* @param {string} columnName
|
|
18
18
|
* @returns column, object
|
package/es/table/core.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get table by id
|
|
3
3
|
* @param {array} tables
|
|
4
4
|
* @param {string} tableId
|
|
5
|
-
* @returns object
|
|
5
|
+
* @returns table, object
|
|
6
6
|
*/
|
|
7
7
|
var getTableById = function getTableById(tables, tableId) {
|
|
8
8
|
if (!Array.isArray(tables) || !tableId) return null;
|
package/es/table/row.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get table row by id
|
|
3
3
|
* @param {object} table
|
|
4
4
|
* @param {string} rowId the id of row
|
|
5
|
-
* @returns object
|
|
5
|
+
* @returns row, object
|
|
6
6
|
*/
|
|
7
7
|
var getRowById = function getRowById(table, rowId) {
|
|
8
8
|
if (!table || !table.id_row_map || !rowId) return null;
|
|
@@ -10,10 +10,10 @@ var getRowById = function getRowById(table, rowId) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Get table rows by ids
|
|
14
14
|
* @param {object} table { id_row_map, ... }
|
|
15
15
|
* @param {array} rowsIds [ row._id, ... ]
|
|
16
|
-
* @returns
|
|
16
|
+
* @returns rows, array
|
|
17
17
|
*/
|
|
18
18
|
var getRowsByIds = function getRowsByIds(table, rowsIds) {
|
|
19
19
|
if (!table || !table.id_row_map || !Array.isArray(rowsIds)) return [];
|
package/es/view/core.js
CHANGED
|
@@ -4,10 +4,10 @@ import { getValidSorts } from '../sort/core.js';
|
|
|
4
4
|
import { CellType } from '../constants/cell-type.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {array} views { _id
|
|
7
|
+
* Get view by id
|
|
8
|
+
* @param {array} views e.g. [{ _id, ... }, ...]
|
|
9
9
|
* @param {string} viewId
|
|
10
|
-
* @returns object
|
|
10
|
+
* @returns view, object
|
|
11
11
|
*/
|
|
12
12
|
var getViewById = function getViewById(views, viewId) {
|
|
13
13
|
if (!Array.isArray(views) || !viewId) return null;
|
|
@@ -17,10 +17,10 @@ var getViewById = function getViewById(views, viewId) {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param {object} view { filters
|
|
20
|
+
* Check whether the view contains filters
|
|
21
|
+
* @param {object} view e.g. { filters, ... }
|
|
22
22
|
* @param {array} columns
|
|
23
|
-
* @returns
|
|
23
|
+
* @returns bool
|
|
24
24
|
*/
|
|
25
25
|
var isFilterView = function isFilterView(view, columns) {
|
|
26
26
|
var validFilters = getValidFilters(view.filters, columns);
|
|
@@ -28,10 +28,10 @@ var isFilterView = function isFilterView(view, columns) {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param {object} view { groupbys
|
|
31
|
+
* Check whether the view contains groupbys
|
|
32
|
+
* @param {object} view e.g. { groupbys, ... }
|
|
33
33
|
* @param {array} columns
|
|
34
|
-
* @returns
|
|
34
|
+
* @returns bool
|
|
35
35
|
*/
|
|
36
36
|
var isGroupView = function isGroupView(view, columns) {
|
|
37
37
|
var validGroupbys = getValidGroupbys(view.groupbys, columns);
|
|
@@ -39,32 +39,31 @@ var isGroupView = function isGroupView(view, columns) {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {object} view { sorts
|
|
42
|
+
* Check whether the view contains sorts
|
|
43
|
+
* @param {object} view e.g. { sorts, ... }
|
|
44
44
|
* @param {array} columns
|
|
45
|
-
* @returns
|
|
45
|
+
* @returns bool
|
|
46
46
|
*/
|
|
47
47
|
var isSortView = function isSortView(view, columns) {
|
|
48
|
-
var
|
|
49
|
-
var validSorts = getValidSorts(sorts, columns);
|
|
48
|
+
var validSorts = getValidSorts(view.sorts, columns);
|
|
50
49
|
return validSorts.length > 0;
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @param {object} view {
|
|
53
|
+
* Check is default view which no contains filters, sorts, groupbys etc.
|
|
54
|
+
* @param {object} view e.g. { filters, groupbys, sorts, ... }
|
|
56
55
|
* @param {array} columns
|
|
57
|
-
* @returns
|
|
56
|
+
* @returns bool
|
|
58
57
|
*/
|
|
59
58
|
var isDefaultView = function isDefaultView(view, columns) {
|
|
60
59
|
return !isFilterView(view, columns) && !isSortView(view, columns) && !isGroupView(view, columns);
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @param {object} view { filters, groupbys, sorts, ... }
|
|
66
|
-
* @param {object} table
|
|
67
|
-
* @returns
|
|
63
|
+
* Get link columns which used either in filters, groupbys, sorts etc.
|
|
64
|
+
* @param {object} view e.g. { filters, groupbys, sorts, ... }
|
|
65
|
+
* @param {object} table e.g. { columns, ... }
|
|
66
|
+
* @returns link columns, array
|
|
68
67
|
*/
|
|
69
68
|
var getLinkColumnsUsedInFilters = function getLinkColumnsUsedInFilters(view, table) {
|
|
70
69
|
var filters = view.filters,
|
package/es/view/formula.js
CHANGED
|
@@ -2,9 +2,9 @@ import { CellType } from '../constants/cell-type.js';
|
|
|
2
2
|
import { FORMULA_COLUMN_TYPES_MAP } from '../constants/formula.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {object} linkColumn { key, data: { display_column_key, ... }, ... }
|
|
7
|
-
* @returns object
|
|
5
|
+
* Transform the formats of link column to link-formula's
|
|
6
|
+
* @param {object} linkColumn e.g. { key, data: { display_column_key, ... }, ... }
|
|
7
|
+
* @returns converted link column, object
|
|
8
8
|
*/
|
|
9
9
|
var transLink2LinkFormula = function transLink2LinkFormula(linkColumn) {
|
|
10
10
|
var key = linkColumn.key,
|
|
@@ -26,10 +26,10 @@ var transLink2LinkFormula = function transLink2LinkFormula(linkColumn) {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param {array} formulaColumns
|
|
31
|
-
* @param {object} table
|
|
32
|
-
* @returns array
|
|
29
|
+
* Get sorted formula columns
|
|
30
|
+
* @param {array} formulaColumns the formula columns waiting to sort
|
|
31
|
+
* @param {object} table e.g. { columns, ... }
|
|
32
|
+
* @returns sorted formula columns, array
|
|
33
33
|
*/
|
|
34
34
|
var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, table) {
|
|
35
35
|
if (!Array.isArray(formulaColumns) || !table || !Array.isArray(table.columns)) return [];
|
|
@@ -70,18 +70,20 @@ var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, t
|
|
|
70
70
|
var data = formulaColumn.data;
|
|
71
71
|
var operated_columns = data.operated_columns;
|
|
72
72
|
keyInDegreeMap[formulaColumnKey] = 0;
|
|
73
|
-
Array.isArray(operated_columns)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
keyEdgesMap[dependColumnKey]
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
if (Array.isArray(operated_columns)) {
|
|
74
|
+
operated_columns.forEach(function (dependColumnKey) {
|
|
75
|
+
var dependColumn = keyColumnMap[dependColumnKey];
|
|
76
|
+
if (!dependColumn) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
keyInDegreeMap[formulaColumnKey] += 1;
|
|
80
|
+
if (keyEdgesMap[dependColumnKey]) {
|
|
81
|
+
keyEdgesMap[dependColumnKey].push(formulaColumnKey);
|
|
82
|
+
} else {
|
|
83
|
+
keyEdgesMap[dependColumnKey] = [formulaColumnKey];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
85
87
|
});
|
|
86
88
|
var sortedList = [];
|
|
87
89
|
var waitingQueue = [];
|
|
@@ -94,12 +96,14 @@ var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, t
|
|
|
94
96
|
var columnKey = waitingQueue.shift();
|
|
95
97
|
var edges = keyEdgesMap[columnKey];
|
|
96
98
|
sortedList.push(columnKey);
|
|
97
|
-
Array.isArray(edges)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
if (Array.isArray(edges)) {
|
|
100
|
+
edges.forEach(function (edge) {
|
|
101
|
+
keyInDegreeMap[edge] -= 1;
|
|
102
|
+
if (keyInDegreeMap[edge] === 0) {
|
|
103
|
+
waitingQueue.push(edge);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
103
107
|
}
|
|
104
108
|
return sortedList.map(function (columnKey) {
|
|
105
109
|
return keyColumnMap[columnKey];
|
|
@@ -107,9 +111,9 @@ var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, t
|
|
|
107
111
|
};
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @param {object} table { columns
|
|
112
|
-
* @returns array
|
|
114
|
+
* Get table formula columns and link columns
|
|
115
|
+
* @param {object} table e.g. { columns, ... }
|
|
116
|
+
* @returns formula and link columns, array
|
|
113
117
|
*/
|
|
114
118
|
var getFormulaColumnsContainLinks = function getFormulaColumnsContainLinks(table) {
|
|
115
119
|
var columns = table.columns;
|
|
@@ -130,9 +134,9 @@ var getFormulaColumnsContainLinks = function getFormulaColumnsContainLinks(table
|
|
|
130
134
|
};
|
|
131
135
|
|
|
132
136
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @param {object} table { columns
|
|
135
|
-
* @returns array
|
|
137
|
+
* Get sorted formula and link columns from table
|
|
138
|
+
* @param {object} table e.g. { columns, ... }
|
|
139
|
+
* @returns sorted formula and link columns, array
|
|
136
140
|
*/
|
|
137
141
|
var getSortedFormulaColumnsContainLinks = function getSortedFormulaColumnsContainLinks(table) {
|
|
138
142
|
var formulaColumns = getFormulaColumnsContainLinks(table);
|
package/es/view/group.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {array} paths e.g. [0, 1, 2]
|
|
4
|
-
* @param {array} groups
|
|
5
|
-
* @returns object
|
|
2
|
+
* Get group by paths
|
|
3
|
+
* @param {array} paths e.g. [ 0, 1, 2 ]
|
|
4
|
+
* @param {array} groups grouped rows
|
|
5
|
+
* @returns group, object
|
|
6
6
|
*/
|
|
7
7
|
var getGroupByPath = function getGroupByPath(paths, groups) {
|
|
8
8
|
if (!Array.isArray(paths) || !Array.isArray(groups)) {
|
package/es/view/summaries.js
CHANGED
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import { getRowsByIds } from '../table/row.js';
|
|
2
2
|
import { isTableRows } from '../row/core.js';
|
|
3
|
-
import '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
import '../constants/group.js';
|
|
5
|
-
import '../validate/filter.js';
|
|
6
|
-
import '../filter/core.js';
|
|
7
|
-
import '@babel/runtime/helpers/toConsumableArray';
|
|
8
|
-
import '../constants/filter/filter-column-options.js';
|
|
9
|
-
import '../constants/filter/filter-modifier.js';
|
|
10
|
-
import '../constants/filter/filter-predicate.js';
|
|
11
|
-
import '../constants/filter/filter-is-within.js';
|
|
12
|
-
import '../date.js';
|
|
13
|
-
import { isNumber } from '../number.js';
|
|
14
|
-
import '../cell-value-get/cell-value.js';
|
|
15
3
|
import { isNumericColumn } from '../column/number.js';
|
|
16
|
-
import '../
|
|
4
|
+
import { isNumber } from '../number.js';
|
|
17
5
|
import { FORMULA_COLUMN_TYPES_MAP } from '../constants/formula.js';
|
|
18
|
-
import '../constants/row-color.js';
|
|
19
6
|
|
|
20
7
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param {object} table
|
|
23
|
-
* @param {array} rows table
|
|
24
|
-
* @param {object} formulaRows
|
|
25
|
-
* @returns
|
|
8
|
+
* Calculate summaries of table numeric columns
|
|
9
|
+
* @param {object} table e.g. { columns, ... }
|
|
10
|
+
* @param {array} rows e.g. table rows: [{ _id, ...}, ...] | view rows: [ row._id, ... ]
|
|
11
|
+
* @param {object} formulaRows for numeric formula columns
|
|
12
|
+
* @returns summaries: { [column.key]: { sum, average, median, max, min, ... }, ... }, object
|
|
26
13
|
*/
|
|
27
14
|
var getSummaries = function getSummaries(table, rows, formulaRows) {
|
|
28
15
|
var numericColumns = table.columns.filter(function (column) {
|
|
@@ -88,10 +75,10 @@ var getSummaries = function getSummaries(table, rows, formulaRows) {
|
|
|
88
75
|
};
|
|
89
76
|
|
|
90
77
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @param {array} subgroups { summaries, ... }
|
|
78
|
+
* Calculate group summaries by subgroup
|
|
79
|
+
* @param {array} subgroups e.g. [{ summaries, ... }, ...]
|
|
93
80
|
* @param {array} numericColumns
|
|
94
|
-
* @returns
|
|
81
|
+
* @returns summaries: { [column.key]: { sum, average, median, max, min, ... }, ... }, object
|
|
95
82
|
*/
|
|
96
83
|
var getSummariesWithSubgroups = function getSummariesWithSubgroups(subgroups, numericColumns) {
|
|
97
84
|
var subgroupsLen = subgroups.length;
|
|
@@ -104,8 +91,8 @@ var getSummariesWithSubgroups = function getSummariesWithSubgroups(subgroups, nu
|
|
|
104
91
|
var max;
|
|
105
92
|
var min;
|
|
106
93
|
subgroups.forEach(function (subgroup) {
|
|
107
|
-
var
|
|
108
|
-
var summary =
|
|
94
|
+
var subSummaries = subgroup.summaries;
|
|
95
|
+
var summary = subSummaries[column.key];
|
|
109
96
|
var subgroupSum = summary.sum,
|
|
110
97
|
subgroupAverage = summary.average,
|
|
111
98
|
subgroupMedian = summary.median,
|
|
@@ -139,7 +126,7 @@ var getSummariesWithSubgroups = function getSummariesWithSubgroups(subgroups, nu
|
|
|
139
126
|
median = medianArr[parseInt(medianArr.length / 2)];
|
|
140
127
|
}
|
|
141
128
|
}
|
|
142
|
-
average
|
|
129
|
+
average /= subgroupsLen;
|
|
143
130
|
summaries[column.key] = {
|
|
144
131
|
sum: sum,
|
|
145
132
|
average: average,
|
|
@@ -152,10 +139,11 @@ var getSummariesWithSubgroups = function getSummariesWithSubgroups(subgroups, nu
|
|
|
152
139
|
};
|
|
153
140
|
|
|
154
141
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param {array} groups { subgroups, row_ids, ... }
|
|
157
|
-
* @param {object} table
|
|
158
|
-
* @param {object} formulaRows
|
|
142
|
+
* Calculate group summaries
|
|
143
|
+
* @param {array} groups e.g. [{ subgroups, row_ids, ... }, ...]
|
|
144
|
+
* @param {object} table e.g. { columns, ... }
|
|
145
|
+
* @param {object} formulaRows for numeric formula columns
|
|
146
|
+
* @returns void
|
|
159
147
|
*/
|
|
160
148
|
var updateGroupSummaries = function updateGroupSummaries(groups, table, formulaRows) {
|
|
161
149
|
var numericColumns = table.columns.filter(function (column) {
|