mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 00:36:00 +00:00
connection context menu
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
import contextMenu from '../utility/contextMenu';
|
||||||
|
|
||||||
export let icon;
|
export let icon;
|
||||||
export let title;
|
export let title;
|
||||||
@@ -10,9 +11,10 @@
|
|||||||
export let statusIcon = undefined;
|
export let statusIcon = undefined;
|
||||||
export let statusTitle = undefined;
|
export let statusTitle = undefined;
|
||||||
export let extInfo = undefined;
|
export let extInfo = undefined;
|
||||||
|
export let menu = undefined;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="main" class:isBold draggable on:click>
|
<div class="main" class:isBold draggable on:click use:contextMenu={menu}>
|
||||||
{prefix}
|
{prefix}
|
||||||
{#if isBusy}
|
{#if isBusy}
|
||||||
<FontIcon icon="icon loading" />
|
<FontIcon icon="icon loading" />
|
||||||
|
|||||||
@@ -1,7 +1,38 @@
|
|||||||
|
<script context="module">
|
||||||
|
const getContextMenu = (data, $openedConnections) => () => {
|
||||||
|
const handleRefresh = () => {
|
||||||
|
axios.post('server-connections/refresh', { conid: data._id });
|
||||||
|
};
|
||||||
|
const handleDisconnect = () => {
|
||||||
|
openedConnections.update(list => list.filter(x => x != data._id));
|
||||||
|
};
|
||||||
|
const handleConnect = () => {
|
||||||
|
openedConnections.update(list => _.uniq([...list, data._id]));
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
!$openedConnections.includes(data._id) && {
|
||||||
|
text: 'Connect',
|
||||||
|
onClick: handleConnect,
|
||||||
|
},
|
||||||
|
$openedConnections.includes(data._id) &&
|
||||||
|
data.status && {
|
||||||
|
text: 'Refresh',
|
||||||
|
onClick: handleRefresh,
|
||||||
|
},
|
||||||
|
$openedConnections.includes(data._id) && {
|
||||||
|
text: 'Disconnect',
|
||||||
|
onClick: handleDisconnect,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
import { currentDatabase, extensions, openedConnections } from '../stores';
|
import { currentDatabase, extensions, openedConnections } from '../stores';
|
||||||
|
import axios from '../utility/axios';
|
||||||
|
|
||||||
export let commonProps;
|
export let commonProps;
|
||||||
export let data;
|
export let data;
|
||||||
@@ -35,8 +66,27 @@
|
|||||||
if (status && status.name == 'error') {
|
if (status && status.name == 'error') {
|
||||||
statusTitle = status.message;
|
statusTitle = status.message;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
statusIcon = null;
|
||||||
|
statusTitle = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const handleEdit = () => {
|
||||||
|
// showModal(modalState => <ConnectionModal modalState={modalState} connection={data} />);
|
||||||
|
// };
|
||||||
|
// const handleDelete = () => {
|
||||||
|
// showModal(modalState => (
|
||||||
|
// <ConfirmModal
|
||||||
|
// modalState={modalState}
|
||||||
|
// message={`Really delete connection ${data.displayName || data.server}?`}
|
||||||
|
// onConfirm={() => axios.post('connections/delete', data)}
|
||||||
|
// />
|
||||||
|
// ));
|
||||||
|
// };
|
||||||
|
// const handleCreateDatabase = () => {
|
||||||
|
// showModal(modalState => <CreateDatabaseModal modalState={modalState} conid={data._id} />);
|
||||||
|
// };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
@@ -47,6 +97,7 @@
|
|||||||
statusIcon={statusIcon || engineStatusIcon}
|
statusIcon={statusIcon || engineStatusIcon}
|
||||||
statusTitle={statusTitle || engineStatusTitle}
|
statusTitle={statusTitle || engineStatusTitle}
|
||||||
{extInfo}
|
{extInfo}
|
||||||
|
menu={getContextMenu(data, $openedConnections)}
|
||||||
on:click
|
on:click
|
||||||
on:click={() => ($openedConnections = _.uniq([...$openedConnections, data._id]))}
|
on:click={() => ($openedConnections = _.uniq([...$openedConnections, data._id]))}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import _ from 'lodash';
|
||||||
import { currentDropDownMenu } from '../stores';
|
import { currentDropDownMenu } from '../stores';
|
||||||
import DropDownMenu from './DropDownMenu.svelte';
|
import DropDownMenu from './DropDownMenu.svelte';
|
||||||
</script>
|
</script>
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
<DropDownMenu
|
<DropDownMenu
|
||||||
left={$currentDropDownMenu.left}
|
left={$currentDropDownMenu.left}
|
||||||
top={$currentDropDownMenu.top}
|
top={$currentDropDownMenu.top}
|
||||||
items={$currentDropDownMenu.items}
|
items={_.compact(_.flatten($currentDropDownMenu.items))}
|
||||||
on:close={() => ($currentDropDownMenu = null)}
|
on:close={() => ($currentDropDownMenu = null)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -15,5 +15,8 @@ export default function contextMenu(node, items) {
|
|||||||
destroy() {
|
destroy() {
|
||||||
node.removeEventListener('contextmenu', handleContextMenu);
|
node.removeEventListener('contextmenu', handleContextMenu);
|
||||||
},
|
},
|
||||||
|
update(value) {
|
||||||
|
items = value;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const tabContextMenu = (tabid, props) => () => {
|
const getContextMenu = (tabid, props) => () => {
|
||||||
const { conid, database } = props || {};
|
const { conid, database } = props || {};
|
||||||
const res = [
|
const res = [
|
||||||
{
|
{
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
class:selected={tab.selected}
|
class:selected={tab.selected}
|
||||||
on:click={e => handleTabClick(e, tab.tabid)}
|
on:click={e => handleTabClick(e, tab.tabid)}
|
||||||
on:mouseup={e => handleMouseUp(e, tab.tabid)}
|
on:mouseup={e => handleMouseUp(e, tab.tabid)}
|
||||||
use:contextMenu={tabContextMenu(tab.tabid, tab.props)}
|
use:contextMenu={getContextMenu(tab.tabid, tab.props)}
|
||||||
>
|
>
|
||||||
<FontIcon icon={tab.busy ? 'icon loading' : tab.icon} />
|
<FontIcon icon={tab.busy ? 'icon loading' : tab.icon} />
|
||||||
<span class="file-name">
|
<span class="file-name">
|
||||||
|
|||||||
Reference in New Issue
Block a user