dtable-utils 0.0.3-beta.1 → 0.0.3
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 +2 -30
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +19 -227
- package/es/cell-value-get/collaborator.js +3 -9
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/duration.js +1 -1
- package/es/cell-value-get/geolocation.js +5 -29
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +18 -42
- package/es/cell-value-get/option.js +7 -17
- package/es/cell-value-set/number.js +1 -53
- package/es/column/{core.js → common.js} +14 -2
- package/es/column/date.js +1 -1
- package/es/column/number.js +1 -1
- package/es/common.js +10 -9
- package/es/constants/column.js +2 -127
- package/es/constants/filter/index.js +1 -5
- package/es/date.js +1 -1
- package/es/index.js +10 -62
- package/es/validate/filter.js +1 -1
- package/lib/cell-value-get/cell-value.js +18 -231
- package/lib/cell-value-get/collaborator.js +2 -9
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/duration.js +1 -0
- package/lib/cell-value-get/geolocation.js +5 -30
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +17 -42
- package/lib/cell-value-get/option.js +6 -18
- package/lib/cell-value-set/number.js +0 -53
- package/lib/column/{core.js → common.js} +14 -1
- package/lib/column/date.js +2 -2
- package/lib/column/number.js +3 -3
- package/lib/common.js +11 -13
- package/lib/constants/column.js +1 -134
- package/lib/constants/filter/index.js +0 -5
- package/lib/index.js +8 -176
- package/lib/validate/filter.js +3 -3
- package/package.json +3 -5
- package/es/cell-value-get/rate.js +0 -6
- package/es/cell-value-set/date.js +0 -20
- package/es/color/gradient-color.js +0 -100
- package/es/column/color.js +0 -415
- package/es/column/option.js +0 -115
- package/es/constants/color.js +0 -16
- package/es/constants/column-permission.js +0 -7
- package/es/constants/grid-header.js +0 -6
- package/es/constants/group.js +0 -23
- package/es/constants/limit.js +0 -3
- package/es/constants/reg.js +0 -4
- package/es/constants/row-color.js +0 -11
- package/es/constants/sort.js +0 -11
- package/es/filter/core.js +0 -287
- package/es/filter/filter-column/array.js +0 -82
- package/es/filter/filter-column/checkbox.js +0 -8
- package/es/filter/filter-column/collaborator.js +0 -67
- package/es/filter/filter-column/creator.js +0 -50
- package/es/filter/filter-column/date.js +0 -59
- package/es/filter/filter-column/digital-sign.js +0 -26
- package/es/filter/filter-column/file.js +0 -24
- package/es/filter/filter-column/formula.js +0 -49
- package/es/filter/filter-column/geolocation.js +0 -53
- package/es/filter/filter-column/link.js +0 -12
- package/es/filter/filter-column/long-text.js +0 -25
- package/es/filter/filter-column/multiple-select.js +0 -60
- package/es/filter/filter-column/number.js +0 -93
- package/es/filter/filter-column/single-select.js +0 -41
- package/es/filter/filter-column/text.js +0 -55
- package/es/filter/filter-row.js +0 -198
- package/es/group/core.js +0 -107
- package/es/group/group-row.js +0 -366
- package/es/link/core.js +0 -78
- package/es/number.js +0 -13
- package/es/row/color.js +0 -278
- package/es/row/core.js +0 -161
- package/es/sort/core.js +0 -32
- package/es/sort/sort-column/array.js +0 -63
- package/es/sort/sort-column/checkbox.js +0 -15
- package/es/sort/sort-column/collaborator.js +0 -9
- package/es/sort/sort-column/date.js +0 -25
- package/es/sort/sort-column/formula.js +0 -40
- package/es/sort/sort-column/link.js +0 -23
- package/es/sort/sort-column/multiple-select.js +0 -45
- package/es/sort/sort-column/number.js +0 -18
- package/es/sort/sort-column/single-select.js +0 -22
- package/es/sort/sort-column/text.js +0 -47
- package/es/sort/sort-row.js +0 -126
- package/es/table/column.js +0 -27
- package/es/table/core.js +0 -14
- package/es/table/index.js +0 -14
- package/es/table/row.js +0 -25
- package/es/validate/geolocation.js +0 -5
- package/es/view/core.js +0 -135
- package/es/view/formula.js +0 -143
- package/es/view/group.js +0 -32
- package/es/view/summaries.js +0 -179
- package/lib/cell-value-get/rate.js +0 -10
- package/lib/cell-value-set/date.js +0 -24
- package/lib/color/gradient-color.js +0 -110
- package/lib/column/color.js +0 -424
- package/lib/column/option.js +0 -123
- package/lib/constants/color.js +0 -20
- package/lib/constants/column-permission.js +0 -11
- package/lib/constants/grid-header.js +0 -10
- package/lib/constants/group.js +0 -36
- package/lib/constants/limit.js +0 -7
- package/lib/constants/reg.js +0 -9
- package/lib/constants/row-color.js +0 -17
- package/lib/constants/sort.js +0 -18
- package/lib/filter/core.js +0 -301
- package/lib/filter/filter-column/array.js +0 -86
- package/lib/filter/filter-column/checkbox.js +0 -12
- package/lib/filter/filter-column/collaborator.js +0 -75
- package/lib/filter/filter-column/creator.js +0 -54
- package/lib/filter/filter-column/date.js +0 -63
- package/lib/filter/filter-column/digital-sign.js +0 -30
- package/lib/filter/filter-column/file.js +0 -28
- package/lib/filter/filter-column/formula.js +0 -53
- package/lib/filter/filter-column/geolocation.js +0 -57
- package/lib/filter/filter-column/link.js +0 -16
- package/lib/filter/filter-column/long-text.js +0 -29
- package/lib/filter/filter-column/multiple-select.js +0 -68
- package/lib/filter/filter-column/number.js +0 -97
- package/lib/filter/filter-column/single-select.js +0 -45
- package/lib/filter/filter-column/text.js +0 -59
- package/lib/filter/filter-row.js +0 -204
- package/lib/group/core.js +0 -117
- package/lib/group/group-row.js +0 -377
- package/lib/link/core.js +0 -90
- package/lib/number.js +0 -18
- package/lib/row/color.js +0 -286
- package/lib/row/core.js +0 -170
- package/lib/sort/core.js +0 -37
- package/lib/sort/sort-column/array.js +0 -67
- package/lib/sort/sort-column/checkbox.js +0 -19
- package/lib/sort/sort-column/collaborator.js +0 -13
- package/lib/sort/sort-column/date.js +0 -29
- package/lib/sort/sort-column/formula.js +0 -44
- package/lib/sort/sort-column/link.js +0 -27
- package/lib/sort/sort-column/multiple-select.js +0 -50
- package/lib/sort/sort-column/number.js +0 -22
- package/lib/sort/sort-column/single-select.js +0 -26
- package/lib/sort/sort-column/text.js +0 -52
- package/lib/sort/sort-row.js +0 -136
- package/lib/table/column.js +0 -32
- package/lib/table/core.js +0 -18
- package/lib/table/index.js +0 -18
- package/lib/table/row.js +0 -30
- package/lib/validate/geolocation.js +0 -9
- package/lib/view/core.js +0 -144
- package/lib/view/formula.js +0 -150
- package/lib/view/group.js +0 -36
- package/lib/view/summaries.js +0 -185
package/es/group/group-row.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
3
|
-
import { isTableRows } from '../row/core.js';
|
|
4
|
-
import { getRowsByIds } from '../table/row.js';
|
|
5
|
-
import { deleteInvalidGroupby } from './core.js';
|
|
6
|
-
import { DateUtils } from '../date.js';
|
|
7
|
-
import { isDateColumn } from '../column/date.js';
|
|
8
|
-
import { getCollaboratorsNames } from '../cell-value-get/collaborator.js';
|
|
9
|
-
import { getGeolocationByGranularity } from '../cell-value-get/geolocation.js';
|
|
10
|
-
import { getFormulaDisplayString } from '../cell-value-get/cell-value.js';
|
|
11
|
-
import { sortCheckbox } from '../sort/sort-column/checkbox.js';
|
|
12
|
-
import { sortCollaborator } from '../sort/sort-column/collaborator.js';
|
|
13
|
-
import { sortDate } from '../sort/sort-column/date.js';
|
|
14
|
-
import { sortNumber } from '../sort/sort-column/number.js';
|
|
15
|
-
import { sortText } from '../sort/sort-column/text.js';
|
|
16
|
-
import { CellType } from '../constants/cell-type.js';
|
|
17
|
-
import { SINGLE_CELL_VALUE_COLUMN_TYPE_MAP, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, DATE_COLUMN_OPTIONS } from '../constants/column.js';
|
|
18
|
-
import { FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from '../constants/formula.js';
|
|
19
|
-
import { sortFormula } from '../sort/sort-column/formula.js';
|
|
20
|
-
import { sortLink } from '../sort/sort-column/link.js';
|
|
21
|
-
import { sortMultipleSelect } from '../sort/sort-column/multiple-select.js';
|
|
22
|
-
import { sortSingleSelect } from '../sort/sort-column/single-select.js';
|
|
23
|
-
import { MAX_GROUP_LEVEL } from '../constants/group.js';
|
|
24
|
-
import { SORT_TYPE, SORT_COLUMN_OPTIONS, TEXT_SORTER_COLUMN_TYPES, NUMBER_SORTER_COLUMN_TYPES } from '../constants/sort.js';
|
|
25
|
-
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
-
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; }
|
|
28
|
-
var _getCellValue = function _getCellValue(row, formulaRows, groupby) {
|
|
29
|
-
var column_key = groupby.column_key,
|
|
30
|
-
column = groupby.column;
|
|
31
|
-
var cellValue = row[column_key];
|
|
32
|
-
var type = column.type;
|
|
33
|
-
if (FORMULA_COLUMN_TYPES_MAP[type]) {
|
|
34
|
-
var formulaRow = formulaRows[row._id] || {};
|
|
35
|
-
return formulaRow[column_key];
|
|
36
|
-
}
|
|
37
|
-
// link column value is calculate as a special formula column
|
|
38
|
-
if (type === CellType.LINK) {
|
|
39
|
-
var _formulaRow = formulaRows[row._id] || {};
|
|
40
|
-
return _formulaRow[column_key] || [];
|
|
41
|
-
}
|
|
42
|
-
return cellValue;
|
|
43
|
-
};
|
|
44
|
-
var _getFormattedCellValue = function _getFormattedCellValue(cellValue, groupby) {
|
|
45
|
-
var column = groupby.column,
|
|
46
|
-
countType = groupby.count_type;
|
|
47
|
-
var columnType = column.type,
|
|
48
|
-
columnData = column.data;
|
|
49
|
-
switch (columnType) {
|
|
50
|
-
case CellType.TEXT:
|
|
51
|
-
case CellType.URL:
|
|
52
|
-
case CellType.EMAIL:
|
|
53
|
-
case CellType.LAST_MODIFIER:
|
|
54
|
-
case CellType.CREATOR:
|
|
55
|
-
{
|
|
56
|
-
return cellValue || null;
|
|
57
|
-
}
|
|
58
|
-
case CellType.DATE:
|
|
59
|
-
case CellType.CTIME:
|
|
60
|
-
case CellType.MTIME:
|
|
61
|
-
{
|
|
62
|
-
return DateUtils.getDateByGranularity(cellValue, countType) || null;
|
|
63
|
-
}
|
|
64
|
-
case CellType.NUMBER:
|
|
65
|
-
case CellType.DURATION:
|
|
66
|
-
case CellType.RATE:
|
|
67
|
-
{
|
|
68
|
-
return cellValue || cellValue === 0 ? cellValue : null;
|
|
69
|
-
}
|
|
70
|
-
case CellType.CHECKBOX:
|
|
71
|
-
{
|
|
72
|
-
return !!cellValue;
|
|
73
|
-
}
|
|
74
|
-
case CellType.SINGLE_SELECT:
|
|
75
|
-
{
|
|
76
|
-
return cellValue || null;
|
|
77
|
-
}
|
|
78
|
-
case CellType.MULTIPLE_SELECT:
|
|
79
|
-
{
|
|
80
|
-
return Array.isArray(cellValue) ? cellValue : [];
|
|
81
|
-
}
|
|
82
|
-
case CellType.COLLABORATOR:
|
|
83
|
-
{
|
|
84
|
-
if (!Array.isArray(cellValue)) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
var collaborator_email_map = groupby.collaborator_email_map;
|
|
88
|
-
return cellValue.filter(function (email) {
|
|
89
|
-
return collaborator_email_map[email];
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
case CellType.GEOLOCATION:
|
|
93
|
-
{
|
|
94
|
-
return getGeolocationByGranularity(cellValue, countType);
|
|
95
|
-
}
|
|
96
|
-
case CellType.FORMULA:
|
|
97
|
-
case CellType.LINK_FORMULA:
|
|
98
|
-
{
|
|
99
|
-
var _ref = columnData || {},
|
|
100
|
-
result_type = _ref.result_type;
|
|
101
|
-
if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
|
|
102
|
-
return cellValue || cellValue === 0 ? cellValue : null;
|
|
103
|
-
}
|
|
104
|
-
if (result_type === FORMULA_RESULT_TYPE.DATE) {
|
|
105
|
-
return DateUtils.getDateByGranularity(cellValue, countType) || null;
|
|
106
|
-
}
|
|
107
|
-
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
108
|
-
return !!cellValue;
|
|
109
|
-
}
|
|
110
|
-
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
111
|
-
var newCellValue = cellValue;
|
|
112
|
-
if (isDateColumn(column) && Array.isArray(cellValue) && cellValue.length > 0) {
|
|
113
|
-
return DateUtils.getDateByGranularity(cellValue[0], countType) || null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// convert to string
|
|
117
|
-
return getFormulaDisplayString(newCellValue, columnData) || null;
|
|
118
|
-
}
|
|
119
|
-
return cellValue || null;
|
|
120
|
-
}
|
|
121
|
-
case CellType.LINK:
|
|
122
|
-
{
|
|
123
|
-
if (!Array.isArray(cellValue) || cellValue.length === 0) {
|
|
124
|
-
return [];
|
|
125
|
-
}
|
|
126
|
-
return cellValue.map(function (linked) {
|
|
127
|
-
return linked.display_value;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
default:
|
|
131
|
-
{
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
var _getStrCellValue = function _getStrCellValue(cellValue, columnType) {
|
|
137
|
-
var sCellValue = null;
|
|
138
|
-
if (SINGLE_CELL_VALUE_COLUMN_TYPE_MAP[columnType]) {
|
|
139
|
-
sCellValue = typeof cellValue === 'string' ? cellValue : String(cellValue);
|
|
140
|
-
} else if (MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[columnType]) {
|
|
141
|
-
sCellValue = _toConsumableArray(cellValue).sort().toString();
|
|
142
|
-
}
|
|
143
|
-
return sCellValue;
|
|
144
|
-
};
|
|
145
|
-
var _findGroupIndexWithMultipleGroupbys = function _findGroupIndexWithMultipleGroupbys(sCellValue, cellValue2GroupIndexMap, groupsLength) {
|
|
146
|
-
var target = cellValue2GroupIndexMap[sCellValue];
|
|
147
|
-
if (target && target.index > -1) {
|
|
148
|
-
return target.index;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// eslint-disable-next-line
|
|
152
|
-
cellValue2GroupIndexMap[sCellValue] = {};
|
|
153
|
-
|
|
154
|
-
// eslint-disable-next-line
|
|
155
|
-
cellValue2GroupIndexMap[sCellValue].subgroups = {};
|
|
156
|
-
|
|
157
|
-
// eslint-disable-next-line
|
|
158
|
-
cellValue2GroupIndexMap[sCellValue].index = groupsLength;
|
|
159
|
-
return -1;
|
|
160
|
-
};
|
|
161
|
-
var _findGroupIndex = function _findGroupIndex(sCellValue, cellValue2GroupIndexMap, groupsLength) {
|
|
162
|
-
var index = cellValue2GroupIndexMap[sCellValue];
|
|
163
|
-
if (index > -1) {
|
|
164
|
-
return index;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// eslint-disable-next-line
|
|
168
|
-
cellValue2GroupIndexMap[sCellValue] = groupsLength;
|
|
169
|
-
return -1;
|
|
170
|
-
};
|
|
171
|
-
var getSortedGroups = function getSortedGroups(groups, groupbys, value, level) {
|
|
172
|
-
var _groupbys$level = groupbys[level],
|
|
173
|
-
column = _groupbys$level.column,
|
|
174
|
-
sort_type = _groupbys$level.sort_type;
|
|
175
|
-
var collaborators = value.collaborators;
|
|
176
|
-
var columnType = column.type,
|
|
177
|
-
columnData = column.data;
|
|
178
|
-
var normalizedSortType = sort_type || SORT_TYPE.UP;
|
|
179
|
-
var option_id_index_map = {};
|
|
180
|
-
if (columnType === CellType.SINGLE_SELECT || columnType === CellType.MULTIPLE_SELECT) {
|
|
181
|
-
var _ref2 = columnData || {},
|
|
182
|
-
options = _ref2.options;
|
|
183
|
-
if (Array.isArray(options)) {
|
|
184
|
-
options.forEach(function (option, index) {
|
|
185
|
-
option_id_index_map[option.id] = index;
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
groups.sort(function (currGroupRow, nextGroupRow) {
|
|
190
|
-
var currCellVal = currGroupRow.cell_value;
|
|
191
|
-
var nextCellVal = nextGroupRow.cell_value;
|
|
192
|
-
if (SORT_COLUMN_OPTIONS.includes(columnType)) {
|
|
193
|
-
var sortResult;
|
|
194
|
-
if (TEXT_SORTER_COLUMN_TYPES.includes(columnType)) {
|
|
195
|
-
sortResult = sortText(currCellVal, nextCellVal, normalizedSortType);
|
|
196
|
-
} else if (NUMBER_SORTER_COLUMN_TYPES.includes(columnType)) {
|
|
197
|
-
sortResult = sortNumber(currCellVal, nextCellVal, normalizedSortType);
|
|
198
|
-
} else if (DATE_COLUMN_OPTIONS.includes(columnType)) {
|
|
199
|
-
sortResult = sortDate(currCellVal, nextCellVal, normalizedSortType);
|
|
200
|
-
} else if (columnType === CellType.CHECKBOX) {
|
|
201
|
-
sortResult = sortCheckbox(currCellVal, nextCellVal, normalizedSortType);
|
|
202
|
-
} else if (columnType === CellType.COLLABORATOR) {
|
|
203
|
-
var currCollaborators = currCellVal;
|
|
204
|
-
var nextCollaborators = nextCellVal;
|
|
205
|
-
if (collaborators) {
|
|
206
|
-
currCollaborators = getCollaboratorsNames(currCollaborators, collaborators);
|
|
207
|
-
nextCollaborators = getCollaboratorsNames(nextCollaborators, collaborators);
|
|
208
|
-
}
|
|
209
|
-
sortResult = sortCollaborator(currCollaborators, nextCollaborators, normalizedSortType);
|
|
210
|
-
} else if (columnType === CellType.SINGLE_SELECT) {
|
|
211
|
-
sortResult = sortSingleSelect(currCellVal, nextCellVal, {
|
|
212
|
-
sort_type: normalizedSortType,
|
|
213
|
-
option_id_index_map: option_id_index_map
|
|
214
|
-
});
|
|
215
|
-
} else if (columnType === CellType.MULTIPLE_SELECT) {
|
|
216
|
-
sortResult = sortMultipleSelect(currCellVal, nextCellVal, {
|
|
217
|
-
sort_type: normalizedSortType,
|
|
218
|
-
option_id_index_map: option_id_index_map
|
|
219
|
-
});
|
|
220
|
-
} else if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
|
|
221
|
-
var currOriginalCellVal = currGroupRow.original_cell_value;
|
|
222
|
-
var nextOriginalCellVal = nextGroupRow.original_cell_value;
|
|
223
|
-
sortResult = sortFormula(currOriginalCellVal, nextOriginalCellVal, normalizedSortType, {
|
|
224
|
-
columnData: columnData,
|
|
225
|
-
value: value
|
|
226
|
-
});
|
|
227
|
-
} else if (columnType === CellType.LINK) {
|
|
228
|
-
var _currOriginalCellVal = currGroupRow.original_cell_value;
|
|
229
|
-
var _nextOriginalCellVal = nextGroupRow.original_cell_value;
|
|
230
|
-
sortResult = sortLink(_currOriginalCellVal, _nextOriginalCellVal, normalizedSortType, {
|
|
231
|
-
columnData: columnData,
|
|
232
|
-
value: value
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
return sortResult;
|
|
236
|
-
}
|
|
237
|
-
if (currCellVal === '') return 1;
|
|
238
|
-
if (nextCellVal === '') return -1;
|
|
239
|
-
return 0;
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// for nested group.
|
|
243
|
-
var isNestedGroup = Array.isArray(groups[0].subgroups) && groups[0].subgroups.length > 0;
|
|
244
|
-
if (isNestedGroup) {
|
|
245
|
-
var nextLevel = level + 1;
|
|
246
|
-
|
|
247
|
-
// eslint-disable-next-line
|
|
248
|
-
groups = groups.map(function (group) {
|
|
249
|
-
var sortedSubgroups = getSortedGroups(group.subgroups, groupbys, value, nextLevel);
|
|
250
|
-
return _objectSpread(_objectSpread({}, group), {}, {
|
|
251
|
-
subgroups: sortedSubgroups
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
return groups;
|
|
256
|
-
};
|
|
257
|
-
var groupRowsWithMultipleGroupbys = function groupRowsWithMultipleGroupbys(groupbys, rows, formulaRows, value) {
|
|
258
|
-
var validGroupbys = groupbys.length > MAX_GROUP_LEVEL ? groupbys.slice(0, MAX_GROUP_LEVEL) : _toConsumableArray(groupbys);
|
|
259
|
-
var groups = [];
|
|
260
|
-
var cellValue2GroupIndexMap = {};
|
|
261
|
-
rows.forEach(function (row) {
|
|
262
|
-
var rowId = row._id;
|
|
263
|
-
var updatedGroup;
|
|
264
|
-
var updateCellValue2GroupIndexMap;
|
|
265
|
-
for (var level = 0; level < validGroupbys.length; level++) {
|
|
266
|
-
var currentGroupby = validGroupbys[level];
|
|
267
|
-
var column = currentGroupby.column,
|
|
268
|
-
column_key = currentGroupby.column_key;
|
|
269
|
-
var columnType = column.type;
|
|
270
|
-
var cellValue = _getCellValue(row, formulaRows, currentGroupby);
|
|
271
|
-
var formattedValue = _getFormattedCellValue(cellValue, currentGroupby);
|
|
272
|
-
var sCellValue = _getStrCellValue(formattedValue, columnType);
|
|
273
|
-
var group = {
|
|
274
|
-
cell_value: formattedValue,
|
|
275
|
-
original_cell_value: cellValue,
|
|
276
|
-
row_ids: null,
|
|
277
|
-
column_key: column_key,
|
|
278
|
-
subgroups: [],
|
|
279
|
-
summaries: {}
|
|
280
|
-
};
|
|
281
|
-
if (level === 0) {
|
|
282
|
-
var groupedRowIndex = _findGroupIndexWithMultipleGroupbys(sCellValue, cellValue2GroupIndexMap, groups.length);
|
|
283
|
-
updateCellValue2GroupIndexMap = cellValue2GroupIndexMap[sCellValue].subgroups;
|
|
284
|
-
if (groupedRowIndex < 0) {
|
|
285
|
-
groups.push(group);
|
|
286
|
-
updatedGroup = groups[groups.length - 1];
|
|
287
|
-
} else {
|
|
288
|
-
updatedGroup = groups[groupedRowIndex];
|
|
289
|
-
}
|
|
290
|
-
} else {
|
|
291
|
-
var _groupedRowIndex = _findGroupIndexWithMultipleGroupbys(sCellValue, updateCellValue2GroupIndexMap, updatedGroup.subgroups.length);
|
|
292
|
-
updateCellValue2GroupIndexMap = updateCellValue2GroupIndexMap[sCellValue].subgroups;
|
|
293
|
-
if (_groupedRowIndex < 0) {
|
|
294
|
-
updatedGroup.subgroups.push(group);
|
|
295
|
-
updatedGroup = updatedGroup.subgroups[updatedGroup.subgroups.length - 1];
|
|
296
|
-
} else {
|
|
297
|
-
updatedGroup = updatedGroup.subgroups[_groupedRowIndex];
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// update row_ids in the deepest group.
|
|
301
|
-
if (level === validGroupbys.length - 1) {
|
|
302
|
-
if (!updatedGroup.row_ids) {
|
|
303
|
-
updatedGroup.row_ids = [rowId];
|
|
304
|
-
} else {
|
|
305
|
-
updatedGroup.row_ids.push(rowId);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
groups = getSortedGroups(groups, validGroupbys, value, 0);
|
|
312
|
-
return groups;
|
|
313
|
-
};
|
|
314
|
-
var groupTableRows = function groupTableRows(groupbys, rows, formulaRows, value) {
|
|
315
|
-
if (groupbys.length === 0) {
|
|
316
|
-
return [];
|
|
317
|
-
}
|
|
318
|
-
if (groupbys.length > 1) {
|
|
319
|
-
return groupRowsWithMultipleGroupbys(groupbys, rows, formulaRows, value);
|
|
320
|
-
}
|
|
321
|
-
var groupby = groupbys[0];
|
|
322
|
-
var column_key = groupby.column_key,
|
|
323
|
-
column = groupby.column;
|
|
324
|
-
var columnType = column.type;
|
|
325
|
-
var groups = [];
|
|
326
|
-
var cellValue2GroupIndexMap = {};
|
|
327
|
-
rows.forEach(function (r) {
|
|
328
|
-
var cellValue = _getCellValue(r, formulaRows, groupby);
|
|
329
|
-
var formattedValue = _getFormattedCellValue(cellValue, groupby);
|
|
330
|
-
var sCellValue = _getStrCellValue(formattedValue, columnType);
|
|
331
|
-
var groupedRowIndex = _findGroupIndex(sCellValue, cellValue2GroupIndexMap, groups.length);
|
|
332
|
-
if (groupedRowIndex > -1) {
|
|
333
|
-
groups[groupedRowIndex].row_ids.push(r._id);
|
|
334
|
-
} else {
|
|
335
|
-
groups.push({
|
|
336
|
-
cell_value: formattedValue,
|
|
337
|
-
original_cell_value: cellValue,
|
|
338
|
-
column_key: column_key,
|
|
339
|
-
row_ids: [r._id],
|
|
340
|
-
subgroups: null,
|
|
341
|
-
summaries: {}
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// sort groups
|
|
347
|
-
groups = getSortedGroups(groups, groupbys, value, 0);
|
|
348
|
-
return groups;
|
|
349
|
-
};
|
|
350
|
-
var groupViewRows = function groupViewRows(groupbys, table, rows, formulaRows, value) {
|
|
351
|
-
if (rows.length === 0) {
|
|
352
|
-
return [];
|
|
353
|
-
}
|
|
354
|
-
var rowsData = getRowsByIds(table, rows);
|
|
355
|
-
return groupTableRows(groupbys, rowsData, formulaRows, value);
|
|
356
|
-
};
|
|
357
|
-
var getGroupedRowsWithoutFormulaCalculation = function getGroupedRowsWithoutFormulaCalculation(groupbys, rows, table, value) {
|
|
358
|
-
var _ref3 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
359
|
-
_ref3$formulaRows = _ref3.formulaRows,
|
|
360
|
-
formulaRows = _ref3$formulaRows === void 0 ? null : _ref3$formulaRows;
|
|
361
|
-
var columns = table.columns;
|
|
362
|
-
var validGroupbys = deleteInvalidGroupby(groupbys, columns, table, value);
|
|
363
|
-
return isTableRows(rows) ? groupTableRows(validGroupbys, rows, formulaRows, value) : groupViewRows(validGroupbys, table, rows, formulaRows, value);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
export { getGroupedRowsWithoutFormulaCalculation, groupTableRows, groupViewRows };
|
package/es/link/core.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* get link by id
|
|
5
|
-
* @param {array} links [{ _id, ... }]
|
|
6
|
-
* @param {string} linkId
|
|
7
|
-
* @returns object
|
|
8
|
-
*/
|
|
9
|
-
var getLinkById = function getLinkById(links, linkId) {
|
|
10
|
-
if (!Array.isArray(links) || !linkId) return null;
|
|
11
|
-
return links.find(function (link) {
|
|
12
|
-
return link._id === linkId;
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* check is valid link by link column's data
|
|
18
|
-
* @param {object} columnData
|
|
19
|
-
* @returns boolean
|
|
20
|
-
*/
|
|
21
|
-
var isValidLink = function isValidLink(linkColumnData) {
|
|
22
|
-
if (!linkColumnData) return false;
|
|
23
|
-
var link_id = linkColumnData.link_id,
|
|
24
|
-
table_id = linkColumnData.table_id,
|
|
25
|
-
other_table_id = linkColumnData.other_table_id,
|
|
26
|
-
display_column_key = linkColumnData.display_column_key;
|
|
27
|
-
return !!(link_id && table_id && other_table_id && display_column_key);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* get current table's id
|
|
32
|
-
* @param {string} currentTableID
|
|
33
|
-
* @param {string} tableID
|
|
34
|
-
* @param {string} otherTableID
|
|
35
|
-
* @returns string
|
|
36
|
-
*/
|
|
37
|
-
var getLinkTableID = function getLinkTableID(currentTableID, tableID, otherTableID) {
|
|
38
|
-
return currentTableID === tableID ? tableID : otherTableID;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* get linked table's id
|
|
43
|
-
* @param {string} currentTableID
|
|
44
|
-
* @param {string} tableID
|
|
45
|
-
* @param {string} otherTableID
|
|
46
|
-
* @returns string
|
|
47
|
-
*/
|
|
48
|
-
var getLinkedTableID = function getLinkedTableID(currentTableID, tableID, otherTableID) {
|
|
49
|
-
return currentTableID === tableID ? otherTableID : tableID;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* get linked rows ids of the row id
|
|
54
|
-
* @param {array} links [ { _id: '', table1_id, table2_id: '', table1_table2_map: {}, table2_table1_map: {} }, ... ]
|
|
55
|
-
* @param {string} link_id
|
|
56
|
-
* @param {string} table1Id
|
|
57
|
-
* @param {string} table2Id
|
|
58
|
-
* @param {string} rowId
|
|
59
|
-
* @returns array, linked rows ids
|
|
60
|
-
*/
|
|
61
|
-
var getLinkCellValue = function getLinkCellValue(links, linkId, table1Id, table2Id, rowId) {
|
|
62
|
-
if (!Array.isArray(links) || links.length === 0 || !table1Id || !table2Id || !rowId) return [];
|
|
63
|
-
var linkBetween2Tables = getLinkById(links, linkId);
|
|
64
|
-
if (!linkBetween2Tables) return [];
|
|
65
|
-
var linkMap = {};
|
|
66
|
-
if (table1Id === table2Id) {
|
|
67
|
-
linkMap = linkBetween2Tables.table2_table1_map;
|
|
68
|
-
} else {
|
|
69
|
-
linkMap = linkBetween2Tables.table1_id === table1Id ? linkBetween2Tables.table1_table2_map : linkBetween2Tables.table2_table1_map;
|
|
70
|
-
}
|
|
71
|
-
var linkedRowIds = linkMap[rowId];
|
|
72
|
-
if (!linkedRowIds) {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
return _toConsumableArray(linkedRowIds);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export { getLinkById, getLinkCellValue, getLinkTableID, getLinkedTableID, isValidLink };
|
package/es/number.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* check whether is number
|
|
3
|
-
* @param {number} number
|
|
4
|
-
* @returns boolean
|
|
5
|
-
*/
|
|
6
|
-
var isNumber = function isNumber(number) {
|
|
7
|
-
return (number || number === 0) && Object.prototype.toString.call(number) === '[object Number]';
|
|
8
|
-
};
|
|
9
|
-
var isNumberEqual = function isNumberEqual(number1, number2) {
|
|
10
|
-
return number1 === number2 || Math.abs(number1 - number2) < 0.00001;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export { isNumber, isNumberEqual };
|