mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 09:44:00 +00:00
duplicate cloud connection
This commit is contained in:
@@ -172,4 +172,22 @@ module.exports = {
|
||||
_id: `cloud://${folid}/${cntid}`,
|
||||
};
|
||||
},
|
||||
|
||||
duplicateConnection_meta: true,
|
||||
async duplicateConnection({ conid }) {
|
||||
const m = conid.match(/^cloud\:\/\/(.+)\/(.+)$/);
|
||||
if (!m) {
|
||||
throw new Error('Invalid cloud connection ID format');
|
||||
}
|
||||
const folid = m[1];
|
||||
const cntid = m[2];
|
||||
const respGet = await getCloudContent(folid, cntid);
|
||||
const conn = JSON.parse(respGet.content);
|
||||
const conn2 = {
|
||||
...conn,
|
||||
displayName: getConnectionLabel(conn) + ' - copy',
|
||||
};
|
||||
const respPut = await putCloudContent(folid, undefined, JSON.stringify(conn2), conn2.displayName, 'connection');
|
||||
return respPut;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -13,23 +13,47 @@
|
||||
<script lang="ts">
|
||||
import { filterName } from 'dbgate-tools';
|
||||
import ConnectionAppObject, { openConnection } from './ConnectionAppObject.svelte';
|
||||
import { _t } from '../translations';
|
||||
|
||||
export let data;
|
||||
export let passProps;
|
||||
|
||||
function createMenu() {
|
||||
return [];
|
||||
const res = [];
|
||||
switch (data.type) {
|
||||
case 'connection':
|
||||
res.push({
|
||||
text: _t('connection.connect', { defaultMessage: 'Connect' }),
|
||||
onClick: handleConnect,
|
||||
isBold: true,
|
||||
});
|
||||
res.push({ divider: true });
|
||||
res.push({
|
||||
text: _t('connection.duplicate', { defaultMessage: 'Duplicate' }),
|
||||
onClick: handleDuplicateConnection,
|
||||
});
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
async function handleDuplicateConnection() {
|
||||
await apiCall('cloud/duplicate-connection', { conid: data.conid });
|
||||
}
|
||||
|
||||
async function handleConnect() {
|
||||
const conn = await apiCall('connections/get', { conid: data.conid });
|
||||
$cloudConnectionsStore = {
|
||||
...$cloudConnectionsStore,
|
||||
[data.conid]: conn,
|
||||
};
|
||||
openConnection(conn);
|
||||
}
|
||||
|
||||
async function handleOpenContent() {
|
||||
switch (data.type) {
|
||||
case 'connection':
|
||||
const conn = await apiCall('connections/get', { conid: data.conid });
|
||||
$cloudConnectionsStore = {
|
||||
...$cloudConnectionsStore,
|
||||
[data.conid]: conn,
|
||||
};
|
||||
openConnection(conn);
|
||||
await handleConnect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
const handleOpenConnectionTab = () => {
|
||||
openNewTab({
|
||||
title: getConnectionLabel(data),
|
||||
icon: 'img connection',
|
||||
icon: data._id.startsWith('cloud://') ? 'img cloud-connection' : 'img connection',
|
||||
tabComponent: 'ConnectionTab',
|
||||
props: {
|
||||
conid: data._id,
|
||||
@@ -430,7 +430,7 @@
|
||||
{...$$restProps}
|
||||
{data}
|
||||
title={getConnectionLabel(data, { showUnsaved: true })}
|
||||
icon={data.singleDatabase ? 'img database' : 'img server'}
|
||||
icon={data._id.startsWith('cloud://') ? 'img cloud-connection' : data.singleDatabase ? 'img database' : 'img server'}
|
||||
isBold={data.singleDatabase
|
||||
? $currentDatabase?.connection?._id == data._id && $currentDatabase?.name == data.defaultDatabase
|
||||
: $currentDatabase?.connection?._id == data._id}
|
||||
|
||||
@@ -32,7 +32,10 @@ async function loadCloudConnection(conid) {
|
||||
|
||||
function ensureCloudConnectionsLoaded(...conids) {
|
||||
const conns = getCloudConnectionsStore();
|
||||
_.uniq(conids).forEach(conid => {
|
||||
|
||||
cloudConnectionsStore.update(store => _.pick(store, conids));
|
||||
|
||||
conids.forEach(conid => {
|
||||
if (!conns[conid]) {
|
||||
loadCloudConnection(conid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user