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 {
constructor(
public table: TableInfo,
public table: TableInfo | ViewInfo,
dbs: MultipleDatabaseInfo,
config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc,
@@ -483,62 +483,62 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
}
}
export class PerspectiveViewNode extends PerspectiveTreeNode {
constructor(
public view: ViewInfo,
dbs: MultipleDatabaseInfo,
config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc,
public dataProvider: PerspectiveDataProvider,
databaseConfig: PerspectiveDatabaseConfig,
parentNode: PerspectiveTreeNode
) {
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
}
// export class PerspectiveViewNode extends PerspectiveTreeNode {
// constructor(
// public view: ViewInfo,
// dbs: MultipleDatabaseInfo,
// config: PerspectiveConfig,
// setConfig: ChangePerspectiveConfigFunc,
// public dataProvider: PerspectiveDataProvider,
// databaseConfig: PerspectiveDatabaseConfig,
// parentNode: PerspectiveTreeNode
// ) {
// super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
// }
getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps {
return {
schemaName: this.view.schemaName,
pureName: this.view.pureName,
dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.view),
condition: this.getChildrenCondition(),
};
}
// getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps {
// return {
// schemaName: this.view.schemaName,
// pureName: this.view.pureName,
// dataColumns: this.getDataLoadColumns(),
// databaseConfig: this.databaseConfig,
// orderBy: this.getOrderBy(this.view),
// condition: this.getChildrenCondition(),
// };
// }
get codeName() {
return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName;
}
// get codeName() {
// return this.view.schemaName ? `${this.view.schemaName}:${this.view.pureName}` : this.view.pureName;
// }
get title() {
return this.view.pureName;
}
// get title() {
// return this.view.pureName;
// }
get isExpandable() {
return true;
}
// get isExpandable() {
// return true;
// }
get childNodes(): PerspectiveTreeNode[] {
return getTableChildPerspectiveNodes(
this.view,
this.dbs,
this.config,
this.setConfig,
this.dataProvider,
this.databaseConfig,
this
);
}
// get childNodes(): PerspectiveTreeNode[] {
// return getTableChildPerspectiveNodes(
// this.view,
// this.dbs,
// this.config,
// this.setConfig,
// this.dataProvider,
// this.databaseConfig,
// this
// );
// }
get icon() {
return 'img table';
}
// get icon() {
// return 'img table';
// }
getBaseTableFromThis() {
return this.view;
}
}
// getBaseTableFromThis() {
// return this.view;
// }
// }
export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
constructor(
@@ -609,7 +609,7 @@ export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
constructor(
public customJoin: PerspectiveCustomJoinConfig,
table: TableInfo,
table: TableInfo | ViewInfo,
dbs: MultipleDatabaseInfo,
config: PerspectiveConfig,
setConfig: ChangePerspectiveConfigFunc,
@@ -730,10 +730,20 @@ export function getTableChildPerspectiveNodes(
if (join.database) newConfig.database = join.database;
const db = dbs?.[newConfig.conid]?.[newConfig.database];
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(
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 SelectField from '../forms/SelectField.svelte';
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 {
ChangePerspectiveConfigFunc,
@@ -52,6 +58,12 @@
schemaName: refSchemaName,
pureName: refTableName,
});
$: refViewInfo = useViewInfo({
conid: conidOverride || conid,
database: databaseOverride || database,
schemaName: refSchemaName,
pureName: refTableName,
});
let columns = editValue?.columns || [];
// let fromTableName = pureName;
@@ -76,7 +88,7 @@
// ];
$: refTableList = [
..._.sortBy($refDbInfo?.tables || [], ['schemaName', 'pureName']),
// ..._.sortBy($dbInfo?.views || [], ['schemaName', 'pureName']),
..._.sortBy($refDbInfo?.views || [], ['schemaName', 'pureName']),
];
let refTableOptions = [];
@@ -221,9 +233,10 @@
const refTable = $refDbInfo?.tables?.find(
x => x.pureName == refTableName && x.schemaName == refSchemaName
);
columns = refTable?.primaryKey?.columns?.map(col => ({
refColumnName: col.columnName,
}));
columns =
refTable?.primaryKey?.columns?.map(col => ({
refColumnName: col.columnName,
})) || [];
}
}}
/>
@@ -265,7 +278,7 @@
value={column.refColumnName}
isNative
notSelected
options={($refTableInfo?.columns || []).map(col => ({
options={($refTableInfo?.columns || $refViewInfo?.columns || []).map(col => ({
label: col.columnName,
value: col.columnName,
}))}

View File

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