mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 08:13:57 +00:00
perspective tre shows dependencies
This commit is contained in:
@@ -10,9 +10,9 @@ export abstract class PerspectiveTreeNode {
|
|||||||
) {}
|
) {}
|
||||||
abstract get title();
|
abstract get title();
|
||||||
abstract get codeName();
|
abstract get codeName();
|
||||||
abstract get props();
|
|
||||||
abstract get isExpandable();
|
abstract get isExpandable();
|
||||||
abstract get childNodes(): PerspectiveTreeNode[];
|
abstract get childNodes(): PerspectiveTreeNode[];
|
||||||
|
abstract get icon(): string;
|
||||||
get uniqueName() {
|
get uniqueName() {
|
||||||
if (this.parentNode) return `${this.parentNode.uniqueName}.${this.codeName}`;
|
if (this.parentNode) return `${this.parentNode.uniqueName}.${this.codeName}`;
|
||||||
return this.codeName;
|
return this.codeName;
|
||||||
@@ -61,6 +61,12 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|||||||
table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName);
|
table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get icon() {
|
||||||
|
if (this.column.autoIncrement) return 'img autoincrement';
|
||||||
|
if (this.foreignKey) return 'img foreign-key';
|
||||||
|
return 'img column';
|
||||||
|
}
|
||||||
|
|
||||||
get codeName() {
|
get codeName() {
|
||||||
return this.column.columnName;
|
return this.column.columnName;
|
||||||
}
|
}
|
||||||
@@ -69,10 +75,6 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|||||||
return this.column.columnName;
|
return this.column.columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
get props() {
|
|
||||||
return this.column;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isExpandable() {
|
get isExpandable() {
|
||||||
return !!this.foreignKey;
|
return !!this.foreignKey;
|
||||||
}
|
}
|
||||||
@@ -83,10 +85,40 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|||||||
x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
|
x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
|
||||||
);
|
);
|
||||||
return getTableChildPerspectiveNodes(tbl, this.db, this.config, this.setConfig, this);
|
return getTableChildPerspectiveNodes(tbl, this.db, this.config, this.setConfig, this);
|
||||||
// return (
|
}
|
||||||
// tbl?.columns?.map(col => new PerspectiveTableColumnNode(col, tbl, this.db, this.config, this.setConfig, this)) ||
|
}
|
||||||
// []
|
|
||||||
// );
|
export class PerspectiveTableReferenceNode extends PerspectiveTreeNode {
|
||||||
|
foreignKey: ForeignKeyInfo;
|
||||||
|
constructor(
|
||||||
|
public fk: ForeignKeyInfo,
|
||||||
|
public table: TableInfo,
|
||||||
|
public db: DatabaseInfo,
|
||||||
|
config: PerspectiveConfig,
|
||||||
|
setConfig: ChangePerspectiveConfigFunc,
|
||||||
|
parentColumn: PerspectiveTreeNode
|
||||||
|
) {
|
||||||
|
super(config, setConfig, parentColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
get codeName() {
|
||||||
|
return this.table.schemaName ? `${this.table.schemaName}:${this.table.pureName}` : this.table.pureName;
|
||||||
|
}
|
||||||
|
|
||||||
|
get title() {
|
||||||
|
return this.table.pureName;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isExpandable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
get childNodes(): PerspectiveTreeNode[] {
|
||||||
|
return getTableChildPerspectiveNodes(this.table, this.db, this.config, this.setConfig, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get icon() {
|
||||||
|
return 'img table';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,5 +130,15 @@ export function getTableChildPerspectiveNodes(
|
|||||||
parentColumn: PerspectiveTreeNode
|
parentColumn: PerspectiveTreeNode
|
||||||
) {
|
) {
|
||||||
if (!table) return [];
|
if (!table) return [];
|
||||||
return table.columns.map(col => new PerspectiveTableColumnNode(col, table, db, config, setConfig, parentColumn));
|
const res = [];
|
||||||
|
res.push(
|
||||||
|
...table.columns.map(col => new PerspectiveTableColumnNode(col, table, db, config, setConfig, parentColumn))
|
||||||
|
);
|
||||||
|
if (db && table.dependencies) {
|
||||||
|
for (const fk of table.dependencies) {
|
||||||
|
const tbl = db.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
|
||||||
|
if (tbl) res.push(new PerspectiveTableReferenceNode(fk, tbl, db, config, setConfig, parentColumn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,20 @@
|
|||||||
import { plusExpandIcon } from '../icons/expandIcons';
|
import { plusExpandIcon } from '../icons/expandIcons';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
|
||||||
export let column;
|
export let node;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span class="expandColumnIcon" style={`margin-right: ${5 + column.level * 10}px`}>
|
<span class="expandColumnIcon" style={`margin-right: ${5 + node.level * 10}px`}>
|
||||||
<FontIcon
|
<FontIcon
|
||||||
icon={column.isExpandable ? plusExpandIcon(column.isExpanded) : 'icon invisible-box'}
|
icon={node.isExpandable ? plusExpandIcon(node.isExpanded) : 'icon invisible-box'}
|
||||||
on:click={() => column.toggleExpanded()}
|
on:click={() => node.toggleExpanded()}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={column.isChecked}
|
checked={node.isChecked}
|
||||||
on:click={e => {
|
on:click={e => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
@@ -24,13 +24,15 @@
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
const newValue = !column.isChecked;
|
const newValue = !node.isChecked;
|
||||||
// display.setColumnVisibility(column.uniquePath, newValue);
|
// display.setColumnVisibility(column.uniquePath, newValue);
|
||||||
// dispatch('setvisibility', newValue);
|
// dispatch('setvisibility', newValue);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ColumnLabel {...column.props} showDataType />
|
<FontIcon icon={node.icon} />
|
||||||
|
|
||||||
|
<span>{node.title}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { each } from 'svelte/internal';
|
import PerspectiveNodeRow from './PerspectiveNodeRow.svelte';
|
||||||
import ColumnLabel from '../elements/ColumnLabel.svelte';
|
|
||||||
import PerspectiveColumnRow from './PerspectiveColumnRow.svelte';
|
|
||||||
|
|
||||||
export let columns = [];
|
export let nodes = [];
|
||||||
|
|
||||||
function processFlatColumns(res, columns) {
|
function processFlatColumns(res, columns) {
|
||||||
for (const col of columns) {
|
for (const col of columns) {
|
||||||
@@ -21,6 +19,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each getFlatColumns(columns) as column}
|
{#each getFlatColumns(nodes) as node}
|
||||||
<PerspectiveColumnRow {column} />
|
<PerspectiveNodeRow {node} />
|
||||||
{/each}
|
{/each}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
||||||
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
||||||
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
|
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
|
||||||
import PerspectiveColumns from './PerspectiveColumns.svelte';
|
import PerspectiveTree from './PerspectiveTree.svelte';
|
||||||
import PerspectiveCore from './PerspectiveCore.svelte';
|
import PerspectiveCore from './PerspectiveCore.svelte';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
@@ -39,29 +39,29 @@
|
|||||||
// $: console.log('tableInfo', $tableInfo);
|
// $: console.log('tableInfo', $tableInfo);
|
||||||
// $: console.log('viewInfo', $viewInfo);
|
// $: console.log('viewInfo', $viewInfo);
|
||||||
|
|
||||||
function getTableColumns(table, dbInfo, config, setConfig) {
|
function getTableNodes(table, dbInfo, config, setConfig) {
|
||||||
return getTableChildPerspectiveNodes(table, dbInfo, config, setConfig, null);
|
return getTableChildPerspectiveNodes(table, dbInfo, config, setConfig, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewColumns(view, dbInfo, config, setConfig) {
|
function getViewNodes(view, dbInfo, config, setConfig) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// $: console.log('CFG', config);
|
// $: console.log('CFG', config);
|
||||||
|
|
||||||
$: columns = $tableInfo
|
$: nodes = $tableInfo
|
||||||
? getTableColumns($tableInfo, $dbInfo, config, setConfig)
|
? getTableNodes($tableInfo, $dbInfo, config, setConfig)
|
||||||
: $viewInfo
|
: $viewInfo
|
||||||
? getViewColumns($viewInfo, $dbInfo, config, setConfig)
|
? getViewNodes($viewInfo, $dbInfo, config, setConfig)
|
||||||
: null;
|
: null;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
|
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
|
||||||
<div class="left" slot="1">
|
<div class="left" slot="1">
|
||||||
<WidgetColumnBar>
|
<WidgetColumnBar>
|
||||||
<WidgetColumnBarItem title="Columns" name="columns" height="45%">
|
<WidgetColumnBarItem title="Choose data" name="perspectiveTree" height="45%">
|
||||||
{#if columns}
|
{#if nodes}
|
||||||
<PerspectiveColumns {columns} />
|
<PerspectiveTree {nodes} />
|
||||||
{/if}
|
{/if}
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
</WidgetColumnBar>
|
</WidgetColumnBar>
|
||||||
|
|||||||
Reference in New Issue
Block a user