dtable-utils 0.0.3 → 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 +42 -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 +145 -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 +25 -0
- package/es/sort/sort-column/single-select.js +30 -0
- package/es/sort/sort-column/text.js +61 -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 +153 -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 +29 -0
- package/lib/sort/sort-column/single-select.js +34 -0
- package/lib/sort/sort-column/text.js +66 -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
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { COLLABORATOR_COLUMN_TYPES, DEFAULT_DATE_FORMAT } from '../constants/column.js';
|
|
3
|
-
import { FORMULA_RESULT_TYPE } from '../constants/formula.js';
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
2
|
import { DateUtils } from '../date.js';
|
|
5
3
|
import { getCollaboratorsName } from './collaborator.js';
|
|
6
4
|
import { getDateDisplayString } from './date.js';
|
|
@@ -10,9 +8,68 @@ import { getGeolocationDisplayString } from './geolocation.js';
|
|
|
10
8
|
import { getLongtextDisplayString } from './long-text.js';
|
|
11
9
|
import { getNumberDisplayString } from './number.js';
|
|
12
10
|
import { getMultipleOptionName, getOptionName } from './option.js';
|
|
11
|
+
import { CellType } from '../constants/cell-type.js';
|
|
12
|
+
import { COLLABORATOR_COLUMN_TYPES, DEFAULT_DATE_FORMAT } from '../constants/column.js';
|
|
13
|
+
import { FORMULA_RESULT_TYPE } from '../constants/formula.js';
|
|
13
14
|
|
|
14
15
|
var ARRAY_VALUE_COLUMN_TYPES = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* the helper of 'getCellValueStringResult'
|
|
19
|
+
* @param {any} cellValue
|
|
20
|
+
* @param {object} column
|
|
21
|
+
* @param {array} collaborators
|
|
22
|
+
* @param {bool} isArchiveView
|
|
23
|
+
* @returns formatted array cell value, string
|
|
24
|
+
*/
|
|
25
|
+
var _getArrayColumnCellValue = function _getArrayColumnCellValue(cellValue, column, _ref) {
|
|
26
|
+
var collaborators = _ref.collaborators,
|
|
27
|
+
isArchiveView = _ref.isArchiveView;
|
|
28
|
+
if (!Array.isArray(cellValue) || cellValue.length === 0 || !column.data) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
var key = column.key,
|
|
32
|
+
data = column.data;
|
|
33
|
+
var array_type = data.array_type,
|
|
34
|
+
array_data = data.array_data;
|
|
35
|
+
var newColumn = {
|
|
36
|
+
key: key,
|
|
37
|
+
type: array_type,
|
|
38
|
+
data: array_data
|
|
39
|
+
};
|
|
40
|
+
// cellValue itself is an array
|
|
41
|
+
if (ARRAY_VALUE_COLUMN_TYPES.includes(array_type)) {
|
|
42
|
+
return getCellValueStringResult(_defineProperty({}, key, cellValue), newColumn, {
|
|
43
|
+
collaborators: collaborators
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// cellValue itself is a single value
|
|
48
|
+
if (array_type === CellType.STRING) {
|
|
49
|
+
newColumn.type = CellType.TEXT;
|
|
50
|
+
var _result = cellValue.map(function (item) {
|
|
51
|
+
return getCellValueStringResult(_defineProperty({}, key, item), newColumn);
|
|
52
|
+
});
|
|
53
|
+
return _result.filter(Boolean).join(', ');
|
|
54
|
+
}
|
|
55
|
+
if (array_type === CellType.BOOL) {
|
|
56
|
+
newColumn.type = CellType.CHECKBOX;
|
|
57
|
+
var _result2 = cellValue.map(function (item) {
|
|
58
|
+
return getCellValueStringResult(_defineProperty({}, key, item), newColumn);
|
|
59
|
+
});
|
|
60
|
+
return _result2.filter(Boolean).join(', ');
|
|
61
|
+
}
|
|
62
|
+
var result = cellValue.map(function (item) {
|
|
63
|
+
return getCellValueStringResult(_defineProperty({}, key, item), newColumn, {
|
|
64
|
+
collaborators: collaborators,
|
|
65
|
+
isArchiveView: isArchiveView
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
return result.filter(function (item) {
|
|
69
|
+
return item || item === 0;
|
|
70
|
+
}).join(', ');
|
|
71
|
+
};
|
|
72
|
+
|
|
16
73
|
/**
|
|
17
74
|
* Get formatted formula result to display. It will not be formatted
|
|
18
75
|
* if formula result_type is array and array_type is collaborator, creator or last-modifier etc.
|
|
@@ -66,27 +123,27 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
|
|
|
66
123
|
|
|
67
124
|
/**
|
|
68
125
|
* Get formatted cell value to display.
|
|
69
|
-
* @param {object} row e.g. { [column.key]: '
|
|
126
|
+
* @param {object} row e.g. { [column.key]: '' }
|
|
70
127
|
* @param {string} type column type
|
|
71
128
|
* @param {string} key column key
|
|
72
129
|
* @param {object} data column data
|
|
73
130
|
* @param {object} formulaRows formula results of rows. Default as "{}"
|
|
74
|
-
* @param {array} collaborators e.g. [{ email
|
|
131
|
+
* @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
|
|
75
132
|
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
76
133
|
* @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
77
134
|
* @returns formatted cell value, string|array
|
|
78
135
|
*/
|
|
79
136
|
var getCellValueDisplayString = function getCellValueDisplayString(row, type, key) {
|
|
80
|
-
var
|
|
81
|
-
data =
|
|
82
|
-
|
|
83
|
-
formulaRows =
|
|
84
|
-
|
|
85
|
-
collaborators =
|
|
86
|
-
|
|
87
|
-
isBaiduMap =
|
|
88
|
-
|
|
89
|
-
geolocationHyphen =
|
|
137
|
+
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
138
|
+
data = _ref2.data,
|
|
139
|
+
_ref2$formulaRows = _ref2.formulaRows,
|
|
140
|
+
formulaRows = _ref2$formulaRows === void 0 ? {} : _ref2$formulaRows,
|
|
141
|
+
_ref2$collaborators = _ref2.collaborators,
|
|
142
|
+
collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
|
|
143
|
+
_ref2$isBaiduMap = _ref2.isBaiduMap,
|
|
144
|
+
isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
|
|
145
|
+
_ref2$geolocationHyph = _ref2.geolocationHyphen,
|
|
146
|
+
geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
|
|
90
147
|
if (!row) return '';
|
|
91
148
|
var cellValue = row[key];
|
|
92
149
|
switch (type) {
|
|
@@ -123,9 +180,9 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
123
180
|
}
|
|
124
181
|
case CellType.DATE:
|
|
125
182
|
{
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
format =
|
|
183
|
+
var _ref3 = data || {},
|
|
184
|
+
_ref3$format = _ref3.format,
|
|
185
|
+
format = _ref3$format === void 0 ? DEFAULT_DATE_FORMAT : _ref3$format;
|
|
129
186
|
return getDateDisplayString(cellValue, format);
|
|
130
187
|
}
|
|
131
188
|
case CellType.CTIME:
|
|
@@ -145,7 +202,8 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
145
202
|
case CellType.FORMULA:
|
|
146
203
|
case CellType.LINK_FORMULA:
|
|
147
204
|
{
|
|
148
|
-
var formulaRow = formulaRows[row._id]
|
|
205
|
+
var formulaRow = formulaRows && formulaRows[row._id];
|
|
206
|
+
if (!formulaRow) return '';
|
|
149
207
|
return getFormulaDisplayString(formulaRow[key], data);
|
|
150
208
|
}
|
|
151
209
|
case CellType.DIGITAL_SIGN:
|
|
@@ -162,4 +220,176 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
162
220
|
}
|
|
163
221
|
};
|
|
164
222
|
|
|
165
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Format cell value to string
|
|
225
|
+
* @param {object} row { [column.key]: '', ... }
|
|
226
|
+
* @param {object} column
|
|
227
|
+
* @param {object} formulaRows formula results of rows. Default as "{}"
|
|
228
|
+
* @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
|
|
229
|
+
* @param {bool} isArchiveView If is archive view, get original cell value from "row", otherwise get cell value from "formulaRows"
|
|
230
|
+
* @returns formatted cell value, string
|
|
231
|
+
*/
|
|
232
|
+
var getCellValueStringResult = function getCellValueStringResult(row, column) {
|
|
233
|
+
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
234
|
+
_ref4$formulaRows = _ref4.formulaRows,
|
|
235
|
+
formulaRows = _ref4$formulaRows === void 0 ? {} : _ref4$formulaRows,
|
|
236
|
+
_ref4$collaborators = _ref4.collaborators,
|
|
237
|
+
collaborators = _ref4$collaborators === void 0 ? [] : _ref4$collaborators,
|
|
238
|
+
_ref4$isArchiveView = _ref4.isArchiveView,
|
|
239
|
+
isArchiveView = _ref4$isArchiveView === void 0 ? false : _ref4$isArchiveView;
|
|
240
|
+
if (!row || !column) return '';
|
|
241
|
+
var key = column.key,
|
|
242
|
+
type = column.type,
|
|
243
|
+
data = column.data;
|
|
244
|
+
var cellValue = row[key];
|
|
245
|
+
switch (type) {
|
|
246
|
+
case CellType.TEXT:
|
|
247
|
+
case CellType.EMAIL:
|
|
248
|
+
case CellType.URL:
|
|
249
|
+
case CellType.AUTO_NUMBER:
|
|
250
|
+
{
|
|
251
|
+
return cellValue || '';
|
|
252
|
+
}
|
|
253
|
+
case CellType.RATE:
|
|
254
|
+
{
|
|
255
|
+
// number
|
|
256
|
+
return cellValue ? String(cellValue) : '';
|
|
257
|
+
}
|
|
258
|
+
case CellType.CHECKBOX:
|
|
259
|
+
{
|
|
260
|
+
if (typeof cellValue === 'boolean') {
|
|
261
|
+
return String(cellValue);
|
|
262
|
+
}
|
|
263
|
+
return cellValue === 'true' ? 'true' : 'false';
|
|
264
|
+
}
|
|
265
|
+
case CellType.LONG_TEXT:
|
|
266
|
+
{
|
|
267
|
+
// the data returned by archive view is a string, not a result in long-text format
|
|
268
|
+
if (isArchiveView) {
|
|
269
|
+
cellValue = {
|
|
270
|
+
text: cellValue
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return getLongtextDisplayString(cellValue);
|
|
274
|
+
}
|
|
275
|
+
case CellType.NUMBER:
|
|
276
|
+
{
|
|
277
|
+
return getNumberDisplayString(cellValue, data);
|
|
278
|
+
}
|
|
279
|
+
case CellType.DURATION:
|
|
280
|
+
{
|
|
281
|
+
return getDurationDisplayString(cellValue, data);
|
|
282
|
+
}
|
|
283
|
+
case CellType.GEOLOCATION:
|
|
284
|
+
{
|
|
285
|
+
return getGeolocationDisplayString(cellValue, data);
|
|
286
|
+
}
|
|
287
|
+
case CellType.SINGLE_SELECT:
|
|
288
|
+
{
|
|
289
|
+
if (!data) return '';
|
|
290
|
+
return getOptionName(data.options, cellValue);
|
|
291
|
+
}
|
|
292
|
+
case CellType.MULTIPLE_SELECT:
|
|
293
|
+
{
|
|
294
|
+
if (!data) return '';
|
|
295
|
+
return getMultipleOptionName(data.options, cellValue);
|
|
296
|
+
}
|
|
297
|
+
case CellType.DATE:
|
|
298
|
+
{
|
|
299
|
+
var _ref5 = data || {},
|
|
300
|
+
_ref5$format = _ref5.format,
|
|
301
|
+
format = _ref5$format === void 0 ? DEFAULT_DATE_FORMAT : _ref5$format;
|
|
302
|
+
// patch: compatible with previous format
|
|
303
|
+
var normalizedFormat = format === 'D/M/YYYY' ? format.replace(/D\/M\/YYYY/, 'DD/MM/YYYY') : format;
|
|
304
|
+
return getDateDisplayString(cellValue, normalizedFormat);
|
|
305
|
+
}
|
|
306
|
+
case CellType.CTIME:
|
|
307
|
+
case CellType.MTIME:
|
|
308
|
+
{
|
|
309
|
+
return DateUtils.format(cellValue, 'YYYY-MM-DD HH:MM:SS');
|
|
310
|
+
}
|
|
311
|
+
case CellType.COLLABORATOR:
|
|
312
|
+
{
|
|
313
|
+
return getCollaboratorsName(collaborators, cellValue);
|
|
314
|
+
}
|
|
315
|
+
case CellType.CREATOR:
|
|
316
|
+
case CellType.LAST_MODIFIER:
|
|
317
|
+
{
|
|
318
|
+
return cellValue === 'anonymous' ? cellValue : getCollaboratorsName(collaborators, [cellValue]);
|
|
319
|
+
}
|
|
320
|
+
case CellType.LINK:
|
|
321
|
+
{
|
|
322
|
+
var computedCellValue = cellValue;
|
|
323
|
+
if (!isArchiveView) {
|
|
324
|
+
var formulaRow = formulaRows && formulaRows[row._id];
|
|
325
|
+
computedCellValue = formulaRow && formulaRow[key];
|
|
326
|
+
}
|
|
327
|
+
if (!Array.isArray(computedCellValue) || computedCellValue.length === 0) {
|
|
328
|
+
return '';
|
|
329
|
+
}
|
|
330
|
+
var displayCellValue = computedCellValue.map(function (linked) {
|
|
331
|
+
return linked.display_value;
|
|
332
|
+
});
|
|
333
|
+
var isTwoDimensionalArray = displayCellValue.some(function (item) {
|
|
334
|
+
return Array.isArray(item);
|
|
335
|
+
});
|
|
336
|
+
if (isTwoDimensionalArray) {
|
|
337
|
+
var result = displayCellValue.map(function (item) {
|
|
338
|
+
return _getArrayColumnCellValue(item, column, {
|
|
339
|
+
collaborators: collaborators,
|
|
340
|
+
isArchiveView: isArchiveView
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
return result.filter(Boolean).join(', ');
|
|
344
|
+
}
|
|
345
|
+
return _getArrayColumnCellValue(displayCellValue, column, {
|
|
346
|
+
collaborators: collaborators
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
case CellType.FORMULA:
|
|
350
|
+
case CellType.LINK_FORMULA:
|
|
351
|
+
{
|
|
352
|
+
var _computedCellValue = cellValue;
|
|
353
|
+
if (!isArchiveView) {
|
|
354
|
+
var _formulaRow = formulaRows && formulaRows[row._id];
|
|
355
|
+
_computedCellValue = _formulaRow && _formulaRow[key];
|
|
356
|
+
}
|
|
357
|
+
var result_type = data.result_type;
|
|
358
|
+
if (result_type === FORMULA_RESULT_TYPE.STRING) {
|
|
359
|
+
return _computedCellValue || '';
|
|
360
|
+
}
|
|
361
|
+
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
362
|
+
if (typeof _computedCellValue === 'boolean') return String(_computedCellValue);
|
|
363
|
+
return _computedCellValue === 'true' ? 'true' : 'false';
|
|
364
|
+
}
|
|
365
|
+
if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
|
|
366
|
+
// data is stored in the data of the current column
|
|
367
|
+
return getNumberDisplayString(_computedCellValue, data);
|
|
368
|
+
}
|
|
369
|
+
if (result_type === FORMULA_RESULT_TYPE.DATE) {
|
|
370
|
+
// data is stored in the data of the current column
|
|
371
|
+
var _format = data.format;
|
|
372
|
+
return getDateDisplayString(_computedCellValue, _format);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// FORMULA_RESULT_TYPE.ARRAY
|
|
376
|
+
return _getArrayColumnCellValue(_computedCellValue, column, {
|
|
377
|
+
collaborators: collaborators,
|
|
378
|
+
isArchiveView: isArchiveView
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
case CellType.FILE:
|
|
382
|
+
case CellType.IMAGE:
|
|
383
|
+
case CellType.DIGITAL_SIGN:
|
|
384
|
+
case CellType.BUTTON:
|
|
385
|
+
{
|
|
386
|
+
return '';
|
|
387
|
+
}
|
|
388
|
+
default:
|
|
389
|
+
{
|
|
390
|
+
return cellValue ? String(cellValue) : '';
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
export { getCellValueDisplayString, getCellValueStringResult, getFormulaDisplayString };
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get collaborator by email
|
|
3
|
+
* @param {array} collaborators e.g. [{ email, name, ... }, ...]
|
|
4
|
+
* @param {string} email
|
|
5
|
+
* @returns collaborator, object
|
|
6
|
+
*/
|
|
7
|
+
var getCollaborator = function getCollaborator(collaborators, email) {
|
|
8
|
+
if (!Array.isArray(collaborators) || !email) return null;
|
|
9
|
+
return collaborators.find(function (collaborator) {
|
|
10
|
+
return collaborator.email === email;
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
1
14
|
/**
|
|
2
15
|
* Get collaborators name list of given emails
|
|
3
16
|
* @param {array} emails e.g. ['email', ...]
|
|
4
|
-
* @param {array} collaborators e.g. [{ email
|
|
17
|
+
* @param {array} collaborators e.g. [{ email, name, ... }, ...]
|
|
5
18
|
* @returns name list, array. e.g. ['name1', 'name2']
|
|
6
19
|
*/
|
|
7
20
|
var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators) {
|
|
@@ -20,7 +33,7 @@ var getCollaboratorsNames = function getCollaboratorsNames(emails, collaborators
|
|
|
20
33
|
|
|
21
34
|
/**
|
|
22
35
|
* Get concatenated collaborators names of given emails.
|
|
23
|
-
* @param {array} collaborators e.g. [{ email
|
|
36
|
+
* @param {array} collaborators e.g. [{ email, name, ... }, ...]
|
|
24
37
|
* @param {array} emails e.g. ['email', ...]
|
|
25
38
|
* @returns concatenated collaborators names, string. e.g. 'name1, name2'
|
|
26
39
|
*/
|
|
@@ -30,4 +43,4 @@ var getCollaboratorsName = function getCollaboratorsName(collaborators, emails)
|
|
|
30
43
|
return collaboratorsNames.join(', ');
|
|
31
44
|
};
|
|
32
45
|
|
|
33
|
-
export { getCollaboratorsName, getCollaboratorsNames };
|
|
46
|
+
export { getCollaborator, getCollaboratorsName, getCollaboratorsNames };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get signature image url to display
|
|
3
|
-
* @param {object} digitalSign object, e.g. { sign_image_url
|
|
3
|
+
* @param {object} digitalSign object, e.g. { sign_image_url, ... }
|
|
4
4
|
* @returns signature image url, string
|
|
5
5
|
*/
|
|
6
6
|
var getDigitalSignImageUrl = function getDigitalSignImageUrl(digitalSign) {
|
|
@@ -69,8 +69,8 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
|
|
|
69
69
|
}
|
|
70
70
|
var decimalDigits = DURATION_DECIMAL_DIGITS[duration_format];
|
|
71
71
|
var decimalSuffix = getDurationDecimalSuffix(duration_format, decimal);
|
|
72
|
-
var hours = parseInt(positiveValue / 3600
|
|
73
|
-
var minutes = parseInt((positiveValue - hours * 3600) / 60
|
|
72
|
+
var hours = parseInt(positiveValue / 3600);
|
|
73
|
+
var minutes = parseInt((positiveValue - hours * 3600) / 60);
|
|
74
74
|
var displayString = duration < 0 ? '-' : '';
|
|
75
75
|
if (duration_format === DURATION_FORMATS_MAP.H_MM) {
|
|
76
76
|
displayString += "".concat(hours, ":").concat(minutes > 9 ? minutes : "0".concat(minutes));
|
|
@@ -83,4 +83,4 @@ var getDurationDisplayString = function getDurationDisplayString(duration, forma
|
|
|
83
83
|
return displayString;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
export { getDurationDecimalSuffix, getDurationDisplayString };
|
|
86
|
+
export { getDurationDecimalSuffix, getDurationDisplayString, getMathRoundedDuration };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
import { GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
|
|
2
|
+
import { isValidPosition } from '../validate/geolocation.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Get formatted geolocation
|
|
7
6
|
* @param {object} loc
|
|
8
|
-
* @param {object} formats , e.g. { geo_format
|
|
7
|
+
* @param {object} formats , e.g. { geo_format, ... }
|
|
9
8
|
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
10
9
|
* @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
11
10
|
* @returns formatted geolocation, string
|
|
@@ -16,66 +15,89 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
|
|
|
16
15
|
isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
|
|
17
16
|
_ref$hyphen = _ref.hyphen,
|
|
18
17
|
hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
|
|
19
|
-
if (!loc)
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
18
|
+
if (!loc) return '';
|
|
22
19
|
var _ref2 = formats || {},
|
|
23
20
|
geo_format = _ref2.geo_format;
|
|
24
21
|
switch (geo_format) {
|
|
25
22
|
case 'lng_lat':
|
|
26
23
|
{
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
lat = _ref3.lat;
|
|
24
|
+
var lng = loc.lng,
|
|
25
|
+
lat = loc.lat;
|
|
30
26
|
if (!isValidPosition(lng, lat)) return '';
|
|
31
27
|
return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
|
|
32
28
|
}
|
|
33
29
|
case 'country_region':
|
|
34
30
|
{
|
|
35
|
-
var
|
|
36
|
-
country_region = _ref4.country_region;
|
|
31
|
+
var country_region = loc.country_region;
|
|
37
32
|
return country_region || '';
|
|
38
33
|
}
|
|
39
34
|
case 'province':
|
|
40
35
|
{
|
|
41
|
-
var
|
|
42
|
-
province = _ref5.province;
|
|
36
|
+
var province = loc.province;
|
|
43
37
|
return province || '';
|
|
44
38
|
}
|
|
45
39
|
case 'province_city':
|
|
46
40
|
{
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
city = _ref6.city;
|
|
41
|
+
var _province = loc.province,
|
|
42
|
+
city = loc.city;
|
|
50
43
|
return "".concat(_province || '').concat(hyphen).concat(city || '').trim();
|
|
51
44
|
}
|
|
52
45
|
case 'province_city_district':
|
|
53
46
|
{
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
district = _ref7.district;
|
|
47
|
+
var _province2 = loc.province,
|
|
48
|
+
_city = loc.city,
|
|
49
|
+
district = loc.district;
|
|
58
50
|
return "".concat(_province2 || '').concat(hyphen).concat(_city || '').concat(hyphen).concat(district || '').trim();
|
|
59
51
|
}
|
|
60
52
|
case 'map_selection':
|
|
61
53
|
{
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
title = _ref8.title;
|
|
54
|
+
var address = loc.address,
|
|
55
|
+
title = loc.title;
|
|
65
56
|
return "".concat(address || '').concat(hyphen).concat(title || '').trim();
|
|
66
57
|
}
|
|
67
58
|
default:
|
|
68
59
|
{
|
|
69
60
|
// default as 'geolocation'
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
detail = _ref9.detail;
|
|
61
|
+
var _province3 = loc.province,
|
|
62
|
+
_city2 = loc.city,
|
|
63
|
+
_district = loc.district,
|
|
64
|
+
detail = loc.detail;
|
|
75
65
|
if (!_province3 && !_city2 && !_district && !detail) return '';
|
|
76
66
|
return "".concat(_province3 || '').concat(hyphen).concat(_city2 || '').concat(hyphen).concat(_district || '').concat(hyphen).concat(detail || '').trim();
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
69
|
};
|
|
80
70
|
|
|
81
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Get geolocation by granularity
|
|
73
|
+
* @param {object} geolocation e.g. { province, ... }
|
|
74
|
+
* @param {string} granularity
|
|
75
|
+
* @returns geolocation string
|
|
76
|
+
*/
|
|
77
|
+
var getGeolocationByGranularity = function getGeolocationByGranularity(geolocation, granularity) {
|
|
78
|
+
if (!geolocation) return '';
|
|
79
|
+
var province = geolocation.province,
|
|
80
|
+
city = geolocation.city,
|
|
81
|
+
district = geolocation.district,
|
|
82
|
+
country_region = geolocation.country_region;
|
|
83
|
+
switch (granularity) {
|
|
84
|
+
case GROUP_GEOLOCATION_GRANULARITY.CITY:
|
|
85
|
+
{
|
|
86
|
+
return city || '';
|
|
87
|
+
}
|
|
88
|
+
case GROUP_GEOLOCATION_GRANULARITY.DISTRICT:
|
|
89
|
+
{
|
|
90
|
+
return district || '';
|
|
91
|
+
}
|
|
92
|
+
case GROUP_GEOLOCATION_GRANULARITY.COUNTRY:
|
|
93
|
+
{
|
|
94
|
+
return country_region || '';
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
{
|
|
98
|
+
return province || '';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { getGeolocationByGranularity, getGeolocationDisplayString };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NPminus as minus } from '../helper/number-precision/index.js';
|
|
2
|
-
import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
|
|
3
2
|
import { getDurationDisplayString } from './duration.js';
|
|
3
|
+
import { DEFAULT_NUMBER_FORMAT } from '../constants/column.js';
|
|
4
|
+
import { DISPLAY_INTERNAL_ERRORS } from '../constants/formula.js';
|
|
4
5
|
|
|
5
6
|
var separatorMap = {
|
|
6
7
|
comma: ',',
|
|
@@ -8,6 +9,37 @@ var separatorMap = {
|
|
|
8
9
|
no: '',
|
|
9
10
|
space: ' '
|
|
10
11
|
};
|
|
12
|
+
var _getDecimalDigits = function _getDecimalDigits(number) {
|
|
13
|
+
if (Number.isInteger(number)) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
var valueArr = String(number).split('.');
|
|
17
|
+
var digitsLength = valueArr[1] ? valueArr[1].length : 8;
|
|
18
|
+
return digitsLength > 8 ? 8 : digitsLength;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get fixed number by precision
|
|
23
|
+
* @param {number} number
|
|
24
|
+
* @param {object} formats e.g. { enable_precision, precision, ... }
|
|
25
|
+
* @returns fixed number, string
|
|
26
|
+
*/
|
|
27
|
+
var getPrecisionNumber = function getPrecisionNumber(number, formats) {
|
|
28
|
+
var _ref = formats || {},
|
|
29
|
+
_ref$precision = _ref.precision,
|
|
30
|
+
precision = _ref$precision === void 0 ? 2 : _ref$precision,
|
|
31
|
+
_ref$enable_precision = _ref.enable_precision,
|
|
32
|
+
enable_precision = _ref$enable_precision === void 0 ? false : _ref$enable_precision;
|
|
33
|
+
var type = Object.prototype.toString.call(number);
|
|
34
|
+
if (type !== '[object Number]') {
|
|
35
|
+
if (type === '[object String]' && DISPLAY_INTERNAL_ERRORS.includes(number)) {
|
|
36
|
+
return number;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
var decimalDigits = enable_precision ? precision : _getDecimalDigits(number);
|
|
41
|
+
return number.toFixed(decimalDigits);
|
|
42
|
+
};
|
|
11
43
|
|
|
12
44
|
/**
|
|
13
45
|
* removeZerosFromEnd('0.0100') // '0.01'
|
|
@@ -34,19 +66,19 @@ var getDecimalDigitsFromNumber = function getDecimalDigitsFromNumber(number) {
|
|
|
34
66
|
var digitsLength = decimalPart ? decimalPart.length : 8;
|
|
35
67
|
return digitsLength > 8 ? 8 : digitsLength;
|
|
36
68
|
};
|
|
37
|
-
var toThousands = function toThousands(number,
|
|
38
|
-
var formats =
|
|
39
|
-
|
|
40
|
-
isCurrency =
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
decimal =
|
|
44
|
-
|
|
45
|
-
thousands =
|
|
46
|
-
|
|
47
|
-
precision =
|
|
48
|
-
|
|
49
|
-
enable_precision =
|
|
69
|
+
var toThousands = function toThousands(number, _ref2) {
|
|
70
|
+
var formats = _ref2.formats,
|
|
71
|
+
_ref2$isCurrency = _ref2.isCurrency,
|
|
72
|
+
isCurrency = _ref2$isCurrency === void 0 ? true : _ref2$isCurrency;
|
|
73
|
+
var _ref3 = formats || {},
|
|
74
|
+
_ref3$decimal = _ref3.decimal,
|
|
75
|
+
decimal = _ref3$decimal === void 0 ? 'dot' : _ref3$decimal,
|
|
76
|
+
_ref3$thousands = _ref3.thousands,
|
|
77
|
+
thousands = _ref3$thousands === void 0 ? 'no' : _ref3$thousands,
|
|
78
|
+
_ref3$precision = _ref3.precision,
|
|
79
|
+
precision = _ref3$precision === void 0 ? 2 : _ref3$precision,
|
|
80
|
+
_ref3$enable_precisio = _ref3.enable_precision,
|
|
81
|
+
enable_precision = _ref3$enable_precisio === void 0 ? false : _ref3$enable_precisio;
|
|
50
82
|
|
|
51
83
|
// handle numbers in scientific notation
|
|
52
84
|
if (String(number).includes('e')) {
|
|
@@ -65,7 +97,7 @@ var toThousands = function toThousands(number, _ref) {
|
|
|
65
97
|
}
|
|
66
98
|
return numericString;
|
|
67
99
|
}
|
|
68
|
-
return number;
|
|
100
|
+
return String(number);
|
|
69
101
|
}
|
|
70
102
|
var decimalString = separatorMap[decimal];
|
|
71
103
|
var thousandsString = separatorMap[thousands];
|
|
@@ -118,9 +150,9 @@ var getNumberDisplayString = function getNumberDisplayString(number, formats) {
|
|
|
118
150
|
if (isNaN(number) || number === Infinity || number === -Infinity) return String(number);
|
|
119
151
|
|
|
120
152
|
// formats: old version maybe 'null'
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
format =
|
|
153
|
+
var _ref4 = formats || {},
|
|
154
|
+
_ref4$format = _ref4.format,
|
|
155
|
+
format = _ref4$format === void 0 ? DEFAULT_NUMBER_FORMAT : _ref4$format;
|
|
124
156
|
switch (format) {
|
|
125
157
|
case 'number':
|
|
126
158
|
{
|
|
@@ -219,4 +251,4 @@ var replaceNumberNotAllowInput = function replaceNumberNotAllowInput(sNum, forma
|
|
|
219
251
|
}
|
|
220
252
|
};
|
|
221
253
|
|
|
222
|
-
export { getNumberDisplayString, replaceNumberNotAllowInput };
|
|
254
|
+
export { getNumberDisplayString, getPrecisionNumber, replaceNumberNotAllowInput };
|