dtable-utils 0.0.1 → 0.0.3-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 +30 -2
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +227 -19
- package/es/cell-value-get/collaborator.js +9 -3
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/geolocation.js +41 -10
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +42 -18
- package/es/cell-value-get/option.js +17 -7
- package/es/cell-value-get/rate.js +6 -0
- package/es/cell-value-set/date.js +20 -0
- package/es/cell-value-set/number.js +53 -1
- package/es/color/gradient-color.js +100 -0
- package/es/column/color.js +415 -0
- package/es/column/{common.js → core.js} +3 -15
- package/es/column/date.js +2 -3
- package/es/column/number.js +3 -5
- package/es/column/option.js +115 -0
- package/es/common.js +10 -1
- package/es/constants/color.js +16 -0
- package/es/constants/column-permission.js +7 -0
- package/es/constants/column.js +127 -2
- package/es/constants/filter/index.js +5 -1
- package/es/constants/grid-header.js +6 -0
- package/es/constants/group.js +23 -0
- package/es/constants/limit.js +3 -0
- package/es/constants/reg.js +4 -0
- package/es/constants/row-color.js +11 -0
- package/es/constants/sort.js +11 -0
- package/es/date.js +1 -1
- package/es/filter/core.js +287 -0
- package/es/filter/filter-column/array.js +82 -0
- package/es/filter/filter-column/checkbox.js +8 -0
- package/es/filter/filter-column/collaborator.js +67 -0
- package/es/filter/filter-column/creator.js +50 -0
- package/es/filter/filter-column/date.js +59 -0
- package/es/filter/filter-column/digital-sign.js +26 -0
- package/es/filter/filter-column/file.js +24 -0
- package/es/filter/filter-column/formula.js +49 -0
- package/es/filter/filter-column/geolocation.js +53 -0
- package/es/filter/filter-column/link.js +12 -0
- package/es/filter/filter-column/long-text.js +25 -0
- package/es/filter/filter-column/multiple-select.js +60 -0
- package/es/filter/filter-column/number.js +93 -0
- package/es/filter/filter-column/single-select.js +41 -0
- package/es/filter/filter-column/text.js +55 -0
- package/es/filter/filter-row.js +198 -0
- package/es/group/core.js +107 -0
- package/es/group/group-row.js +366 -0
- package/es/index.js +62 -10
- package/es/link/core.js +78 -0
- package/es/number.js +13 -0
- package/es/row/color.js +278 -0
- package/es/row/core.js +161 -0
- package/es/sort/core.js +32 -0
- package/es/sort/sort-column/array.js +63 -0
- package/es/sort/sort-column/checkbox.js +15 -0
- package/es/sort/sort-column/collaborator.js +9 -0
- package/es/sort/sort-column/date.js +25 -0
- package/es/sort/sort-column/formula.js +40 -0
- package/es/sort/sort-column/link.js +23 -0
- package/es/sort/sort-column/multiple-select.js +45 -0
- package/es/sort/sort-column/number.js +18 -0
- package/es/sort/sort-column/single-select.js +22 -0
- package/es/sort/sort-column/text.js +47 -0
- package/es/sort/sort-row.js +126 -0
- package/es/table/column.js +27 -0
- package/es/table/core.js +14 -0
- package/es/table/index.js +14 -0
- package/es/table/row.js +25 -0
- package/es/validate/filter.js +1 -1
- package/es/validate/geolocation.js +5 -0
- package/es/view/core.js +135 -0
- package/es/view/formula.js +143 -0
- package/es/view/group.js +32 -0
- package/es/view/summaries.js +179 -0
- package/lib/cell-value-get/cell-value.js +231 -18
- package/lib/cell-value-get/collaborator.js +9 -2
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/geolocation.js +42 -10
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +42 -17
- package/lib/cell-value-get/option.js +18 -6
- package/lib/cell-value-get/rate.js +10 -0
- package/lib/cell-value-set/date.js +24 -0
- package/lib/cell-value-set/number.js +53 -0
- package/lib/color/gradient-color.js +110 -0
- package/lib/column/color.js +424 -0
- package/lib/column/{common.js → core.js} +3 -16
- package/lib/column/date.js +2 -3
- package/lib/column/number.js +3 -5
- package/lib/column/option.js +123 -0
- package/lib/common.js +14 -0
- package/lib/constants/color.js +20 -0
- package/lib/constants/column-permission.js +11 -0
- package/lib/constants/column.js +134 -1
- package/lib/constants/filter/index.js +5 -0
- package/lib/constants/grid-header.js +10 -0
- package/lib/constants/group.js +36 -0
- package/lib/constants/limit.js +7 -0
- package/lib/constants/reg.js +9 -0
- package/lib/constants/row-color.js +17 -0
- package/lib/constants/sort.js +18 -0
- package/lib/filter/core.js +301 -0
- package/lib/filter/filter-column/array.js +86 -0
- package/lib/filter/filter-column/checkbox.js +12 -0
- package/lib/filter/filter-column/collaborator.js +75 -0
- package/lib/filter/filter-column/creator.js +54 -0
- package/lib/filter/filter-column/date.js +63 -0
- package/lib/filter/filter-column/digital-sign.js +30 -0
- package/lib/filter/filter-column/file.js +28 -0
- package/lib/filter/filter-column/formula.js +53 -0
- package/lib/filter/filter-column/geolocation.js +57 -0
- package/lib/filter/filter-column/link.js +16 -0
- package/lib/filter/filter-column/long-text.js +29 -0
- package/lib/filter/filter-column/multiple-select.js +68 -0
- package/lib/filter/filter-column/number.js +97 -0
- package/lib/filter/filter-column/single-select.js +45 -0
- package/lib/filter/filter-column/text.js +59 -0
- package/lib/filter/filter-row.js +204 -0
- package/lib/group/core.js +117 -0
- package/lib/group/group-row.js +377 -0
- package/lib/index.js +176 -6
- package/lib/link/core.js +90 -0
- package/lib/number.js +18 -0
- package/lib/row/color.js +286 -0
- package/lib/row/core.js +170 -0
- package/lib/sort/core.js +37 -0
- package/lib/sort/sort-column/array.js +67 -0
- package/lib/sort/sort-column/checkbox.js +19 -0
- package/lib/sort/sort-column/collaborator.js +13 -0
- package/lib/sort/sort-column/date.js +29 -0
- package/lib/sort/sort-column/formula.js +44 -0
- package/lib/sort/sort-column/link.js +27 -0
- package/lib/sort/sort-column/multiple-select.js +50 -0
- package/lib/sort/sort-column/number.js +22 -0
- package/lib/sort/sort-column/single-select.js +26 -0
- package/lib/sort/sort-column/text.js +52 -0
- package/lib/sort/sort-row.js +136 -0
- package/lib/table/column.js +32 -0
- package/lib/table/core.js +18 -0
- package/lib/table/index.js +18 -0
- package/lib/table/row.js +30 -0
- package/lib/validate/filter.js +3 -3
- package/lib/validate/geolocation.js +9 -0
- package/lib/view/core.js +144 -0
- package/lib/view/formula.js +150 -0
- package/lib/view/group.js +36 -0
- package/lib/view/summaries.js +185 -0
- package/package.json +4 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { getFormattedFilters, deleteInvalidFilter } from './core.js';
|
|
2
|
+
import { checkboxFilter } from './filter-column/checkbox.js';
|
|
3
|
+
import { collaboratorFilter } from './filter-column/collaborator.js';
|
|
4
|
+
import { creatorFilter } from './filter-column/creator.js';
|
|
5
|
+
import { dateFilter } from './filter-column/date.js';
|
|
6
|
+
import { digitalSignFilter } from './filter-column/digital-sign.js';
|
|
7
|
+
import { fileFilter } from './filter-column/file.js';
|
|
8
|
+
import { formulaFilter } from './filter-column/formula.js';
|
|
9
|
+
import { geolocationFilter } from './filter-column/geolocation.js';
|
|
10
|
+
import { textFilter } from './filter-column/text.js';
|
|
11
|
+
import { longTextFilter } from './filter-column/long-text.js';
|
|
12
|
+
import { multipleSelectFilter } from './filter-column/multiple-select.js';
|
|
13
|
+
import { numberFilter } from './filter-column/number.js';
|
|
14
|
+
import { singleSelectFilter } from './filter-column/single-select.js';
|
|
15
|
+
import { linkFilter } from './filter-column/link.js';
|
|
16
|
+
import { FILTER_CONJUNCTION_TYPE } from '../constants/filter/index.js';
|
|
17
|
+
import { DateUtils } from '../date.js';
|
|
18
|
+
import { CellType } from '../constants/cell-type.js';
|
|
19
|
+
import { DATE_FORMAT_MAP } from '../constants/column.js';
|
|
20
|
+
|
|
21
|
+
var getFilterResult = function getFilterResult(row, filter, _ref) {
|
|
22
|
+
var formulaRow = _ref.formulaRow,
|
|
23
|
+
username = _ref.username,
|
|
24
|
+
userId = _ref.userId;
|
|
25
|
+
var column_key = filter.column_key,
|
|
26
|
+
column = filter.column;
|
|
27
|
+
var cellValue = row[column_key];
|
|
28
|
+
switch (column.type) {
|
|
29
|
+
case CellType.CHECKBOX:
|
|
30
|
+
{
|
|
31
|
+
return checkboxFilter(cellValue, filter);
|
|
32
|
+
}
|
|
33
|
+
case CellType.SINGLE_SELECT:
|
|
34
|
+
{
|
|
35
|
+
return singleSelectFilter(cellValue, filter);
|
|
36
|
+
}
|
|
37
|
+
case CellType.MULTIPLE_SELECT:
|
|
38
|
+
{
|
|
39
|
+
return multipleSelectFilter(cellValue, filter);
|
|
40
|
+
}
|
|
41
|
+
case CellType.DURATION:
|
|
42
|
+
case CellType.NUMBER:
|
|
43
|
+
case CellType.RATE:
|
|
44
|
+
{
|
|
45
|
+
return numberFilter(cellValue, filter);
|
|
46
|
+
}
|
|
47
|
+
case CellType.DATE:
|
|
48
|
+
{
|
|
49
|
+
return dateFilter(cellValue, filter);
|
|
50
|
+
}
|
|
51
|
+
case CellType.CTIME:
|
|
52
|
+
case CellType.MTIME:
|
|
53
|
+
{
|
|
54
|
+
cellValue = DateUtils.format(cellValue, DATE_FORMAT_MAP.YYYY_MM_DD_HH_MM_SS);
|
|
55
|
+
return dateFilter(cellValue, filter);
|
|
56
|
+
}
|
|
57
|
+
case CellType.COLLABORATOR:
|
|
58
|
+
{
|
|
59
|
+
return collaboratorFilter(cellValue, filter, username);
|
|
60
|
+
}
|
|
61
|
+
case CellType.LONG_TEXT:
|
|
62
|
+
{
|
|
63
|
+
return longTextFilter(cellValue, filter);
|
|
64
|
+
}
|
|
65
|
+
case CellType.TEXT:
|
|
66
|
+
case CellType.AUTO_NUMBER:
|
|
67
|
+
case CellType.EMAIL:
|
|
68
|
+
case CellType.URL:
|
|
69
|
+
{
|
|
70
|
+
return textFilter(cellValue, filter, userId);
|
|
71
|
+
}
|
|
72
|
+
case CellType.IMAGE:
|
|
73
|
+
case CellType.FILE:
|
|
74
|
+
{
|
|
75
|
+
return fileFilter(cellValue, filter);
|
|
76
|
+
}
|
|
77
|
+
case CellType.LAST_MODIFIER:
|
|
78
|
+
case CellType.CREATOR:
|
|
79
|
+
{
|
|
80
|
+
return creatorFilter(cellValue, filter, username);
|
|
81
|
+
}
|
|
82
|
+
case CellType.GEOLOCATION:
|
|
83
|
+
{
|
|
84
|
+
return geolocationFilter(cellValue, filter);
|
|
85
|
+
}
|
|
86
|
+
case CellType.FORMULA:
|
|
87
|
+
case CellType.LINK_FORMULA:
|
|
88
|
+
{
|
|
89
|
+
cellValue = formulaRow[column_key];
|
|
90
|
+
return formulaFilter(cellValue, filter, {
|
|
91
|
+
username: username,
|
|
92
|
+
userId: userId
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
case CellType.LINK:
|
|
96
|
+
{
|
|
97
|
+
cellValue = formulaRow[column_key];
|
|
98
|
+
cellValue = Array.isArray(cellValue) ? cellValue.map(function (linked) {
|
|
99
|
+
return linked.display_value;
|
|
100
|
+
}) : null;
|
|
101
|
+
return linkFilter(cellValue, filter, {
|
|
102
|
+
username: username,
|
|
103
|
+
userId: userId
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
case CellType.DIGITAL_SIGN:
|
|
107
|
+
{
|
|
108
|
+
return digitalSignFilter(cellValue, filter);
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
{
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var filterRow = function filterRow(row, filterConjunction, filters) {
|
|
117
|
+
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
118
|
+
_ref2$formulaRow = _ref2.formulaRow,
|
|
119
|
+
formulaRow = _ref2$formulaRow === void 0 ? {} : _ref2$formulaRow,
|
|
120
|
+
_ref2$username = _ref2.username,
|
|
121
|
+
username = _ref2$username === void 0 ? '' : _ref2$username,
|
|
122
|
+
userId = _ref2.userId;
|
|
123
|
+
if (filterConjunction === FILTER_CONJUNCTION_TYPE.AND) {
|
|
124
|
+
return filters.every(function (filter) {
|
|
125
|
+
return getFilterResult(row, filter, {
|
|
126
|
+
formulaRow: formulaRow,
|
|
127
|
+
username: username,
|
|
128
|
+
userId: userId
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (filterConjunction === FILTER_CONJUNCTION_TYPE.OR) {
|
|
133
|
+
return filters.some(function (filter) {
|
|
134
|
+
return getFilterResult(row, filter, {
|
|
135
|
+
formulaRow: formulaRow,
|
|
136
|
+
username: username,
|
|
137
|
+
userId: userId
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
var filterRows = function filterRows(filterConjunction, filters, rows, _ref3) {
|
|
144
|
+
var formulaRows = _ref3.formulaRows,
|
|
145
|
+
username = _ref3.username,
|
|
146
|
+
userId = _ref3.userId;
|
|
147
|
+
var filteredRows = [];
|
|
148
|
+
var formattedFilters = getFormattedFilters(filters);
|
|
149
|
+
rows.forEach(function (row) {
|
|
150
|
+
var rowId = row._id;
|
|
151
|
+
var formulaRow = formulaRows && formulaRows[rowId] ? formulaRows[rowId] : {};
|
|
152
|
+
if (filterRow(row, filterConjunction, formattedFilters, {
|
|
153
|
+
formulaRow: formulaRow,
|
|
154
|
+
username: username,
|
|
155
|
+
userId: userId
|
|
156
|
+
})) {
|
|
157
|
+
filteredRows.push(rowId);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return filteredRows;
|
|
161
|
+
};
|
|
162
|
+
var getFilteredRowsWithoutFormulaCalculation = function getFilteredRowsWithoutFormulaCalculation(filterConjunction, filters, rows, table) {
|
|
163
|
+
var _ref4 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
164
|
+
_ref4$formulaRows = _ref4.formulaRows,
|
|
165
|
+
formulaRows = _ref4$formulaRows === void 0 ? null : _ref4$formulaRows,
|
|
166
|
+
_ref4$username = _ref4.username,
|
|
167
|
+
username = _ref4$username === void 0 ? null : _ref4$username,
|
|
168
|
+
_ref4$userId = _ref4.userId,
|
|
169
|
+
userId = _ref4$userId === void 0 ? null : _ref4$userId;
|
|
170
|
+
var columns = table.columns;
|
|
171
|
+
var validFilters = [];
|
|
172
|
+
try {
|
|
173
|
+
validFilters = deleteInvalidFilter(filters, columns);
|
|
174
|
+
} catch (err) {
|
|
175
|
+
return {
|
|
176
|
+
row_ids: [],
|
|
177
|
+
error_message: err.message
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
var filteredRows = [];
|
|
181
|
+
if (validFilters.length === 0) {
|
|
182
|
+
filteredRows = rows.map(function (row) {
|
|
183
|
+
return row._id;
|
|
184
|
+
});
|
|
185
|
+
} else {
|
|
186
|
+
filteredRows = filterRows(filterConjunction, validFilters, rows, {
|
|
187
|
+
formulaRows: formulaRows,
|
|
188
|
+
username: username,
|
|
189
|
+
userId: userId
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
row_ids: filteredRows,
|
|
194
|
+
error_message: null
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export { filterRow, filterRows, getFilteredRowsWithoutFormulaCalculation };
|
package/es/group/core.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import { isDateColumn } from '../column/date.js';
|
|
3
|
+
import { getLinkedTableID } from '../link/core.js';
|
|
4
|
+
import { getTableColumnByKey } from '../table/column.js';
|
|
5
|
+
import { getTableById } from '../table/core.js';
|
|
6
|
+
import { CellType } from '../constants/cell-type.js';
|
|
7
|
+
import { SUPPORT_GROUP_COLUMN_TYPES, GROUP_DATE_GRANULARITY, GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
|
|
8
|
+
|
|
9
|
+
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; }
|
|
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
|
+
|
|
12
|
+
/**
|
|
13
|
+
* check is valid groupby
|
|
14
|
+
* @param {object} groupby { column_key: '', count_type: '', sort_type: '' }
|
|
15
|
+
* @param {array} columns
|
|
16
|
+
* @returns boolean
|
|
17
|
+
*/
|
|
18
|
+
var isValidGroupby = function isValidGroupby(groupby, columns) {
|
|
19
|
+
if (!groupby || !Array.isArray(columns)) return false;
|
|
20
|
+
var column_key = groupby.column_key;
|
|
21
|
+
var groupbyColumn = columns.find(function (column) {
|
|
22
|
+
return column.key === column_key;
|
|
23
|
+
});
|
|
24
|
+
if (!groupbyColumn) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return SUPPORT_GROUP_COLUMN_TYPES.includes(groupbyColumn.type);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* get valid groupbys
|
|
32
|
+
* @param {array} groupbys
|
|
33
|
+
* @param {array} columns
|
|
34
|
+
* @returns array
|
|
35
|
+
*/
|
|
36
|
+
var getValidGroupbys = function getValidGroupbys(groupbys, columns) {
|
|
37
|
+
if (!Array.isArray(groupbys) || !Array.isArray(columns)) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return groupbys.filter(function (groupby) {
|
|
41
|
+
return isValidGroupby(groupby, columns);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var deleteInvalidGroupby = function deleteInvalidGroupby(groupbys, columns, currentTable, value) {
|
|
45
|
+
var validGroupbys = getValidGroupbys(groupbys, columns);
|
|
46
|
+
var cleanGroupbys = [];
|
|
47
|
+
validGroupbys.forEach(function (groupby) {
|
|
48
|
+
var groupbyColumnKey = groupby.column_key,
|
|
49
|
+
count_type = groupby.count_type;
|
|
50
|
+
var groupbyColumn = columns.find(function (column) {
|
|
51
|
+
return groupbyColumnKey === column.key;
|
|
52
|
+
});
|
|
53
|
+
var columnType = groupbyColumn.type,
|
|
54
|
+
columnData = groupbyColumn.data;
|
|
55
|
+
var newGroupby = _objectSpread(_objectSpread({}, groupby), {}, {
|
|
56
|
+
column: groupbyColumn
|
|
57
|
+
});
|
|
58
|
+
switch (columnType) {
|
|
59
|
+
case CellType.DATE:
|
|
60
|
+
case CellType.CTIME:
|
|
61
|
+
case CellType.MTIME:
|
|
62
|
+
{
|
|
63
|
+
newGroupby.count_type = count_type || GROUP_DATE_GRANULARITY.MONTH;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case CellType.GEOLOCATION:
|
|
67
|
+
{
|
|
68
|
+
newGroupby.count_type = count_type || GROUP_GEOLOCATION_GRANULARITY.PROVINCE;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case CellType.COLLABORATOR:
|
|
72
|
+
{
|
|
73
|
+
var collaborator_email_map = {};
|
|
74
|
+
value.collaborators.forEach(function (collaborator) {
|
|
75
|
+
collaborator_email_map[collaborator.email] = true;
|
|
76
|
+
});
|
|
77
|
+
newGroupby.collaborator_email_map = collaborator_email_map;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case CellType.LINK:
|
|
81
|
+
{
|
|
82
|
+
var table_id = columnData.table_id,
|
|
83
|
+
other_table_id = columnData.other_table_id,
|
|
84
|
+
display_column_key = columnData.display_column_key;
|
|
85
|
+
var currentTableId = currentTable ? currentTable._id : '';
|
|
86
|
+
var linkedTableID = getLinkedTableID(currentTableId, table_id, other_table_id);
|
|
87
|
+
var linkedTable = getTableById(value.tables, linkedTableID);
|
|
88
|
+
var displayColumn = getTableColumnByKey(linkedTable, display_column_key);
|
|
89
|
+
newGroupby.linked_table = linkedTable;
|
|
90
|
+
newGroupby.display_column = displayColumn;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case CellType.FORMULA:
|
|
94
|
+
case CellType.LINK_FORMULA:
|
|
95
|
+
{
|
|
96
|
+
if (isDateColumn(groupbyColumn) && !count_type) {
|
|
97
|
+
newGroupby.count_type = GROUP_DATE_GRANULARITY.MONTH;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
cleanGroupbys.push(newGroupby);
|
|
103
|
+
});
|
|
104
|
+
return cleanGroupbys;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { deleteInvalidGroupby, getValidGroupbys, isValidGroupby };
|
|
@@ -0,0 +1,366 @@
|
|
|
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 };
|