perspective fixes

This commit is contained in:
Jan Prochazka
2022-08-28 07:52:36 +02:00
parent 4e799885b5
commit 894a864110
4 changed files with 88 additions and 29 deletions

View File

@@ -352,8 +352,6 @@ export abstract class PerspectiveTreeNode {
// } // }
findNodeByDesignerId(designerId: string): PerspectiveTreeNode { findNodeByDesignerId(designerId: string): PerspectiveTreeNode {
console.log('findNodeByDesignerId', designerId, this.level, this.designerId);
if (!this.designerId) { if (!this.designerId) {
return null; return null;
} }

View File

@@ -42,13 +42,34 @@ function getPerspectiveDefaultColumns(
return [[columns[0]], null]; return [[columns[0]], null];
} }
export function processPerspectiveDefaultColunns( export function shouldProcessPerspectiveDefaultColunns(
config: PerspectiveConfig,
dbInfos: MultipleDatabaseInfo,
conid: string,
database: string
) {
const nodesNotProcessed = config.nodes.filter(x => !x.defaultColumnsProcessed);
if (nodesNotProcessed.length == 0) return false;
for (const node of nodesNotProcessed) {
const db = dbInfos?.[node.conid || conid]?.[node.database || database];
if (!db) return false;
const table = db.tables.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
if (!table && !view) return false;
}
return true;
}
function processPerspectiveDefaultColunnsStep(
config: PerspectiveConfig, config: PerspectiveConfig,
dbInfos: MultipleDatabaseInfo, dbInfos: MultipleDatabaseInfo,
conid: string, conid: string,
database: string database: string
) { ) {
console.log('processPerspectiveDefaultColunns');
const rootNode = config.nodes.find(x => x.designerId == config.rootDesignerId); const rootNode = config.nodes.find(x => x.designerId == config.rootDesignerId);
if (!rootNode) return null; if (!rootNode) return null;
const rootDb = dbInfos?.[rootNode.conid || conid]?.[rootNode.database || database]; const rootDb = dbInfos?.[rootNode.conid || conid]?.[rootNode.database || database];
@@ -56,8 +77,6 @@ export function processPerspectiveDefaultColunns(
const rootTable = rootDb.tables.find(x => x.pureName == rootNode.pureName && x.schemaName == rootNode.schemaName); const rootTable = rootDb.tables.find(x => x.pureName == rootNode.pureName && x.schemaName == rootNode.schemaName);
const rootView = rootDb.views.find(x => x.pureName == rootNode.pureName && x.schemaName == rootNode.schemaName); const rootView = rootDb.views.find(x => x.pureName == rootNode.pureName && x.schemaName == rootNode.schemaName);
console.log('CREATE ROOT');
const root = new PerspectiveTableNode( const root = new PerspectiveTableNode(
rootTable || rootView, rootTable || rootView,
dbInfos, dbInfos,
@@ -69,8 +88,6 @@ export function processPerspectiveDefaultColunns(
config.rootDesignerId config.rootDesignerId
); );
console.log('ROOT', root);
for (const node of config.nodes) { for (const node of config.nodes) {
if (node.defaultColumnsProcessed) continue; if (node.defaultColumnsProcessed) continue;
@@ -81,7 +98,6 @@ export function processPerspectiveDefaultColunns(
const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName); const view = db.views.find(x => x.pureName == node.pureName && x.schemaName == node.schemaName);
if (table || view) { if (table || view) {
console.log('FINDING', node.pureName);
const treeNode = root.findNodeByDesignerId(node.designerId); const treeNode = root.findNodeByDesignerId(node.designerId);
if (!treeNode) continue; if (!treeNode) continue;
const circularColumns = treeNode.childNodes.filter(x => x.isCircular).map(x => x.columnName); const circularColumns = treeNode.childNodes.filter(x => x.isCircular).map(x => x.columnName);
@@ -141,3 +157,35 @@ export function processPerspectiveDefaultColunns(
return null; return null;
} }
function markAllProcessed(config: PerspectiveConfig): PerspectiveConfig {
return {
...config,
nodes: config.nodes.map(x => ({
...x,
defaultColumnsProcessed: true,
})),
};
}
export function processPerspectiveDefaultColunns(
config: PerspectiveConfig,
dbInfos: MultipleDatabaseInfo,
conid: string,
database: string
) {
while (config.nodes.filter(x => !x.defaultColumnsProcessed).length > 0) {
const newConfig = processPerspectiveDefaultColunnsStep(config, dbInfos, conid, database);
if (!newConfig) {
return markAllProcessed(config);
}
if (
newConfig.nodes.filter(x => x.defaultColumnsProcessed).length <=
config.nodes.filter(x => x.defaultColumnsProcessed).length
) {
return markAllProcessed(config);
}
config = newConfig;
}
return markAllProcessed(config);
}

View File

@@ -52,20 +52,30 @@
oldValue.nodes.map(node => { oldValue.nodes.map(node => {
const table = newValue.tables?.find(x => x.designerId == node.designerId); const table = newValue.tables?.find(x => x.designerId == node.designerId);
const nodeChanged = {
...node,
};
if (table) {
nodeChanged.alias = table?.alias;
}
if (settings?.isCalledFromArrange) {
// when called from arrange, position must be set to prevent cycle
nodeChanged.position = { x: table?.left || 0, y: table?.top || 0 };
}
if (!table && settings?.removeTables) { if (!table && settings?.removeTables) {
return null; return null;
} }
const nodeChanged = {
...node,
alias: table?.alias,
};
if (table && (table.left != node.position?.x || table.top != node.position?.y)) { if (table && (table.left != node.position?.x || table.top != node.position?.y)) {
if (!settings?.isCalledFromArrange) { if (!settings?.isCalledFromArrange) {
isArranged = false; isArranged = false;
} }
nodeChanged.position = { x: table.left, y: table.top }; // nodeChanged.position = { x: table.left, y: table.top };
} }
return nodeChanged; return nodeChanged;
}) })
), ),
@@ -94,7 +104,6 @@
async function detectAutoArrange(config: PerspectiveConfig, dbInfos) { async function detectAutoArrange(config: PerspectiveConfig, dbInfos) {
if (config.nodes.find(x => !x.position)) { if (config.nodes.find(x => !x.position)) {
await tick(); await tick();
console.log('ARRANGE', config.nodes.length);
runCommand('designer.arrange'); runCommand('designer.arrange');
} }
} }

View File

@@ -37,6 +37,7 @@
PerspectiveTableColumnNode, PerspectiveTableColumnNode,
PerspectiveTableNode, PerspectiveTableNode,
processPerspectiveDefaultColunns, processPerspectiveDefaultColunns,
shouldProcessPerspectiveDefaultColunns,
} from 'dbgate-datalib'; } from 'dbgate-datalib';
import _ from 'lodash'; import _ from 'lodash';
@@ -150,20 +151,23 @@
: null; : null;
$: { $: {
tick().then(() => { if (shouldProcessPerspectiveDefaultColunns(config, $dbInfos, conid, database)) {
const newConfig = processPerspectiveDefaultColunns(config, $dbInfos, conid, database); setConfig(cfg => processPerspectiveDefaultColunns(cfg, $dbInfos, conid, database));
if (newConfig) {
if (
newConfig.nodes.filter(x => x.defaultColumnsProcessed).length >
config.nodes.filter(x => x.defaultColumnsProcessed).length
) {
console.log('CONFIG CHANGED');
setConfig(() => newConfig);
} else {
console.warn('No new default columns', newConfig);
} }
} // tick().then(() => {
}); // const newConfig = processPerspectiveDefaultColunns(config, $dbInfos, conid, database);
// if (newConfig) {
// if (
// newConfig.nodes.filter(x => x.defaultColumnsProcessed).length >
// config.nodes.filter(x => x.defaultColumnsProcessed).length
// ) {
// console.log('CONFIG CHANGED');
// setConfig(() => newConfig);
// } else {
// console.warn('No new default columns', newConfig);
// }
// }
// });
} }
</script> </script>