dbgate-datalib 5.1.0 → 5.1.2

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.
@@ -4,15 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTableChildPerspectiveNodes = exports.PerspectiveCustomJoinTreeNode = exports.PerspectiveTableReferenceNode = exports.PerspectiveTableNode = exports.PerspectiveTableColumnNode = exports.PerspectiveTreeNode = void 0;
7
+ const dbgate_tools_1 = require("dbgate-tools");
8
+ const PerspectiveConfig_1 = require("./PerspectiveConfig");
9
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
7
10
  const compact_1 = __importDefault(require("lodash/compact"));
8
11
  const uniq_1 = __importDefault(require("lodash/uniq"));
9
12
  const flatten_1 = __importDefault(require("lodash/flatten"));
10
13
  const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
11
14
  const sortBy_1 = __importDefault(require("lodash/sortBy"));
12
15
  const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
16
+ const findIndex_1 = __importDefault(require("lodash/findIndex"));
13
17
  const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
14
18
  const dbgate_filterparser_1 = require("dbgate-filterparser");
15
- const getPerspectiveDefaultColumns_1 = require("./getPerspectiveDefaultColumns");
19
+ // import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
20
+ const v1_1 = __importDefault(require("uuid/v1"));
16
21
  // export function groupPerspectiveLoadProps(
17
22
  // ...list: PerspectiveDataLoadPropsWithNode[]
18
23
  // ): PerspectiveDataLoadPropsWithNode[] {
@@ -34,13 +39,23 @@ const getPerspectiveDefaultColumns_1 = require("./getPerspectiveDefaultColumns")
34
39
  // return res;
35
40
  // }
36
41
  class PerspectiveTreeNode {
37
- constructor(dbs, config, setConfig, parentNode, dataProvider, databaseConfig) {
42
+ constructor(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId) {
38
43
  this.dbs = dbs;
39
44
  this.config = config;
40
45
  this.setConfig = setConfig;
41
46
  this.parentNode = parentNode;
42
47
  this.dataProvider = dataProvider;
43
48
  this.databaseConfig = databaseConfig;
49
+ this.designerId = designerId;
50
+ this.childNodesCache = null;
51
+ this.nodeConfig = config.nodes.find(x => x.designerId == designerId);
52
+ this.parentNodeConfig = parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeConfig;
53
+ }
54
+ get childNodes() {
55
+ if (!this.childNodesCache) {
56
+ this.childNodesCache = this.generateChildNodes();
57
+ }
58
+ return this.childNodesCache;
44
59
  }
45
60
  get fieldName() {
46
61
  return this.codeName;
@@ -66,6 +81,9 @@ class PerspectiveTreeNode {
66
81
  return this;
67
82
  return (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.rootNode;
68
83
  }
84
+ get isSortable() {
85
+ return false;
86
+ }
69
87
  matchChildRow(parentRow, childRow) {
70
88
  return true;
71
89
  }
@@ -73,25 +91,37 @@ class PerspectiveTreeNode {
73
91
  var _a;
74
92
  return code == this.tableCode || ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.hasTableCode(code));
75
93
  }
76
- get uniqueName() {
77
- if (this.parentNode)
78
- return `${this.parentNode.uniqueName}::${this.codeName}`;
79
- return this.codeName;
80
- }
94
+ // get uniqueName() {
95
+ // if (this.parentNode) return `${this.parentNode.uniqueName}::${this.codeName}`;
96
+ // return this.codeName;
97
+ // }
81
98
  get level() {
82
99
  if (this.parentNode)
83
100
  return this.parentNode.level + 1;
84
101
  return 0;
85
102
  }
86
103
  get isExpanded() {
87
- return this.config.expandedColumns.includes(this.uniqueName);
104
+ var _a, _b;
105
+ return (_b = (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.expandedColumns) === null || _b === void 0 ? void 0 : _b.includes(this.codeName);
88
106
  }
89
- get isChecked() {
90
- if (this.config.checkedColumns.includes(this.uniqueName))
107
+ get isCheckedColumn() {
108
+ var _a, _b;
109
+ if ((_b = (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.checkedColumns) === null || _b === void 0 ? void 0 : _b.includes(this.codeName))
91
110
  return true;
92
- if (this.config.uncheckedColumns.includes(this.uniqueName))
93
- return false;
94
- return this.defaultChecked;
111
+ return false;
112
+ }
113
+ get isChecked() {
114
+ return this.isCheckedColumn;
115
+ }
116
+ get isCheckedNode() {
117
+ var _a, _b;
118
+ return !!this.designerId && !!((_b = (_a = this.config.nodes) === null || _a === void 0 ? void 0 : _a.find(x => x.designerId == this.designerId)) === null || _b === void 0 ? void 0 : _b.isNodeChecked);
119
+ }
120
+ get isSecondaryChecked() {
121
+ return false;
122
+ }
123
+ get secondaryCheckable() {
124
+ return false;
95
125
  }
96
126
  get columnTitle() {
97
127
  return this.title;
@@ -109,6 +139,15 @@ class PerspectiveTreeNode {
109
139
  var _a, _b;
110
140
  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
141
  }
142
+ get isCircular() {
143
+ return false;
144
+ }
145
+ hasDesignerIdInIncestors(designerId) {
146
+ var _a;
147
+ if (designerId == this.designerId)
148
+ return true;
149
+ return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.hasDesignerIdInIncestors(designerId)) || false;
150
+ }
112
151
  getChildMatchColumns() {
113
152
  return [];
114
153
  }
@@ -118,33 +157,69 @@ class PerspectiveTreeNode {
118
157
  parseFilterCondition(source = null) {
119
158
  return null;
120
159
  }
160
+ get hasUncheckedNodeInPath() {
161
+ if (!this.parentNode)
162
+ return false;
163
+ if (!this.isCheckedNode)
164
+ return true;
165
+ return this.parentNode.hasUncheckedNodeInPath;
166
+ }
121
167
  get childDataColumn() {
122
- if (!this.isExpandable && this.isChecked) {
168
+ if (this.isCheckedColumn) {
123
169
  return this.codeName;
124
170
  }
125
171
  return null;
126
172
  }
127
173
  toggleExpanded(value) {
128
- this.includeInColumnSet('expandedColumns', this.uniqueName, value == null ? !this.isExpanded : value);
174
+ this.includeInNodeSet('expandedColumns', value == null ? !this.isExpanded : value);
129
175
  }
130
176
  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
- }
177
+ this.includeInNodeSet('checkedColumns', value == null ? !this.isChecked : value);
178
+ }
179
+ toggleCheckedNode(value) {
180
+ this.setConfig(cfg => {
181
+ var _a;
182
+ const oldCheckedValue = (_a = cfg.nodes.find(x => x.designerId == this.designerId)) === null || _a === void 0 ? void 0 : _a.isNodeChecked;
183
+ const [cfgChanged, nodeCfg] = this.ensureNodeConfig(cfg);
184
+ const res = Object.assign(Object.assign({}, cfgChanged), { nodes: cfgChanged.nodes.map(node => node.designerId == (this.designerId || nodeCfg.designerId)
185
+ ? Object.assign(Object.assign({}, node), { isNodeChecked: value == null ? !oldCheckedValue : value }) : node) });
186
+ return res;
187
+ });
137
188
  }
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) })));
189
+ toggleSecondaryChecked(value) { }
190
+ createReferenceConfigColumns() {
191
+ return null;
192
+ }
193
+ ensureNodeConfig(cfg) {
194
+ var _a, _b;
195
+ let node = cfg.nodes.find(x => x.designerId == this.designerId);
196
+ if (!node) {
197
+ const nodeConfig = Object.assign(Object.assign({}, (0, PerspectiveConfig_1.createPerspectiveNodeConfig)(this.namedObject)), { isAutoGenerated: true, conid: (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.conid, database: (_b = this.parentNodeConfig) === null || _b === void 0 ? void 0 : _b.database });
198
+ const refConfig = {
199
+ designerId: (0, v1_1.default)(),
200
+ sourceId: this.parentNode.designerId,
201
+ targetId: nodeConfig.designerId,
202
+ isAutoGenerated: true,
203
+ columns: this.createReferenceConfigColumns(),
204
+ };
205
+ return [
206
+ Object.assign(Object.assign({}, cfg), { nodes: [...cfg.nodes, nodeConfig], references: [...cfg.references, refConfig] }),
207
+ nodeConfig,
208
+ ];
144
209
  }
210
+ return [cfg, node];
211
+ }
212
+ includeInNodeSet(field, isIncluded) {
213
+ this.setConfig(cfg => {
214
+ var _a;
215
+ const changedFields = n => (Object.assign(Object.assign({}, n), { [field]: isIncluded ? [...(n[field] || []), this.codeName] : (n[field] || []).filter(x => x != this.codeName) }));
216
+ const [cfgChanged, nodeCfg] = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.ensureNodeConfig(cfg);
217
+ return Object.assign(Object.assign({}, cfgChanged), { nodes: cfgChanged.nodes.map(n => { var _a; return n.designerId == (((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.designerId) || (nodeCfg === null || nodeCfg === void 0 ? void 0 : nodeCfg.designerId)) ? changedFields(n) : n; }) });
218
+ });
145
219
  }
146
220
  getFilter() {
147
- return this.config.filters[this.uniqueName];
221
+ var _a, _b;
222
+ return (_b = (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.filters) === null || _b === void 0 ? void 0 : _b[this.codeName];
148
223
  }
149
224
  getDataLoadColumns() {
150
225
  return (0, compact_1.default)((0, uniq_1.default)([
@@ -172,8 +247,8 @@ class PerspectiveTreeNode {
172
247
  getOrderBy(table) {
173
248
  var _a;
174
249
  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);
250
+ var _a, _b;
251
+ const sort = (_b = (_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.find(x => x.columnName == node.columnName);
177
252
  if (sort) {
178
253
  return {
179
254
  columnName: node.columnName,
@@ -212,13 +287,29 @@ class PerspectiveTreeNode {
212
287
  const child = this.childNodes.find(x => x.codeName == uniquePath[0]);
213
288
  return child === null || child === void 0 ? void 0 : child.findChildNodeByUniquePath(uniquePath.slice(1));
214
289
  }
215
- findNodeByUniqueName(uniqueName) {
216
- if (!uniqueName)
290
+ // findNodeByUniqueName(uniqueName: string): PerspectiveTreeNode {
291
+ // if (!uniqueName) return null;
292
+ // const uniquePath = uniqueName.split('::');
293
+ // if (uniquePath[0] != this.codeName) return null;
294
+ // return this.findChildNodeByUniquePath(uniquePath.slice(1));
295
+ // }
296
+ findNodeByDesignerId(designerId) {
297
+ if (!this.designerId) {
217
298
  return null;
218
- const uniquePath = uniqueName.split('::');
219
- if (uniquePath[0] != this.codeName)
299
+ }
300
+ if (!designerId) {
220
301
  return null;
221
- return this.findChildNodeByUniquePath(uniquePath.slice(1));
302
+ }
303
+ if (designerId == this.designerId) {
304
+ return this;
305
+ }
306
+ for (const child of this.childNodes) {
307
+ const res = child.findNodeByDesignerId(designerId);
308
+ if (res) {
309
+ return res;
310
+ }
311
+ }
312
+ return null;
222
313
  }
223
314
  get supportsParentFilter() {
224
315
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -227,11 +318,14 @@ class PerspectiveTreeNode {
227
318
  ((_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
319
  }
229
320
  get isParentFilter() {
230
- return !!(this.config.parentFilters || []).find(x => x.uniqueName == this.uniqueName);
321
+ var _a;
322
+ return !!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.isParentFilter);
231
323
  }
232
324
  buildParentFilterConditions() {
233
325
  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)));
326
+ const leafNodes = (0, compact_1.default)((((_a = this.config) === null || _a === void 0 ? void 0 : _a.nodes) || [])
327
+ .filter(x => x.isParentFilter)
328
+ .map(x => this.rootNode.findNodeByDesignerId(x.designerId)));
235
329
  const conditions = (0, compact_1.default)(leafNodes.map(leafNode => {
236
330
  var _a, _b;
237
331
  if (leafNode == this)
@@ -249,7 +343,7 @@ class PerspectiveTreeNode {
249
343
  let node = leafNode;
250
344
  let index = 1;
251
345
  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)) {
346
+ 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.designerId) != (this === null || this === void 0 ? void 0 : this.designerId)) {
253
347
  node = node.parentNode;
254
348
  let alias = `pert_${index}`;
255
349
  select.from.relations.push({
@@ -260,8 +354,9 @@ class PerspectiveTreeNode {
260
354
  });
261
355
  lastAlias = alias;
262
356
  lastNode = node;
357
+ index += 1;
263
358
  }
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))
359
+ if (((_b = node === null || node === void 0 ? void 0 : node.parentNode) === null || _b === void 0 ? void 0 : _b.designerId) != (this === null || this === void 0 ? void 0 : this.designerId))
265
360
  return null;
266
361
  select.where = {
267
362
  conditionType: 'and',
@@ -280,12 +375,22 @@ class PerspectiveTreeNode {
280
375
  getParentJoinCondition(alias, parentAlias) {
281
376
  return [];
282
377
  }
378
+ get sortOrder() {
379
+ var _a, _b, _c;
380
+ return (_c = (_b = (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.find(x => x.columnName == this.columnName)) === null || _c === void 0 ? void 0 : _c.order;
381
+ }
382
+ get sortOrderIndex() {
383
+ var _a, _b, _c;
384
+ return ((_b = (_a = this.parentNodeConfig) === null || _a === void 0 ? void 0 : _a.sort) === null || _b === void 0 ? void 0 : _b.length) > 1
385
+ ? (0, findIndex_1.default)((_c = this.parentNodeConfig) === null || _c === void 0 ? void 0 : _c.sort, x => x.columnName == this.columnName)
386
+ : -1;
387
+ }
283
388
  }
284
389
  exports.PerspectiveTreeNode = PerspectiveTreeNode;
285
390
  class PerspectiveTableColumnNode extends PerspectiveTreeNode {
286
- constructor(column, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
391
+ constructor(column, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
287
392
  var _a, _b, _c, _d, _e;
288
- super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
393
+ super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
289
394
  this.column = column;
290
395
  this.table = table;
291
396
  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));
@@ -329,6 +434,13 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
329
434
  return res;
330
435
  });
331
436
  }
437
+ createReferenceConfigColumns() {
438
+ var _a, _b;
439
+ return (_b = (_a = this.foreignKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => ({
440
+ source: col.columnName,
441
+ target: col.refColumnName,
442
+ }));
443
+ }
332
444
  getNodeLoadProps(parentRows) {
333
445
  if (!this.foreignKey)
334
446
  return null;
@@ -367,6 +479,9 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
367
479
  get isExpandable() {
368
480
  return !!this.foreignKey;
369
481
  }
482
+ get isSortable() {
483
+ return true;
484
+ }
370
485
  get filterType() {
371
486
  return (0, dbgate_filterparser_1.getFilterType)(this.column.dataType);
372
487
  }
@@ -374,7 +489,29 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
374
489
  var _a, _b;
375
490
  return !!((_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.hasTableCode(this.tableCode));
376
491
  }
377
- get childNodes() {
492
+ get isSecondaryChecked() {
493
+ return super.isCheckedColumn;
494
+ }
495
+ get isChecked() {
496
+ if (this.foreignKey)
497
+ return this.isCheckedNode;
498
+ return super.isCheckedColumn;
499
+ }
500
+ get secondaryCheckable() {
501
+ return !!this.foreignKey;
502
+ }
503
+ toggleChecked(value) {
504
+ if (this.foreignKey) {
505
+ this.toggleCheckedNode(value);
506
+ }
507
+ else {
508
+ super.toggleChecked(value);
509
+ }
510
+ }
511
+ toggleSecondaryChecked(value) {
512
+ super.toggleChecked(value == null ? !this.isSecondaryChecked : value);
513
+ }
514
+ generateChildNodes() {
378
515
  var _a, _b;
379
516
  if (!this.foreignKey)
380
517
  return [];
@@ -439,8 +576,8 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
439
576
  }
440
577
  exports.PerspectiveTableColumnNode = PerspectiveTableColumnNode;
441
578
  class PerspectiveTableNode extends PerspectiveTreeNode {
442
- constructor(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
443
- super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
579
+ constructor(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
580
+ super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
444
581
  this.table = table;
445
582
  this.dataProvider = dataProvider;
446
583
  }
@@ -458,12 +595,13 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
458
595
  return this.table.schemaName ? `${this.table.schemaName}:${this.table.pureName}` : this.table.pureName;
459
596
  }
460
597
  get title() {
461
- return this.table.pureName;
598
+ var _a;
599
+ return ((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.alias) || this.table.pureName;
462
600
  }
463
601
  get isExpandable() {
464
602
  return true;
465
603
  }
466
- get childNodes() {
604
+ generateChildNodes() {
467
605
  return getTableChildPerspectiveNodes(this.table, this.dbs, this.config, this.setConfig, this.dataProvider, this.databaseConfig, this);
468
606
  }
469
607
  get icon() {
@@ -541,8 +679,8 @@ exports.PerspectiveTableNode = PerspectiveTableNode;
541
679
  // }
542
680
  // }
543
681
  class PerspectiveTableReferenceNode extends PerspectiveTableNode {
544
- constructor(foreignKey, table, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode) {
545
- super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode);
682
+ constructor(foreignKey, table, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode, designerId) {
683
+ super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
546
684
  this.foreignKey = foreignKey;
547
685
  this.dataProvider = dataProvider;
548
686
  this.isMultiple = isMultiple;
@@ -576,6 +714,13 @@ class PerspectiveTableReferenceNode extends PerspectiveTableNode {
576
714
  condition: this.getChildrenCondition(),
577
715
  };
578
716
  }
717
+ createReferenceConfigColumns() {
718
+ var _a, _b;
719
+ return (_b = (_a = this.foreignKey) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => ({
720
+ source: col.refColumnName,
721
+ target: col.columnName,
722
+ }));
723
+ }
579
724
  get columnTitle() {
580
725
  return this.table.pureName;
581
726
  }
@@ -591,6 +736,12 @@ class PerspectiveTableReferenceNode extends PerspectiveTableNode {
591
736
  }
592
737
  return super.codeName;
593
738
  }
739
+ get isChecked() {
740
+ return this.isCheckedNode;
741
+ }
742
+ toggleChecked(value) {
743
+ this.toggleCheckedNode(value);
744
+ }
594
745
  getParentJoinCondition(alias, parentAlias) {
595
746
  if (!this.foreignKey)
596
747
  return [];
@@ -615,8 +766,8 @@ class PerspectiveTableReferenceNode extends PerspectiveTableNode {
615
766
  }
616
767
  exports.PerspectiveTableReferenceNode = PerspectiveTableReferenceNode;
617
768
  class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
618
- constructor(customJoin, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
619
- super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode);
769
+ constructor(customJoin, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId) {
770
+ super(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId);
620
771
  this.customJoin = customJoin;
621
772
  this.dataProvider = dataProvider;
622
773
  }
@@ -648,18 +799,24 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
648
799
  condition: this.getChildrenCondition(),
649
800
  };
650
801
  }
651
- get title() {
652
- return this.customJoin.joinName;
653
- }
802
+ // get title() {
803
+ // return this.customJoin.joinName || this.customJoin.refTableName;
804
+ // }
654
805
  get icon() {
655
806
  return 'icon custom-join';
656
807
  }
657
808
  get codeName() {
658
- return this.customJoin.joinid;
809
+ return this.customJoin.refNodeDesignerId;
659
810
  }
660
811
  get customJoinConfig() {
661
812
  return this.customJoin;
662
813
  }
814
+ get isChecked() {
815
+ return this.isCheckedNode;
816
+ }
817
+ toggleChecked(value) {
818
+ this.toggleCheckedNode(value);
819
+ }
663
820
  getParentJoinCondition(alias, parentAlias) {
664
821
  return this.customJoin.columns.map(column => {
665
822
  const res = {
@@ -681,17 +838,45 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
681
838
  }
682
839
  }
683
840
  exports.PerspectiveCustomJoinTreeNode = PerspectiveCustomJoinTreeNode;
684
- function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, databaseConfig, parentColumn) {
685
- var _a, _b, _c;
841
+ function findDesignerIdForNode(config, parentNode, nodeCreateFunc) {
842
+ const node = nodeCreateFunc(null);
843
+ const refColumns = node.createReferenceConfigColumns();
844
+ if (!(refColumns === null || refColumns === void 0 ? void 0 : refColumns.length)) {
845
+ return node;
846
+ }
847
+ const ref1 = config.references.find(x => x.sourceId == parentNode.designerId &&
848
+ (0, isEqual_1.default)(refColumns.map(x => x.source), x.columns.map(x => x.source)) &&
849
+ (0, isEqual_1.default)(refColumns.map(x => x.target), x.columns.map(x => x.target)) &&
850
+ (0, dbgate_tools_1.equalFullName)(config.nodes.find(n => n.designerId == x.targetId), node.namedObject));
851
+ if (ref1 && !parentNode.hasDesignerIdInIncestors(ref1.targetId)) {
852
+ // console.log('FOUND1', node.title, ref1.targetId, refColumns);
853
+ return nodeCreateFunc(ref1.targetId);
854
+ }
855
+ const ref2 = config.references.find(x => x.targetId == parentNode.designerId &&
856
+ (0, isEqual_1.default)(refColumns.map(x => x.target), x.columns.map(x => x.source)) &&
857
+ (0, isEqual_1.default)(refColumns.map(x => x.source), x.columns.map(x => x.target)) &&
858
+ (0, dbgate_tools_1.equalFullName)(config.nodes.find(n => n.designerId == x.sourceId), node.namedObject));
859
+ if (ref2 && !parentNode.hasDesignerIdInIncestors(ref2.sourceId)) {
860
+ // console.log('FOUND2', node.title, ref2.sourceId, refColumns);
861
+ return nodeCreateFunc(ref2.sourceId);
862
+ }
863
+ return node;
864
+ }
865
+ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode) {
866
+ var _a, _b, _c, _d;
686
867
  if (!table)
687
868
  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
- }
869
+ const db = parentNode.db;
870
+ const columnNodes = table.columns.map(col => findDesignerIdForNode(config, parentNode, designerId => new PerspectiveTableColumnNode(col, table, dbs, config, setConfig, dataProvider, databaseConfig, parentNode, designerId)));
871
+ // if (!columnNodes.find(x => x.isChecked)) {
872
+ // const circularColumns = columnNodes.filter(x => x.isCircular).map(x => x.columnName);
873
+ // const defaultColumns = getPerspectiveDefaultColumns(table, db, circularColumns);
874
+ // for (const node of columnNodes) {
875
+ // if (defaultColumns.includes(node.columnName)) {
876
+ // no
877
+ // }
878
+ // }
879
+ // }
695
880
  const res = [];
696
881
  res.push(...columnNodes);
697
882
  const dependencies = [];
@@ -700,28 +885,75 @@ function getTableChildPerspectiveNodes(table, dbs, config, setConfig, dataProvid
700
885
  const tbl = db.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
701
886
  if (tbl) {
702
887
  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));
888
+ dependencies.push(findDesignerIdForNode(config, parentNode, designerId => new PerspectiveTableReferenceNode(fk, tbl, dbs, config, setConfig, dataProvider, databaseConfig, isMultiple, parentNode, designerId)));
704
889
  }
705
890
  }
706
891
  }
707
892
  res.push(...(0, sortBy_1.default)(dependencies, 'title'));
708
893
  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));
894
+ for (const node of config.nodes) {
895
+ if (node.designerId == ((_a = parentNode.parentNode) === null || _a === void 0 ? void 0 : _a.designerId) || res.find(x => x.designerId == node.designerId)) {
896
+ // already used as FK
897
+ continue;
898
+ }
899
+ for (const ref of config.references) {
900
+ if ((ref.sourceId == parentNode.designerId && ref.targetId == node.designerId) ||
901
+ (ref.targetId == parentNode.designerId && ref.sourceId == node.designerId)) {
902
+ const newConfig = Object.assign({}, databaseConfig);
903
+ if (node.conid)
904
+ newConfig.conid = node.conid;
905
+ if (node.database)
906
+ newConfig.database = node.database;
907
+ const db = (_b = dbs === null || dbs === void 0 ? void 0 : dbs[newConfig.conid]) === null || _b === void 0 ? void 0 : _b[newConfig.database];
908
+ const table = (_c = db === null || db === void 0 ? void 0 : db.tables) === null || _c === void 0 ? void 0 : _c.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
909
+ const view = (_d = db === null || db === void 0 ? void 0 : db.views) === null || _d === void 0 ? void 0 : _d.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
910
+ const join = {
911
+ refNodeDesignerId: node.designerId,
912
+ referenceDesignerId: ref.designerId,
913
+ baseDesignerId: parentNode.designerId,
914
+ joinName: node.alias,
915
+ refTableName: node.pureName,
916
+ refSchemaName: node.schemaName,
917
+ conid: node.conid,
918
+ database: node.database,
919
+ columns: ref.sourceId == parentNode.designerId
920
+ ? ref.columns.map(col => ({ baseColumnName: col.source, refColumnName: col.target }))
921
+ : ref.columns.map(col => ({ baseColumnName: col.target, refColumnName: col.source })),
922
+ };
923
+ if (table || view) {
924
+ customs.push(new PerspectiveCustomJoinTreeNode(join, table || view, dbs, config, setConfig, dataProvider, newConfig, parentNode, node.designerId));
925
+ }
721
926
  }
722
927
  }
723
928
  }
724
929
  res.push(...(0, sortBy_1.default)(customs, 'title'));
930
+ // const customs = [];
931
+ // for (const join of config.customJoins || []) {
932
+ // if (join.baseUniqueName == parentColumn.uniqueName) {
933
+ // const newConfig = { ...databaseConfig };
934
+ // if (join.conid) newConfig.conid = join.conid;
935
+ // if (join.database) newConfig.database = join.database;
936
+ // const db = dbs?.[newConfig.conid]?.[newConfig.database];
937
+ // const table = db?.tables?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
938
+ // const view = db?.views?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
939
+ // if (table || view) {
940
+ // customs.push(
941
+ // new PerspectiveCustomJoinTreeNode(
942
+ // join,
943
+ // table || view,
944
+ // dbs,
945
+ // config,
946
+ // setConfig,
947
+ // dataProvider,
948
+ // newConfig,
949
+ // parentColumn,
950
+ // null
951
+ // )
952
+ // );
953
+ // }
954
+ // }
955
+ // }
956
+ // res.push(..._sortBy(customs, 'title'));
725
957
  return res;
726
958
  }
727
959
  exports.getTableChildPerspectiveNodes = getTableChildPerspectiveNodes;
package/lib/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export * from './PerspectiveDisplay';
18
18
  export * from './PerspectiveDataProvider';
19
19
  export * from './PerspectiveCache';
20
20
  export * from './PerspectiveConfig';
21
+ export * from './processPerspectiveDefaultColunns';
package/lib/index.js CHANGED
@@ -34,3 +34,4 @@ __exportStar(require("./PerspectiveDisplay"), exports);
34
34
  __exportStar(require("./PerspectiveDataProvider"), exports);
35
35
  __exportStar(require("./PerspectiveCache"), exports);
36
36
  __exportStar(require("./PerspectiveConfig"), exports);
37
+ __exportStar(require("./processPerspectiveDefaultColunns"), exports);
@@ -0,0 +1,4 @@
1
+ import { MultipleDatabaseInfo, PerspectiveConfig } from './PerspectiveConfig';
2
+ export declare function perspectiveNodesHaveStructure(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): boolean;
3
+ export declare function shouldProcessPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): boolean;
4
+ export declare function processPerspectiveDefaultColunns(config: PerspectiveConfig, dbInfos: MultipleDatabaseInfo, conid: string, database: string): PerspectiveConfig;