perspective custom joins supports views

This commit is contained in:
Jan Prochazka
2022-08-06 17:03:48 +02:00
parent 86d7d61cc5
commit cc019281d4
3 changed files with 94 additions and 65 deletions

View File

@@ -415,7 +415,7 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
export class PerspectiveTableNode extends PerspectiveTreeNode { export class PerspectiveTableNode extends PerspectiveTreeNode {
constructor( constructor(
public table: TableInfo, public table: TableInfo | ViewInfo,
dbs: MultipleDatabaseInfo, dbs: MultipleDatabaseInfo,
config: PerspectiveConfig, config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc, setConfig: ChangePerspectiveConfigFunc,
@@ -483,62 +483,62 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
} }
} }
export class PerspectiveViewNode extends PerspectiveTreeNode { // export class PerspectiveViewNode extends PerspectiveTreeNode {
constructor( // constructor(
public view: ViewInfo, // public view: ViewInfo,
dbs: MultipleDatabaseInfo, // dbs: MultipleDatabaseInfo,
config: PerspectiveConfig, // config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc, // setConfig: ChangePerspectiveConfigFunc,
public dataProvider: PerspectiveDataProvider, // public dataProvider: PerspectiveDataProvider,
databaseConfig: PerspectiveDatabaseConfig, // databaseConfig: PerspectiveDatabaseConfig,
parentNode: PerspectiveTreeNode // parentNode: PerspectiveTreeNode
) { // ) {
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig); // super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
} // }
getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps { // getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps {
return { // return {
schemaName: this.view.schemaName, // schemaName: this.view.schemaName,
pureName: this.view.pureName, // pureName: this.view.pureName,
dataColumns: this.getDataLoadColumns(), // dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, // databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.view), // orderBy: this.getOrderBy(this.view),
condition: this.getChildrenCondition(), // condition: this.getChildrenCondition(),
}; // };
} // }
get codeName() { // get codeName() {
return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName; // return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName;
} // }
get title() { // get title() {
return this.view.pureName; // return this.view.pureName;
} // }
get isExpandable() { // get isExpandable() {
return true; // return true;
} // }
get childNodes(): PerspectiveTreeNode[] { // get childNodes(): PerspectiveTreeNode[] {
return getTableChildPerspectiveNodes( // return getTableChildPerspectiveNodes(
this.view, // this.view,
this.dbs, // this.dbs,
this.config, // this.config,
this.setConfig, // this.setConfig,
this.dataProvider, // this.dataProvider,
this.databaseConfig, // this.databaseConfig,
this // this
); // );
} // }
get icon() { // get icon() {
return 'img table'; // return 'img table';
} // }
getBaseTableFromThis() { // getBaseTableFromThis() {
return this.view; // return this.view;
} // }
} // }
export class PerspectiveTableReferenceNode extends PerspectiveTableNode { export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
constructor( constructor(
@@ -609,7 +609,7 @@ export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode { export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
constructor( constructor(
public customJoin: PerspectiveCustomJoinConfig, public customJoin: PerspectiveCustomJoinConfig,
table: TableInfo, table: TableInfo | ViewInfo,
dbs: MultipleDatabaseInfo, dbs: MultipleDatabaseInfo,
config: PerspectiveConfig, config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc, setConfig: ChangePerspectiveConfigFunc,
@@ -730,10 +730,20 @@ export function getTableChildPerspectiveNodes(
if (join.database) newConfig.database = join.database; if (join.database) newConfig.database = join.database;
const db = dbs?.[newConfig.conid]?.[newConfig.database]; const db = dbs?.[newConfig.conid]?.[newConfig.database];
const table = db?.tables?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName); const table = db?.tables?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
const view = db?.views?.find(x => x.pureName == join.refTableName && x.schemaName == join.refSchemaName);
if (table) { if (table || view) {
customs.push( customs.push(
new PerspectiveCustomJoinTreeNode(join, table, dbs, config, setConfig, dataProvider, newConfig, parentColumn) new PerspectiveCustomJoinTreeNode(
join,
table || view,
dbs,
config,
setConfig,
dataProvider,
newConfig,
parentColumn
)
); );
} }
} }

View File

@@ -8,7 +8,13 @@
import { fullNameFromString, fullNameToLabel, fullNameToString } from 'dbgate-tools'; import { fullNameFromString, fullNameToLabel, fullNameToString } from 'dbgate-tools';
import SelectField from '../forms/SelectField.svelte'; import SelectField from '../forms/SelectField.svelte';
import _ from 'lodash'; import _ from 'lodash';
import { useConnectionList, useDatabaseInfo, useDatabaseList, useTableInfo } from '../utility/metadataLoaders'; import {
useConnectionList,
useDatabaseInfo,
useDatabaseList,
useTableInfo,
useViewInfo,
} from '../utility/metadataLoaders';
import { onMount, tick } from 'svelte'; import { onMount, tick } from 'svelte';
import { import {
ChangePerspectiveConfigFunc, ChangePerspectiveConfigFunc,
@@ -52,6 +58,12 @@
schemaName: refSchemaName, schemaName: refSchemaName,
pureName: refTableName, pureName: refTableName,
}); });
$: refViewInfo = useViewInfo({
conid: conidOverride || conid,
database: databaseOverride || database,
schemaName: refSchemaName,
pureName: refTableName,
});
let columns = editValue?.columns || []; let columns = editValue?.columns || [];
// let fromTableName = pureName; // let fromTableName = pureName;
@@ -76,7 +88,7 @@
// ]; // ];
$: refTableList = [ $: refTableList = [
..._.sortBy($refDbInfo?.tables || [], ['schemaName', 'pureName']), ..._.sortBy($refDbInfo?.tables || [], ['schemaName', 'pureName']),
// ..._.sortBy($dbInfo?.views || [], ['schemaName', 'pureName']), ..._.sortBy($refDbInfo?.views || [], ['schemaName', 'pureName']),
]; ];
let refTableOptions = []; let refTableOptions = [];
@@ -221,9 +233,10 @@
const refTable = $refDbInfo?.tables?.find( const refTable = $refDbInfo?.tables?.find(
x => x.pureName == refTableName && x.schemaName == refSchemaName x => x.pureName == refTableName && x.schemaName == refSchemaName
); );
columns = refTable?.primaryKey?.columns?.map(col => ({ columns =
refTable?.primaryKey?.columns?.map(col => ({
refColumnName: col.columnName, refColumnName: col.columnName,
})); })) || [];
} }
}} }}
/> />
@@ -265,7 +278,7 @@
value={column.refColumnName} value={column.refColumnName}
isNative isNative
notSelected notSelected
options={($refTableInfo?.columns || []).map(col => ({ options={($refTableInfo?.columns || $refViewInfo?.columns || []).map(col => ({
label: col.columnName, label: col.columnName,
value: col.columnName, value: col.columnName,
}))} }))}

View File

@@ -25,7 +25,6 @@
PerspectiveDataProvider, PerspectiveDataProvider,
PerspectiveTableColumnNode, PerspectiveTableColumnNode,
PerspectiveTableNode, PerspectiveTableNode,
PerspectiveViewNode,
} from 'dbgate-datalib'; } from 'dbgate-datalib';
import _ from 'lodash'; import _ from 'lodash';
@@ -103,10 +102,17 @@
$: dataProvider = new PerspectiveDataProvider(cache, loader); $: dataProvider = new PerspectiveDataProvider(cache, loader);
$: loader = new PerspectiveDataLoader(apiCall); $: loader = new PerspectiveDataLoader(apiCall);
$: root = $tableInfo $: root =
? new PerspectiveTableNode($tableInfo, $dbInfos, config, setConfig, dataProvider, { conid, database }, null) $tableInfo || $viewInfo
: $viewInfo ? new PerspectiveTableNode(
? new PerspectiveViewNode($viewInfo, $dbInfos, config, setConfig, dataProvider, { conid, database }, null) $tableInfo || $viewInfo,
$dbInfos,
config,
setConfig,
dataProvider,
{ conid, database },
null
)
: null; : null;
// $: console.log('CONFIG', config); // $: console.log('CONFIG', config);