mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
dictionary descriptions saved to app
This commit is contained in:
parent
ae861ef1ae
commit
9a486c47b0
@ -186,13 +186,19 @@ module.exports = {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.virtualReferences = [];
|
res.virtualReferences = [];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
res.dictionaryDescriptions = JSON.parse(
|
||||||
|
await fs.readFile(path.join(dir, 'dictionary-descriptions.config.json'), { encoding: 'utf-8' })
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
res.dictionaryDescriptions = [];
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
saveVfk_meta: true,
|
async saveConfigFile(appFolder, filename, filterFunc, newItem) {
|
||||||
async saveVfk({ appFolder, schemaName, pureName, refSchemaName, refTableName, columns }) {
|
const file = path.join(appdir(), appFolder, filename);
|
||||||
const file = path.join(appdir(), appFolder, 'virtual-references.config.json');
|
|
||||||
|
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
@ -201,33 +207,57 @@ module.exports = {
|
|||||||
json = [];
|
json = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (columns.length == 1) {
|
if (filterFunc) {
|
||||||
json = json.filter(
|
json = json.filter(filterFunc);
|
||||||
x =>
|
}
|
||||||
|
|
||||||
|
json = [...json, newItem];
|
||||||
|
|
||||||
|
await fs.writeFile(file, JSON.stringify(json, undefined, 2));
|
||||||
|
|
||||||
|
socket.emitChanged(`app-files-changed-${appFolder}`);
|
||||||
|
socket.emitChanged('used-apps-changed');
|
||||||
|
},
|
||||||
|
|
||||||
|
saveVirtualReference_meta: true,
|
||||||
|
async saveVirtualReference({ appFolder, schemaName, pureName, refSchemaName, refTableName, columns }) {
|
||||||
|
await this.saveConfigFile(
|
||||||
|
appFolder,
|
||||||
|
'virtual-references.config.json',
|
||||||
|
columns.length == 1
|
||||||
|
? x =>
|
||||||
!(
|
!(
|
||||||
x.schemaName == schemaName &&
|
x.schemaName == schemaName &&
|
||||||
x.pureName == pureName &&
|
x.pureName == pureName &&
|
||||||
x.columns.length == 1 &&
|
x.columns.length == 1 &&
|
||||||
x.columns[0].columnName == columns[0].columnName
|
x.columns[0].columnName == columns[0].columnName
|
||||||
)
|
)
|
||||||
);
|
: null,
|
||||||
}
|
|
||||||
|
|
||||||
json = [
|
|
||||||
...json,
|
|
||||||
{
|
{
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
refSchemaName,
|
refSchemaName,
|
||||||
refTableName,
|
refTableName,
|
||||||
columns,
|
columns,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
|
||||||
await fs.writeFile(file, JSON.stringify(json, undefined, 2));
|
saveDictionaryDescription_meta: true,
|
||||||
|
async saveDictionaryDescription({ appFolder, pureName, schemaName, expresssion, columns, delimiter }) {
|
||||||
socket.emitChanged(`app-files-changed-${appFolder}`);
|
await this.saveConfigFile(
|
||||||
socket.emitChanged('used-apps-changed');
|
appFolder,
|
||||||
|
'dictionary-descriptions.config.json',
|
||||||
|
x => !(x.schemaName == schemaName && x.pureName == pureName),
|
||||||
|
{
|
||||||
|
schemaName,
|
||||||
|
pureName,
|
||||||
|
expresssion,
|
||||||
|
columns,
|
||||||
|
delimiter,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -101,10 +101,10 @@ export function extendDatabaseInfoFromApps(db: DatabaseInfo, apps: ApplicationDe
|
|||||||
...(table.foreignKeys || []),
|
...(table.foreignKeys || []),
|
||||||
..._flatten(apps.map(app => app.virtualReferences || []))
|
..._flatten(apps.map(app => app.virtualReferences || []))
|
||||||
.filter(fk => fk.pureName == table.pureName && fk.schemaName == table.schemaName)
|
.filter(fk => fk.pureName == table.pureName && fk.schemaName == table.schemaName)
|
||||||
.map(fk => ({ ...fk, isVirtual: true })),
|
.map(fk => ({ ...fk, constraintType: 'foreignKey', isVirtual: true })),
|
||||||
],
|
],
|
||||||
})),
|
})),
|
||||||
};
|
} as DatabaseInfo;
|
||||||
return addTableDependencies(dbExt);
|
return addTableDependencies(dbExt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
packages/types/appdefs.d.ts
vendored
6
packages/types/appdefs.d.ts
vendored
@ -19,10 +19,10 @@ interface VirtualReferenceDefinition {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ColumnDescriptionDefinition {
|
interface DictionaryDescriptionDefinition {
|
||||||
pureName: string;
|
pureName: string;
|
||||||
schemaName?: string;
|
schemaName?: string;
|
||||||
expresssion?: string;
|
expresssion: string;
|
||||||
columns: string[];
|
columns: string[];
|
||||||
delimiter: string;
|
delimiter: string;
|
||||||
}
|
}
|
||||||
@ -33,5 +33,5 @@ export interface ApplicationDefinition {
|
|||||||
queries: ApplicationQuery[];
|
queries: ApplicationQuery[];
|
||||||
commands: ApplicationCommand[];
|
commands: ApplicationCommand[];
|
||||||
virtualReferences: VirtualReferenceDefinition[];
|
virtualReferences: VirtualReferenceDefinition[];
|
||||||
columnDescriptions: ColumnDescriptionDefinition[];
|
dictionaryDescriptions: DictionaryDescriptionDefinition[];
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import { subscribeConnectionPingers } from './utility/connectionsPinger';
|
import { subscribeConnectionPingers } from './utility/connectionsPinger';
|
||||||
import { subscribePermissionCompiler } from './utility/hasPermission';
|
import { subscribePermissionCompiler } from './utility/hasPermission';
|
||||||
import { apiCall } from './utility/api';
|
import { apiCall } from './utility/api';
|
||||||
|
import { getUsedApps } from './utility/metadataLoaders';
|
||||||
|
|
||||||
let loadedApi = false;
|
let loadedApi = false;
|
||||||
|
|
||||||
@ -30,7 +31,8 @@
|
|||||||
const settings = await apiCall('config/get-settings');
|
const settings = await apiCall('config/get-settings');
|
||||||
const connections = await apiCall('connections/list');
|
const connections = await apiCall('connections/list');
|
||||||
const config = await apiCall('config/get');
|
const config = await apiCall('config/get');
|
||||||
loadedApi = settings && connections && config;
|
const apps = await getUsedApps();
|
||||||
|
loadedApi = settings && connections && config && apps;
|
||||||
|
|
||||||
if (loadedApi) {
|
if (loadedApi) {
|
||||||
subscribeApiDependendStores();
|
subscribeApiDependendStores();
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export const extractKey = props => props.name;
|
export const extractKey = props => props.name;
|
||||||
|
|
||||||
export function filterAppsForDatabase(connection, database, $apps) {
|
|
||||||
const db = (connection?.databases || []).find(x => x.name == database);
|
|
||||||
return $apps.filter(app => db && db[`useApp:${app.name}`]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase, $apps) {
|
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase, $apps) {
|
||||||
const apps = filterAppsForDatabase(connection, name, $apps);
|
const apps = filterAppsForDatabase(connection, name, $apps);
|
||||||
const handleNewQuery = () => {
|
const handleNewQuery = () => {
|
||||||
@ -244,6 +239,7 @@
|
|||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
||||||
|
import { filterAppsForDatabase } from '../utility/appTools';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
export let passProps;
|
export let passProps;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
useConnectionInfo,
|
useConnectionInfo,
|
||||||
|
useConnectionList,
|
||||||
useDatabaseInfo,
|
useDatabaseInfo,
|
||||||
useDatabaseServerVersion,
|
useDatabaseServerVersion,
|
||||||
useServerVersion,
|
useServerVersion,
|
||||||
@ -49,6 +50,7 @@
|
|||||||
$: serverVersion = useDatabaseServerVersion({ conid, database });
|
$: serverVersion = useDatabaseServerVersion({ conid, database });
|
||||||
$: apps = useUsedApps();
|
$: apps = useUsedApps();
|
||||||
$: extendedDbInfo = extendDatabaseInfoFromApps($dbinfo, $apps);
|
$: extendedDbInfo = extendDatabaseInfoFromApps($dbinfo, $apps);
|
||||||
|
$: connections = useConnectionList();
|
||||||
|
|
||||||
// $: console.log('serverVersion', $serverVersion);
|
// $: console.log('serverVersion', $serverVersion);
|
||||||
|
|
||||||
@ -70,7 +72,7 @@
|
|||||||
extendedDbInfo,
|
extendedDbInfo,
|
||||||
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
||||||
$serverVersion,
|
$serverVersion,
|
||||||
table => getDictionaryDescription(table, conid, database)
|
table => getDictionaryDescription(table, conid, database, $apps, $connections)
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@ -86,7 +88,7 @@
|
|||||||
extendedDbInfo,
|
extendedDbInfo,
|
||||||
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
||||||
$serverVersion,
|
$serverVersion,
|
||||||
table => getDictionaryDescription(table, conid, database)
|
table => getDictionaryDescription(table, conid, database, $apps, $connections)
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
@ -9,11 +9,13 @@
|
|||||||
export let name;
|
export let name;
|
||||||
export let options;
|
export let options;
|
||||||
export let isClearable = false;
|
export let isClearable = false;
|
||||||
|
export let selectFieldComponent = SelectField;
|
||||||
|
|
||||||
const { values, setFieldValue } = getFormContext();
|
const { values, setFieldValue } = getFormContext();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SelectField
|
<svelte:component
|
||||||
|
this={selectFieldComponent}
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
value={$values && $values[name]}
|
value={$values && $values[name]}
|
||||||
options={_.compact(options)}
|
options={_.compact(options)}
|
||||||
|
@ -1,47 +1,22 @@
|
|||||||
<script lang="ts" context="module">
|
|
||||||
export async function saveDbToApp(conid, database, app) {
|
|
||||||
if (app == '#new') {
|
|
||||||
const folder = await apiCall('apps/create-folder', { folder: database });
|
|
||||||
|
|
||||||
await apiCall('connections/update-database', {
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
values: {
|
|
||||||
[`useApp:${folder}`]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
await apiCall('connections/update-database', {
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
values: {
|
|
||||||
[`useApp:${app}`]: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { filterAppsForDatabase } from '../appobj/DatabaseAppObject.svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
import SelectField from '../forms/SelectField.svelte';
|
import SelectField from '../forms/SelectField.svelte';
|
||||||
import { currentDatabase } from '../stores';
|
import { currentDatabase } from '../stores';
|
||||||
import { apiCall } from '../utility/api';
|
import { filterAppsForDatabase } from '../utility/appTools';
|
||||||
import { useAppFolders, useUsedApps } from '../utility/metadataLoaders';
|
import { useAppFolders, useUsedApps } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
export let value = '#new';
|
export let value = '#new';
|
||||||
|
export let disableInitialize = false;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
$: appFolders = useAppFolders();
|
$: appFolders = useAppFolders();
|
||||||
$: usedApps = useUsedApps();
|
$: usedApps = useUsedApps();
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (value == '#new' && $currentDatabase) {
|
if (!disableInitialize && value == '#new' && $currentDatabase) {
|
||||||
const filtered = filterAppsForDatabase($currentDatabase.connection, $currentDatabase.name, $usedApps || []);
|
const filtered = filterAppsForDatabase($currentDatabase.connection, $currentDatabase.name, $usedApps || []);
|
||||||
const common = _.intersection(
|
const common = _.intersection(
|
||||||
($appFolders || []).map(x => x.name),
|
($appFolders || []).map(x => x.name),
|
||||||
@ -49,6 +24,7 @@
|
|||||||
);
|
);
|
||||||
if (common.length > 0) {
|
if (common.length > 0) {
|
||||||
value = common[0] as string;
|
value = common[0] as string;
|
||||||
|
dispatch('change', value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,6 +36,7 @@
|
|||||||
{value}
|
{value}
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
value = e.detail;
|
value = e.detail;
|
||||||
|
dispatch('change', value);
|
||||||
}}
|
}}
|
||||||
options={[
|
options={[
|
||||||
{ label: '(New application linked to current DB)', value: '#new' },
|
{ label: '(New application linked to current DB)', value: '#new' },
|
@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import FormProvider from '../forms/FormProvider.svelte';
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
|
import _ from 'lodash';
|
||||||
import FormSubmit from '../forms/FormSubmit.svelte';
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
import { closeCurrentModal } from './modalTools';
|
import { closeCurrentModal } from './modalTools';
|
||||||
import { useTableInfo } from '../utility/metadataLoaders';
|
import { useAppFolders, useConnectionList, useTableInfo, useUsedApps } from '../utility/metadataLoaders';
|
||||||
import TableControl from '../elements/TableControl.svelte';
|
import TableControl from '../elements/TableControl.svelte';
|
||||||
import TextField from '../forms/TextField.svelte';
|
import TextField from '../forms/TextField.svelte';
|
||||||
import FormTextField from '../forms/FormTextField.svelte';
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
@ -19,6 +20,10 @@
|
|||||||
} from '../utility/dictionaryDescriptionTools';
|
} from '../utility/dictionaryDescriptionTools';
|
||||||
import { includes } from 'lodash';
|
import { includes } from 'lodash';
|
||||||
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
||||||
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
|
import TargetApplicationSelect from '../forms/TargetApplicationSelect.svelte';
|
||||||
|
import { currentDatabase } from '../stores';
|
||||||
|
import { filterAppsForDatabase } from '../utility/appTools';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
@ -28,18 +33,41 @@
|
|||||||
|
|
||||||
$: tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
$: tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
||||||
|
|
||||||
$: descriptionInfo = getDictionaryDescription($tableInfo, conid, database, true);
|
$: apps = useUsedApps();
|
||||||
|
$: appFolders = useAppFolders();
|
||||||
|
$: connections = useConnectionList();
|
||||||
|
|
||||||
const values = writable({});
|
$: descriptionInfo = getDictionaryDescription($tableInfo, conid, database, $apps, $connections, true);
|
||||||
|
|
||||||
|
const values = writable({ targetApplication: '#new' } as any);
|
||||||
|
|
||||||
function initValues(descriptionInfo) {
|
function initValues(descriptionInfo) {
|
||||||
$values = {
|
$values = {
|
||||||
|
targetApplication: $values.targetApplication,
|
||||||
columns: descriptionInfo.expression,
|
columns: descriptionInfo.expression,
|
||||||
delimiter: descriptionInfo.delimiter,
|
delimiter: descriptionInfo.delimiter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (descriptionInfo) initValues(descriptionInfo);
|
$: {
|
||||||
|
if (descriptionInfo) initValues(descriptionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if ($values.targetApplication == '#new' && $currentDatabase) {
|
||||||
|
const filtered = filterAppsForDatabase($currentDatabase.connection, $currentDatabase.name, $apps || []);
|
||||||
|
const common = _.intersection(
|
||||||
|
($appFolders || []).map(x => x.name),
|
||||||
|
filtered.map(x => x.name)
|
||||||
|
);
|
||||||
|
if (common.length > 0) {
|
||||||
|
$values = {
|
||||||
|
...$values,
|
||||||
|
targetApplication: common[0],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormProviderCore {values}>
|
<FormProviderCore {values}>
|
||||||
@ -75,7 +103,14 @@
|
|||||||
|
|
||||||
<FormTextField name="delimiter" label="Delimiter" />
|
<FormTextField name="delimiter" label="Delimiter" />
|
||||||
|
|
||||||
<FormCheckboxField name="useForAllDatabases" label="Use for all databases" />
|
<FormSelectField
|
||||||
|
label="Target application"
|
||||||
|
name="targetApplication"
|
||||||
|
disableInitialize
|
||||||
|
selectFieldComponent={TargetApplicationSelect}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- <FormCheckboxField name="useForAllDatabases" label="Use for all databases" /> -->
|
||||||
|
|
||||||
<svelte:fragment slot="footer">
|
<svelte:fragment slot="footer">
|
||||||
<FormSubmit
|
<FormSubmit
|
||||||
@ -89,7 +124,7 @@
|
|||||||
database,
|
database,
|
||||||
$values.columns,
|
$values.columns,
|
||||||
$values.delimiter,
|
$values.delimiter,
|
||||||
$values.useForAllDatabases
|
$values.targetApplication
|
||||||
);
|
);
|
||||||
onConfirm();
|
onConfirm();
|
||||||
}}
|
}}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import { closeCurrentModal, showModal } from './modalTools';
|
import { closeCurrentModal, showModal } from './modalTools';
|
||||||
import DefineDictionaryDescriptionModal from './DefineDictionaryDescriptionModal.svelte';
|
import DefineDictionaryDescriptionModal from './DefineDictionaryDescriptionModal.svelte';
|
||||||
import ScrollableTableControl from '../elements/ScrollableTableControl.svelte';
|
import ScrollableTableControl from '../elements/ScrollableTableControl.svelte';
|
||||||
import { getTableInfo } from '../utility/metadataLoaders';
|
import { getTableInfo, useConnectionList, useUsedApps } from '../utility/metadataLoaders';
|
||||||
import { getDictionaryDescription } from '../utility/dictionaryDescriptionTools';
|
import { getDictionaryDescription } from '../utility/dictionaryDescriptionTools';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { dumpSqlSelect } from 'dbgate-sqltree';
|
import { dumpSqlSelect } from 'dbgate-sqltree';
|
||||||
@ -33,6 +33,9 @@
|
|||||||
|
|
||||||
let checkedKeys = [];
|
let checkedKeys = [];
|
||||||
|
|
||||||
|
$: apps = useUsedApps();
|
||||||
|
$: connections = useConnectionList();
|
||||||
|
|
||||||
function defineDescription() {
|
function defineDescription() {
|
||||||
showModal(DefineDictionaryDescriptionModal, {
|
showModal(DefineDictionaryDescriptionModal, {
|
||||||
conid,
|
conid,
|
||||||
@ -45,7 +48,7 @@
|
|||||||
|
|
||||||
async function reload() {
|
async function reload() {
|
||||||
tableInfo = await getTableInfo({ conid, database, schemaName, pureName });
|
tableInfo = await getTableInfo({ conid, database, schemaName, pureName });
|
||||||
description = getDictionaryDescription(tableInfo, conid, database);
|
description = getDictionaryDescription(tableInfo, conid, database, $apps, $connections);
|
||||||
|
|
||||||
if (!tableInfo || !description) return;
|
if (!tableInfo || !description) return;
|
||||||
if (tableInfo?.primaryKey?.columns?.length != 1) return;
|
if (tableInfo?.primaryKey?.columns?.length != 1) return;
|
||||||
@ -112,6 +115,8 @@
|
|||||||
|
|
||||||
$: {
|
$: {
|
||||||
search;
|
search;
|
||||||
|
$apps;
|
||||||
|
$connections;
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { useDatabaseInfo, useTableInfo } from '../utility/metadataLoaders';
|
import { useDatabaseInfo, useTableInfo } from '../utility/metadataLoaders';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import TargetApplicationSelect, { saveDbToApp } from '../elements/TargetApplicationSelect.svelte';
|
import TargetApplicationSelect from '../forms/TargetApplicationSelect.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
|
import { saveDbToApp } from '../utility/appTools';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
@ -155,7 +156,7 @@
|
|||||||
value={'Save'}
|
value={'Save'}
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
const appFolder = await saveDbToApp(conid, database, dstApp);
|
const appFolder = await saveDbToApp(conid, database, dstApp);
|
||||||
await apiCall('apps/save-vfk', {
|
await apiCall('apps/save-virtual-reference', {
|
||||||
appFolder,
|
appFolder,
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
|
33
packages/web/src/utility/appTools.ts
Normal file
33
packages/web/src/utility/appTools.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { ApplicationDefinition, StoredConnection } from 'dbgate-types';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
|
|
||||||
|
export async function saveDbToApp(conid: string, database: string, app: string) {
|
||||||
|
if (app == '#new') {
|
||||||
|
const folder = await apiCall('apps/create-folder', { folder: database });
|
||||||
|
|
||||||
|
await apiCall('connections/update-database', {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
values: {
|
||||||
|
[`useApp:${folder}`]: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
await apiCall('connections/update-database', {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
values: {
|
||||||
|
[`useApp:${app}`]: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function filterAppsForDatabase(connection, database: string, $apps): ApplicationDefinition[] {
|
||||||
|
const db = (connection?.databases || []).find(x => x.name == database);
|
||||||
|
return $apps.filter(app => db && db[`useApp:${app.name}`]);
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import { DictionaryDescription } from 'dbgate-datalib';
|
import { DictionaryDescription } from 'dbgate-datalib';
|
||||||
import { TableInfo } from 'dbgate-types';
|
import { ApplicationDefinition, TableInfo } from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { getLocalStorage, setLocalStorage, removeLocalStorage } from './storageCache';
|
import { apiCall } from './api';
|
||||||
|
import { filterAppsForDatabase, saveDbToApp } from './appTools';
|
||||||
|
|
||||||
function checkDescriptionColumns(columns: string[], table: TableInfo) {
|
function checkDescriptionColumns(columns: string[], table: TableInfo) {
|
||||||
if (!columns?.length) return false;
|
if (!columns?.length) return false;
|
||||||
@ -14,17 +15,20 @@ export function getDictionaryDescription(
|
|||||||
table: TableInfo,
|
table: TableInfo,
|
||||||
conid: string,
|
conid: string,
|
||||||
database: string,
|
database: string,
|
||||||
|
apps: ApplicationDefinition[],
|
||||||
|
connections,
|
||||||
skipCheckSaved: boolean = false
|
skipCheckSaved: boolean = false
|
||||||
): DictionaryDescription {
|
): DictionaryDescription {
|
||||||
const keySpecific = `dictionary_spec_${table.schemaName}||${table.pureName}||${conid}||${database}`;
|
const conn = connections.find(x => x._id == conid);
|
||||||
const keyCommon = `dictionary_spec_${table.schemaName}||${table.pureName}`;
|
const dbApps = filterAppsForDatabase(conn, database, apps);
|
||||||
|
|
||||||
const cachedSpecific = getLocalStorage(keySpecific);
|
const cached = _.flatten(dbApps.map(x => x.dictionaryDescriptions || [])).find(
|
||||||
const cachedCommon = getLocalStorage(keyCommon);
|
x => x.pureName == table.pureName && x.schemaName == table.schemaName
|
||||||
|
);
|
||||||
|
|
||||||
if (cachedSpecific && (skipCheckSaved || checkDescriptionColumns(cachedSpecific.columns, table)))
|
if (cached && (skipCheckSaved || checkDescriptionColumns(cached.columns, table))) {
|
||||||
return cachedSpecific;
|
return cached;
|
||||||
if (cachedCommon && (skipCheckSaved || checkDescriptionColumns(cachedCommon.columns, table))) return cachedCommon;
|
}
|
||||||
|
|
||||||
const descColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
|
const descColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
|
||||||
if (descColumn) {
|
if (descColumn) {
|
||||||
@ -57,29 +61,22 @@ export function changeDelimitedColumnList(columns, columnName, isChecked) {
|
|||||||
return parsed.join(',');
|
return parsed.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveDictionaryDescription(
|
export async function saveDictionaryDescription(
|
||||||
table: TableInfo,
|
table: TableInfo,
|
||||||
conid: string,
|
conid: string,
|
||||||
database: string,
|
database: string,
|
||||||
expression: string,
|
expression: string,
|
||||||
delimiter: string,
|
delimiter: string,
|
||||||
useForAllDatabases: boolean
|
targetApplication: string
|
||||||
) {
|
) {
|
||||||
const keySpecific = `dictionary_spec_${table.schemaName}||${table.pureName}||${conid}||${database}`;
|
const appFolder = await saveDbToApp(conid, database, targetApplication);
|
||||||
const keyCommon = `dictionary_spec_${table.schemaName}||${table.pureName}`;
|
|
||||||
|
|
||||||
removeLocalStorage(keySpecific);
|
await apiCall('apps/save-dictionary-description', {
|
||||||
if (useForAllDatabases) removeLocalStorage(keyCommon);
|
appFolder,
|
||||||
|
schemaName: table.schemaName,
|
||||||
const description = {
|
pureName: table.pureName,
|
||||||
columns: parseDelimitedColumnList(expression),
|
columns: parseDelimitedColumnList(expression),
|
||||||
expression,
|
expression,
|
||||||
delimiter,
|
delimiter,
|
||||||
};
|
});
|
||||||
|
|
||||||
if (useForAllDatabases) {
|
|
||||||
setLocalStorage(keyCommon, description);
|
|
||||||
} else {
|
|
||||||
setLocalStorage(keySpecific, description);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user