2022-06-12 17:30:54 +00:00
|
|
|
<script lang="ts">
|
2022-06-20 20:14:48 +00:00
|
|
|
import {
|
|
|
|
getTableChildPerspectiveNodes,
|
|
|
|
PerspectiveDataLoadProps,
|
2022-07-21 09:26:44 +00:00
|
|
|
PerspectiveDataProvider,
|
2022-06-20 20:14:48 +00:00
|
|
|
PerspectiveTableColumnNode,
|
|
|
|
PerspectiveTableNode,
|
|
|
|
} 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-07-21 10:33:29 +00:00
|
|
|
import debug from 'debug';
|
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-20 20:14:48 +00:00
|
|
|
import PerspectiveTable from './PerspectiveTable.svelte';
|
|
|
|
import { apiCall } from '../utility/api';
|
|
|
|
import { Select } from 'dbgate-sqltree';
|
2022-07-21 09:26:44 +00:00
|
|
|
import ManagerInnerContainer from '../elements/ManagerInnerContainer.svelte';
|
2022-07-21 10:33:29 +00:00
|
|
|
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
|
2022-07-21 13:43:17 +00:00
|
|
|
import stableStringify from 'json-stable-stringify';
|
|
|
|
import createRef from '../utility/createRef';
|
|
|
|
import { tick } from 'svelte';
|
2022-07-21 10:33:29 +00:00
|
|
|
|
|
|
|
const dbg = debug('dbgate:PerspectiveView');
|
2022-06-12 17:30:54 +00:00
|
|
|
|
|
|
|
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-07-21 15:05:07 +00:00
|
|
|
export let loadedCounts;
|
2022-06-16 15:05:42 +00:00
|
|
|
|
2022-07-21 09:26:44 +00:00
|
|
|
export let cache;
|
|
|
|
|
2022-06-12 17:30:54 +00:00
|
|
|
let managerSize;
|
2022-07-21 13:43:17 +00:00
|
|
|
let nextCacheRef = createRef(null);
|
2022-06-12 17:30:54 +00:00
|
|
|
|
|
|
|
$: 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-07-21 13:43:17 +00:00
|
|
|
$: dataProvider = new PerspectiveDataProvider(cache, loader);
|
|
|
|
$: loader = new PerspectiveDataLoader(apiCall);
|
2022-07-21 10:33:29 +00:00
|
|
|
$: root = $tableInfo
|
2022-07-21 15:05:07 +00:00
|
|
|
? new PerspectiveTableNode(
|
|
|
|
$tableInfo,
|
|
|
|
$dbInfo,
|
|
|
|
config,
|
|
|
|
setConfig,
|
|
|
|
dataProvider,
|
|
|
|
{ conid, database },
|
|
|
|
null
|
|
|
|
)
|
2022-07-21 10:33:29 +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%">
|
2022-06-30 19:14:56 +00:00
|
|
|
<ManagerInnerContainer width={managerSize}>
|
|
|
|
{#if root}
|
|
|
|
<PerspectiveTree {root} />
|
|
|
|
{/if}
|
|
|
|
</ManagerInnerContainer>
|
2022-06-12 17:30:54 +00:00
|
|
|
</WidgetColumnBarItem>
|
|
|
|
</WidgetColumnBar>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<svelte:fragment slot="2">
|
2022-07-28 16:57:15 +00:00
|
|
|
<PerspectiveTable {root} {loadedCounts} {setConfig} />
|
2022-06-12 17:30:54 +00:00
|
|
|
</svelte:fragment>
|
|
|
|
</HorizontalSplitter>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.left {
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
background-color: var(--theme-bg-0);
|
|
|
|
}
|
|
|
|
</style>
|