feat: Sprint 1 final — delete host, Alpine modal events, grid/list toggle, transfers panel
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user