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
|
@@ -1,20 +1,44 @@
|
|
|
1
|
+
import { getColumnOptions } from '../column/option.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get option by id
|
|
5
|
+
* @param {array} options e.g. [{ id, name, ... }]
|
|
6
|
+
* @param {string} optionId
|
|
7
|
+
* @returns option, object
|
|
8
|
+
*/
|
|
9
|
+
var getOption = function getOption(options, optionId) {
|
|
10
|
+
if (!Array.isArray(options) || !optionId) return null;
|
|
11
|
+
return options.find(function (option) {
|
|
12
|
+
return option.id === optionId;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
17
|
* Get option name of the given id
|
|
3
|
-
* @param {array} options e.g. [ { id
|
|
4
|
-
* @param {string}
|
|
18
|
+
* @param {array} options e.g. [ { id, color, name, ... } ]
|
|
19
|
+
* @param {string} targetOptionId option id
|
|
5
20
|
* @returns option name, string
|
|
6
21
|
*/
|
|
7
|
-
var getOptionName = function getOptionName(options,
|
|
8
|
-
if (!
|
|
9
|
-
var targetOption = options
|
|
10
|
-
return option.id === targetOptionID;
|
|
11
|
-
});
|
|
22
|
+
var getOptionName = function getOptionName(options, targetOptionId) {
|
|
23
|
+
if (!targetOptionId || !Array.isArray(options)) return '';
|
|
24
|
+
var targetOption = getOption(options, targetOptionId);
|
|
12
25
|
return targetOption ? targetOption.name : '';
|
|
13
26
|
};
|
|
14
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Get column option name by id
|
|
30
|
+
* @param {object} column e.g. { data: { options, ... }, ... }
|
|
31
|
+
* @param {string} optionId
|
|
32
|
+
* @returns option name, string
|
|
33
|
+
*/
|
|
34
|
+
var getColumnOptionNameById = function getColumnOptionNameById(column, optionId) {
|
|
35
|
+
var options = getColumnOptions(column);
|
|
36
|
+
return getOptionName(options, optionId);
|
|
37
|
+
};
|
|
38
|
+
|
|
15
39
|
/**
|
|
16
40
|
* Get concatenated options names of given ids.
|
|
17
|
-
* @param {array} options e.g. [ { id
|
|
41
|
+
* @param {array} options e.g. [ { id, color, name, ... }, ... ]
|
|
18
42
|
* @param {array} targetOptionsIds e.g. [ option.id, ... ]
|
|
19
43
|
* @returns concatenated options names, string. e.g. 'name1, name2'
|
|
20
44
|
*/
|
|
@@ -29,4 +53,4 @@ var getMultipleOptionName = function getMultipleOptionName(options, targetOption
|
|
|
29
53
|
}).join(', ');
|
|
30
54
|
};
|
|
31
55
|
|
|
32
|
-
export { getMultipleOptionName, getOptionName };
|
|
56
|
+
export { getColumnOptionNameById, getMultipleOptionName, getOption, getOptionName };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DateUtils } from '../date.js';
|
|
2
|
+
import { getFloatNumber } from './number.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse string to date
|
|
6
|
+
* @param {string} text
|
|
7
|
+
* @param {string} format default as "YYYY-MM-DD"
|
|
8
|
+
* @returns date, string
|
|
9
|
+
*/
|
|
10
|
+
var formatTextToDate = function formatTextToDate(text) {
|
|
11
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
|
|
12
|
+
if (typeof text !== 'string' || !text.trim()) return null;
|
|
13
|
+
var isAllNumber = /^[0-9]+$/.test(text);
|
|
14
|
+
var dateObj = {};
|
|
15
|
+
if (isAllNumber) {
|
|
16
|
+
dateObj = new Date(getFloatNumber(text));
|
|
17
|
+
} else {
|
|
18
|
+
dateObj = DateUtils.parseDateWithFormat(text, format);
|
|
19
|
+
}
|
|
20
|
+
if (format.indexOf('HH:mm') < 0) {
|
|
21
|
+
return DateUtils.format(dateObj, 'YYYY-MM-DD') || null;
|
|
22
|
+
}
|
|
23
|
+
return DateUtils.format(dateObj, 'YYYY-MM-DD HH:MM') || null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { formatTextToDate };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { NPdivide as divide } from '../helper/number-precision/index.js';
|
|
2
|
+
import { isNumber } from '../number.js';
|
|
3
|
+
import { DURATION_FORMATS_MAP, DURATION_FORMATS } from '../constants/column.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* @param {string} sNumber e.g. '1.23'
|
|
@@ -50,4 +52,54 @@ var formatStringToNumber = function formatStringToNumber(sNum, formats) {
|
|
|
50
52
|
return value;
|
|
51
53
|
};
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
/**
|
|
56
|
+
* parse duration to seconds depend on formats
|
|
57
|
+
* @param {string} duration
|
|
58
|
+
* @param {object} data { duration_format: '' }
|
|
59
|
+
* @returns number
|
|
60
|
+
*/
|
|
61
|
+
var formatDurationToNumber = function formatDurationToNumber(duration, data) {
|
|
62
|
+
if (duration === 0) return 0;
|
|
63
|
+
if (!duration) return null;
|
|
64
|
+
var _ref2 = data || {},
|
|
65
|
+
duration_format = _ref2.duration_format;
|
|
66
|
+
duration_format = duration_format || DURATION_FORMATS_MAP.H_MM;
|
|
67
|
+
if (DURATION_FORMATS.findIndex(function (format) {
|
|
68
|
+
return format.type === duration_format;
|
|
69
|
+
}) < 0) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
var numericDuration = duration - 0;
|
|
73
|
+
if (isNumber(numericDuration)) {
|
|
74
|
+
return duration_format === DURATION_FORMATS_MAP.H_MM ? numericDuration * 60 : numericDuration;
|
|
75
|
+
}
|
|
76
|
+
var stringifyDuration = String(duration);
|
|
77
|
+
var isNegative = stringifyDuration[0] === '-';
|
|
78
|
+
if (isNegative) {
|
|
79
|
+
stringifyDuration = stringifyDuration.substring(1);
|
|
80
|
+
}
|
|
81
|
+
var timeParts = stringifyDuration.split(/[::]/); // support ':' and ':'.
|
|
82
|
+
var timePartsLen = timeParts.length;
|
|
83
|
+
var hoursIndex;
|
|
84
|
+
var minutesIndex;
|
|
85
|
+
var secondsIndex;
|
|
86
|
+
if (duration_format === DURATION_FORMATS_MAP.H_MM) {
|
|
87
|
+
hoursIndex = timePartsLen - 2;
|
|
88
|
+
minutesIndex = timePartsLen - 1;
|
|
89
|
+
} else {
|
|
90
|
+
hoursIndex = timePartsLen - 3;
|
|
91
|
+
minutesIndex = timePartsLen - 2;
|
|
92
|
+
secondsIndex = timePartsLen - 1;
|
|
93
|
+
}
|
|
94
|
+
var hours = timeParts[hoursIndex] - 0;
|
|
95
|
+
var minutes = timeParts[minutesIndex] - 0;
|
|
96
|
+
var seconds = timeParts[secondsIndex] - 0;
|
|
97
|
+
if (!isNumber(hours) && !isNumber(minutes) && !isNumber(seconds)) return null;
|
|
98
|
+
hours = isNumber(hours) ? hours : 0;
|
|
99
|
+
minutes = isNumber(minutes) ? minutes : 0;
|
|
100
|
+
seconds = isNumber(seconds) ? seconds : 0;
|
|
101
|
+
var result = hours * 3600 + minutes * 60 + seconds;
|
|
102
|
+
return isNegative ? -result : result;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { formatDurationToNumber, formatStringToNumber, getFloatNumber };
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import deepCopy from 'deep-copy';
|
|
3
|
+
import { deleteInvalidFilter, getFormattedFilters } from '../filter/core.js';
|
|
4
|
+
import { filterRows, filterRow } from '../filter/filter-row.js';
|
|
5
|
+
import { ValidateFilter } from '../validate/filter.js';
|
|
6
|
+
import { isNumberColumn } from '../column/number.js';
|
|
7
|
+
import { getRowsByIds } from '../table/row.js';
|
|
8
|
+
import { sortTableRows } from '../sort/sort-row.js';
|
|
9
|
+
import { isTableRows } from '../row/core.js';
|
|
10
|
+
import RowColorUtils from './row-color.js';
|
|
11
|
+
import GradientColorUtils from './gradient-color.js';
|
|
12
|
+
import { CellType } from '../constants/cell-type.js';
|
|
13
|
+
import '../constants/column.js';
|
|
14
|
+
import { FILTER_CONJUNCTION_TYPE } from '../constants/filter/index.js';
|
|
15
|
+
import '../constants/formula.js';
|
|
16
|
+
import '../constants/sort.js';
|
|
17
|
+
import '../constants/group.js';
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
var COMPUTED_COLUMN_TYPES = [CellType.LINK, CellType.FORMULA, CellType.LINK_FORMULA];
|
|
22
|
+
var BY_RULES = 'by_rules';
|
|
23
|
+
var BY_NUMERIC_RANGE = 'by_numeric_range';
|
|
24
|
+
var BY_REPEAT_VALUE = 'by_repeat_value';
|
|
25
|
+
var isColumnHasColorRules = function isColumnHasColorRules(column) {
|
|
26
|
+
var colorbys = column && column.colorbys;
|
|
27
|
+
if (!colorbys) return false;
|
|
28
|
+
var type = colorbys.type,
|
|
29
|
+
colorByRules = colorbys.color_by_rules,
|
|
30
|
+
rangeSettings = colorbys.range_settings,
|
|
31
|
+
repeatValueSettings = colorbys.repeat_value_settings;
|
|
32
|
+
if (type === BY_RULES) {
|
|
33
|
+
return colorByRules && Array.isArray(colorByRules) && colorByRules.length > 0;
|
|
34
|
+
}
|
|
35
|
+
if (type === BY_REPEAT_VALUE) {
|
|
36
|
+
return repeatValueSettings;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// type === BY_NUMERIC_RANGE
|
|
40
|
+
return rangeSettings && Object.keys(rangeSettings).length > 0;
|
|
41
|
+
};
|
|
42
|
+
var hasRelatedColumnColorRule = function hasRelatedColumnColorRule(columns, updatedColumnKeyMap) {
|
|
43
|
+
return (
|
|
44
|
+
// the updated column is one of current table, and the column has color_rules
|
|
45
|
+
columns.some(function (column) {
|
|
46
|
+
return updatedColumnKeyMap[column.key] && isColumnHasColorRules(column);
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
var isColumnColorRulesValid = function isColumnColorRulesValid(column) {
|
|
51
|
+
var columns = [column];
|
|
52
|
+
var colorbys = column.colorbys;
|
|
53
|
+
var type = colorbys.type,
|
|
54
|
+
colorByRules = colorbys.color_by_rules;
|
|
55
|
+
if (type === BY_RULES) {
|
|
56
|
+
var isHasValidColorRule = colorByRules.some(function (rule) {
|
|
57
|
+
var filters = rule.filters;
|
|
58
|
+
if (filters.length === 0) return false;
|
|
59
|
+
return filters.some(function (filter) {
|
|
60
|
+
return !ValidateFilter.validate(filter, columns).error_message;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return isHasValidColorRule;
|
|
64
|
+
}
|
|
65
|
+
if (type === BY_REPEAT_VALUE) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (type === BY_NUMERIC_RANGE) {
|
|
69
|
+
// gradient color is only used for number column
|
|
70
|
+
return isNumberColumn(column);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
var isColumnColorsView = function isColumnColorsView(columns) {
|
|
75
|
+
return columns.some(function (column) {
|
|
76
|
+
if (!isColumnHasColorRules(column)) return false;
|
|
77
|
+
|
|
78
|
+
// valid color rule: the column maybe changed type
|
|
79
|
+
if (!isColumnColorRulesValid(column)) return false;
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
var getValidRulesColumns = function getValidRulesColumns(columns) {
|
|
84
|
+
// judgement current table's columns has own color_rules columns or not
|
|
85
|
+
var ownRulesColumns = columns.filter(function (column) {
|
|
86
|
+
return isColumnHasColorRules(column);
|
|
87
|
+
});
|
|
88
|
+
if (ownRulesColumns.length === 0) return [];
|
|
89
|
+
|
|
90
|
+
// judgement current table's columns has valid color_rules columns ro not
|
|
91
|
+
var validRulesColumns = ownRulesColumns.filter(function (column) {
|
|
92
|
+
return isColumnColorRulesValid(column);
|
|
93
|
+
});
|
|
94
|
+
if (validRulesColumns.length === 0) return [];
|
|
95
|
+
return validRulesColumns;
|
|
96
|
+
};
|
|
97
|
+
var getSortedViewRows = function getSortedViewRows(column, view, table, value, _ref) {
|
|
98
|
+
var username = _ref.username,
|
|
99
|
+
userId = _ref.userId;
|
|
100
|
+
var filter = {
|
|
101
|
+
column_key: column.key,
|
|
102
|
+
filter_predicate: 'is_not_empty',
|
|
103
|
+
filter_term: '',
|
|
104
|
+
column: column
|
|
105
|
+
};
|
|
106
|
+
var formulaRows = view.formula_rows;
|
|
107
|
+
var filterRowIds = filterRows(FILTER_CONJUNCTION_TYPE.AND, [filter], table.rows, {
|
|
108
|
+
formulaRows: formulaRows,
|
|
109
|
+
username: username,
|
|
110
|
+
userId: userId
|
|
111
|
+
});
|
|
112
|
+
var sort = {
|
|
113
|
+
sort_type: 'up',
|
|
114
|
+
column_key: column.key
|
|
115
|
+
};
|
|
116
|
+
var rows = getRowsByIds(table, filterRowIds);
|
|
117
|
+
var sortedRowIds = sortTableRows([sort], rows, [column], {
|
|
118
|
+
formulaRows: formulaRows,
|
|
119
|
+
value: value
|
|
120
|
+
});
|
|
121
|
+
return getRowsByIds(table, sortedRowIds);
|
|
122
|
+
};
|
|
123
|
+
var getCellValue = function getCellValue(row, column, formulaRows) {
|
|
124
|
+
var key = column.key,
|
|
125
|
+
type = column.type;
|
|
126
|
+
var cellValue = row[key];
|
|
127
|
+
if (COMPUTED_COLUMN_TYPES.includes(type)) {
|
|
128
|
+
var formulaRow = formulaRows && formulaRows[row._id] || {};
|
|
129
|
+
if (CellType.LINK === type) {
|
|
130
|
+
var startCellValues = formulaRow[key] && Array.isArray(formulaRow[key]) ? formulaRow[key] : [];
|
|
131
|
+
var _ref2 = startCellValues.length > 0 ? startCellValues[0] : {},
|
|
132
|
+
_ref2$display_value = _ref2.display_value,
|
|
133
|
+
display_value = _ref2$display_value === void 0 ? null : _ref2$display_value;
|
|
134
|
+
cellValue = display_value;
|
|
135
|
+
} else {
|
|
136
|
+
var cellValues = formulaRow[key];
|
|
137
|
+
cellValue = Array.isArray(cellValues) ? cellValues[0] : cellValues;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return cellValue;
|
|
141
|
+
};
|
|
142
|
+
var getFormattedColumn = function getFormattedColumn(column, view, table, value, rows, _ref3) {
|
|
143
|
+
var username = _ref3.username,
|
|
144
|
+
userId = _ref3.userId;
|
|
145
|
+
var dupColumn = deepCopy(column);
|
|
146
|
+
var colorbys = dupColumn.colorbys;
|
|
147
|
+
var type = colorbys.type,
|
|
148
|
+
colorByRules = colorbys.color_by_rules,
|
|
149
|
+
rangeSettings = colorbys.range_settings,
|
|
150
|
+
repeatValueSettings = colorbys.repeat_value_settings,
|
|
151
|
+
duplicateColumnKey = colorbys.duplicate_column_key;
|
|
152
|
+
if (type === BY_RULES) {
|
|
153
|
+
// formatted color rules
|
|
154
|
+
var formattedColorRules = colorByRules.map(function (colorRule) {
|
|
155
|
+
var filters = colorRule.filters;
|
|
156
|
+
var validFilters = [];
|
|
157
|
+
try {
|
|
158
|
+
validFilters = deleteInvalidFilter(filters, [column]);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
validFilters = [];
|
|
161
|
+
}
|
|
162
|
+
validFilters = getFormattedFilters(validFilters);
|
|
163
|
+
|
|
164
|
+
// return formatted colorRule
|
|
165
|
+
return _objectSpread(_objectSpread({}, colorRule), {}, {
|
|
166
|
+
filters: validFilters
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
dupColumn.colorbys = _objectSpread(_objectSpread({}, colorbys), {}, {
|
|
170
|
+
color_by_rules: formattedColorRules
|
|
171
|
+
});
|
|
172
|
+
return dupColumn;
|
|
173
|
+
}
|
|
174
|
+
if (type === BY_REPEAT_VALUE) {
|
|
175
|
+
var _ref4 = value || {},
|
|
176
|
+
_ref4$collaborators = _ref4.collaborators,
|
|
177
|
+
collaborators = _ref4$collaborators === void 0 ? [] : _ref4$collaborators;
|
|
178
|
+
var formattedColumn = RowColorUtils.getFormattedDuplicateColumns([dupColumn], [duplicateColumnKey], {
|
|
179
|
+
collaborators: collaborators
|
|
180
|
+
});
|
|
181
|
+
var duplicate_rows_ids_map = {};
|
|
182
|
+
var formulaRows = view.formula_rows;
|
|
183
|
+
for (var i = 0; i < rows.length; i++) {
|
|
184
|
+
var row = rows[i];
|
|
185
|
+
var rowId = row._id;
|
|
186
|
+
var formulaRow = formulaRows && formulaRows[rowId];
|
|
187
|
+
var rowValue = RowColorUtils.getDuplicateRowValue(row, formattedColumn, formulaRow);
|
|
188
|
+
if (!rowValue) continue;
|
|
189
|
+
var rowIds = duplicate_rows_ids_map[rowValue];
|
|
190
|
+
if (rowIds && rowIds.length > 0) {
|
|
191
|
+
rowIds.push(rowId);
|
|
192
|
+
} else {
|
|
193
|
+
duplicate_rows_ids_map[rowValue] = [rowId];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
dupColumn.duplicate_rows_ids_map = duplicate_rows_ids_map;
|
|
197
|
+
dupColumn.colorbys = _objectSpread(_objectSpread({}, colorbys), {}, {
|
|
198
|
+
repeat_value_settings: repeatValueSettings
|
|
199
|
+
});
|
|
200
|
+
return dupColumn;
|
|
201
|
+
}
|
|
202
|
+
// type === BY_NUMERIC_RANGE
|
|
203
|
+
// column type has been changed
|
|
204
|
+
if (!isNumberColumn(column)) {
|
|
205
|
+
dupColumn.gradientColorUtils = null;
|
|
206
|
+
dupColumn.colorbys = _objectSpread(_objectSpread({}, colorbys), {}, {
|
|
207
|
+
range_settings: {}
|
|
208
|
+
});
|
|
209
|
+
return dupColumn;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// add gradient_colors computed properties for dumColumn
|
|
213
|
+
var colorType = rangeSettings.color_type,
|
|
214
|
+
isCustomStartValue = rangeSettings.is_custom_start_value,
|
|
215
|
+
isCustomEndValue = rangeSettings.is_custom_end_value,
|
|
216
|
+
startValue = rangeSettings.start_value,
|
|
217
|
+
endValue = rangeSettings.end_value;
|
|
218
|
+
var min = startValue;
|
|
219
|
+
var max = endValue;
|
|
220
|
+
if ((!isCustomStartValue || !isCustomEndValue) && table.rows.length > 0) {
|
|
221
|
+
// sort rows
|
|
222
|
+
var sortedRows = getSortedViewRows(column, view, table, value, {
|
|
223
|
+
username: username,
|
|
224
|
+
userId: userId
|
|
225
|
+
});
|
|
226
|
+
var _formulaRows = view.formula_rows;
|
|
227
|
+
// number rows length need great than zero
|
|
228
|
+
if (sortedRows.length > 0) {
|
|
229
|
+
var startRow = sortedRows[0];
|
|
230
|
+
var endRow = sortedRows[sortedRows.length - 1];
|
|
231
|
+
var startCellValue = getCellValue(startRow, column, _formulaRows);
|
|
232
|
+
var endCellValue = getCellValue(endRow, column, _formulaRows);
|
|
233
|
+
min = isCustomStartValue ? startValue : startCellValue;
|
|
234
|
+
max = isCustomEndValue ? endValue : endCellValue;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
var gradientColorUtils = new GradientColorUtils({
|
|
238
|
+
colorType: colorType,
|
|
239
|
+
min: min,
|
|
240
|
+
max: max
|
|
241
|
+
});
|
|
242
|
+
dupColumn.gradientColorUtils = gradientColorUtils;
|
|
243
|
+
return dupColumn;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Calculate column color
|
|
248
|
+
* @param {array} rows
|
|
249
|
+
* @param {object} view
|
|
250
|
+
* @param {object} table e.g. { id_row_map, ... }
|
|
251
|
+
* @param {object} value e.g. { tables, collaborators, ... }
|
|
252
|
+
* @param {string} username
|
|
253
|
+
* @param {userId} username
|
|
254
|
+
* @returns column color, object
|
|
255
|
+
*/
|
|
256
|
+
var getColumnColors = function getColumnColors(rows, view, table, value) {
|
|
257
|
+
var _ref5 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
258
|
+
_ref5$username = _ref5.username,
|
|
259
|
+
username = _ref5$username === void 0 ? '' : _ref5$username,
|
|
260
|
+
_ref5$userId = _ref5.userId,
|
|
261
|
+
userId = _ref5$userId === void 0 ? '' : _ref5$userId;
|
|
262
|
+
var columns = table.columns;
|
|
263
|
+
var validRulesColumns = getValidRulesColumns(columns);
|
|
264
|
+
if (validRulesColumns.length === 0) return {};
|
|
265
|
+
|
|
266
|
+
// formatted column's color_rules
|
|
267
|
+
validRulesColumns = validRulesColumns.map(function (column) {
|
|
268
|
+
return getFormattedColumn(column, view, table, value, rows, {
|
|
269
|
+
username: username,
|
|
270
|
+
userId: userId
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* column_colors data struct
|
|
276
|
+
* {
|
|
277
|
+
* row_id: {[column_key]: value, [column_key]: value},
|
|
278
|
+
* row_id: {[column_key]: value, [column_key]: value},
|
|
279
|
+
* }
|
|
280
|
+
*/
|
|
281
|
+
var column_colors = {};
|
|
282
|
+
var formulaRows = view.formula_rows;
|
|
283
|
+
var tableRows = isTableRows(rows) ? rows : getRowsByIds(table, rows);
|
|
284
|
+
var rowsLength = tableRows.length;
|
|
285
|
+
|
|
286
|
+
// forEach rows
|
|
287
|
+
var _loop = function _loop() {
|
|
288
|
+
var row = tableRows[i];
|
|
289
|
+
|
|
290
|
+
// forEach own color_rules columns
|
|
291
|
+
var column_color = {};
|
|
292
|
+
var rowId = row._id;
|
|
293
|
+
var formulaRow = formulaRows && formulaRows[rowId] || {};
|
|
294
|
+
for (var j = 0; j < validRulesColumns.length; j++) {
|
|
295
|
+
var column = validRulesColumns[j];
|
|
296
|
+
var columnKey = column.key,
|
|
297
|
+
colorbys = column.colorbys,
|
|
298
|
+
_column$duplicate_row = column.duplicate_rows_ids_map,
|
|
299
|
+
duplicate_rows_ids_map = _column$duplicate_row === void 0 ? {} : _column$duplicate_row;
|
|
300
|
+
var type = colorbys.type,
|
|
301
|
+
colorByRules = colorbys.color_by_rules,
|
|
302
|
+
rangeSettings = colorbys.range_settings,
|
|
303
|
+
repeatValueSettings = colorbys.repeat_value_settings,
|
|
304
|
+
duplicateColumnKey = colorbys.duplicate_column_key;
|
|
305
|
+
if (type === BY_RULES) {
|
|
306
|
+
// obtain the row data that meets the rules and record the color
|
|
307
|
+
for (var m = 0; m < colorByRules.length; m++) {
|
|
308
|
+
var colorRule = colorByRules[m];
|
|
309
|
+
var filter_conjunction = colorRule.filter_conjunction,
|
|
310
|
+
filters = colorRule.filters,
|
|
311
|
+
color = colorRule.color;
|
|
312
|
+
if (filterRow(row, filter_conjunction, filters, {
|
|
313
|
+
formulaRow: formulaRow,
|
|
314
|
+
username: username,
|
|
315
|
+
userId: userId
|
|
316
|
+
})) {
|
|
317
|
+
column_color[columnKey] = color;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (type === BY_REPEAT_VALUE) {
|
|
323
|
+
var _color = repeatValueSettings.color;
|
|
324
|
+
var _ref6 = value || {},
|
|
325
|
+
_ref6$collaborators = _ref6.collaborators,
|
|
326
|
+
collaborators = _ref6$collaborators === void 0 ? [] : _ref6$collaborators;
|
|
327
|
+
var formattedColumn = RowColorUtils.getFormattedDuplicateColumns([column], [duplicateColumnKey], {
|
|
328
|
+
collaborators: collaborators
|
|
329
|
+
});
|
|
330
|
+
var rowValue = RowColorUtils.getDuplicateRowValue(row, formattedColumn, formulaRow);
|
|
331
|
+
if (!rowValue) continue;
|
|
332
|
+
var rowIds = duplicate_rows_ids_map[rowValue];
|
|
333
|
+
if (rowIds && rowIds.length > 1) {
|
|
334
|
+
var hasRowId = rowIds.some(function (id) {
|
|
335
|
+
return id === rowId;
|
|
336
|
+
});
|
|
337
|
+
if (hasRowId) {
|
|
338
|
+
column_color[columnKey] = _color;
|
|
339
|
+
var firstDuplicateRowId = rowIds[0];
|
|
340
|
+
if (!column_colors[firstDuplicateRowId]) {
|
|
341
|
+
column_colors[firstDuplicateRowId] = column_color;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (type === BY_NUMERIC_RANGE) {
|
|
347
|
+
if (Object.keys(rangeSettings).length === 0) break;
|
|
348
|
+
var cellValue = getCellValue(row, column, formulaRows);
|
|
349
|
+
if (cellValue || cellValue === 0) {
|
|
350
|
+
var gradientColorUtils = column.gradientColorUtils;
|
|
351
|
+
var cellColor = gradientColorUtils.getCellColor(cellValue);
|
|
352
|
+
if (cellColor) {
|
|
353
|
+
column_color[columnKey] = cellColor;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (Object.keys(column_color).length > 0) {
|
|
359
|
+
column_colors[rowId] = column_color;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
for (var i = 0; i < rowsLength; i++) {
|
|
363
|
+
_loop();
|
|
364
|
+
}
|
|
365
|
+
return column_colors;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Update column color by updated rows.
|
|
370
|
+
* @param {array} rows updated rows | rows ids
|
|
371
|
+
* @param {object} view
|
|
372
|
+
* @param {object} table e.g. { id_row_map, ... }
|
|
373
|
+
* @param {object} value e.g. { tables, collaborators, ... }
|
|
374
|
+
* @param {string} username
|
|
375
|
+
* @param {userId} username
|
|
376
|
+
* @returns column color, object
|
|
377
|
+
*/
|
|
378
|
+
var updateColumnColorsByUpdateRows = function updateColumnColorsByUpdateRows(rows, view, table, value) {
|
|
379
|
+
var _ref7 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
380
|
+
_ref7$username = _ref7.username,
|
|
381
|
+
username = _ref7$username === void 0 ? '' : _ref7$username,
|
|
382
|
+
_ref7$userId = _ref7.userId,
|
|
383
|
+
userId = _ref7$userId === void 0 ? '' : _ref7$userId;
|
|
384
|
+
var columns = table.columns;
|
|
385
|
+
var validRulesColumns = getValidRulesColumns(columns);
|
|
386
|
+
if (validRulesColumns.length === 0) return {};
|
|
387
|
+
var hasByGradientColorRule = validRulesColumns.some(function (column) {
|
|
388
|
+
var colorbys = column.colorbys;
|
|
389
|
+
return colorbys.type === BY_NUMERIC_RANGE;
|
|
390
|
+
});
|
|
391
|
+
var hasRepeatValueColorRule = validRulesColumns.some(function (column) {
|
|
392
|
+
var colorbys = column.colorbys;
|
|
393
|
+
return colorbys.type === BY_REPEAT_VALUE;
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// if columns has one column which colorbys type is by_gradient_color,
|
|
397
|
+
// recalculate all the rows background color
|
|
398
|
+
if (hasByGradientColorRule || hasRepeatValueColorRule) {
|
|
399
|
+
view.column_colors = getColumnColors(table.rows, view, table, value, {
|
|
400
|
+
username: username,
|
|
401
|
+
userId: userId
|
|
402
|
+
});
|
|
403
|
+
return view.column_colors;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// recalculate the updated rows background color
|
|
407
|
+
var updatedRows = isTableRows(rows) ? rows : getRowsByIds(table, rows);
|
|
408
|
+
var columnColors = getColumnColors(updatedRows, view, table, value, {
|
|
409
|
+
username: username,
|
|
410
|
+
userId: userId
|
|
411
|
+
});
|
|
412
|
+
var column_colors = view.column_colors;
|
|
413
|
+
if (!column_colors) {
|
|
414
|
+
column_colors = {};
|
|
415
|
+
view.column_colors = column_colors;
|
|
416
|
+
}
|
|
417
|
+
updatedRows.forEach(function (row) {
|
|
418
|
+
var rowId = row._id;
|
|
419
|
+
var columnColor = columnColors[rowId];
|
|
420
|
+
column_colors[rowId] = columnColor;
|
|
421
|
+
});
|
|
422
|
+
return view.column_colors;
|
|
423
|
+
};
|
|
424
|
+
var ColumnColorUtils = {
|
|
425
|
+
isColumnHasColorRules: isColumnHasColorRules,
|
|
426
|
+
hasRelatedColumnColorRule: hasRelatedColumnColorRule,
|
|
427
|
+
isColumnColorRulesValid: isColumnColorRulesValid,
|
|
428
|
+
isColumnColorsView: isColumnColorsView,
|
|
429
|
+
getValidRulesColumns: getValidRulesColumns,
|
|
430
|
+
getSortedViewRows: getSortedViewRows,
|
|
431
|
+
getCellValue: getCellValue,
|
|
432
|
+
getFormattedColumn: getFormattedColumn,
|
|
433
|
+
getColumnColors: getColumnColors,
|
|
434
|
+
updateColumnColorsByUpdateRows: updateColumnColorsByUpdateRows
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
export { ColumnColorUtils as default };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import { COLOR_GRADATION_OPTIONS } from '../constants/color.js';
|
|
5
|
+
|
|
6
|
+
var GradientColorUtils = /*#__PURE__*/function () {
|
|
7
|
+
function GradientColorUtils(_ref) {
|
|
8
|
+
var colorType = _ref.colorType,
|
|
9
|
+
max = _ref.max,
|
|
10
|
+
min = _ref.min;
|
|
11
|
+
_classCallCheck(this, GradientColorUtils);
|
|
12
|
+
var newColorType = colorType || 'color_gradation_1';
|
|
13
|
+
var colors = COLOR_GRADATION_OPTIONS[newColorType];
|
|
14
|
+
this.startColor = this.hexToRgb(colors[0]);
|
|
15
|
+
this.endColor = this.hexToRgb(colors[4]);
|
|
16
|
+
this.min = min;
|
|
17
|
+
this.max = max;
|
|
18
|
+
this.computeMap = {};
|
|
19
|
+
}
|
|
20
|
+
_createClass(GradientColorUtils, [{
|
|
21
|
+
key: "hexToRgb",
|
|
22
|
+
value: function hexToRgb(hexCode) {
|
|
23
|
+
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
24
|
+
var nextHexCode = hexCode.toLowerCase();
|
|
25
|
+
if (nextHexCode && reg.test(nextHexCode)) {
|
|
26
|
+
if (nextHexCode.length === 4) {
|
|
27
|
+
var newHexCode = '#';
|
|
28
|
+
for (var i = 1; i < 4; i += 1) {
|
|
29
|
+
newHexCode += nextHexCode.slice(i, i + 1).concat(nextHexCode.slice(i, i + 1));
|
|
30
|
+
}
|
|
31
|
+
nextHexCode = newHexCode;
|
|
32
|
+
}
|
|
33
|
+
var hexCodeChange = [];
|
|
34
|
+
for (var _i = 1; _i < 7; _i += 2) {
|
|
35
|
+
hexCodeChange.push(parseInt("0x".concat(nextHexCode.slice(_i, _i + 2))));
|
|
36
|
+
}
|
|
37
|
+
return "RGB(".concat(hexCodeChange.join(','), ")");
|
|
38
|
+
}
|
|
39
|
+
return nextHexCode;
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "getColorGradation",
|
|
43
|
+
value: function getColorGradation(color1, color2, value1, value2, value) {
|
|
44
|
+
var rgb1 = color1.split(',');
|
|
45
|
+
var r1 = parseInt(rgb1[0].split('(')[1]);
|
|
46
|
+
var g1 = parseInt(rgb1[1]);
|
|
47
|
+
var b1 = parseInt(rgb1[2].split(')')[0]);
|
|
48
|
+
var rgb2 = color2.split(',');
|
|
49
|
+
var r2 = parseInt(rgb2[0].split('(')[1]);
|
|
50
|
+
var g2 = parseInt(rgb2[1]);
|
|
51
|
+
var b2 = parseInt(rgb2[2].split(')')[0]);
|
|
52
|
+
var r = Math.round(r1 - (r1 - r2) / (value1 - value2) * (value1 - value));
|
|
53
|
+
var g = Math.round(g1 - (g1 - g2) / (value1 - value2) * (value1 - value));
|
|
54
|
+
var b = Math.round(b1 - (b1 - b2) / (value1 - value2) * (value1 - value));
|
|
55
|
+
return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "getCellColor",
|
|
59
|
+
value: function getCellColor(value) {
|
|
60
|
+
if (this.computeMap[value]) {
|
|
61
|
+
return this.computeMap[value];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// eslint-disable-next-line
|
|
65
|
+
if (value == this.min) {
|
|
66
|
+
if (this.computeMap[value]) {
|
|
67
|
+
this.computeMap[value] = this.startColor;
|
|
68
|
+
} else {
|
|
69
|
+
this.computeMap = _defineProperty({}, value, this.startColor);
|
|
70
|
+
}
|
|
71
|
+
return this.computeMap[value];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line
|
|
75
|
+
if (value == this.max) {
|
|
76
|
+
if (this.computeMap[value]) {
|
|
77
|
+
this.computeMap[value] = this.endColor;
|
|
78
|
+
} else {
|
|
79
|
+
this.computeMap = _defineProperty({}, value, this.endColor);
|
|
80
|
+
}
|
|
81
|
+
return this.computeMap[value];
|
|
82
|
+
}
|
|
83
|
+
if (value > this.min && value < this.max) {
|
|
84
|
+
var color1 = this.startColor,
|
|
85
|
+
color2 = this.endColor,
|
|
86
|
+
value1 = this.min,
|
|
87
|
+
value2 = this.max;
|
|
88
|
+
var color = this.getColorGradation(color1, color2, value1, value2, value);
|
|
89
|
+
this.computeMap[value] = color;
|
|
90
|
+
return this.computeMap[value];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// value < min || value > max
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}]);
|
|
97
|
+
return GradientColorUtils;
|
|
98
|
+
}();
|
|
99
|
+
|
|
100
|
+
export { GradientColorUtils as default };
|