2022-01-27 13:31:46 +00:00
|
|
|
<script lang="ts" context="module">
|
|
|
|
export const extractKey = data => data.name;
|
|
|
|
export const createMatcher = data => filter => filterName(filter, data.name);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-01-29 11:42:00 +00:00
|
|
|
import _, { find } from 'lodash';
|
2022-01-27 13:31:46 +00:00
|
|
|
import { filterName } from 'dbgate-tools';
|
|
|
|
|
2022-01-27 16:01:58 +00:00
|
|
|
import { currentApplication, currentDatabase } from '../stores';
|
2022-01-27 13:31:46 +00:00
|
|
|
|
|
|
|
import AppObjectCore from './AppObjectCore.svelte';
|
|
|
|
import { showModal } from '../modals/modalTools';
|
|
|
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
|
|
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
|
|
|
import { apiCall } from '../utility/api';
|
2022-01-29 11:42:00 +00:00
|
|
|
import { useConnectionList } from '../utility/metadataLoaders';
|
2022-01-27 13:31:46 +00:00
|
|
|
|
|
|
|
export let data;
|
|
|
|
|
2022-01-29 11:42:00 +00:00
|
|
|
$: connections = useConnectionList();
|
|
|
|
|
2022-01-27 13:31:46 +00:00
|
|
|
const handleDelete = () => {
|
|
|
|
showModal(ConfirmModal, {
|
|
|
|
message: `Really delete application ${data.name}?`,
|
|
|
|
onConfirm: () => {
|
|
|
|
apiCall('apps/delete-folder', { folder: data.name });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleRename = () => {
|
|
|
|
const { name } = data;
|
|
|
|
|
|
|
|
showModal(InputTextModal, {
|
|
|
|
value: name,
|
|
|
|
label: 'New application name',
|
|
|
|
header: 'Rename application',
|
|
|
|
onConfirm: async newFolder => {
|
|
|
|
await apiCall('apps/rename-folder', {
|
|
|
|
folder: data.name,
|
|
|
|
newFolder: newFolder,
|
|
|
|
});
|
|
|
|
if ($currentApplication == data.name) {
|
|
|
|
$currentApplication = newFolder;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-01-27 16:01:58 +00:00
|
|
|
function setOnCurrentDb(value) {
|
|
|
|
apiCall('connections/update-database', {
|
|
|
|
conid: $currentDatabase?.connection?._id,
|
|
|
|
database: $currentDatabase?.name,
|
|
|
|
values: {
|
|
|
|
[`useApp:${data.name}`]: value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-27 13:31:46 +00:00
|
|
|
function createMenu() {
|
|
|
|
return [
|
|
|
|
{ text: 'Delete', onClick: handleDelete },
|
|
|
|
{ text: 'Rename', onClick: handleRename },
|
2022-01-27 16:01:58 +00:00
|
|
|
|
|
|
|
$currentDatabase && [
|
2022-01-29 11:42:00 +00:00
|
|
|
!isOnCurrentDb($currentDatabase, $connections) && {
|
|
|
|
text: 'Enable on current database',
|
|
|
|
onClick: () => setOnCurrentDb(true),
|
|
|
|
},
|
|
|
|
isOnCurrentDb($currentDatabase, $connections) && {
|
|
|
|
text: 'Disable on current database',
|
|
|
|
onClick: () => setOnCurrentDb(false),
|
|
|
|
},
|
2022-01-27 16:01:58 +00:00
|
|
|
],
|
2022-01-27 13:31:46 +00:00
|
|
|
];
|
|
|
|
}
|
2022-01-29 11:42:00 +00:00
|
|
|
|
|
|
|
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}`];
|
|
|
|
}
|
2022-01-27 13:31:46 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<AppObjectCore
|
|
|
|
{...$$restProps}
|
|
|
|
{data}
|
|
|
|
title={data.name}
|
|
|
|
icon={'img app'}
|
2022-01-29 11:42:00 +00:00
|
|
|
statusIcon={isOnCurrentDb($currentDatabase, $connections) ? 'icon check' : null}
|
|
|
|
statusTitle={`Application ${data.name} is used for database ${$currentDatabase?.name}`}
|
2022-01-27 13:31:46 +00:00
|
|
|
isBold={data.name == $currentApplication}
|
|
|
|
on:click={() => ($currentApplication = data.name)}
|
|
|
|
menu={createMenu}
|
|
|
|
/>
|