dtable-utils 0.0.3 → 4.2.0
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 +56 -5
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +250 -20
- package/es/cell-value-get/collaborator.js +16 -3
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/duration.js +3 -3
- package/es/cell-value-get/geolocation.js +52 -30
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +51 -19
- package/es/cell-value-get/option.js +33 -9
- package/es/cell-value-get/rate.js +11 -0
- package/es/cell-value-set/date.js +26 -0
- package/es/cell-value-set/number.js +53 -1
- package/es/color/column-color.js +437 -0
- package/es/color/gradient-color.js +100 -0
- package/es/color/row-color.js +289 -0
- package/es/column/{common.js → core.js} +2 -14
- package/es/column/date.js +1 -1
- package/es/column/number.js +1 -1
- package/es/column/option.js +143 -0
- package/es/common.js +23 -3
- 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/formula.js +2 -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 +322 -0
- package/es/filter/filter-column/array.js +87 -0
- package/es/filter/filter-column/checkbox.js +14 -0
- package/es/filter/filter-column/collaborator.js +72 -0
- package/es/filter/filter-column/creator.js +59 -0
- package/es/filter/filter-column/date.js +102 -0
- package/es/filter/filter-column/digital-sign.js +29 -0
- package/es/filter/filter-column/file.js +27 -0
- package/es/filter/filter-column/formula.js +57 -0
- package/es/filter/filter-column/geolocation.js +58 -0
- package/es/filter/filter-column/link.js +20 -0
- package/es/filter/filter-column/long-text.js +28 -0
- package/es/filter/filter-column/multiple-select.js +64 -0
- package/es/filter/filter-column/number.js +97 -0
- package/es/filter/filter-column/single-select.js +45 -0
- package/es/filter/filter-column/text.js +60 -0
- package/es/filter/filter-row.js +233 -0
- package/es/group/core.js +116 -0
- package/es/group/group-row.js +402 -0
- package/es/index.js +63 -11
- package/es/link/core.js +78 -0
- package/es/number.js +21 -0
- package/es/row/core.js +180 -0
- package/es/sort/core.js +91 -0
- package/es/sort/sort-column/array.js +72 -0
- package/es/sort/sort-column/checkbox.js +22 -0
- package/es/sort/sort-column/collaborator.js +16 -0
- package/es/sort/sort-column/date.js +25 -0
- package/es/sort/sort-column/formula.js +49 -0
- package/es/sort/sort-column/link.js +32 -0
- package/es/sort/sort-column/multiple-select.js +45 -0
- package/es/sort/sort-column/number.js +31 -0
- package/es/sort/sort-column/single-select.js +36 -0
- package/es/sort/sort-column/text.js +69 -0
- package/es/sort/sort-row.js +110 -0
- package/es/table/column.js +27 -0
- package/es/table/core.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 +134 -0
- package/es/view/formula.js +147 -0
- package/es/view/group.js +32 -0
- package/es/view/summaries.js +167 -0
- package/lib/cell-value-get/cell-value.js +254 -19
- package/lib/cell-value-get/collaborator.js +16 -2
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/duration.js +3 -2
- package/lib/cell-value-get/geolocation.js +53 -30
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +51 -18
- package/lib/cell-value-get/option.js +34 -8
- package/lib/cell-value-get/rate.js +15 -0
- package/lib/cell-value-set/date.js +30 -0
- package/lib/cell-value-set/number.js +53 -0
- package/lib/color/column-color.js +446 -0
- package/lib/color/gradient-color.js +110 -0
- package/lib/color/row-color.js +297 -0
- package/lib/column/{common.js → core.js} +1 -14
- package/lib/column/date.js +2 -2
- package/lib/column/number.js +3 -3
- package/lib/column/option.js +151 -0
- package/lib/common.js +27 -3
- 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/formula.js +2 -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 +336 -0
- package/lib/filter/filter-column/array.js +91 -0
- package/lib/filter/filter-column/checkbox.js +18 -0
- package/lib/filter/filter-column/collaborator.js +80 -0
- package/lib/filter/filter-column/creator.js +63 -0
- package/lib/filter/filter-column/date.js +106 -0
- package/lib/filter/filter-column/digital-sign.js +33 -0
- package/lib/filter/filter-column/file.js +31 -0
- package/lib/filter/filter-column/formula.js +61 -0
- package/lib/filter/filter-column/geolocation.js +62 -0
- package/lib/filter/filter-column/link.js +24 -0
- package/lib/filter/filter-column/long-text.js +32 -0
- package/lib/filter/filter-column/multiple-select.js +72 -0
- package/lib/filter/filter-column/number.js +101 -0
- package/lib/filter/filter-column/single-select.js +49 -0
- package/lib/filter/filter-column/text.js +64 -0
- package/lib/filter/filter-row.js +239 -0
- package/lib/group/core.js +126 -0
- package/lib/group/group-row.js +413 -0
- package/lib/index.js +177 -7
- package/lib/link/core.js +90 -0
- package/lib/number.js +26 -0
- package/lib/row/core.js +189 -0
- package/lib/sort/core.js +102 -0
- package/lib/sort/sort-column/array.js +76 -0
- package/lib/sort/sort-column/checkbox.js +26 -0
- package/lib/sort/sort-column/collaborator.js +20 -0
- package/lib/sort/sort-column/date.js +29 -0
- package/lib/sort/sort-column/formula.js +53 -0
- package/lib/sort/sort-column/link.js +36 -0
- package/lib/sort/sort-column/multiple-select.js +49 -0
- package/lib/sort/sort-column/number.js +35 -0
- package/lib/sort/sort-column/single-select.js +40 -0
- package/lib/sort/sort-column/text.js +74 -0
- package/lib/sort/sort-row.js +115 -0
- package/lib/table/column.js +32 -0
- package/lib/table/core.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 +143 -0
- package/lib/view/formula.js +154 -0
- package/lib/view/group.js +36 -0
- package/lib/view/summaries.js +173 -0
- package/package.json +5 -3
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filter text
|
|
5
|
+
* @param {string} text
|
|
6
|
+
* @param {string} filter_predicate
|
|
7
|
+
* @param {string} filter_term
|
|
8
|
+
* @param {string} userId
|
|
9
|
+
* @returns bool
|
|
10
|
+
*/
|
|
11
|
+
var textFilter = function textFilter(text, _ref, userId) {
|
|
12
|
+
var filter_predicate = _ref.filter_predicate,
|
|
13
|
+
filter_term = _ref.filter_term;
|
|
14
|
+
switch (filter_predicate) {
|
|
15
|
+
case FILTER_PREDICATE_TYPE.CONTAINS:
|
|
16
|
+
{
|
|
17
|
+
if (!filter_term) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (!text) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return text.toString().toLowerCase().indexOf(filter_term.toLowerCase()) > -1;
|
|
24
|
+
}
|
|
25
|
+
case FILTER_PREDICATE_TYPE.NOT_CONTAIN:
|
|
26
|
+
{
|
|
27
|
+
if (!filter_term || !text) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return text.toString().toLowerCase().indexOf(filter_term.toLowerCase()) < 0;
|
|
31
|
+
}
|
|
32
|
+
case FILTER_PREDICATE_TYPE.IS:
|
|
33
|
+
{
|
|
34
|
+
return !filter_term || text === filter_term;
|
|
35
|
+
}
|
|
36
|
+
case FILTER_PREDICATE_TYPE.IS_NOT:
|
|
37
|
+
{
|
|
38
|
+
return !filter_term || text !== filter_term;
|
|
39
|
+
}
|
|
40
|
+
case FILTER_PREDICATE_TYPE.EMPTY:
|
|
41
|
+
{
|
|
42
|
+
return !text;
|
|
43
|
+
}
|
|
44
|
+
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
|
|
45
|
+
{
|
|
46
|
+
return !!text;
|
|
47
|
+
}
|
|
48
|
+
case FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID:
|
|
49
|
+
{
|
|
50
|
+
if (!userId) return false;
|
|
51
|
+
return text === userId;
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
{
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { textFilter };
|
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Filter row
|
|
119
|
+
* @param {object} row e.g. { _id, .... }
|
|
120
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
121
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
122
|
+
* @param {object} formulaRow
|
|
123
|
+
* @param {string} username
|
|
124
|
+
* @param {string} userId
|
|
125
|
+
* @returns filter result, bool
|
|
126
|
+
*/
|
|
127
|
+
var filterRow = function filterRow(row, filterConjunction, filters) {
|
|
128
|
+
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
129
|
+
_ref2$formulaRow = _ref2.formulaRow,
|
|
130
|
+
formulaRow = _ref2$formulaRow === void 0 ? {} : _ref2$formulaRow,
|
|
131
|
+
_ref2$username = _ref2.username,
|
|
132
|
+
username = _ref2$username === void 0 ? '' : _ref2$username,
|
|
133
|
+
userId = _ref2.userId;
|
|
134
|
+
if (filterConjunction === FILTER_CONJUNCTION_TYPE.AND) {
|
|
135
|
+
return filters.every(function (filter) {
|
|
136
|
+
return getFilterResult(row, filter, {
|
|
137
|
+
formulaRow: formulaRow,
|
|
138
|
+
username: username,
|
|
139
|
+
userId: userId
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (filterConjunction === FILTER_CONJUNCTION_TYPE.OR) {
|
|
144
|
+
return filters.some(function (filter) {
|
|
145
|
+
return getFilterResult(row, filter, {
|
|
146
|
+
formulaRow: formulaRow,
|
|
147
|
+
username: username,
|
|
148
|
+
userId: userId
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Filter rows
|
|
157
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
158
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
159
|
+
* @param {array} rows e.g. [{ _id, .... }, ...]
|
|
160
|
+
* @param {object} formulaRows
|
|
161
|
+
* @param {string} username
|
|
162
|
+
* @param {userId} username
|
|
163
|
+
* @returns filtered rows ids, array
|
|
164
|
+
*/
|
|
165
|
+
var filterRows = function filterRows(filterConjunction, filters, rows, _ref3) {
|
|
166
|
+
var formulaRows = _ref3.formulaRows,
|
|
167
|
+
username = _ref3.username,
|
|
168
|
+
userId = _ref3.userId;
|
|
169
|
+
var filteredRows = [];
|
|
170
|
+
var formattedFilters = getFormattedFilters(filters);
|
|
171
|
+
rows.forEach(function (row) {
|
|
172
|
+
var rowId = row._id;
|
|
173
|
+
var formulaRow = formulaRows && formulaRows[rowId] ? formulaRows[rowId] : {};
|
|
174
|
+
if (filterRow(row, filterConjunction, formattedFilters, {
|
|
175
|
+
formulaRow: formulaRow,
|
|
176
|
+
username: username,
|
|
177
|
+
userId: userId
|
|
178
|
+
})) {
|
|
179
|
+
filteredRows.push(rowId);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return filteredRows;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Filter rows without formula calculation
|
|
187
|
+
* The "formulaRows" need to be provided if you want to filter formula, link columns etc.
|
|
188
|
+
* @param {string} filterConjunction e.g. 'And' | 'Or'
|
|
189
|
+
* @param {array} filters e.g. [{ column_key, filter_predicate, ... }, ...]
|
|
190
|
+
* @param {array} rows e.g. [{ _id, .... }, ...]
|
|
191
|
+
* @param {object} table e.g. { columns, ... }
|
|
192
|
+
* @param {object} formulaRows
|
|
193
|
+
* @param {string} username
|
|
194
|
+
* @param {userId} username
|
|
195
|
+
* @returns filtered rows: row_ids and error message: error_message, object
|
|
196
|
+
*/
|
|
197
|
+
var getFilteredRowsWithoutFormulaCalculation = function getFilteredRowsWithoutFormulaCalculation(filterConjunction, filters, rows, table) {
|
|
198
|
+
var _ref4 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
199
|
+
_ref4$formulaRows = _ref4.formulaRows,
|
|
200
|
+
formulaRows = _ref4$formulaRows === void 0 ? null : _ref4$formulaRows,
|
|
201
|
+
_ref4$username = _ref4.username,
|
|
202
|
+
username = _ref4$username === void 0 ? null : _ref4$username,
|
|
203
|
+
_ref4$userId = _ref4.userId,
|
|
204
|
+
userId = _ref4$userId === void 0 ? null : _ref4$userId;
|
|
205
|
+
var columns = table.columns;
|
|
206
|
+
var validFilters = [];
|
|
207
|
+
try {
|
|
208
|
+
validFilters = deleteInvalidFilter(filters, columns);
|
|
209
|
+
} catch (err) {
|
|
210
|
+
return {
|
|
211
|
+
row_ids: [],
|
|
212
|
+
error_message: err.message
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
var filteredRows = [];
|
|
216
|
+
if (validFilters.length === 0) {
|
|
217
|
+
filteredRows = rows.map(function (row) {
|
|
218
|
+
return row._id;
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
filteredRows = filterRows(filterConjunction, validFilters, rows, {
|
|
222
|
+
formulaRows: formulaRows,
|
|
223
|
+
username: username,
|
|
224
|
+
userId: userId
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
row_ids: filteredRows,
|
|
229
|
+
error_message: null
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export { filterRow, filterRows, getFilteredRowsWithoutFormulaCalculation };
|
package/es/group/core.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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 e.g. { column_key, count_type, sort_type, ... }
|
|
15
|
+
* @param {array} columns
|
|
16
|
+
* @returns bool
|
|
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 e.g. [{ column_key, count_type, ... }, ...]
|
|
33
|
+
* @param {array} columns
|
|
34
|
+
* @returns valid groupbys, 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
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get valid and formatted groupbys
|
|
47
|
+
* @param {array} groupbys e.g. [{ column_key, count_type, ... }, ...]
|
|
48
|
+
* @param {array} columns
|
|
49
|
+
* @param {object} currentTable e.g. { _id, ... }
|
|
50
|
+
* @param {object} value e.g. { tables, collaborators }
|
|
51
|
+
* @returns valid and formatted groupbys
|
|
52
|
+
*/
|
|
53
|
+
var deleteInvalidGroupby = function deleteInvalidGroupby(groupbys, columns, currentTable, value) {
|
|
54
|
+
var validGroupbys = getValidGroupbys(groupbys, columns);
|
|
55
|
+
var cleanGroupbys = [];
|
|
56
|
+
validGroupbys.forEach(function (groupby) {
|
|
57
|
+
var groupbyColumnKey = groupby.column_key,
|
|
58
|
+
count_type = groupby.count_type;
|
|
59
|
+
var groupbyColumn = columns.find(function (column) {
|
|
60
|
+
return groupbyColumnKey === column.key;
|
|
61
|
+
});
|
|
62
|
+
var columnType = groupbyColumn.type,
|
|
63
|
+
columnData = groupbyColumn.data;
|
|
64
|
+
var newGroupby = _objectSpread(_objectSpread({}, groupby), {}, {
|
|
65
|
+
column: groupbyColumn
|
|
66
|
+
});
|
|
67
|
+
switch (columnType) {
|
|
68
|
+
case CellType.DATE:
|
|
69
|
+
case CellType.CTIME:
|
|
70
|
+
case CellType.MTIME:
|
|
71
|
+
{
|
|
72
|
+
newGroupby.count_type = count_type || GROUP_DATE_GRANULARITY.MONTH;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case CellType.GEOLOCATION:
|
|
76
|
+
{
|
|
77
|
+
newGroupby.count_type = count_type || GROUP_GEOLOCATION_GRANULARITY.PROVINCE;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case CellType.COLLABORATOR:
|
|
81
|
+
{
|
|
82
|
+
var collaborator_email_map = {};
|
|
83
|
+
value.collaborators.forEach(function (collaborator) {
|
|
84
|
+
collaborator_email_map[collaborator.email] = true;
|
|
85
|
+
});
|
|
86
|
+
newGroupby.collaborator_email_map = collaborator_email_map;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case CellType.LINK:
|
|
90
|
+
{
|
|
91
|
+
var table_id = columnData.table_id,
|
|
92
|
+
other_table_id = columnData.other_table_id,
|
|
93
|
+
display_column_key = columnData.display_column_key;
|
|
94
|
+
var currentTableId = currentTable ? currentTable._id : '';
|
|
95
|
+
var linkedTableID = getLinkedTableID(currentTableId, table_id, other_table_id);
|
|
96
|
+
var linkedTable = getTableById(value.tables, linkedTableID);
|
|
97
|
+
var displayColumn = getTableColumnByKey(linkedTable, display_column_key);
|
|
98
|
+
newGroupby.linked_table = linkedTable;
|
|
99
|
+
newGroupby.display_column = displayColumn;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case CellType.FORMULA:
|
|
103
|
+
case CellType.LINK_FORMULA:
|
|
104
|
+
{
|
|
105
|
+
if (isDateColumn(groupbyColumn) && !count_type) {
|
|
106
|
+
newGroupby.count_type = GROUP_DATE_GRANULARITY.MONTH;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
cleanGroupbys.push(newGroupby);
|
|
112
|
+
});
|
|
113
|
+
return cleanGroupbys;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export { deleteInvalidGroupby, getValidGroupbys, isValidGroupby };
|