dbgate-datalib 5.0.7 → 5.1.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/lib/FreeTableGridDisplay.d.ts +8 -4
- package/lib/GridDisplay.d.ts +1 -1
- package/lib/PerspectiveCache.d.ts +39 -0
- package/lib/PerspectiveCache.js +99 -0
- package/lib/PerspectiveConfig.d.ts +63 -0
- package/lib/PerspectiveConfig.js +30 -0
- package/lib/PerspectiveDataLoader.d.ts +9 -0
- package/lib/PerspectiveDataLoader.js +136 -0
- package/lib/PerspectiveDataProvider.d.ts +42 -0
- package/lib/PerspectiveDataProvider.js +179 -0
- package/lib/PerspectiveDisplay.d.ts +55 -0
- package/lib/PerspectiveDisplay.js +223 -0
- package/lib/PerspectiveTreeNode.d.ts +146 -0
- package/lib/PerspectiveTreeNode.js +727 -0
- package/lib/TableGridDisplay.d.ts +8 -4
- package/lib/ViewGridDisplay.d.ts +8 -4
- package/lib/getPerspectiveDefaultColumns.d.ts +2 -0
- package/lib/getPerspectiveDefaultColumns.js +30 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +11 -1
- package/lib/tests/PerspectiveDisplay.test.d.ts +1 -0
- package/lib/tests/PerspectiveDisplay.test.js +79 -0
- package/lib/tests/artistDataAlbum.d.ts +20 -0
- package/lib/tests/artistDataAlbum.js +58 -0
- package/lib/tests/artistDataAlbumTrack.d.ts +20 -0
- package/lib/tests/artistDataAlbumTrack.js +79 -0
- package/lib/tests/artistDataFlat.d.ts +10 -0
- package/lib/tests/artistDataFlat.js +23 -0
- package/lib/tests/chinookDbInfo.d.ts +2 -0
- package/lib/tests/chinookDbInfo.js +1775 -0
- package/package.json +9 -4
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTableChildPerspectiveNodes = exports.PerspectiveCustomJoinTreeNode = exports.PerspectiveTableReferenceNode = exports.PerspectiveTableNode = exports.PerspectiveTableColumnNode = exports.PerspectiveTreeNode = void 0;
|
|
7
|
+
const compact_1 = __importDefault(require("lodash/compact"));
|
|
8
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
9
|
+
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
10
|
+
const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
|
|
11
|
+
const sortBy_1 = __importDefault(require("lodash/sortBy"));
|
|
12
|
+
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
13
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
14
|
+
const dbgate_filterparser_1 = require("dbgate-filterparser");
|
|
15
|
+
const getPerspectiveDefaultColumns_1 = require("./getPerspectiveDefaultColumns");
|
|
16
|
+
// export function groupPerspectiveLoadProps(
|
|
17
|
+
// ...list: PerspectiveDataLoadPropsWithNode[]
|
|
18
|
+
// ): PerspectiveDataLoadPropsWithNode[] {
|
|
19
|
+
// const res: PerspectiveDataLoadPropsWithNode[] = [];
|
|
20
|
+
// for (const item of list) {
|
|
21
|
+
// const existing = res.find(
|
|
22
|
+
// x =>
|
|
23
|
+
// x.node == item.node &&
|
|
24
|
+
// x.props.schemaName == item.props.schemaName &&
|
|
25
|
+
// x.props.pureName == item.props.pureName &&
|
|
26
|
+
// _isEqual(x.props.bindingColumns, item.props.bindingColumns)
|
|
27
|
+
// );
|
|
28
|
+
// if (existing) {
|
|
29
|
+
// existing.props.bindingValues.push(...item.props.bindingValues);
|
|
30
|
+
// } else {
|
|
31
|
+
// res.push(_cloneDeep(item));
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// return res;
|
|
35
|
+
// }
|
|
36
|
+
class PerspectiveTreeNode {
|
|
37
|
+
constructor(dbs, config, setConfig, parentNode, dataProvider, databaseConfig) {
|
|
38
|
+
this.dbs = dbs;
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.setConfig = setConfig;
|
|
41
|
+
this.parentNode = parentNode;
|
|
42
|
+
this.dataProvider = dataProvider;
|
|
43
|
+
this.databaseConfig = databaseConfig;
|
|
44
|
+
}
|
|
45
|
+
get fieldName() {
|
|
46
|
+
return this.codeName;
|
|
47
|
+
}
|
|
48
|
+
get headerTableAttributes() {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
get dataField() {
|
|
52
|
+
return this.codeName;
|
|
53
|
+
}
|
|
54
|
+
get tableCode() {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
get namedObject() {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
get isRoot() {
|
|
61
|
+
return this.parentNode == null;
|
|
62
|
+
}
|
|
63
|
+
get rootNode() {
|
|
64
|
+
var _a;
|
|
65
|
+
if (this.isRoot)
|
|
66
|
+
return this;
|
|
67
|
+
return (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.rootNode;
|
|
68
|
+
}
|
|
69
|
+
matchChildRow(parentRow, childRow) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
hasTableCode(code) {
|
|
73
|
+
var _a;
|
|
74
|
+
return code == this.tableCode || ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.hasTableCode(code));
|
|
75
|
+
}
|
|
76
|
+
get uniqueName() {
|
|
77
|
+
if (this.parentNode)
|
|
78
|
+
return `${this.parentNode.uniqueName}::${this.codeName}`;
|
|
79
|
+
return this.codeName;
|
|
80
|
+
}
|
|
81
|
+
get level() {
|
|
82
|
+
if (this.parentNode)
|
|
83
|
+
return this.parentNode.level + 1;
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
get isExpanded() {
|
|
87
|
+
return this.config.expandedColumns.includes(this.uniqueName);
|
|
88
|
+
}
|
|
89
|
+
get isChecked() {
|
|
90
|
+
if (this.config.checkedColumns.includes(this.uniqueName))
|
|
91
|
+
return true;
|
|
92
|
+
if (this.config.uncheckedColumns.includes(this.uniqueName))
|
|
93
|
+
return false;
|
|
94
|
+
return this.defaultChecked;
|
|
95
|
+
}
|
|
96
|
+
get columnTitle() {
|
|
97
|
+
return this.title;
|
|
98
|
+
}
|
|
99
|
+
get filterType() {
|
|
100
|
+
return 'string';
|
|
101
|
+
}
|
|
102
|
+
get columnName() {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
get customJoinConfig() {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
get db() {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
return (_b = (_a = this.dbs) === null || _a === void 0 ? void 0 : _a[this.databaseConfig.conid]) === null || _b === void 0 ? void 0 : _b[this.databaseConfig.database];
|
|
111
|
+
}
|
|
112
|
+
getChildMatchColumns() {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
getParentMatchColumns() {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
parseFilterCondition(source = null) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
get childDataColumn() {
|
|
122
|
+
if (!this.isExpandable && this.isChecked) {
|
|
123
|
+
return this.codeName;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
toggleExpanded(value) {
|
|
128
|
+
this.includeInColumnSet('expandedColumns', this.uniqueName, value == null ? !this.isExpanded : value);
|
|
129
|
+
}
|
|
130
|
+
toggleChecked(value) {
|
|
131
|
+
if (this.defaultChecked) {
|
|
132
|
+
this.includeInColumnSet('uncheckedColumns', this.uniqueName, value == null ? this.isChecked : value);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.includeInColumnSet('checkedColumns', this.uniqueName, value == null ? !this.isChecked : value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
includeInColumnSet(field, uniqueName, isIncluded) {
|
|
139
|
+
if (isIncluded) {
|
|
140
|
+
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { [field]: [...(cfg[field] || []), uniqueName] })));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { [field]: (cfg[field] || []).filter(x => x != uniqueName) })));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
getFilter() {
|
|
147
|
+
return this.config.filters[this.uniqueName];
|
|
148
|
+
}
|
|
149
|
+
getDataLoadColumns() {
|
|
150
|
+
return (0, compact_1.default)((0, uniq_1.default)([
|
|
151
|
+
...this.childNodes.map(x => x.childDataColumn),
|
|
152
|
+
...(0, flatten_1.default)(this.childNodes.filter(x => x.isExpandable && x.isChecked).map(x => x.getChildMatchColumns())),
|
|
153
|
+
...this.getParentMatchColumns(),
|
|
154
|
+
]));
|
|
155
|
+
}
|
|
156
|
+
getChildrenCondition(source = null) {
|
|
157
|
+
const conditions = (0, compact_1.default)([
|
|
158
|
+
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
|
159
|
+
...this.buildParentFilterConditions(),
|
|
160
|
+
]);
|
|
161
|
+
if (conditions.length == 0) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
if (conditions.length == 1) {
|
|
165
|
+
return conditions[0];
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
conditionType: 'and',
|
|
169
|
+
conditions,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
getOrderBy(table) {
|
|
173
|
+
var _a;
|
|
174
|
+
const res = (0, compact_1.default)(this.childNodes.map(node => {
|
|
175
|
+
var _a, _b, _c, _d;
|
|
176
|
+
const sort = (_d = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b[(_c = node === null || node === void 0 ? void 0 : node.parentNode) === null || _c === void 0 ? void 0 : _c.uniqueName]) === null || _d === void 0 ? void 0 : _d.find(x => x.uniqueName == node.uniqueName);
|
|
177
|
+
if (sort) {
|
|
178
|
+
return {
|
|
179
|
+
columnName: node.columnName,
|
|
180
|
+
order: sort.order,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}));
|
|
184
|
+
return res.length > 0
|
|
185
|
+
? res
|
|
186
|
+
: ((_a = table === null || table === void 0 ? void 0 : table.primaryKey) === null || _a === void 0 ? void 0 : _a.columns.map(x => ({ columnName: x.columnName, order: 'ASC' }))) || [
|
|
187
|
+
{ columnName: table === null || table === void 0 ? void 0 : table.columns[0].columnName, order: 'ASC' },
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
getBaseTables() {
|
|
191
|
+
const res = [];
|
|
192
|
+
const table = this.getBaseTableFromThis();
|
|
193
|
+
if (table)
|
|
194
|
+
res.push({ table, node: this });
|
|
195
|
+
for (const child of this.childNodes) {
|
|
196
|
+
if (!child.isChecked)
|
|
197
|
+
continue;
|
|
198
|
+
res.push(...child.getBaseTables());
|
|
199
|
+
}
|
|
200
|
+
return res;
|
|
201
|
+
}
|
|
202
|
+
getBaseTableFromThis() {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
get filterInfo() {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
findChildNodeByUniquePath(uniquePath) {
|
|
209
|
+
if (uniquePath.length == 0) {
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
const child = this.childNodes.find(x => x.codeName == uniquePath[0]);
|
|
213
|
+
return child === null || child === void 0 ? void 0 : child.findChildNodeByUniquePath(uniquePath.slice(1));
|
|
214
|
+
}
|
|
215
|
+
findNodeByUniqueName(uniqueName) {
|
|
216
|
+
if (!uniqueName)
|
|
217
|
+
return null;
|
|
218
|
+
const uniquePath = uniqueName.split('::');
|
|
219
|
+
if (uniquePath[0] != this.codeName)
|
|
220
|
+
return null;
|
|
221
|
+
return this.findChildNodeByUniquePath(uniquePath.slice(1));
|
|
222
|
+
}
|
|
223
|
+
get supportsParentFilter() {
|
|
224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
225
|
+
return ((((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.isRoot) || ((_b = this.parentNode) === null || _b === void 0 ? void 0 : _b.supportsParentFilter)) &&
|
|
226
|
+
((_d = (_c = this.parentNode) === null || _c === void 0 ? void 0 : _c.databaseConfig) === null || _d === void 0 ? void 0 : _d.conid) == ((_e = this.databaseConfig) === null || _e === void 0 ? void 0 : _e.conid) &&
|
|
227
|
+
((_g = (_f = this.parentNode) === null || _f === void 0 ? void 0 : _f.databaseConfig) === null || _g === void 0 ? void 0 : _g.database) == ((_h = this.databaseConfig) === null || _h === void 0 ? void 0 : _h.database));
|
|
228
|
+
}
|
|
229
|
+
get isParentFilter() {
|
|
230
|
+
return !!(this.config.parentFilters || []).find(x => x.uniqueName == this.uniqueName);
|
|
231
|
+
}
|
|
232
|
+
buildParentFilterConditions() {
|
|
233
|
+
var _a;
|
|
234
|
+
const leafNodes = (0, compact_1.default)((((_a = this.config) === null || _a === void 0 ? void 0 : _a.parentFilters) || []).map(x => this.rootNode.findNodeByUniqueName(x.uniqueName)));
|
|
235
|
+
const conditions = (0, compact_1.default)(leafNodes.map(leafNode => {
|
|
236
|
+
var _a, _b;
|
|
237
|
+
if (leafNode == this)
|
|
238
|
+
return null;
|
|
239
|
+
const select = {
|
|
240
|
+
commandType: 'select',
|
|
241
|
+
from: {
|
|
242
|
+
name: leafNode.namedObject,
|
|
243
|
+
alias: 'pert_0',
|
|
244
|
+
relations: [],
|
|
245
|
+
},
|
|
246
|
+
selectAll: true,
|
|
247
|
+
};
|
|
248
|
+
let lastNode = leafNode;
|
|
249
|
+
let node = leafNode;
|
|
250
|
+
let index = 1;
|
|
251
|
+
let lastAlias = 'pert_0';
|
|
252
|
+
while ((node === null || node === void 0 ? void 0 : node.parentNode) && ((_a = node === null || node === void 0 ? void 0 : node.parentNode) === null || _a === void 0 ? void 0 : _a.uniqueName) != (this === null || this === void 0 ? void 0 : this.uniqueName)) {
|
|
253
|
+
node = node.parentNode;
|
|
254
|
+
let alias = `pert_${index}`;
|
|
255
|
+
select.from.relations.push({
|
|
256
|
+
joinType: 'INNER JOIN',
|
|
257
|
+
alias,
|
|
258
|
+
name: node.namedObject,
|
|
259
|
+
conditions: lastNode.getParentJoinCondition(lastAlias, alias),
|
|
260
|
+
});
|
|
261
|
+
lastAlias = alias;
|
|
262
|
+
lastNode = node;
|
|
263
|
+
}
|
|
264
|
+
if (((_b = node === null || node === void 0 ? void 0 : node.parentNode) === null || _b === void 0 ? void 0 : _b.uniqueName) != (this === null || this === void 0 ? void 0 : this.uniqueName))
|
|
265
|
+
return null;
|
|
266
|
+
select.where = {
|
|
267
|
+
conditionType: 'and',
|
|
268
|
+
conditions: (0, compact_1.default)([
|
|
269
|
+
...lastNode.getParentJoinCondition(lastAlias, this.namedObject.pureName),
|
|
270
|
+
leafNode.getChildrenCondition({ alias: 'pert_0' }),
|
|
271
|
+
]),
|
|
272
|
+
};
|
|
273
|
+
return {
|
|
274
|
+
conditionType: 'exists',
|
|
275
|
+
subQuery: select,
|
|
276
|
+
};
|
|
277
|
+
}));
|
|
278
|
+
return conditions;
|
|
279
|
+
}
|
|
280
|
+
getParentJoinCondition(alias, parentAlias) {
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.PerspectiveTreeNode = PerspectiveTreeNode;
|
|
285
|
+
class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|
286
|
+
constructor(column, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
|
|
287
|
+
var _a, _b, _c, _d, _e;
|
|
288
|
+
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
|
|
289
|
+
this.column = column;
|
|
290
|
+
this.table = table;
|
|
291
|
+
this.isTable = !!((_b = (_a = this.db) === null || _a === void 0 ? void 0 : _a.tables) === null || _b === void 0 ? void 0 : _b.find(x => x.schemaName == table.schemaName && x.pureName == table.pureName));
|
|
292
|
+
this.isView = !!((_d = (_c = this.db) === null || _c === void 0 ? void 0 : _c.views) === null || _d === void 0 ? void 0 : _d.find(x => x.schemaName == table.schemaName && x.pureName == table.pureName));
|
|
293
|
+
this.foreignKey = (_e = table === null || table === void 0 ? void 0 : table.foreignKeys) === null || _e === void 0 ? void 0 : _e.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName);
|
|
294
|
+
this.refTable = this.db.tables.find(x => { var _a, _b; return x.pureName == ((_a = this.foreignKey) === null || _a === void 0 ? void 0 : _a.refTableName) && x.schemaName == ((_b = this.foreignKey) === null || _b === void 0 ? void 0 : _b.refSchemaName); });
|
|
295
|
+
}
|
|
296
|
+
matchChildRow(parentRow, childRow) {
|
|
297
|
+
if (!this.foreignKey)
|
|
298
|
+
return false;
|
|
299
|
+
return parentRow[this.foreignKey.columns[0].columnName] == childRow[this.foreignKey.columns[0].refColumnName];
|
|
300
|
+
}
|
|
301
|
+
getChildMatchColumns() {
|
|
302
|
+
if (!this.foreignKey)
|
|
303
|
+
return [];
|
|
304
|
+
return [this.foreignKey.columns[0].columnName];
|
|
305
|
+
}
|
|
306
|
+
getParentMatchColumns() {
|
|
307
|
+
if (!this.foreignKey)
|
|
308
|
+
return [];
|
|
309
|
+
return [this.foreignKey.columns[0].refColumnName];
|
|
310
|
+
}
|
|
311
|
+
getParentJoinCondition(alias, parentAlias) {
|
|
312
|
+
if (!this.foreignKey)
|
|
313
|
+
return [];
|
|
314
|
+
return this.foreignKey.columns.map(column => {
|
|
315
|
+
const res = {
|
|
316
|
+
conditionType: 'binary',
|
|
317
|
+
operator: '=',
|
|
318
|
+
left: {
|
|
319
|
+
exprType: 'column',
|
|
320
|
+
columnName: column.columnName,
|
|
321
|
+
source: { alias: parentAlias },
|
|
322
|
+
},
|
|
323
|
+
right: {
|
|
324
|
+
exprType: 'column',
|
|
325
|
+
columnName: column.refColumnName,
|
|
326
|
+
source: { alias },
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
return res;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
getNodeLoadProps(parentRows) {
|
|
333
|
+
if (!this.foreignKey)
|
|
334
|
+
return null;
|
|
335
|
+
return {
|
|
336
|
+
schemaName: this.foreignKey.refSchemaName,
|
|
337
|
+
pureName: this.foreignKey.refTableName,
|
|
338
|
+
bindingColumns: [this.foreignKey.columns[0].refColumnName],
|
|
339
|
+
bindingValues: (0, uniqBy_1.default)(parentRows.map(row => [row[this.foreignKey.columns[0].columnName]]), json_stable_stringify_1.default),
|
|
340
|
+
dataColumns: this.getDataLoadColumns(),
|
|
341
|
+
databaseConfig: this.databaseConfig,
|
|
342
|
+
orderBy: this.getOrderBy(this.refTable),
|
|
343
|
+
condition: this.getChildrenCondition(),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
get icon() {
|
|
347
|
+
if (this.isCircular)
|
|
348
|
+
return 'img circular';
|
|
349
|
+
if (this.column.autoIncrement)
|
|
350
|
+
return 'img autoincrement';
|
|
351
|
+
if (this.foreignKey)
|
|
352
|
+
return 'img foreign-key';
|
|
353
|
+
return 'img column';
|
|
354
|
+
}
|
|
355
|
+
get codeName() {
|
|
356
|
+
return this.column.columnName;
|
|
357
|
+
}
|
|
358
|
+
get columnName() {
|
|
359
|
+
return this.column.columnName;
|
|
360
|
+
}
|
|
361
|
+
get fieldName() {
|
|
362
|
+
return this.codeName + 'Ref';
|
|
363
|
+
}
|
|
364
|
+
get title() {
|
|
365
|
+
return this.column.columnName;
|
|
366
|
+
}
|
|
367
|
+
get isExpandable() {
|
|
368
|
+
return !!this.foreignKey;
|
|
369
|
+
}
|
|
370
|
+
get filterType() {
|
|
371
|
+
return (0, dbgate_filterparser_1.getFilterType)(this.column.dataType);
|
|
372
|
+
}
|
|
373
|
+
get isCircular() {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
return !!((_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.hasTableCode(this.tableCode));
|
|
376
|
+
}
|
|
377
|
+
get childNodes() {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
if (!this.foreignKey)
|
|
380
|
+
return [];
|
|
381
|
+
const tbl = (_b = (_a = this === null || this === void 0 ? void 0 : this.db) === null || _a === void 0 ? void 0 : _a.tables) === null || _b === void 0 ? void 0 : _b.find(x => { var _a, _b; return x.pureName == ((_a = this.foreignKey) === null || _a === void 0 ? void 0 : _a.refTableName) && x.schemaName == ((_b = this.foreignKey) === null || _b === void 0 ? void 0 : _b.refSchemaName); });
|
|
382
|
+
return getTableChildPerspectiveNodes(tbl, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this);
|
|
383
|
+
}
|
|
384
|
+
getBaseTableFromThis() {
|
|
385
|
+
return this.refTable;
|
|
386
|
+
}
|
|
387
|
+
get filterInfo() {
|
|
388
|
+
return {
|
|
389
|
+
columnName: this.columnName,
|
|
390
|
+
filterType: this.filterType,
|
|
391
|
+
pureName: this.column.pureName,
|
|
392
|
+
schemaName: this.column.schemaName,
|
|
393
|
+
foreignKey: this.foreignKey,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
parseFilterCondition(source = null) {
|
|
397
|
+
const filter = this.getFilter();
|
|
398
|
+
if (!filter)
|
|
399
|
+
return null;
|
|
400
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, this.filterType);
|
|
401
|
+
if (!condition)
|
|
402
|
+
return null;
|
|
403
|
+
return (0, cloneDeepWith_1.default)(condition, (expr) => {
|
|
404
|
+
if (expr.exprType == 'placeholder') {
|
|
405
|
+
return {
|
|
406
|
+
exprType: 'column',
|
|
407
|
+
columnName: this.column.columnName,
|
|
408
|
+
source,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
get headerTableAttributes() {
|
|
414
|
+
if (this.foreignKey) {
|
|
415
|
+
return {
|
|
416
|
+
schemaName: this.foreignKey.refSchemaName,
|
|
417
|
+
pureName: this.foreignKey.refTableName,
|
|
418
|
+
conid: this.databaseConfig.conid,
|
|
419
|
+
database: this.databaseConfig.database,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
get tableCode() {
|
|
425
|
+
if (this.foreignKey) {
|
|
426
|
+
return `${this.foreignKey.refSchemaName}|${this.foreignKey.refTableName}`;
|
|
427
|
+
}
|
|
428
|
+
return `${this.table.schemaName}|${this.table.pureName}`;
|
|
429
|
+
}
|
|
430
|
+
get namedObject() {
|
|
431
|
+
if (this.foreignKey) {
|
|
432
|
+
return {
|
|
433
|
+
schemaName: this.foreignKey.refSchemaName,
|
|
434
|
+
pureName: this.foreignKey.refTableName,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
exports.PerspectiveTableColumnNode = PerspectiveTableColumnNode;
|
|
441
|
+
class PerspectiveTableNode extends PerspectiveTreeNode {
|
|
442
|
+
constructor(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
|
|
443
|
+
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
|
|
444
|
+
this.table = table;
|
|
445
|
+
this.dataProvider = dataProvider;
|
|
446
|
+
}
|
|
447
|
+
getNodeLoadProps(parentRows) {
|
|
448
|
+
return {
|
|
449
|
+
schemaName: this.table.schemaName,
|
|
450
|
+
pureName: this.table.pureName,
|
|
451
|
+
dataColumns: this.getDataLoadColumns(),
|
|
452
|
+
databaseConfig: this.databaseConfig,
|
|
453
|
+
orderBy: this.getOrderBy(this.table),
|
|
454
|
+
condition: this.getChildrenCondition(),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
get codeName() {
|
|
458
|
+
return this.table.schemaName ? `${this.table.schemaName}:${this.table.pureName}` : this.table.pureName;
|
|
459
|
+
}
|
|
460
|
+
get title() {
|
|
461
|
+
return this.table.pureName;
|
|
462
|
+
}
|
|
463
|
+
get isExpandable() {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
get childNodes() {
|
|
467
|
+
return getTableChildPerspectiveNodes(this.table, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this);
|
|
468
|
+
}
|
|
469
|
+
get icon() {
|
|
470
|
+
return 'img table';
|
|
471
|
+
}
|
|
472
|
+
getBaseTableFromThis() {
|
|
473
|
+
return this.table;
|
|
474
|
+
}
|
|
475
|
+
get headerTableAttributes() {
|
|
476
|
+
return {
|
|
477
|
+
schemaName: this.table.schemaName,
|
|
478
|
+
pureName: this.table.pureName,
|
|
479
|
+
conid: this.databaseConfig.conid,
|
|
480
|
+
database: this.databaseConfig.database,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
get tableCode() {
|
|
484
|
+
return `${this.table.schemaName}|${this.table.pureName}`;
|
|
485
|
+
}
|
|
486
|
+
get namedObject() {
|
|
487
|
+
return {
|
|
488
|
+
schemaName: this.table.schemaName,
|
|
489
|
+
pureName: this.table.pureName,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
exports.PerspectiveTableNode = PerspectiveTableNode;
|
|
494
|
+
// export class PerspectiveViewNode extends PerspectiveTreeNode {
|
|
495
|
+
// constructor(
|
|
496
|
+
// public view: ViewInfo,
|
|
497
|
+
// dbs: MultipleDatabaseInfo,
|
|
498
|
+
// config: PerspectiveConfig,
|
|
499
|
+
// setConfig: ChangePerspectiveConfigFunc,
|
|
500
|
+
// public dataProvider: PerspectiveDataProvider,
|
|
501
|
+
// databaseConfig: PerspectiveDatabaseConfig,
|
|
502
|
+
// parentNode: PerspectiveTreeNode
|
|
503
|
+
// ) {
|
|
504
|
+
// super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
|
|
505
|
+
// }
|
|
506
|
+
// getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps {
|
|
507
|
+
// return {
|
|
508
|
+
// schemaName: this.view.schemaName,
|
|
509
|
+
// pureName: this.view.pureName,
|
|
510
|
+
// dataColumns: this.getDataLoadColumns(),
|
|
511
|
+
// databaseConfig: this.databaseConfig,
|
|
512
|
+
// orderBy: this.getOrderBy(this.view),
|
|
513
|
+
// condition: this.getChildrenCondition(),
|
|
514
|
+
// };
|
|
515
|
+
// }
|
|
516
|
+
// get codeName() {
|
|
517
|
+
// return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName;
|
|
518
|
+
// }
|
|
519
|
+
// get title() {
|
|
520
|
+
// return this.view.pureName;
|
|
521
|
+
// }
|
|
522
|
+
// get isExpandable() {
|
|
523
|
+
// return true;
|
|
524
|
+
// }
|
|
525
|
+
// get childNodes(): PerspectiveTreeNode[] {
|
|
526
|
+
// return getTableChildPerspectiveNodes(
|
|
527
|
+
// this.view,
|
|
528
|
+
// this.dbs,
|
|
529
|
+
// this.config,
|
|
530
|
+
// this.setConfig,
|
|
531
|
+
// this.dataProvider,
|
|
532
|
+
// this.databaseConfig,
|
|
533
|
+
// this
|
|
534
|
+
// );
|
|
535
|
+
// }
|
|
536
|
+
// get icon() {
|
|
537
|
+
// return 'img table';
|
|
538
|
+
// }
|
|
539
|
+
// getBaseTableFromThis() {
|
|
540
|
+
// return this.view;
|
|
541
|
+
// }
|
|
542
|
+
// }
|
|
543
|
+
class PerspectiveTableReferenceNode extends PerspectiveTableNode {
|
|
544
|
+
constructor(foreignKey, table, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode) {
|
|
545
|
+
super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode);
|
|
546
|
+
this.foreignKey = foreignKey;
|
|
547
|
+
this.dataProvider = dataProvider;
|
|
548
|
+
this.isMultiple = isMultiple;
|
|
549
|
+
}
|
|
550
|
+
matchChildRow(parentRow, childRow) {
|
|
551
|
+
if (!this.foreignKey)
|
|
552
|
+
return false;
|
|
553
|
+
return parentRow[this.foreignKey.columns[0].refColumnName] == childRow[this.foreignKey.columns[0].columnName];
|
|
554
|
+
}
|
|
555
|
+
getChildMatchColumns() {
|
|
556
|
+
if (!this.foreignKey)
|
|
557
|
+
return [];
|
|
558
|
+
return [this.foreignKey.columns[0].refColumnName];
|
|
559
|
+
}
|
|
560
|
+
getParentMatchColumns() {
|
|
561
|
+
if (!this.foreignKey)
|
|
562
|
+
return [];
|
|
563
|
+
return [this.foreignKey.columns[0].columnName];
|
|
564
|
+
}
|
|
565
|
+
getNodeLoadProps(parentRows) {
|
|
566
|
+
if (!this.foreignKey)
|
|
567
|
+
return null;
|
|
568
|
+
return {
|
|
569
|
+
schemaName: this.table.schemaName,
|
|
570
|
+
pureName: this.table.pureName,
|
|
571
|
+
bindingColumns: [this.foreignKey.columns[0].columnName],
|
|
572
|
+
bindingValues: (0, uniqBy_1.default)(parentRows.map(row => [row[this.foreignKey.columns[0].refColumnName]]), json_stable_stringify_1.default),
|
|
573
|
+
dataColumns: this.getDataLoadColumns(),
|
|
574
|
+
databaseConfig: this.databaseConfig,
|
|
575
|
+
orderBy: this.getOrderBy(this.table),
|
|
576
|
+
condition: this.getChildrenCondition(),
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
get columnTitle() {
|
|
580
|
+
return this.table.pureName;
|
|
581
|
+
}
|
|
582
|
+
get title() {
|
|
583
|
+
if (this.isMultiple) {
|
|
584
|
+
return `${super.title} (${this.foreignKey.columns.map(x => x.columnName).join(', ')})`;
|
|
585
|
+
}
|
|
586
|
+
return super.title;
|
|
587
|
+
}
|
|
588
|
+
get codeName() {
|
|
589
|
+
if (this.isMultiple) {
|
|
590
|
+
return `${super.codeName}-${this.foreignKey.columns.map(x => x.columnName).join('_')}`;
|
|
591
|
+
}
|
|
592
|
+
return super.codeName;
|
|
593
|
+
}
|
|
594
|
+
getParentJoinCondition(alias, parentAlias) {
|
|
595
|
+
if (!this.foreignKey)
|
|
596
|
+
return [];
|
|
597
|
+
return this.foreignKey.columns.map(column => {
|
|
598
|
+
const res = {
|
|
599
|
+
conditionType: 'binary',
|
|
600
|
+
operator: '=',
|
|
601
|
+
left: {
|
|
602
|
+
exprType: 'column',
|
|
603
|
+
columnName: column.refColumnName,
|
|
604
|
+
source: { alias: parentAlias },
|
|
605
|
+
},
|
|
606
|
+
right: {
|
|
607
|
+
exprType: 'column',
|
|
608
|
+
columnName: column.columnName,
|
|
609
|
+
source: { alias },
|
|
610
|
+
},
|
|
611
|
+
};
|
|
612
|
+
return res;
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
exports.PerspectiveTableReferenceNode = PerspectiveTableReferenceNode;
|
|
617
|
+
class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
|
|
618
|
+
constructor(customJoin, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
|
|
619
|
+
super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode);
|
|
620
|
+
this.customJoin = customJoin;
|
|
621
|
+
this.dataProvider = dataProvider;
|
|
622
|
+
}
|
|
623
|
+
matchChildRow(parentRow, childRow) {
|
|
624
|
+
for (const column of this.customJoin.columns) {
|
|
625
|
+
if (parentRow[column.baseColumnName] != childRow[column.refColumnName]) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
getChildMatchColumns() {
|
|
632
|
+
return this.customJoin.columns.map(x => x.baseColumnName);
|
|
633
|
+
}
|
|
634
|
+
getParentMatchColumns() {
|
|
635
|
+
return this.customJoin.columns.map(x => x.refColumnName);
|
|
636
|
+
}
|
|
637
|
+
getNodeLoadProps(parentRows) {
|
|
638
|
+
// console.log('CUSTOM JOIN', this.customJoin);
|
|
639
|
+
// console.log('this.getDataLoadColumns()', this.getDataLoadColumns());
|
|
640
|
+
return {
|
|
641
|
+
schemaName: this.table.schemaName,
|
|
642
|
+
pureName: this.table.pureName,
|
|
643
|
+
bindingColumns: this.getParentMatchColumns(),
|
|
644
|
+
bindingValues: (0, uniqBy_1.default)(parentRows.map(row => this.customJoin.columns.map(x => row[x.baseColumnName])), json_stable_stringify_1.default),
|
|
645
|
+
dataColumns: this.getDataLoadColumns(),
|
|
646
|
+
databaseConfig: this.databaseConfig,
|
|
647
|
+
orderBy: this.getOrderBy(this.table),
|
|
648
|
+
condition: this.getChildrenCondition(),
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
get title() {
|
|
652
|
+
return this.customJoin.joinName;
|
|
653
|
+
}
|
|
654
|
+
get icon() {
|
|
655
|
+
return 'icon custom-join';
|
|
656
|
+
}
|
|
657
|
+
get codeName() {
|
|
658
|
+
return this.customJoin.joinid;
|
|
659
|
+
}
|
|
660
|
+
get customJoinConfig() {
|
|
661
|
+
return this.customJoin;
|
|
662
|
+
}
|
|
663
|
+
getParentJoinCondition(alias, parentAlias) {
|
|
664
|
+
return this.customJoin.columns.map(column => {
|
|
665
|
+
const res = {
|
|
666
|
+
conditionType: 'binary',
|
|
667
|
+
operator: '=',
|
|
668
|
+
left: {
|
|
669
|
+
exprType: 'column',
|
|
670
|
+
columnName: column.baseColumnName,
|
|
671
|
+
source: { alias: parentAlias },
|
|
672
|
+
},
|
|
673
|
+
right: {
|
|
674
|
+
exprType: 'column',
|
|
675
|
+
columnName: column.refColumnName,
|
|
676
|
+
source: { alias },
|
|
677
|
+
},
|
|
678
|
+
};
|
|
679
|
+
return res;
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
exports.PerspectiveCustomJoinTreeNode = PerspectiveCustomJoinTreeNode;
|
|
684
|
+
function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, databaseConfig, parentColumn) {
|
|
685
|
+
var _a, _b, _c;
|
|
686
|
+
if (!table)
|
|
687
|
+
return [];
|
|
688
|
+
const db = parentColumn.db;
|
|
689
|
+
const columnNodes = table.columns.map(col => new PerspectiveTableColumnNode(col, table, dbs, config, setConfig, dataProvider, databaseConfig, parentColumn));
|
|
690
|
+
const circularColumns = columnNodes.filter(x => x.isCircular).map(x => x.columnName);
|
|
691
|
+
const defaultColumns = (0, getPerspectiveDefaultColumns_1.getPerspectiveDefaultColumns)(table, db, circularColumns);
|
|
692
|
+
for (const node of columnNodes) {
|
|
693
|
+
node.defaultChecked = defaultColumns.includes(node.columnName);
|
|
694
|
+
}
|
|
695
|
+
const res = [];
|
|
696
|
+
res.push(...columnNodes);
|
|
697
|
+
const dependencies = [];
|
|
698
|
+
if (db && (table === null || table === void 0 ? void 0 : table.dependencies)) {
|
|
699
|
+
for (const fk of table === null || table === void 0 ? void 0 : table.dependencies) {
|
|
700
|
+
const tbl = db.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
|
|
701
|
+
if (tbl) {
|
|
702
|
+
const isMultiple = (table === null || table === void 0 ? void 0 : table.dependencies.filter(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName).length) >= 2;
|
|
703
|
+
dependencies.push(new PerspectiveTableReferenceNode(fk, tbl, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentColumn));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
res.push(...(0, sortBy_1.default)(dependencies, 'title'));
|
|
708
|
+
const customs = [];
|
|
709
|
+
for (const join of config.customJoins || []) {
|
|
710
|
+
if (join.baseUniqueName == parentColumn.uniqueName) {
|
|
711
|
+
const newConfig = Object.assign({}, databaseConfig);
|
|
712
|
+
if (join.conid)
|
|
713
|
+
newConfig.conid = join.conid;
|
|
714
|
+
if (join.database)
|
|
715
|
+
newConfig.database = join.database;
|
|
716
|
+
const db = (_a = dbs === null || dbs === void 0 ? void 0 : dbs[newConfig.conid]) === null || _a === void 0 ? void 0 : _a[newConfig.database];
|
|
717
|
+
const table = (_b = db === null || db === void 0 ? void 0 : db.tables) === null || _b === void 0 ? void 0 : _b.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
|
|
718
|
+
const view = (_c = db === null || db === void 0 ? void 0 : db.views) === null || _c === void 0 ? void 0 : _c.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
|
|
719
|
+
if (table || view) {
|
|
720
|
+
customs.push(new PerspectiveCustomJoinTreeNode(join, table || view, dbs, config, setConfig, dataProvider, newConfig, parentColumn));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
res.push(...(0, sortBy_1.default)(customs, 'title'));
|
|
725
|
+
return res;
|
|
726
|
+
}
|
|
727
|
+
exports.getTableChildPerspectiveNodes = getTableChildPerspectiveNodes;
|