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,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var core = require('./core.js');
|
|
7
|
+
var checkbox = require('./sort-column/checkbox.js');
|
|
8
|
+
var collaborator$1 = require('./sort-column/collaborator.js');
|
|
9
|
+
var date = require('./sort-column/date.js');
|
|
10
|
+
var collaborator = require('../cell-value-get/collaborator.js');
|
|
11
|
+
require('../cell-value-get/cell-value.js');
|
|
12
|
+
var number = require('./sort-column/number.js');
|
|
13
|
+
var text = require('./sort-column/text.js');
|
|
14
|
+
var cellType = require('../constants/cell-type.js');
|
|
15
|
+
var column = require('../constants/column.js');
|
|
16
|
+
var formula = require('../constants/formula.js');
|
|
17
|
+
var formula$1 = require('./sort-column/formula.js');
|
|
18
|
+
var link = require('./sort-column/link.js');
|
|
19
|
+
var multipleSelect = require('./sort-column/multiple-select.js');
|
|
20
|
+
var singleSelect = require('./sort-column/single-select.js');
|
|
21
|
+
var option = require('../column/option.js');
|
|
22
|
+
var sort = require('../constants/sort.js');
|
|
23
|
+
|
|
24
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
|
+
|
|
26
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
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 deleteInvalidSort = function deleteInvalidSort(sorts, columns) {
|
|
31
|
+
var validSorts = core.getValidSorts(sorts, columns);
|
|
32
|
+
var cleanSorts = [];
|
|
33
|
+
validSorts.forEach(function (sort) {
|
|
34
|
+
var column_key = sort.column_key;
|
|
35
|
+
var sortColumn = columns.find(function (column) {
|
|
36
|
+
return column.key === column_key;
|
|
37
|
+
});
|
|
38
|
+
var columnType = sortColumn.type;
|
|
39
|
+
var newSort = _objectSpread(_objectSpread({}, sort), {}, {
|
|
40
|
+
column: sortColumn
|
|
41
|
+
});
|
|
42
|
+
switch (columnType) {
|
|
43
|
+
case cellType.CellType.SINGLE_SELECT:
|
|
44
|
+
case cellType.CellType.MULTIPLE_SELECT:
|
|
45
|
+
{
|
|
46
|
+
var options = option.getColumnOptions(sortColumn);
|
|
47
|
+
var option_id_index_map = {};
|
|
48
|
+
options.forEach(function (option, index) {
|
|
49
|
+
option_id_index_map[option.id] = index;
|
|
50
|
+
});
|
|
51
|
+
newSort.option_id_index_map = option_id_index_map;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
cleanSorts.push(newSort);
|
|
56
|
+
});
|
|
57
|
+
return cleanSorts;
|
|
58
|
+
};
|
|
59
|
+
var sortRowsWithMultiSorts = function sortRowsWithMultiSorts(sortRows, sorts, _ref) {
|
|
60
|
+
var _ref$formulaRows = _ref.formulaRows,
|
|
61
|
+
formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
|
|
62
|
+
value = _ref.value;
|
|
63
|
+
sortRows.sort(function (currentRow, nextRow) {
|
|
64
|
+
var initValue = 0;
|
|
65
|
+
sorts.forEach(function (sort$1) {
|
|
66
|
+
var column_key = sort$1.column_key,
|
|
67
|
+
sort_type = sort$1.sort_type,
|
|
68
|
+
column$1 = sort$1.column;
|
|
69
|
+
var columnType = column$1.type,
|
|
70
|
+
columnData = column$1.data;
|
|
71
|
+
var currCellVal = currentRow[column_key];
|
|
72
|
+
var nextCellVal = nextRow[column_key];
|
|
73
|
+
if (column.DATE_COLUMN_OPTIONS.includes(columnType)) {
|
|
74
|
+
initValue = initValue || date.sortDate(currCellVal, nextCellVal, sort_type);
|
|
75
|
+
} else if (columnType === cellType.CellType.SINGLE_SELECT) {
|
|
76
|
+
initValue = initValue || singleSelect.sortSingleSelect(currCellVal, nextCellVal, sort$1);
|
|
77
|
+
} else if (sort.NUMBER_SORTER_COLUMN_TYPES.includes(columnType)) {
|
|
78
|
+
initValue = initValue || number.sortNumber(currCellVal, nextCellVal, sort_type);
|
|
79
|
+
} else if (formula.FORMULA_COLUMN_TYPES_MAP[columnType]) {
|
|
80
|
+
var currentFormulaRow = formulaRows[currentRow._id] || {};
|
|
81
|
+
var nextFormulaRow = formulaRows[nextRow._id] || {};
|
|
82
|
+
currCellVal = currentFormulaRow[column_key];
|
|
83
|
+
nextCellVal = nextFormulaRow[column_key];
|
|
84
|
+
initValue = initValue || formula$1.sortFormula(currCellVal, nextCellVal, sort_type, {
|
|
85
|
+
columnData: columnData,
|
|
86
|
+
value: value
|
|
87
|
+
});
|
|
88
|
+
} else if (columnType === cellType.CellType.COLLABORATOR) {
|
|
89
|
+
var collaborators = value.collaborators;
|
|
90
|
+
var currValidCollaborators = currCellVal;
|
|
91
|
+
var nextValidCollaborators = nextCellVal;
|
|
92
|
+
if (collaborators) {
|
|
93
|
+
currValidCollaborators = collaborator.getCollaboratorsNames(currCellVal, collaborators);
|
|
94
|
+
nextValidCollaborators = collaborator.getCollaboratorsNames(nextCellVal, collaborators);
|
|
95
|
+
}
|
|
96
|
+
initValue = initValue || collaborator$1.sortCollaborator(currValidCollaborators, nextValidCollaborators, sort_type);
|
|
97
|
+
} else if (columnType === cellType.CellType.CHECKBOX) {
|
|
98
|
+
initValue = initValue || checkbox.sortCheckbox(currCellVal, nextCellVal, sort_type);
|
|
99
|
+
} else if (columnType === cellType.CellType.MULTIPLE_SELECT) {
|
|
100
|
+
initValue = initValue || multipleSelect.sortMultipleSelect(currCellVal, nextCellVal, sort$1);
|
|
101
|
+
} else if (columnType === cellType.CellType.LINK) {
|
|
102
|
+
var _currentFormulaRow = formulaRows[currentRow._id] || {};
|
|
103
|
+
var _nextFormulaRow = formulaRows[nextRow._id] || {};
|
|
104
|
+
currCellVal = _currentFormulaRow[column_key];
|
|
105
|
+
nextCellVal = _nextFormulaRow[column_key];
|
|
106
|
+
initValue = initValue || link.sortLink(currCellVal, nextCellVal, sort_type, {
|
|
107
|
+
columnData: columnData,
|
|
108
|
+
value: value
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
initValue = initValue || text.sortText(currCellVal, nextCellVal, sort_type);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return initValue;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
var sortTableRows = function sortTableRows(sorts, rows, columns) {
|
|
118
|
+
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
119
|
+
formulaRows = _ref2.formulaRows,
|
|
120
|
+
value = _ref2.value;
|
|
121
|
+
if (!Array.isArray(rows)) return [];
|
|
122
|
+
var sortRows = rows.slice(0);
|
|
123
|
+
var validSorts = deleteInvalidSort(sorts, columns);
|
|
124
|
+
var normalizedFormulaRows = formulaRows || {};
|
|
125
|
+
sortRowsWithMultiSorts(sortRows, validSorts, {
|
|
126
|
+
formulaRows: normalizedFormulaRows,
|
|
127
|
+
value: value
|
|
128
|
+
});
|
|
129
|
+
return sortRows.map(function (row) {
|
|
130
|
+
return row._id;
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
exports.deleteInvalidSort = deleteInvalidSort;
|
|
135
|
+
exports.sortRowsWithMultiSorts = sortRowsWithMultiSorts;
|
|
136
|
+
exports.sortTableRows = sortTableRows;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get column by key from table
|
|
7
|
+
* @param {object} table
|
|
8
|
+
* @param {string} columnKey
|
|
9
|
+
* @returns column, object
|
|
10
|
+
*/
|
|
11
|
+
var getTableColumnByKey = function getTableColumnByKey(table, columnKey) {
|
|
12
|
+
if (!table || !Array.isArray(table.columns) || !columnKey) return null;
|
|
13
|
+
return table.columns.find(function (column) {
|
|
14
|
+
return column.key === columnKey;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* get column by name from table
|
|
20
|
+
* @param {object} table
|
|
21
|
+
* @param {string} columnName
|
|
22
|
+
* @returns column, object
|
|
23
|
+
*/
|
|
24
|
+
var getTableColumnByName = function getTableColumnByName(table, columnName) {
|
|
25
|
+
if (!table || !Array.isArray(table.columns) || !columnName) return null;
|
|
26
|
+
return table.columns.find(function (column) {
|
|
27
|
+
return column.name === columnName;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.getTableColumnByKey = getTableColumnByKey;
|
|
32
|
+
exports.getTableColumnByName = getTableColumnByName;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get table by id
|
|
7
|
+
* @param {array} tables
|
|
8
|
+
* @param {string} tableId
|
|
9
|
+
* @returns object
|
|
10
|
+
*/
|
|
11
|
+
var getTableById = function getTableById(tables, tableId) {
|
|
12
|
+
if (!Array.isArray(tables) || !tableId) return null;
|
|
13
|
+
return tables.find(function (table) {
|
|
14
|
+
return table._id === tableId;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.getTableById = getTableById;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get table by id
|
|
7
|
+
* @param {array} tables
|
|
8
|
+
* @param {string} tableId
|
|
9
|
+
* @returns table, object
|
|
10
|
+
*/
|
|
11
|
+
var getTableById = function getTableById(tables, tableId) {
|
|
12
|
+
if (!Array.isArray(tables) || !tableId) return null;
|
|
13
|
+
return tables.find(function (table) {
|
|
14
|
+
return table._id === tableId;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.getTableById = getTableById;
|
package/lib/table/row.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get row by id from table
|
|
7
|
+
* @param {object} table
|
|
8
|
+
* @param {string} rowId the id of row
|
|
9
|
+
* @returns object
|
|
10
|
+
*/
|
|
11
|
+
var getRowById = function getRowById(table, rowId) {
|
|
12
|
+
if (!table || !table.id_row_map || !rowId) return null;
|
|
13
|
+
return table.id_row_map[rowId];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* get rows by ids from table
|
|
18
|
+
* @param {object} table { id_row_map, ... }
|
|
19
|
+
* @param {array} rowsIds [ row._id, ... ]
|
|
20
|
+
* @returns array, rows: [ row, ... ]
|
|
21
|
+
*/
|
|
22
|
+
var getRowsByIds = function getRowsByIds(table, rowsIds) {
|
|
23
|
+
if (!table || !table.id_row_map || !Array.isArray(rowsIds)) return [];
|
|
24
|
+
return rowsIds.map(function (rowId) {
|
|
25
|
+
return table.id_row_map[rowId];
|
|
26
|
+
}).filter(Boolean);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.getRowById = getRowById;
|
|
30
|
+
exports.getRowsByIds = getRowsByIds;
|
package/lib/validate/filter.js
CHANGED
|
@@ -9,7 +9,7 @@ var cellType = require('../constants/cell-type.js');
|
|
|
9
9
|
var column = require('../constants/column.js');
|
|
10
10
|
var formula = require('../constants/formula.js');
|
|
11
11
|
var index = require('../constants/filter/index.js');
|
|
12
|
-
var
|
|
12
|
+
var option = require('../column/option.js');
|
|
13
13
|
var date = require('../column/date.js');
|
|
14
14
|
var filterPredicate = require('../constants/filter/filter-predicate.js');
|
|
15
15
|
var filterModifier = require('../constants/filter/filter-modifier.js');
|
|
@@ -307,7 +307,7 @@ var ValidateFilter = /*#__PURE__*/function () {
|
|
|
307
307
|
}
|
|
308
308
|
case cellType.CellType.SINGLE_SELECT:
|
|
309
309
|
{
|
|
310
|
-
var options =
|
|
310
|
+
var options = option.getColumnOptions(filterColumn);
|
|
311
311
|
if (PREDICATES_REQUIRE_ARRAY_TERM.includes(predicate)) {
|
|
312
312
|
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
|
|
313
313
|
return false;
|
|
@@ -349,7 +349,7 @@ var ValidateFilter = /*#__PURE__*/function () {
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
// contains deleted option(s)
|
|
352
|
-
var _options =
|
|
352
|
+
var _options = option.getColumnOptions(filterColumn);
|
|
353
353
|
return this.isValidSelectedOptions(term, _options);
|
|
354
354
|
}
|
|
355
355
|
case cellType.CellType.DATE:
|
package/lib/view/core.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('../filter/core.js');
|
|
6
|
+
var core$1 = require('../group/core.js');
|
|
7
|
+
var core$2 = require('../sort/core.js');
|
|
8
|
+
var cellType = require('../constants/cell-type.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* get view by id
|
|
12
|
+
* @param {array} views { _id: '', ... }
|
|
13
|
+
* @param {string} viewId
|
|
14
|
+
* @returns object
|
|
15
|
+
*/
|
|
16
|
+
var getViewById = function getViewById(views, viewId) {
|
|
17
|
+
if (!Array.isArray(views) || !viewId) return null;
|
|
18
|
+
return views.find(function (view) {
|
|
19
|
+
return view._id === viewId;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* check whether the view contains filters
|
|
25
|
+
* @param {object} view { filters: [], ... }
|
|
26
|
+
* @param {array} columns
|
|
27
|
+
* @returns boolean
|
|
28
|
+
*/
|
|
29
|
+
var isFilterView = function isFilterView(view, columns) {
|
|
30
|
+
var validFilters = core.getValidFilters(view.filters, columns);
|
|
31
|
+
return validFilters.length > 0;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* check whether the view contains groupbys
|
|
36
|
+
* @param {object} view { groupbys: [], ... }
|
|
37
|
+
* @param {array} columns
|
|
38
|
+
* @returns boolean
|
|
39
|
+
*/
|
|
40
|
+
var isGroupView = function isGroupView(view, columns) {
|
|
41
|
+
var validGroupbys = core$1.getValidGroupbys(view.groupbys, columns);
|
|
42
|
+
return validGroupbys.length > 0;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* check whether the view contains sorts
|
|
47
|
+
* @param {object} view { sorts: [], ... }
|
|
48
|
+
* @param {array} columns
|
|
49
|
+
* @returns boolean
|
|
50
|
+
*/
|
|
51
|
+
var isSortView = function isSortView(view, columns) {
|
|
52
|
+
var sorts = view.sorts;
|
|
53
|
+
var validSorts = core$2.getValidSorts(sorts, columns);
|
|
54
|
+
return validSorts.length > 0;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* check is default view which no contains filters, sorts, groupbys etc.
|
|
59
|
+
* @param {object} view { sorts: [], ... }
|
|
60
|
+
* @param {array} columns
|
|
61
|
+
* @returns boolean
|
|
62
|
+
*/
|
|
63
|
+
var isDefaultView = function isDefaultView(view, columns) {
|
|
64
|
+
return !isFilterView(view, columns) && !isSortView(view, columns) && !isGroupView(view, columns);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* get link columns which used either in filters, groupbys, sorts etc.
|
|
69
|
+
* @param {object} view { filters, groupbys, sorts, ... }
|
|
70
|
+
* @param {object} table
|
|
71
|
+
* @returns array, link columns
|
|
72
|
+
*/
|
|
73
|
+
var getLinkColumnsUsedInFilters = function getLinkColumnsUsedInFilters(view, table) {
|
|
74
|
+
var filters = view.filters,
|
|
75
|
+
sorts = view.sorts,
|
|
76
|
+
groupbys = view.groupbys;
|
|
77
|
+
var columns = table.columns;
|
|
78
|
+
if (!Array.isArray(columns)) return [];
|
|
79
|
+
var validFilters = core.getValidFiltersWithoutError(filters, columns);
|
|
80
|
+
var validSorts = core$2.getValidSorts(sorts, columns);
|
|
81
|
+
var validGroupbys = core$1.getValidGroupbys(groupbys, columns);
|
|
82
|
+
var hasFilters = validFilters && validFilters.length > 0;
|
|
83
|
+
var hasSorts = validSorts && validSorts.length > 0;
|
|
84
|
+
var hasGroupbys = validGroupbys && validGroupbys.length > 0;
|
|
85
|
+
if (!hasFilters && !hasSorts && !hasGroupbys) return [];
|
|
86
|
+
var keyLinkColumnMap = {};
|
|
87
|
+
var keyExistLinkColumnMap = {};
|
|
88
|
+
var linkColumns = [];
|
|
89
|
+
columns.forEach(function (column) {
|
|
90
|
+
var key = column.key,
|
|
91
|
+
name = column.name,
|
|
92
|
+
type = column.type,
|
|
93
|
+
data = column.data,
|
|
94
|
+
width = column.width;
|
|
95
|
+
if (type === cellType.CellType.LINK) {
|
|
96
|
+
keyLinkColumnMap[column.key] = {
|
|
97
|
+
key: key,
|
|
98
|
+
name: name,
|
|
99
|
+
type: type,
|
|
100
|
+
data: data,
|
|
101
|
+
width: width
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (Object.keys(keyLinkColumnMap).length === 0) return [];
|
|
106
|
+
if (hasFilters) {
|
|
107
|
+
validFilters.forEach(function (filter) {
|
|
108
|
+
var filterColumnKey = filter.column_key;
|
|
109
|
+
var filterLinkColumn = keyLinkColumnMap[filterColumnKey];
|
|
110
|
+
if (filterLinkColumn && !keyExistLinkColumnMap[filterColumnKey]) {
|
|
111
|
+
linkColumns.push(filterLinkColumn);
|
|
112
|
+
keyExistLinkColumnMap[filterColumnKey] = true;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (hasSorts) {
|
|
117
|
+
validSorts.forEach(function (sort) {
|
|
118
|
+
var sortColumnKey = sort.column_key;
|
|
119
|
+
var sortLinkColumn = keyLinkColumnMap[sortColumnKey];
|
|
120
|
+
if (sortLinkColumn && !keyExistLinkColumnMap[sortColumnKey]) {
|
|
121
|
+
linkColumns.push(sortLinkColumn);
|
|
122
|
+
keyExistLinkColumnMap[sortColumnKey] = true;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (hasGroupbys) {
|
|
127
|
+
validGroupbys.forEach(function (groupby) {
|
|
128
|
+
var groupbyColumnKey = groupby.column_key;
|
|
129
|
+
var groupbyLinkColumn = keyLinkColumnMap[groupbyColumnKey];
|
|
130
|
+
if (groupbyLinkColumn && !keyExistLinkColumnMap[groupbyColumnKey]) {
|
|
131
|
+
linkColumns.push(groupbyLinkColumn);
|
|
132
|
+
keyExistLinkColumnMap[groupbyColumnKey] = true;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return linkColumns;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
exports.getLinkColumnsUsedInFilters = getLinkColumnsUsedInFilters;
|
|
140
|
+
exports.getViewById = getViewById;
|
|
141
|
+
exports.isDefaultView = isDefaultView;
|
|
142
|
+
exports.isFilterView = isFilterView;
|
|
143
|
+
exports.isGroupView = isGroupView;
|
|
144
|
+
exports.isSortView = isSortView;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var cellType = require('../constants/cell-type.js');
|
|
6
|
+
var formula = require('../constants/formula.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* transform the formats of link column to link-formula's
|
|
10
|
+
* @param {object} linkColumn { key, data: { display_column_key, ... }, ... }
|
|
11
|
+
* @returns object
|
|
12
|
+
*/
|
|
13
|
+
var transLink2LinkFormula = function transLink2LinkFormula(linkColumn) {
|
|
14
|
+
var key = linkColumn.key,
|
|
15
|
+
name = linkColumn.name,
|
|
16
|
+
data = linkColumn.data;
|
|
17
|
+
var display_column_key = data.display_column_key;
|
|
18
|
+
return {
|
|
19
|
+
key: key,
|
|
20
|
+
name: name,
|
|
21
|
+
type: cellType.CellType.LINK_FORMULA,
|
|
22
|
+
data: {
|
|
23
|
+
formula: 'lookup',
|
|
24
|
+
link_column_key: key,
|
|
25
|
+
level1_linked_table_column_key: display_column_key,
|
|
26
|
+
level2_linked_table_column_key: null,
|
|
27
|
+
operated_columns: []
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* get sorted formula columns
|
|
34
|
+
* @param {array} formulaColumns
|
|
35
|
+
* @param {object} table
|
|
36
|
+
* @returns array
|
|
37
|
+
*/
|
|
38
|
+
var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, table) {
|
|
39
|
+
if (!Array.isArray(formulaColumns) || !table || !Array.isArray(table.columns)) return [];
|
|
40
|
+
var keyColumnMap = {};
|
|
41
|
+
table.columns.forEach(function (column) {
|
|
42
|
+
var key = column.key,
|
|
43
|
+
type = column.type;
|
|
44
|
+
if (formula.FORMULA_COLUMN_TYPES_MAP[type]) {
|
|
45
|
+
keyColumnMap[key] = column;
|
|
46
|
+
} else if (type === cellType.CellType.LINK && column.data) {
|
|
47
|
+
keyColumnMap[key] = transLink2LinkFormula(column);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// get none-repeating formulas
|
|
52
|
+
var key_sorting_formula_column = {};
|
|
53
|
+
var sorting_formula_column_keys = [];
|
|
54
|
+
formulaColumns.forEach(function (column) {
|
|
55
|
+
var columnKey = column.key;
|
|
56
|
+
if (!key_sorting_formula_column[columnKey]) {
|
|
57
|
+
key_sorting_formula_column[columnKey] = column;
|
|
58
|
+
sorting_formula_column_keys.push(columnKey);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* e.g. formula1 = formula2 + formula3
|
|
64
|
+
* e.g. formula2 = 1 + 2
|
|
65
|
+
* e.g. formula3 = formula2 + 3
|
|
66
|
+
* edges: formula2 --> formula1, formula2 --> formula3; formula3 --> formula1
|
|
67
|
+
* keyInDegreeMap, the total number of formula columns that depend on: { formula1_key: 2, formula2_key: 0, formula3_key: 1 }
|
|
68
|
+
* keyEdgesMap: { formula2_key: [formula1_key, formula3_key], formula3_kye: [formula1_key]}
|
|
69
|
+
*/
|
|
70
|
+
var keyInDegreeMap = {};
|
|
71
|
+
var keyEdgesMap = {};
|
|
72
|
+
sorting_formula_column_keys.forEach(function (formulaColumnKey) {
|
|
73
|
+
var formulaColumn = key_sorting_formula_column[formulaColumnKey];
|
|
74
|
+
var data = formulaColumn.data;
|
|
75
|
+
var operated_columns = data.operated_columns;
|
|
76
|
+
keyInDegreeMap[formulaColumnKey] = 0;
|
|
77
|
+
Array.isArray(operated_columns) && operated_columns.forEach(function (dependColumnKey) {
|
|
78
|
+
var dependColumn = keyColumnMap[dependColumnKey];
|
|
79
|
+
if (!dependColumn) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
keyInDegreeMap[formulaColumnKey]++;
|
|
83
|
+
if (keyEdgesMap[dependColumnKey]) {
|
|
84
|
+
keyEdgesMap[dependColumnKey].push(formulaColumnKey);
|
|
85
|
+
} else {
|
|
86
|
+
keyEdgesMap[dependColumnKey] = [formulaColumnKey];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
var sortedList = [];
|
|
91
|
+
var waitingQueue = [];
|
|
92
|
+
sorting_formula_column_keys.forEach(function (formulaColumnKey) {
|
|
93
|
+
if (keyInDegreeMap[formulaColumnKey] === 0) {
|
|
94
|
+
waitingQueue.push(formulaColumnKey);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
while (waitingQueue.length) {
|
|
98
|
+
var columnKey = waitingQueue.shift();
|
|
99
|
+
var edges = keyEdgesMap[columnKey];
|
|
100
|
+
sortedList.push(columnKey);
|
|
101
|
+
Array.isArray(edges) && edges.forEach(function (edge) {
|
|
102
|
+
keyInDegreeMap[edge]--;
|
|
103
|
+
if (keyInDegreeMap[edge] === 0) {
|
|
104
|
+
waitingQueue.push(edge);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return sortedList.map(function (columnKey) {
|
|
109
|
+
return keyColumnMap[columnKey];
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* get formula columns and link columns from table
|
|
115
|
+
* @param {object} table { columns: [], ... }
|
|
116
|
+
* @returns array
|
|
117
|
+
*/
|
|
118
|
+
var getFormulaColumnsContainLinks = function getFormulaColumnsContainLinks(table) {
|
|
119
|
+
var columns = table.columns;
|
|
120
|
+
var formulaColumns = columns.filter(function (column) {
|
|
121
|
+
var type = column.type,
|
|
122
|
+
data = column.data;
|
|
123
|
+
if (type === cellType.CellType.LINK) {
|
|
124
|
+
return !!data;
|
|
125
|
+
}
|
|
126
|
+
return formula.FORMULA_COLUMN_TYPES_MAP[type] && data;
|
|
127
|
+
});
|
|
128
|
+
return formulaColumns.map(function (column) {
|
|
129
|
+
if (column.type === cellType.CellType.LINK) {
|
|
130
|
+
return transLink2LinkFormula(column);
|
|
131
|
+
}
|
|
132
|
+
return column;
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* get sorted formula columns and link columns from table
|
|
138
|
+
* @param {object} table { columns: [], ... }
|
|
139
|
+
* @returns array
|
|
140
|
+
*/
|
|
141
|
+
var getSortedFormulaColumnsContainLinks = function getSortedFormulaColumnsContainLinks(table) {
|
|
142
|
+
var formulaColumns = getFormulaColumnsContainLinks(table);
|
|
143
|
+
if (formulaColumns.length === 0) return [];
|
|
144
|
+
return getSortedFormulaColumns(formulaColumns, table);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
exports.getFormulaColumnsContainLinks = getFormulaColumnsContainLinks;
|
|
148
|
+
exports.getSortedFormulaColumns = getSortedFormulaColumns;
|
|
149
|
+
exports.getSortedFormulaColumnsContainLinks = getSortedFormulaColumnsContainLinks;
|
|
150
|
+
exports.transLink2LinkFormula = transLink2LinkFormula;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get group by paths.
|
|
7
|
+
* @param {array} paths e.g. [0, 1, 2]
|
|
8
|
+
* @param {array} groups
|
|
9
|
+
* @returns object
|
|
10
|
+
*/
|
|
11
|
+
var getGroupByPath = function getGroupByPath(paths, groups) {
|
|
12
|
+
if (!Array.isArray(paths) || !Array.isArray(groups)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
var level0GroupIndex = paths[0];
|
|
16
|
+
if (level0GroupIndex < 0 || level0GroupIndex >= groups.length) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
var level = 1;
|
|
20
|
+
var foundGroup = groups[level0GroupIndex];
|
|
21
|
+
while (level < paths.length) {
|
|
22
|
+
if (!foundGroup) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
var subGroups = foundGroup.subgroups;
|
|
26
|
+
var currentLevelGroupIndex = paths[level];
|
|
27
|
+
if (!Array.isArray(subGroups) || currentLevelGroupIndex < 0 || currentLevelGroupIndex >= subGroups.length) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
foundGroup = subGroups[currentLevelGroupIndex];
|
|
31
|
+
level += 1;
|
|
32
|
+
}
|
|
33
|
+
return foundGroup;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.getGroupByPath = getGroupByPath;
|