dbgate/packages/web/src/perspectives/PerspectiveView.svelte

82 lines
2.3 KiB
Svelte
Raw Normal View History

2022-06-12 17:30:54 +00:00
<script lang="ts">
2022-06-18 06:00:00 +00:00
import { getTableChildPerspectiveNodes, PerspectiveTableColumnNode } from 'dbgate-datalib';
2022-06-16 15:05:42 +00:00
2022-06-12 17:30:54 +00:00
import _ from 'lodash';
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
2022-06-17 20:30:10 +00:00
import { useDatabaseInfo, useTableInfo, useViewInfo } from '../utility/metadataLoaders';
2022-06-12 17:30:54 +00:00
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
2022-06-18 06:46:40 +00:00
import PerspectiveTree from './PerspectiveTree.svelte';
2022-06-12 17:30:54 +00:00
import PerspectiveCore from './PerspectiveCore.svelte';
export let conid;
export let database;
export let schemaName;
export let pureName;
2022-06-16 15:05:42 +00:00
export let config;
export let setConfig;
2022-06-12 17:30:54 +00:00
let managerSize;
$: if (managerSize) setLocalStorage('perspectiveManagerWidth', managerSize);
function getInitialManagerSize() {
const width = getLocalStorage('perspectiveManagerWidth');
if (_.isNumber(width) && width > 30 && width < 500) {
return `${width}px`;
}
return '300px';
}
2022-06-17 20:30:10 +00:00
const dbInfo = useDatabaseInfo({ conid, database });
2022-06-12 17:30:54 +00:00
const tableInfo = useTableInfo({ conid, database, schemaName, pureName });
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
2022-06-16 15:05:42 +00:00
// $: console.log('tableInfo', $tableInfo);
// $: console.log('viewInfo', $viewInfo);
2022-06-18 06:46:40 +00:00
function getTableNodes(table, dbInfo, config, setConfig) {
2022-06-18 06:00:00 +00:00
return getTableChildPerspectiveNodes(table, dbInfo, config, setConfig, null);
2022-06-16 15:05:42 +00:00
}
2022-06-18 06:46:40 +00:00
function getViewNodes(view, dbInfo, config, setConfig) {
2022-06-16 15:05:42 +00:00
return [];
}
2022-06-18 06:00:00 +00:00
// $: console.log('CFG', config);
2022-06-17 20:30:10 +00:00
2022-06-18 06:46:40 +00:00
$: nodes = $tableInfo
? getTableNodes($tableInfo, $dbInfo, config, setConfig)
2022-06-16 15:05:42 +00:00
: $viewInfo
2022-06-18 06:46:40 +00:00
? getViewNodes($viewInfo, $dbInfo, config, setConfig)
2022-06-16 15:05:42 +00:00
: null;
2022-06-12 17:30:54 +00:00
</script>
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
<div class="left" slot="1">
<WidgetColumnBar>
2022-06-18 06:46:40 +00:00
<WidgetColumnBarItem title="Choose data" name="perspectiveTree" height="45%">
{#if nodes}
<PerspectiveTree {nodes} />
2022-06-16 15:05:42 +00:00
{/if}
2022-06-12 17:30:54 +00:00
</WidgetColumnBarItem>
</WidgetColumnBar>
</div>
<svelte:fragment slot="2">
<PerspectiveCore />
</svelte:fragment>
</HorizontalSplitter>
<style>
.left {
display: flex;
flex: 1;
background-color: var(--theme-bg-0);
}
</style>