refresh schema list

This commit is contained in:
Jan Prochazka
2024-09-19 11:15:44 +02:00
parent 3e5b45de8f
commit 9eb27f5e92
4 changed files with 40 additions and 16 deletions

View File

@@ -199,7 +199,7 @@ module.exports = {
return res.result || null; return res.result || null;
}, },
async loadDataCore(msgtype, { conid, database, ...args }, req) { async loadDataCore(msgtype, { conid, database, ...args }, req) {
testConnectionPermission(conid, req); testConnectionPermission(conid, req);
const opened = await this.ensureOpened(conid, database); const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype, ...args }); const res = await this.sendRequest(opened, { msgtype, ...args });
@@ -219,6 +219,11 @@ module.exports = {
return this.loadDataCore('schemaList', { conid, database }); return this.loadDataCore('schemaList', { conid, database });
}, },
dispatchDatabaseChangedEvent_meta: true,
dispatchDatabaseChangedEvent({ event, conid, database }) {
socket.emitChanged(event, { conid, database });
},
loadKeys_meta: true, loadKeys_meta: true,
async loadKeys({ conid, database, root, filter }, req) { async loadKeys({ conid, database, root, filter }, req) {
testConnectionPermission(conid, req); testConnectionPermission(conid, req);

View File

@@ -1,4 +1,4 @@
<script context="module"> <script context="module" lang="ts">
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) { export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
const resp = await apiCall('database-connections/run-script', { const resp = await apiCall('database-connections/run-script', {
conid, conid,
@@ -15,7 +15,7 @@
} }
} }
export async function runOperationOnDatabase({ conid, database }, operation, syncModel = true) { export async function runOperationOnDatabase({ conid, database }, operation, syncModel: string | boolean = true) {
const resp = await apiCall('database-connections/run-operation', { const resp = await apiCall('database-connections/run-operation', {
conid, conid,
database, database,
@@ -27,7 +27,11 @@
showModal(ErrorMessageModal, { title: 'Error when executing operation', message: errorMessage }); showModal(ErrorMessageModal, { title: 'Error when executing operation', message: errorMessage });
} else { } else {
showSnackbarSuccess('Saved to database'); showSnackbarSuccess('Saved to database');
if (syncModel) apiCall('database-connections/sync-model', { conid, database }); if (_.isString(syncModel)) {
apiCall('database-connections/dispatch-database-changed-event', { event: syncModel, conid, database });
} else if (syncModel) {
apiCall('database-connections/sync-model', { conid, database });
}
} }
} }
</script> </script>

View File

@@ -42,7 +42,7 @@
return res; return res;
} }
$: schemaList = _.uniq( $: realSchemaList = _.uniq(
_.compact([selectedSchema, ...Object.keys(countBySchema), ...(schemaList?.map(x => x.schemaName) ?? [])]) _.compact([selectedSchema, ...Object.keys(countBySchema), ...(schemaList?.map(x => x.schemaName) ?? [])])
); );
$: countBySchema = computeCountBySchema(objectList ?? []); $: countBySchema = computeCountBySchema(objectList ?? []);
@@ -54,10 +54,14 @@
label: 'Schema name', label: 'Schema name',
onConfirm: async name => { onConfirm: async name => {
const dbid = { conid, database }; const dbid = { conid, database };
await runOperationOnDatabase(dbid, { await runOperationOnDatabase(
type: 'createSchema', dbid,
schemaName: name, {
}); type: 'createSchema',
schemaName: name,
},
'schema-list-changed'
);
if (selectedSchema) { if (selectedSchema) {
selectedSchema = name; selectedSchema = name;
} }
@@ -69,10 +73,14 @@
message: `Really drop schema ${$appliedCurrentSchema}?`, message: `Really drop schema ${$appliedCurrentSchema}?`,
onConfirm: async () => { onConfirm: async () => {
const dbid = { conid, database }; const dbid = { conid, database };
runOperationOnDatabase(dbid, { runOperationOnDatabase(
type: 'dropSchema', dbid,
schemaName: $appliedCurrentSchema, {
}); type: 'dropSchema',
schemaName: $appliedCurrentSchema,
},
'schema-list-changed'
);
selectedSchema = null; selectedSchema = null;
}, },
}); });
@@ -81,14 +89,14 @@
$: selectedSchema = localStorage.getItem(valueStorageKey ?? ''); $: selectedSchema = localStorage.getItem(valueStorageKey ?? '');
</script> </script>
{#if schemaList.length > 0} {#if realSchemaList.length > 0}
<div class="wrapper"> <div class="wrapper">
<div class="mr-1">Schema:</div> <div class="mr-1">Schema:</div>
<SelectField <SelectField
isNative isNative
options={[ options={[
{ label: `All schemas (${objectList?.length ?? 0})`, value: '' }, { label: `All schemas (${objectList?.length ?? 0})`, value: '' },
...schemaList.map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })), ...realSchemaList.map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
// ...schemaList.filter(x => countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })), // ...schemaList.filter(x => countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
// ...schemaList.filter(x => !countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })), // ...schemaList.filter(x => !countBySchema[x]).map(x => ({ label: `${x} (${countBySchema[x] ?? 0})`, value: x })),
]} ]}

View File

@@ -16,7 +16,13 @@
import InlineButton from '../buttons/InlineButton.svelte'; import InlineButton from '../buttons/InlineButton.svelte';
import SearchInput from '../elements/SearchInput.svelte'; import SearchInput from '../elements/SearchInput.svelte';
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte'; import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
import { useConnectionInfo, useDatabaseInfo, useDatabaseStatus, useSchemaList, useUsedApps } from '../utility/metadataLoaders'; import {
useConnectionInfo,
useDatabaseInfo,
useDatabaseStatus,
useSchemaList,
useUsedApps,
} from '../utility/metadataLoaders';
import SearchBoxWrapper from '../elements/SearchBoxWrapper.svelte'; import SearchBoxWrapper from '../elements/SearchBoxWrapper.svelte';
import AppObjectList from '../appobj/AppObjectList.svelte'; import AppObjectList from '../appobj/AppObjectList.svelte';
import _ from 'lodash'; import _ from 'lodash';
@@ -80,6 +86,7 @@
const handleRefreshDatabase = () => { const handleRefreshDatabase = () => {
apiCall('database-connections/refresh', { conid, database }); apiCall('database-connections/refresh', { conid, database });
apiCall('database-connections/dispatch-database-changed-event', { event: 'schema-list-changed', conid, database });
}; };
function createAddMenu() { function createAddMenu() {