mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 23:46:23 +00:00
refactor
This commit is contained in:
@@ -2,23 +2,23 @@ import { ColumnInfo, DatabaseInfo, ForeignKeyInfo, TableInfo } from 'dbgate-type
|
|||||||
import { clearConfigCache } from 'prettier';
|
import { clearConfigCache } from 'prettier';
|
||||||
import { ChangePerspectiveConfigFunc, PerspectiveConfig } from './PerspectiveConfig';
|
import { ChangePerspectiveConfigFunc, PerspectiveConfig } from './PerspectiveConfig';
|
||||||
|
|
||||||
export abstract class PerspectiveColumnDefinition {
|
export abstract class PerspectiveTreeNode {
|
||||||
constructor(
|
constructor(
|
||||||
public config: PerspectiveConfig,
|
public config: PerspectiveConfig,
|
||||||
public setConfig: ChangePerspectiveConfigFunc,
|
public setConfig: ChangePerspectiveConfigFunc,
|
||||||
public parentColumn: PerspectiveTableColumnDefinition
|
public parentNode: PerspectiveTreeNode
|
||||||
) {}
|
) {}
|
||||||
abstract get title();
|
abstract get title();
|
||||||
abstract get codeName();
|
abstract get codeName();
|
||||||
abstract get props();
|
abstract get props();
|
||||||
abstract get isExpandable();
|
abstract get isExpandable();
|
||||||
abstract get childColumns(): PerspectiveColumnDefinition[];
|
abstract get childNodes(): PerspectiveTreeNode[];
|
||||||
get uniqueName() {
|
get uniqueName() {
|
||||||
if (this.parentColumn) return `${this.parentColumn.uniqueName}.${this.codeName}`;
|
if (this.parentNode) return `${this.parentNode.uniqueName}.${this.codeName}`;
|
||||||
return this.codeName;
|
return this.codeName;
|
||||||
}
|
}
|
||||||
get level() {
|
get level() {
|
||||||
if (this.parentColumn) return this.parentColumn.level + 1;
|
if (this.parentNode) return this.parentNode.level + 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
get isExpanded() {
|
get isExpanded() {
|
||||||
@@ -44,7 +44,7 @@ export abstract class PerspectiveColumnDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinition {
|
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||||
foreignKey: ForeignKeyInfo;
|
foreignKey: ForeignKeyInfo;
|
||||||
constructor(
|
constructor(
|
||||||
public column: ColumnInfo,
|
public column: ColumnInfo,
|
||||||
@@ -52,7 +52,7 @@ export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinitio
|
|||||||
public db: DatabaseInfo,
|
public db: DatabaseInfo,
|
||||||
config: PerspectiveConfig,
|
config: PerspectiveConfig,
|
||||||
setConfig: ChangePerspectiveConfigFunc,
|
setConfig: ChangePerspectiveConfigFunc,
|
||||||
parentColumn: PerspectiveTableColumnDefinition
|
parentColumn: PerspectiveTreeNode
|
||||||
) {
|
) {
|
||||||
super(config, setConfig, parentColumn);
|
super(config, setConfig, parentColumn);
|
||||||
|
|
||||||
@@ -77,15 +77,26 @@ export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinitio
|
|||||||
return !!this.foreignKey;
|
return !!this.foreignKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
get childColumns(): PerspectiveColumnDefinition[] {
|
get childNodes(): PerspectiveTreeNode[] {
|
||||||
if (!this.foreignKey) return [];
|
if (!this.foreignKey) return [];
|
||||||
const tbl = this?.db?.tables?.find(
|
const tbl = this?.db?.tables?.find(
|
||||||
x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
|
x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
|
||||||
);
|
);
|
||||||
return (
|
return getTableChildPerspectiveNodes(tbl, this.db, this.config, this.setConfig, this);
|
||||||
tbl?.columns?.map(
|
// return (
|
||||||
col => new PerspectiveTableColumnDefinition(col, tbl, this.db, this.config, this.setConfig, this)
|
// tbl?.columns?.map(col => new PerspectiveTableColumnNode(col, tbl, this.db, this.config, this.setConfig, this)) ||
|
||||||
) || []
|
// []
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTableChildPerspectiveNodes(
|
||||||
|
table: TableInfo,
|
||||||
|
db: DatabaseInfo,
|
||||||
|
config: PerspectiveConfig,
|
||||||
|
setConfig: ChangePerspectiveConfigFunc,
|
||||||
|
parentColumn: PerspectiveTreeNode
|
||||||
|
) {
|
||||||
|
if (!table) return [];
|
||||||
|
return table.columns.map(col => new PerspectiveTableColumnNode(col, table, db, config, setConfig, parentColumn));
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
export * from './GridDisplay';
|
export * from './GridDisplay';
|
||||||
export * from './GridConfig';
|
export * from './GridConfig';
|
||||||
export * from './PerspectiveConfig';
|
export * from './PerspectiveConfig';
|
||||||
export * from './PerspectiveColumnDefinition';
|
export * from './PerspectiveTreeNode';
|
||||||
export * from './TableGridDisplay';
|
export * from './TableGridDisplay';
|
||||||
export * from './ViewGridDisplay';
|
export * from './ViewGridDisplay';
|
||||||
export * from './JslGridDisplay';
|
export * from './JslGridDisplay';
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
for (const col of columns) {
|
for (const col of columns) {
|
||||||
res.push(col);
|
res.push(col);
|
||||||
if (col.isExpanded) {
|
if (col.isExpanded) {
|
||||||
processFlatColumns(res, col.childColumns);
|
processFlatColumns(res, col.childNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { PerspectiveTableColumnDefinition } from 'dbgate-datalib';
|
import { getTableChildPerspectiveNodes, PerspectiveTableColumnNode } from 'dbgate-datalib';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@
|
|||||||
// $: console.log('viewInfo', $viewInfo);
|
// $: console.log('viewInfo', $viewInfo);
|
||||||
|
|
||||||
function getTableColumns(table, dbInfo, config, setConfig) {
|
function getTableColumns(table, dbInfo, config, setConfig) {
|
||||||
return table.columns.map(col => new PerspectiveTableColumnDefinition(col, table, dbInfo, config, setConfig, null));
|
return getTableChildPerspectiveNodes(table, dbInfo, config, setConfig, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewColumns(view, dbInfo, config, setConfig) {
|
function getViewColumns(view, dbInfo, config, setConfig) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$: console.log('CFG', config);
|
// $: console.log('CFG', config);
|
||||||
|
|
||||||
$: columns = $tableInfo
|
$: columns = $tableInfo
|
||||||
? getTableColumns($tableInfo, $dbInfo, config, setConfig)
|
? getTableColumns($tableInfo, $dbInfo, config, setConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user