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