diff --git a/app/backend/internal/handler/dashboard.go b/app/backend/internal/handler/dashboard.go index 754d45a..fad7796 100644 --- a/app/backend/internal/handler/dashboard.go +++ b/app/backend/internal/handler/dashboard.go @@ -57,6 +57,17 @@ func CreateHost(c *fiber.Ctx) error { }) } +func DeleteHost(c *fiber.Ctx) error { + id := c.Params("id") + store.Delete(id) + hosts := store.All() + return c.Render("host_list", fiber.Map{ + "Hosts": hosts, + "Active": countByStatus(hosts, "active"), + "Offline": countByStatus(hosts, "offline"), + }) +} + func countByStatus(hosts []model.Host, status string) int { n := 0 for _, h := range hosts { diff --git a/app/backend/internal/model/host.go b/app/backend/internal/model/host.go index dc2842b..f024c30 100644 --- a/app/backend/internal/model/host.go +++ b/app/backend/internal/model/host.go @@ -49,6 +49,15 @@ func (s *HostStore) Search(q, filter string) []Host { return result } +func (s *HostStore) Delete(id string) { + for i, h := range s.Hosts { + if h.ID == id { + s.Hosts = append(s.Hosts[:i], s.Hosts[i+1:]...) + return + } + } +} + func (s *HostStore) Add(name, ip, os, provider, hostType string) Host { h := Host{ ID: randString(8), diff --git a/app/backend/main.go b/app/backend/main.go index 616b53e..2da3357 100644 --- a/app/backend/main.go +++ b/app/backend/main.go @@ -31,6 +31,7 @@ func main() { app.Get("/", handler.Dashboard) app.Get("/hosts", handler.DashboardList) app.Post("/hosts", handler.CreateHost) + app.Delete("/hosts/:id", handler.DeleteHost) app.Get("/api/health", handler.Health) log.Fatal(app.Listen(":1947")) diff --git a/app/backend/static/css/custom.css b/app/backend/static/css/custom.css index ac6f1ee..73d218a 100644 --- a/app/backend/static/css/custom.css +++ b/app/backend/static/css/custom.css @@ -1,5 +1,8 @@ /* Lumina System — Custom CSS */ +/* Alpine cloak — hide until initialized */ +[x-cloak] { display: none !important; } + /* Dot grid background */ .dot-grid { background-image: radial-gradient(#e2e8f0 1.5px, transparent 1.5px); diff --git a/app/backend/views/host_list.html b/app/backend/views/host_list.html index 8804891..2a42ca9 100644 --- a/app/backend/views/host_list.html +++ b/app/backend/views/host_list.html @@ -1,29 +1,61 @@ {{define "host_list"}} -
- {{range .Hosts}} -
-
-
-
- +
+
+ {{range .Hosts}} +
+
+
+
+ +
+
+

{{.Name}}

+

{{.IP}}

+
-
-

{{.Name}}

-

{{.IP}}

+ + {{.Status}} + +
+
+ {{.OS}} + · + {{.Provider}} +
+
+ {{.LastSeen}} +
+ +
- - {{.Status}} -
-
- {{.OS}} - · - {{.Provider}} -
-
- {{.LastSeen}} -
+ {{end}} +
+ +
+ {{range .Hosts}} +
+
+
+ +
+
+
+

{{.Name}}

+ {{.Status}} +
+

{{.IP}} · {{.OS}} · {{.Provider}}

+
+ {{.LastSeen}} +
+ {{end}}
- {{end}} {{if eq (len .Hosts) 0}} -
+

No hosts found

Try a different search or add a new host

{{end}}
+ @click="$dispatch('open-modal')"> Add New Host
-{{end}} +{{end}} \ No newline at end of file diff --git a/app/backend/views/host_modal.html b/app/backend/views/host_modal.html index 3f66256..73a4da0 100644 --- a/app/backend/views/host_modal.html +++ b/app/backend/views/host_modal.html @@ -1,18 +1,19 @@ {{define "host_modal"}} -