diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index e444572..4f2397b 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -43,8 +43,25 @@ async function openNewHost(groupId?: number) { showHostDialog.value = true } -function openEditHost(host: any) { +async function openEditHost(host: any) { editingHost.value = host + inlineHost.value = { + name: host.name || '', + hostname: host.hostname || '', + port: host.port || 22, + protocol: host.protocol || 'ssh', + groupId: host.groupId || host.group?.id || null, + tags: (host.tags || []).join(', '), + credentialId: host.credentialId || null, + } + try { + const [creds, keys] = await Promise.all([ + vault.listCredentials() as Promise, + vault.listKeys() as Promise, + ]) + allCredentials.value = creds + allSshKeys.value = keys + } catch { /* ignore */ } showHostDialog.value = true } @@ -135,13 +152,13 @@ async function createGroupInline() { showGroupDialog.value = false } -async function createHostInline() { +async function saveHostInline() { if (!inlineHost.value.name || !inlineHost.value.hostname) return const tags = inlineHost.value.tags .split(',') .map(t => t.trim()) .filter(Boolean) - await connections.createHost({ + const payload = { name: inlineHost.value.name, hostname: inlineHost.value.hostname, port: inlineHost.value.port, @@ -149,10 +166,21 @@ async function createHostInline() { groupId: inlineHost.value.groupId, credentialId: inlineHost.value.credentialId, tags, - }) + } + if (editingHost.value?.id) { + await connections.updateHost(editingHost.value.id, payload) + } else { + await connections.createHost(payload) + } showHostDialog.value = false + editingHost.value = null inlineHost.value = { name: '', hostname: '', port: 22, protocol: 'ssh', groupId: null, tags: '', credentialId: null } await connections.fetchTree() + // Refresh selected host details if it was the one we edited + if (selectedHost.value?.id === editingHost.value?.id) { + const updated = connections.hosts.find((h: any) => h.id === selectedHost.value.id) + if (updated) selectedHost.value = updated + } } // Client-side search filtering @@ -392,7 +420,7 @@ async function deleteSelectedHost() {
-

{{ showGroupDialog ? 'New Group' : 'New Host' }}

+

{{ showGroupDialog ? 'New Group' : (editingHost?.id ? 'Edit Host' : 'New Host') }}

@@ -405,9 +433,13 @@ async function deleteSelectedHost() {
- -
- Adding to: {{ connections.groups.find((g: any) => g.id === inlineHost.groupId)?.name || 'Group' }} + +
+ +
@@ -449,7 +481,7 @@ async function deleteSelectedHost() {
- +