show app state for current database

This commit is contained in:
Jan Prochazka 2022-01-29 12:42:00 +01:00
parent 83f60f863c
commit ae861ef1ae

View File

@ -4,7 +4,7 @@
</script>
<script lang="ts">
import _ from 'lodash';
import _, { find } from 'lodash';
import { filterName } from 'dbgate-tools';
import { currentApplication, currentDatabase } from '../stores';
@ -14,9 +14,12 @@
import ConfirmModal from '../modals/ConfirmModal.svelte';
import InputTextModal from '../modals/InputTextModal.svelte';
import { apiCall } from '../utility/api';
import { useConnectionList } from '../utility/metadataLoaders';
export let data;
$: connections = useConnectionList();
const handleDelete = () => {
showModal(ConfirmModal, {
message: `Really delete application ${data.name}?`,
@ -61,11 +64,23 @@
{ text: 'Rename', onClick: handleRename },
$currentDatabase && [
{ text: 'Enable on current database', onClick: () => setOnCurrentDb(true) },
{ text: 'Disable on current database', onClick: () => setOnCurrentDb(false) },
!isOnCurrentDb($currentDatabase, $connections) && {
text: 'Enable on current database',
onClick: () => setOnCurrentDb(true),
},
isOnCurrentDb($currentDatabase, $connections) && {
text: 'Disable on current database',
onClick: () => setOnCurrentDb(false),
},
],
];
}
function isOnCurrentDb(currentDb, connections) {
const conn = connections.find(x => x._id == currentDb?.connection?._id);
const db = conn?.databases?.find(x => x.name == currentDb?.name);
return db && db[`useApp:${data.name}`];
}
</script>
<AppObjectCore
@ -73,6 +88,8 @@
{data}
title={data.name}
icon={'img app'}
statusIcon={isOnCurrentDb($currentDatabase, $connections) ? 'icon check' : null}
statusTitle={`Application ${data.name} is used for database ${$currentDatabase?.name}`}
isBold={data.name == $currentApplication}
on:click={() => ($currentApplication = data.name)}
menu={createMenu}