feat: Host CRUD complete — edit, full form fields, connect, toast

- Add UpdateHost handler + PUT /hosts/:id route
- CreateHost now accepts all fields (port, username, auth, notes)
- host_modal.html: full form with port, username, auth type toggle, edit mode
- host_list.html: edit button dispatches edit-host event with host data
- Connect button links to /terminal?host={id} for pre-selection
- Terminal page reads selected host from query param
- Toast notification system via Alpine.js events
- Add default template function for fallback values
This commit is contained in:
swanadiva
2026-07-07 15:51:57 +07:00
parent 3df8416d9b
commit 301115b74d
8 changed files with 285 additions and 58 deletions
+92 -15
View File
@@ -1,6 +1,8 @@
package handler
import (
"strconv"
"github.com/gofiber/fiber/v2"
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/model"
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/store"
@@ -20,12 +22,12 @@ var navItems = []fiber.Map{
func Dashboard(c *fiber.Ctx) error {
hosts := hostStore.All()
return c.Render("index", fiber.Map{
"View": "hosts",
"Title": "Hosts",
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Offline": countByStatus(hosts, "offline"),
"NavItems": navItems,
"View": "hosts",
"Title": "Hosts",
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Offline": countByStatus(hosts, "offline"),
"NavItems": navItems,
})
}
@@ -34,28 +36,103 @@ func DashboardList(c *fiber.Ctx) error {
filter := c.Query("filter", "all")
hosts := hostStore.Search(q, filter)
return c.Render("host_list", fiber.Map{
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Offline": countByStatus(hosts, "offline"),
})
}
func parsePort(s string, def int) int {
i, err := strconv.Atoi(s)
if err != nil || i < 1 || i > 65535 {
return def
}
return i
}
func CreateHost(c *fiber.Ctx) error {
name := c.FormValue("name")
ip := c.FormValue("ip")
os := c.FormValue("os")
provider := c.FormValue("provider")
hostType := c.FormValue("type")
if name == "" || ip == "" {
return c.Status(400).SendString("name and ip required")
}
hostStore.Add(name, ip, os, provider, hostType)
h := model.Host{
Name: name,
IP: ip,
OS: c.FormValue("os"),
Provider: c.FormValue("provider"),
Type: c.FormValue("type"),
Port: parsePort(c.FormValue("port"), 22),
Username: c.FormValue("username"),
AuthType: c.FormValue("authType"),
Password: c.FormValue("password"),
Hostname: c.FormValue("hostname"),
Notes: c.FormValue("notes"),
}
if h.Username == "" {
h.Username = "root"
}
if h.AuthType == "" {
h.AuthType = "key"
}
created := hostStore.AddFull(h)
hosts := hostStore.All()
_ = created
return c.Render("host_list", fiber.Map{
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Offline": countByStatus(hosts, "offline"),
})
}
func UpdateHost(c *fiber.Ctx) error {
id := c.Params("id")
existing, found := hostStore.Get(id)
if !found {
return c.Status(404).SendString("host not found")
}
if v := c.FormValue("name"); v != "" {
existing.Name = v
}
if v := c.FormValue("ip"); v != "" {
existing.IP = v
}
if v := c.FormValue("os"); v != "" {
existing.OS = v
}
if v := c.FormValue("provider"); v != "" {
existing.Provider = v
}
if v := c.FormValue("type"); v != "" {
existing.Type = v
}
if v := c.FormValue("port"); v != "" {
existing.Port = parsePort(v, 22)
}
if v := c.FormValue("username"); v != "" {
existing.Username = v
}
if v := c.FormValue("authType"); v != "" {
existing.AuthType = v
}
if v := c.FormValue("password"); v != "" {
existing.Password = v
}
if v := c.FormValue("hostname"); v != "" {
existing.Hostname = v
}
if v := c.FormValue("notes"); v != "" {
existing.Notes = v
}
hostStore.Update(existing)
hosts := hostStore.All()
return c.Render("host_list", fiber.Map{
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Hosts": hosts,
"Active": countByStatus(hosts, "active"),
"Offline": countByStatus(hosts, "offline"),
})
}
+7 -5
View File
@@ -28,12 +28,14 @@ func Terminal(c *fiber.Ctx) error {
}
}
hostsJSON, _ := json.Marshal(available)
selectedHost := c.Query("host", "")
data := fiber.Map{
"View": "terminal",
"Title": "Terminal",
"NavItems": navItems,
"Hosts": available,
"HostsJSON": string(hostsJSON),
"View": "terminal",
"Title": "Terminal",
"NavItems": navItems,
"Hosts": available,
"HostsJSON": string(hostsJSON),
"SelectedHost": selectedHost,
}
if c.Get("HX-Request") != "" {
return c.Render("terminal_content", data)
+7
View File
@@ -44,6 +44,12 @@ func main() {
}
return m
})
engine.AddFunc("default", func(def, val interface{}) interface{} {
if val == nil || val == "" {
return def
}
return val
})
app := fiber.New(fiber.Config{
Views: engine,
@@ -57,6 +63,7 @@ func main() {
app.Get("/", handler.Dashboard)
app.Get("/hosts", handler.DashboardList)
app.Post("/hosts", handler.CreateHost)
app.Put("/hosts/:id", handler.UpdateHost)
app.Delete("/hosts/:id", handler.DeleteHost)
app.Get("/snippets", handler.Snippets)
app.Get("/snippets/grid", handler.SnippetGrid)
+11 -3
View File
@@ -1,6 +1,8 @@
document.addEventListener('alpine:init', () => {
const el = document.getElementById('hosts-data');
const hostOptions = el ? JSON.parse(el.textContent) : [];
const selEl = document.getElementById('selected-host');
const selectedHostId = selEl ? JSON.parse(selEl.textContent) : '';
function processCommand(cmd, tabName) {
const lines = [];
@@ -86,9 +88,15 @@ document.addEventListener('alpine:init', () => {
},
addTab() {
const host = hostOptions.length > 0
? hostOptions[Math.floor(Math.random() * hostOptions.length)]
: { id: 'h1', name: 'localhost', ip: '127.0.0.1' };
let host;
if (selectedHostId) {
host = hostOptions.find(h => h.id === selectedHostId) || hostOptions[0];
}
if (!host) {
host = hostOptions.length > 0
? hostOptions[Math.floor(Math.random() * hostOptions.length)]
: { id: 'h1', name: 'localhost', ip: '127.0.0.1' };
}
const id = 'tab-' + Date.now() + '-' + Math.random().toString(36).slice(2, 6);
this.tabs.push({ id, name: host.name, host: host.ip, connected: true });
this.activeTab = this.tabs.length - 1;
+26 -9
View File
@@ -3,7 +3,7 @@
<div x-show="view === 'grid'" x-cloak
class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
{{range .Hosts}}
<div class="group bg-white p-5 rounded-2xl border border-outline-variant hover:border-primary hover:shadow-lg transition-all cursor-pointer relative overflow-hidden">
<div class="group bg-white p-5 rounded-2xl border border-outline-variant hover:border-primary hover:shadow-lg transition-all relative overflow-hidden">
<div class="flex justify-between items-start mb-4">
<div class="w-11 h-11 rounded-xl bg-surface-container-low flex items-center justify-center text-primary border border-outline-variant/20 group-hover:bg-primary-container/10 group-hover:border-primary/20 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M5 12h14M12 5l7 7-7 7"/></svg>
@@ -15,19 +15,29 @@
</div>
<h4 class="font-bold text-on-surface group-hover:text-primary transition-colors text-base truncate">{{.Name}}</h4>
<p class="font-mono text-xs text-outline mb-4">{{.IP}}</p>
<p class="font-mono text-xs text-outline mb-1">{{.IP}}</p>
<p class="text-[10px] text-on-surface-variant mb-3" x-data="{ show: false }">
<span class="font-medium">{{.Username | default "root"}}@{{if .Hostname}}{{.Hostname}}{{else}}{{.IP}}{{end}}{{if ne .Port 22}}:{{.Port}}{{end}}</span>
</p>
<div class="flex flex-wrap gap-1.5 mb-4">
<span class="px-2 py-0.5 bg-surface-container-low rounded text-[10px] font-medium text-on-surface-variant">{{.OS}}</span>
<span class="px-2 py-0.5 bg-surface-container-low rounded text-[10px] font-medium text-on-surface-variant">{{.Provider}}</span>
{{if .Type}}<span class="px-2 py-0.5 bg-primary-container/10 text-primary rounded text-[10px] font-bold uppercase">{{.Type}}</span>{{end}}
</div>
<div class="pt-3 border-t border-outline-variant/30 flex justify-between items-center text-xs">
<span class="text-outline italic">Last seen {{.LastSeen}}</span>
<div class="flex gap-1">
<a href="/terminal" class="bg-primary text-white hover:bg-primary-container hover:text-on-primary-container font-bold text-xs py-1.5 px-3 rounded-lg transition-all">Connect</a>
<a href="/terminal?host={{.ID}}" class="bg-primary text-white hover:bg-primary-container hover:text-on-primary-container font-bold text-xs py-1.5 px-3 rounded-lg transition-all">Connect</a>
<button type="button"
@click="$dispatch('edit-host', { ID: '{{.ID}}', Name: '{{.Name}}', IP: '{{.IP}}', Hostname: '{{.Hostname}}', Port: {{.Port}}, Username: '{{.Username}}', OS: '{{.OS}}', Provider: '{{.Provider}}', Type: '{{.Type}}', AuthType: '{{.AuthType}}', Password: '{{.Password}}', Notes: '{{.Notes}}' })"
class="p-1.5 rounded-lg hover:bg-surface-container text-on-surface-variant hover:text-primary transition-colors" title="Edit">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"/></svg>
</button>
<button class="p-1.5 rounded-lg hover:bg-red-50 text-on-surface-variant hover:text-red-500 transition-colors"
hx-delete="/hosts/{{.ID}}" hx-target="#host-list" hx-confirm="Delete {{.Name}}?" title="Delete">
hx-delete="/hosts/{{.ID}}" hx-target="#host-list" hx-confirm="Delete {{.Name}}?" title="Delete"
@click="$dispatch('toast-message', { message: 'Host deleted' })">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>
@@ -46,7 +56,7 @@
<div x-show="view === 'list'" x-cloak
class="bg-white border border-outline-variant rounded-2xl overflow-hidden shadow-sm divide-y divide-outline-variant/30">
{{range .Hosts}}
<div class="flex items-center justify-between p-4 hover:bg-primary/5 transition-colors cursor-pointer group">
<div class="flex items-center justify-between p-4 hover:bg-primary/5 transition-colors group">
<div class="flex items-center gap-4 min-w-0 flex-1">
<div class="w-10 h-10 rounded-lg bg-surface-container-low flex items-center justify-center text-primary shrink-0 border border-outline-variant/20">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M5 12h14M12 5l7 7-7 7"/></svg>
@@ -65,14 +75,20 @@
</div>
</div>
</div>
<div class="flex items-center gap-4 ml-4 shrink-0">
<div class="flex items-center gap-2 ml-4 shrink-0">
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider flex items-center gap-1 {{if eq .Status "active"}}bg-secondary-container/20 text-secondary{{else}}bg-surface-container text-outline{{end}}">
<span class="w-1.5 h-1.5 rounded-full {{if eq .Status "active"}}bg-secondary animate-pulse{{else}}bg-outline{{end}}"></span>
{{.Status}}
</span>
<a href="/terminal" class="bg-primary text-white hover:bg-primary-container hover:text-on-primary-container font-bold text-xs py-1.5 px-4 rounded-lg transition-all">Connect</a>
<a href="/terminal?host={{.ID}}" class="bg-primary text-white hover:bg-primary-container hover:text-on-primary-container font-bold text-xs py-1.5 px-4 rounded-lg transition-all">Connect</a>
<button type="button"
@click="$dispatch('edit-host', { ID: '{{.ID}}', Name: '{{.Name}}', IP: '{{.IP}}', Hostname: '{{.Hostname}}', Port: {{.Port}}, Username: '{{.Username}}', OS: '{{.OS}}', Provider: '{{.Provider}}', Type: '{{.Type}}', AuthType: '{{.AuthType}}', Password: '{{.Password}}', Notes: '{{.Notes}}' })"
class="p-1.5 rounded-lg hover:bg-surface-container text-on-surface-variant hover:text-primary transition-colors" title="Edit">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"/></svg>
</button>
<button class="p-1.5 rounded-lg hover:bg-red-50 text-on-surface-variant hover:text-red-500 transition-colors"
hx-delete="/hosts/{{.ID}}" hx-target="#host-list" hx-confirm="Delete {{.Name}}?" title="Delete">
hx-delete="/hosts/{{.ID}}" hx-target="#host-list" hx-confirm="Delete {{.Name}}?" title="Delete"
@click="$dispatch('toast-message', { message: 'Host deleted' })">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>
@@ -88,8 +104,9 @@
{{if eq (len .Hosts) 0}}
<div class="text-center py-12 text-on-surface-variant">
<svg class="w-12 h-12 mx-auto mb-3 text-outline/40" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M5 12h14M12 5l7 7-7 7"/></svg>
<p class="text-lg font-medium">No hosts found</p>
<p class="text-sm mt-1">Try a different search or add a new host</p>
<p class="text-sm mt-1">Add your first server to get started</p>
</div>
{{end}}
</div>
+130 -25
View File
@@ -1,53 +1,85 @@
{{define "host_modal"}}
<div id="host-modal" class="fixed inset-0 z-50" x-data="{ open: false, type: 'api' }" x-show="open" x-cloak
@open-modal.window="open = true" @keydown.escape.window="open = false">
<div id="host-modal" class="fixed inset-0 z-50" x-data="hostForm()" x-show="open" x-cloak
@open-modal.window="reset(); open = true"
@edit-host.window="populate($event.detail); open = true"
@keydown.escape.window="open = false">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm" @click="open = false"></div>
<div class="absolute inset-0 flex items-center justify-center p-4" x-show="open" x-transition>
<div class="bg-white rounded-2xl max-w-md w-full border border-outline-variant shadow-2xl overflow-hidden p-6 space-y-4 animate-scale-up" @click.outside="open = false">
<div class="flex justify-between items-center border-b border-outline-variant/30 pb-3">
<h3 class="font-bold text-lg text-on-surface">Add Host Credentials</h3>
<div class="bg-white rounded-2xl max-w-lg w-full border border-outline-variant/30 shadow-2xl max-h-[90vh] overflow-y-auto">
<div class="flex justify-between items-center border-b border-outline-variant/30 p-6 pb-4">
<h3 class="font-bold text-lg text-on-surface" x-text="editing ? 'Edit Host' : 'Add Host'"></h3>
<button @click="open = false"
class="text-outline hover:text-primary cursor-pointer p-1 rounded-lg">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
</button>
</div>
<form hx-post="/hosts" hx-target="#host-list" hx-swap="outerHTML"
@submit="open = false"
class="space-y-4 text-sm">
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Host Identifier</label>
<input type="text" name="name" required placeholder="e.g. prod-db-replica"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-medium text-on-surface">
<form :hx-post="editing ? null : '/hosts'"
:hx-put="editing ? '/hosts/' + hostId : null"
hx-target="#host-list" hx-swap="innerHTML"
@submit="open = false; $dispatch('toast-message', { message: editing ? 'Host updated' : 'Host added' })"
class="p-6 space-y-4 text-sm">
<div class="grid grid-cols-2 gap-4">
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Host Identifier</label>
<input type="text" name="name" x-model="form.name" required placeholder="e.g. prod-db-replica"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-medium text-on-surface">
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">IP Address / Domain</label>
<input type="text" name="ip" x-model="form.ip" required placeholder="e.g. 10.0.12.19"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface">
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Hostname (SSH)</label>
<input type="text" name="hostname" x-model="form.hostname" placeholder="e.g. prod.example.com"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">SSH Port</label>
<input type="number" name="port" x-model="form.port" min="1" max="65535" placeholder="22"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
</div>
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">IP Address / Domain</label>
<input type="text" name="ip" required placeholder="e.g. 10.0.12.19"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface">
<label class="text-xs font-bold text-on-surface-variant uppercase">SSH Username</label>
<input type="text" name="username" x-model="form.username" placeholder="root"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-medium text-on-surface">
</div>
<div class="grid grid-cols-2 gap-4">
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Operating System</label>
<select name="os"
<select name="os" x-model="form.os"
class="bg-surface-container-low border border-outline-variant/40 rounded-lg py-2 px-3 focus:outline-none focus:border-primary text-sm text-on-surface">
<option value="Ubuntu 22.04">Ubuntu 22.04</option>
<option value="Ubuntu 24.04">Ubuntu 24.04</option>
<option value="Debian 12">Debian 12</option>
<option value="Alpine 3.19">Alpine 3.19</option>
<option value="Fedora 39">Fedora 39</option>
<option value="Rocky 9">Rocky 9</option>
<option value="CentOS 8">CentOS 8</option>
<option value="Other">Other</option>
</select>
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Provider</label>
<select name="provider"
<select name="provider" x-model="form.provider"
class="bg-surface-container-low border border-outline-variant/40 rounded-lg py-2 px-3 focus:outline-none focus:border-primary text-sm text-on-surface">
<option value="AWS US-East">AWS Cloud</option>
<option value="AWS EU-West">AWS EU-West</option>
<option value="DigitalOcean">DigitalOcean</option>
<option value="Hetzner">Hetzner</option>
<option value="GCP US-Central">GCP Cloud</option>
<option value="Vultr">Vultr</option>
<option value="Linode">Linode</option>
<option value="Local">Local</option>
</select>
</div>
</div>
@@ -55,27 +87,100 @@
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Host Purpose / Type</label>
<div class="grid grid-cols-3 gap-2">
<button type="button" @click="type = 'api'"
:class="type === 'api' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
<button type="button" @click="form.type = 'api'"
:class="form.type === 'api' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">API Node</button>
<button type="button" @click="type = 'db'"
:class="type === 'db' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
<button type="button" @click="form.type = 'db'"
:class="form.type === 'db' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">DB Node</button>
<button type="button" @click="type = 'web'"
:class="type === 'web' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
<button type="button" @click="form.type = 'web'"
:class="form.type === 'web' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
class="py-2.5 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all">Web Node</button>
</div>
<input type="hidden" name="type" :value="type">
<input type="hidden" name="type" :value="form.type">
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Authentication</label>
<div class="grid grid-cols-2 gap-2">
<button type="button" @click="form.authType = 'key'"
:class="form.authType === 'key' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
class="py-2 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all flex items-center justify-center gap-1.5">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.75 5.25a3 3 0 013 3m3 0a6 6 0 01-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1121.75 8.25z"/></svg>
SSH Key
</button>
<button type="button" @click="form.authType = 'password'"
:class="form.authType === 'password' ? 'bg-primary text-white border-primary' : 'bg-surface-container-low border-outline-variant/40 text-on-surface-variant hover:bg-surface-container'"
class="py-2 px-3 border rounded-lg font-bold text-xs uppercase tracking-wider transition-all flex items-center justify-center gap-1.5">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z"/></svg>
Password
</button>
</div>
<input type="hidden" name="authType" :value="form.authType">
</div>
<div x-show="form.authType === 'password'" x-cloak class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Password</label>
<input type="password" name="password" x-model="form.password" placeholder="SSH password"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all font-mono text-on-surface text-xs">
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs font-bold text-on-surface-variant uppercase">Notes</label>
<textarea name="notes" x-model="form.notes" rows="2" placeholder="Optional notes about this host"
class="w-full bg-surface-container-low border border-outline-variant/40 rounded-lg py-2.5 px-4 focus:ring-2 focus:ring-primary/20 focus:border-primary focus:outline-none transition-all text-xs resize-none"></textarea>
</div>
<div class="pt-4 flex justify-end gap-3 border-t border-outline-variant/20">
<button type="button" @click="open = false"
class="px-4 py-2 text-xs font-bold text-outline hover:text-on-surface transition-colors">Cancel</button>
<button type="submit"
class="bg-primary text-white py-2 px-5 rounded-lg font-bold text-xs shadow-md hover:bg-primary-container hover:text-on-primary-container transition-all">Add Host</button>
class="bg-primary text-white py-2 px-5 rounded-lg font-bold text-xs shadow-md hover:bg-primary-container hover:text-on-primary-container transition-all"
x-text="editing ? 'Save Changes' : 'Add Host'"></button>
</div>
</form>
</div>
</div>
</div>
<script>
function hostForm() {
return {
open: false,
editing: false,
hostId: '',
form: {
name: '', ip: '', hostname: '', port: '22', username: 'root',
os: 'Ubuntu 22.04', provider: 'AWS US-East', type: 'api',
authType: 'key', password: '', notes: ''
},
reset() {
this.editing = false;
this.hostId = '';
this.form = {
name: '', ip: '', hostname: '', port: '22', username: 'root',
os: 'Ubuntu 22.04', provider: 'AWS US-East', type: 'api',
authType: 'key', password: '', notes: ''
};
},
populate(host) {
this.editing = true;
this.hostId = host.ID;
this.form = {
name: host.Name || '',
ip: host.IP || '',
hostname: host.Hostname || '',
port: String(host.Port || 22),
username: host.Username || 'root',
os: host.OS || 'Ubuntu 22.04',
provider: host.Provider || 'AWS US-East',
type: host.Type || 'api',
authType: host.AuthType || 'key',
password: host.Password || '',
notes: host.Notes || ''
};
}
};
}
</script>
{{end}}
+10
View File
@@ -109,5 +109,15 @@
</main>
</div>
</div>
<!-- Toast -->
<div x-data="{ show: false, msg: '' }" x-cloak
@toast-message.window="msg = $event.detail.message; show = true; setTimeout(() => show = false, 3000)"
x-show="show" x-transition
class="fixed bottom-6 right-6 z-[200] bg-inverse-surface text-inverse-on-surface px-5 py-3 rounded-xl shadow-xl flex items-center gap-3 text-sm font-medium">
<svg class="w-4 h-4 text-secondary shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
<span x-text="msg"></span>
</div>
</body>
</html>
+1
View File
@@ -31,6 +31,7 @@
</div>
</div>
<script id="hosts-data" type="application/json">{{.HostsJSON}}</script>
<script id="selected-host" type="application/json">"{{.SelectedHost}}"</script>
<script src="/static/xterm/xterm.js"></script>
<script src="/static/js/terminal.js"></script>
</body>