mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 13:05:58 +00:00
rename, delete connection folder #425
This commit is contained in:
@@ -283,6 +283,14 @@ module.exports = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
batchChangeFolder_meta: true,
|
||||||
|
async batchChangeFolder({ folder, newFolder }, req) {
|
||||||
|
// const updated = await this.datastore.find(x => x.parent == folder);
|
||||||
|
const res = await this.datastore.updateAll(x => (x.parent == folder ? { ...x, parent: newFolder } : x));
|
||||||
|
socket.emitChanged('connection-list-changed');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
updateDatabase_meta: true,
|
updateDatabase_meta: true,
|
||||||
async updateDatabase({ conid, database, values }, req) {
|
async updateDatabase({ conid, database, values }, req) {
|
||||||
if (portalConnections) return;
|
if (portalConnections) return;
|
||||||
|
|||||||
@@ -90,6 +90,12 @@ class JsonLinesDatabase {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateAll(mapFunction) {
|
||||||
|
await this._ensureLoaded();
|
||||||
|
this.data = this.data.map(mapFunction);
|
||||||
|
await this._save();
|
||||||
|
}
|
||||||
|
|
||||||
async patch(id, values) {
|
async patch(id, values) {
|
||||||
await this._ensureLoaded();
|
await this._ensureLoaded();
|
||||||
this.data = this.data.map(x => (x._id == id ? { ...x, ...values } : x));
|
this.data = this.data.map(x => (x._id == id ? { ...x, ...values } : x));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import { plusExpandIcon } from '../icons/expandIcons';
|
import { plusExpandIcon } from '../icons/expandIcons';
|
||||||
|
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
import contextMenu from '../utility/contextMenu';
|
||||||
|
|
||||||
import AppObjectListItem from './AppObjectListItem.svelte';
|
import AppObjectListItem from './AppObjectListItem.svelte';
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
export let disableContextMenu = false;
|
export let disableContextMenu = false;
|
||||||
export let passProps;
|
export let passProps;
|
||||||
export let onDropOnGroup = undefined;
|
export let onDropOnGroup = undefined;
|
||||||
|
export let groupContextMenu = null;
|
||||||
|
|
||||||
let isExpanded = true;
|
let isExpanded = true;
|
||||||
|
|
||||||
@@ -45,7 +47,12 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="group" on:click={() => (isExpanded = !isExpanded)} on:drop={handleDrop}>
|
<div
|
||||||
|
class="group"
|
||||||
|
on:click={() => (isExpanded = !isExpanded)}
|
||||||
|
on:drop={handleDrop}
|
||||||
|
use:contextMenu={() => groupContextMenu(group)}
|
||||||
|
>
|
||||||
<span class="expand-icon">
|
<span class="expand-icon">
|
||||||
<FontIcon icon={groupIconFunc(isExpanded)} />
|
<FontIcon icon={groupIconFunc(isExpanded)} />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
export let getIsExpanded = null;
|
export let getIsExpanded = null;
|
||||||
export let setIsExpanded = null;
|
export let setIsExpanded = null;
|
||||||
export let sortGroups = false;
|
export let sortGroups = false;
|
||||||
|
export let groupContextMenu = null;
|
||||||
|
|
||||||
export let groupIconFunc = plusExpandIcon;
|
export let groupIconFunc = plusExpandIcon;
|
||||||
export let groupFunc = undefined;
|
export let groupFunc = undefined;
|
||||||
@@ -98,6 +99,7 @@
|
|||||||
{getIsExpanded}
|
{getIsExpanded}
|
||||||
{setIsExpanded}
|
{setIsExpanded}
|
||||||
{onDropOnGroup}
|
{onDropOnGroup}
|
||||||
|
{groupContextMenu}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
import LargeButton from '../buttons/LargeButton.svelte';
|
import LargeButton from '../buttons/LargeButton.svelte';
|
||||||
import { plusExpandIcon, chevronExpandIcon } from '../icons/expandIcons';
|
import { plusExpandIcon, chevronExpandIcon } from '../icons/expandIcons';
|
||||||
import { safeJsonParse } from 'dbgate-tools';
|
import { safeJsonParse } from 'dbgate-tools';
|
||||||
|
import { showModal } from '../modals/modalTools';
|
||||||
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
|
|
||||||
const connections = useConnectionList();
|
const connections = useConnectionList();
|
||||||
const serverStatus = useServerStatus();
|
const serverStatus = useServerStatus();
|
||||||
@@ -56,9 +59,9 @@
|
|||||||
const handleDropOnGroup = (data, group) => {
|
const handleDropOnGroup = (data, group) => {
|
||||||
const json = safeJsonParse(data);
|
const json = safeJsonParse(data);
|
||||||
if (json?._id) {
|
if (json?._id) {
|
||||||
if (json.parent) {
|
// if (json.parent) {
|
||||||
emptyConnectionGroupNames.update(x => x.filter(y => y != json.parent));
|
// emptyConnectionGroupNames.update(x => x.filter(y => y != json.parent));
|
||||||
}
|
// }
|
||||||
apiCall('connections/update', {
|
apiCall('connections/update', {
|
||||||
_id: json?._id,
|
_id: json?._id,
|
||||||
values: { parent: group },
|
values: { parent: group },
|
||||||
@@ -67,6 +70,41 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const connectionColorFactory = useConnectionColorFactory(3);
|
const connectionColorFactory = useConnectionColorFactory(3);
|
||||||
|
|
||||||
|
function createGroupContextMenu(folder) {
|
||||||
|
const handleRename = () => {
|
||||||
|
showModal(InputTextModal, {
|
||||||
|
value: folder,
|
||||||
|
label: 'New folder name',
|
||||||
|
header: 'Rename folder',
|
||||||
|
onConfirm: async newFolder => {
|
||||||
|
emptyConnectionGroupNames.update(folders => _.uniq(folders.map(fld => (fld == folder ? newFolder : fld))));
|
||||||
|
apiCall('connections/batch-change-folder', {
|
||||||
|
folder,
|
||||||
|
newFolder,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
showModal(ConfirmModal, {
|
||||||
|
message: `Really delete folder ${folder}? Connections in folder will be moved into root folder.`,
|
||||||
|
onConfirm: () => {
|
||||||
|
emptyConnectionGroupNames.update(folders => folders.filter(fld => fld != folder));
|
||||||
|
apiCall('connections/batch-change-folder', {
|
||||||
|
folder,
|
||||||
|
newFolder: '',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ text: 'Rename', onClick: handleRename },
|
||||||
|
{ text: 'Delete', onClick: handleDelete },
|
||||||
|
];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SearchBoxWrapper>
|
<SearchBoxWrapper>
|
||||||
@@ -110,6 +148,7 @@
|
|||||||
onDropOnGroup={handleDropOnGroup}
|
onDropOnGroup={handleDropOnGroup}
|
||||||
emptyGroupNames={$emptyConnectionGroupNames}
|
emptyGroupNames={$emptyConnectionGroupNames}
|
||||||
sortGroups
|
sortGroups
|
||||||
|
groupContextMenu={createGroupContextMenu}
|
||||||
/>
|
/>
|
||||||
{#if (connectionsWithParent?.length > 0 && connectionsWithoutParent?.length > 0) || ($emptyConnectionGroupNames.length > 0 && connectionsWithoutParent?.length > 0)}
|
{#if (connectionsWithParent?.length > 0 && connectionsWithoutParent?.length > 0) || ($emptyConnectionGroupNames.length > 0 && connectionsWithoutParent?.length > 0)}
|
||||||
<div class="br" />
|
<div class="br" />
|
||||||
|
|||||||
Reference in New Issue
Block a user