mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 18:55:59 +00:00
perspective designer auto arrange
This commit is contained in:
@@ -89,6 +89,7 @@ export interface PerspectiveReferenceConfig {
|
|||||||
|
|
||||||
export interface PerspectiveConfig {
|
export interface PerspectiveConfig {
|
||||||
rootDesignerId: string;
|
rootDesignerId: string;
|
||||||
|
isArranged: boolean;
|
||||||
nodes: PerspectiveNodeConfig[];
|
nodes: PerspectiveNodeConfig[];
|
||||||
references: PerspectiveReferenceConfig[];
|
references: PerspectiveReferenceConfig[];
|
||||||
}
|
}
|
||||||
@@ -115,6 +116,7 @@ export function createPerspectiveConfig(rootObject: { schemaName?: string; pureN
|
|||||||
nodes: [rootNode],
|
nodes: [rootNode],
|
||||||
references: [],
|
references: [],
|
||||||
rootDesignerId: rootNode.designerId,
|
rootDesignerId: rootNode.designerId,
|
||||||
|
isArranged: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,8 +175,8 @@
|
|||||||
canvasHeight = Math.max(3000, maxY + 50);
|
canvasHeight = Math.max(3000, maxY + 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
function callChange(changeFunc, skipUndoChain = undefined) {
|
function callChange(changeFunc, skipUndoChain = undefined, settings = undefined) {
|
||||||
onChange(changeFunc, skipUndoChain);
|
onChange(changeFunc, skipUndoChain, settings);
|
||||||
tick().then(recomputeReferencePositions);
|
tick().then(recomputeReferencePositions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,26 +665,30 @@
|
|||||||
|
|
||||||
// layout.print();
|
// layout.print();
|
||||||
|
|
||||||
callChange(current => {
|
callChange(
|
||||||
return {
|
current => {
|
||||||
...current,
|
return {
|
||||||
tables: (current?.tables || []).map(table => {
|
...current,
|
||||||
const node = layout.nodes[table.designerId];
|
tables: (current?.tables || []).map(table => {
|
||||||
// console.log('POSITION', position);
|
const node = layout.nodes[table.designerId];
|
||||||
return node
|
// console.log('POSITION', position);
|
||||||
? {
|
return node
|
||||||
...table,
|
? {
|
||||||
needsArrange: false,
|
...table,
|
||||||
left: node.left,
|
needsArrange: false,
|
||||||
top: node.top,
|
left: node.left,
|
||||||
}
|
top: node.top,
|
||||||
: {
|
}
|
||||||
...table,
|
: {
|
||||||
needsArrange: false,
|
...table,
|
||||||
};
|
needsArrange: false,
|
||||||
}),
|
};
|
||||||
};
|
}),
|
||||||
}, skipUndoChain);
|
};
|
||||||
|
},
|
||||||
|
skipUndoChain,
|
||||||
|
{ isCalledFromArrange: true }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function exportDiagram() {
|
export async function exportDiagram() {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MultipleDatabaseInfo, PerspectiveConfig } from 'dbgate-datalib';
|
import { MultipleDatabaseInfo, PerspectiveConfig } from 'dbgate-datalib';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { onMount } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
|
import runCommand from '../commands/runCommand';
|
||||||
|
|
||||||
import Designer from '../designer/Designer.svelte';
|
import Designer from '../designer/Designer.svelte';
|
||||||
import QueryDesignerReference from '../designer/QueryDesignerReference.svelte';
|
import QueryDesignerReference from '../designer/QueryDesignerReference.svelte';
|
||||||
@@ -36,14 +37,21 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(value) {
|
function handleChange(value, skipUndoChain, settings) {
|
||||||
onChange(oldValue => {
|
onChange(oldValue => {
|
||||||
const newValue = _.isFunction(value) ? value(createDesignerModel(oldValue, dbInfos)) : value;
|
const newValue = _.isFunction(value) ? value(createDesignerModel(oldValue, dbInfos)) : value;
|
||||||
return {
|
let isArranged = oldValue.isArranged;
|
||||||
|
if (settings?.isCalledFromArrange) {
|
||||||
|
isArranged = true;
|
||||||
|
}
|
||||||
|
const res = {
|
||||||
...oldValue,
|
...oldValue,
|
||||||
nodes: oldValue.nodes.map(node => {
|
nodes: oldValue.nodes.map(node => {
|
||||||
const table = newValue.tables?.find(x => x.designerId == node.designerId);
|
const table = newValue.tables?.find(x => x.designerId == node.designerId);
|
||||||
if (table) {
|
if (table && (table.left != node.position?.x || table.top != node.position?.y)) {
|
||||||
|
if (!settings?.isCalledFromArrange) {
|
||||||
|
isArranged = false;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...node,
|
...node,
|
||||||
position: { x: table.left, y: table.top },
|
position: { x: table.left, y: table.top },
|
||||||
@@ -52,8 +60,19 @@
|
|||||||
return node;
|
return node;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
res.isArranged = isArranged;
|
||||||
|
return res;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function detectAutoArrange(config: PerspectiveConfig, dbInfos) {
|
||||||
|
if (config.isArranged && config.nodes.find(x => !x.position)) {
|
||||||
|
await tick();
|
||||||
|
runCommand('designer.arrange');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: detectAutoArrange(config, dbInfos);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Designer
|
<Designer
|
||||||
|
|||||||
@@ -11,6 +11,17 @@
|
|||||||
testEnabled: () => getCurrentEditor() != null,
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
onClick: () => getCurrentEditor().defineCustomJoin(),
|
onClick: () => getCurrentEditor().defineCustomJoin(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'perspective.arrange',
|
||||||
|
category: 'Perspective',
|
||||||
|
icon: 'icon arrange',
|
||||||
|
name: 'Arrange',
|
||||||
|
toolbar: true,
|
||||||
|
isRelatedToTab: true,
|
||||||
|
testEnabled: () => getCurrentEditor()?.canArrange(),
|
||||||
|
onClick: () => getCurrentEditor().arrange(),
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -57,6 +68,7 @@
|
|||||||
import { useMultipleDatabaseInfo } from '../utility/useMultipleDatabaseInfo';
|
import { useMultipleDatabaseInfo } from '../utility/useMultipleDatabaseInfo';
|
||||||
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
||||||
import PerspectiveDesigner from './PerspectiveDesigner.svelte';
|
import PerspectiveDesigner from './PerspectiveDesigner.svelte';
|
||||||
|
import runCommand from '../commands/runCommand';
|
||||||
|
|
||||||
const dbg = debug('dbgate:PerspectiveView');
|
const dbg = debug('dbgate:PerspectiveView');
|
||||||
|
|
||||||
@@ -96,6 +108,18 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canArrange() {
|
||||||
|
return !config.isArranged;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function arrange() {
|
||||||
|
// setConfig(cfg => ({
|
||||||
|
// ...cfg,
|
||||||
|
// isArranged: true,
|
||||||
|
// }));
|
||||||
|
runCommand('designer.arrange');
|
||||||
|
}
|
||||||
|
|
||||||
let perspectiveDatabases = extractPerspectiveDatabases({ conid, database }, config);
|
let perspectiveDatabases = extractPerspectiveDatabases({ conid, database }, config);
|
||||||
$: {
|
$: {
|
||||||
const newDatabases = extractPerspectiveDatabases({ conid, database }, config);
|
const newDatabases = extractPerspectiveDatabases({ conid, database }, config);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<svelte:fragment slot="toolstrip">
|
<svelte:fragment slot="toolstrip">
|
||||||
<ToolStripCommandButton command="designer.arrange" />
|
<ToolStripCommandButton command="perspective.arrange" />
|
||||||
<ToolStripCommandButton command="perspective.refresh" />
|
<ToolStripCommandButton command="perspective.refresh" />
|
||||||
<ToolStripCommandButton command="perspective.customJoin" />
|
<ToolStripCommandButton command="perspective.customJoin" />
|
||||||
<ToolStripSaveButton idPrefix="perspective" />
|
<ToolStripSaveButton idPrefix="perspective" />
|
||||||
|
|||||||
Reference in New Issue
Block a user