mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 23:46:23 +00:00
perspective WIP
This commit is contained in:
@@ -1,14 +1,47 @@
|
|||||||
import { ColumnInfo, ForeignKeyInfo, TableInfo } from 'dbgate-types';
|
import { ColumnInfo, DatabaseInfo, ForeignKeyInfo, TableInfo } from 'dbgate-types';
|
||||||
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 PerspectiveColumnDefinition {
|
||||||
|
constructor(
|
||||||
|
public config: PerspectiveConfig,
|
||||||
|
public setConfig: ChangePerspectiveConfigFunc,
|
||||||
|
public parentColumn: PerspectiveTableColumnDefinition
|
||||||
|
) {}
|
||||||
abstract get title();
|
abstract get title();
|
||||||
|
abstract get codeName();
|
||||||
abstract get props();
|
abstract get props();
|
||||||
abstract get isExpanded();
|
|
||||||
abstract get isExpandable();
|
abstract get isExpandable();
|
||||||
abstract get level();
|
abstract get childColumns(): PerspectiveColumnDefinition[];
|
||||||
abstract toggleExpanded();
|
get uniqueName() {
|
||||||
|
if (this.parentColumn) return `${this.parentColumn.uniqueName}.${this.codeName}`;
|
||||||
|
return this.codeName;
|
||||||
|
}
|
||||||
|
get level() {
|
||||||
|
if (this.parentColumn) return this.parentColumn.level + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
get isExpanded() {
|
||||||
|
return this.config.expandedColumns.includes(this.uniqueName);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleExpanded(value?: boolean) {
|
||||||
|
this.includeInColumnSet('expandedColumns', this.uniqueName, value == null ? !this.isExpanded : value);
|
||||||
|
}
|
||||||
|
|
||||||
|
includeInColumnSet(field: keyof PerspectiveConfig, uniqueName: string, isIncluded: boolean) {
|
||||||
|
if (isIncluded) {
|
||||||
|
this.setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
[field]: [...(cfg[field] || []), uniqueName],
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
this.setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
[field]: (cfg[field] || []).filter(x => x != uniqueName),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinition {
|
export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinition {
|
||||||
@@ -16,16 +49,22 @@ export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinitio
|
|||||||
constructor(
|
constructor(
|
||||||
public column: ColumnInfo,
|
public column: ColumnInfo,
|
||||||
public table: TableInfo,
|
public table: TableInfo,
|
||||||
public config: PerspectiveConfig,
|
public db: DatabaseInfo,
|
||||||
public setConfig: ChangePerspectiveConfigFunc
|
config: PerspectiveConfig,
|
||||||
|
setConfig: ChangePerspectiveConfigFunc,
|
||||||
|
parentColumn: PerspectiveTableColumnDefinition
|
||||||
) {
|
) {
|
||||||
super();
|
super(config, setConfig, parentColumn);
|
||||||
|
|
||||||
this.foreignKey =
|
this.foreignKey =
|
||||||
table.foreignKeys &&
|
table.foreignKeys &&
|
||||||
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 codeName() {
|
||||||
|
return this.column.columnName;
|
||||||
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
return this.column.columnName;
|
return this.column.columnName;
|
||||||
}
|
}
|
||||||
@@ -34,17 +73,19 @@ export class PerspectiveTableColumnDefinition extends PerspectiveColumnDefinitio
|
|||||||
return this.column;
|
return this.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isExpanded() {
|
|
||||||
return this.config.expandedColumns.includes(this.column.uniqueName);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isExpandable() {
|
get isExpandable() {
|
||||||
return !!this.foreignKey;
|
return !!this.foreignKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
get level() {
|
get childColumns(): PerspectiveColumnDefinition[] {
|
||||||
return 0;
|
if (!this.foreignKey) return [];
|
||||||
|
const tbl = this?.db?.tables?.find(
|
||||||
|
x => x.pureName == this.foreignKey?.refTableName && x.schemaName == this.foreignKey?.refSchemaName
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
tbl?.columns?.map(
|
||||||
|
col => new PerspectiveTableColumnDefinition(col, tbl, this.db, this.config, this.setConfig, this)
|
||||||
|
) || []
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleExpanded() {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<span class="expandColumnIcon" style={`margin-right: ${5 + column.level * 10}px`}>
|
<span class="expandColumnIcon" style={`margin-right: ${5 + column.level * 10}px`}>
|
||||||
<FontIcon
|
<FontIcon
|
||||||
icon={column.isExpandable ? plusExpandIcon(column.isExpanded) : 'icon invisible-box'}
|
icon={column.isExpandable ? plusExpandIcon(column.isExpanded) : 'icon invisible-box'}
|
||||||
on:click={() => column.togglExpanded()}
|
on:click={() => column.toggleExpanded()}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,23 @@
|
|||||||
import PerspectiveColumnRow from './PerspectiveColumnRow.svelte';
|
import PerspectiveColumnRow from './PerspectiveColumnRow.svelte';
|
||||||
|
|
||||||
export let columns = [];
|
export let columns = [];
|
||||||
|
|
||||||
|
function processFlatColumns(res, columns) {
|
||||||
|
for (const col of columns) {
|
||||||
|
res.push(col);
|
||||||
|
if (col.isExpanded) {
|
||||||
|
processFlatColumns(res, col.childColumns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFlatColumns(columns) {
|
||||||
|
const res = [];
|
||||||
|
processFlatColumns(res, columns);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each columns as column}
|
{#each getFlatColumns(columns) as column}
|
||||||
<PerspectiveColumnRow {column} />
|
<PerspectiveColumnRow {column} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
|
||||||
import { useTableInfo, useViewInfo } from '../utility/metadataLoaders';
|
import { useDatabaseInfo, useTableInfo, useViewInfo } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
|
||||||
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
|
||||||
@@ -32,24 +32,27 @@
|
|||||||
return '300px';
|
return '300px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dbInfo = useDatabaseInfo({ conid, database });
|
||||||
const tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
const tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
||||||
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
||||||
|
|
||||||
// $: console.log('tableInfo', $tableInfo);
|
// $: console.log('tableInfo', $tableInfo);
|
||||||
// $: console.log('viewInfo', $viewInfo);
|
// $: console.log('viewInfo', $viewInfo);
|
||||||
|
|
||||||
function getTableColumns(table, config, setConfig) {
|
function getTableColumns(table, dbInfo, config, setConfig) {
|
||||||
return table.columns.map(col => new PerspectiveTableColumnDefinition(col, table, config, setConfig));
|
return table.columns.map(col => new PerspectiveTableColumnDefinition(col, table, dbInfo, config, setConfig, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewColumns(view, config, setConfig) {
|
function getViewColumns(view, dbInfo, config, setConfig) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: console.log('CFG', config);
|
||||||
|
|
||||||
$: columns = $tableInfo
|
$: columns = $tableInfo
|
||||||
? getTableColumns($tableInfo, config, setConfig)
|
? getTableColumns($tableInfo, $dbInfo, config, setConfig)
|
||||||
: $viewInfo
|
: $viewInfo
|
||||||
? getViewColumns($viewInfo, config, setConfig)
|
? getViewColumns($viewInfo, $dbInfo, config, setConfig)
|
||||||
: null;
|
: null;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user