borgmatic-monitor/pkg/web/hosts.go
2026-02-24 09:21:41 +01:00

86 lines
1.4 KiB
Go

package web
import (
"fmt"
"net/http"
"github.com/labstack/echo/v5"
"gitnet.fr/deblan/borgmatic-monitor/pkg/database"
. "maragu.dev/gomponents"
// . "maragu.dev/gomponents/components"
. "maragu.dev/gomponents/html"
)
func Hosts(c *echo.Context) error {
var nodes []Node
for _, host := range database.Hosts() {
lastArchive := host.LastArchive()
var body Node
if lastArchive != nil {
body = Div(
Div(
Class("fw-bold"),
I(Class("ri-archive-stack-line me-1")),
Text(fmt.Sprintf(
"%d archive(s)",
host.ArchivesCount(),
)),
),
Div(
I(Class("ri-calendar-line me-1")),
Text(fmt.Sprintf(
"Last update on %s",
lastArchive.End.Format("2006-01-02 15:04:05"),
)),
),
Div(
Class("mt-3"),
A(
Class("btn btn-primary"),
Href(fmt.Sprintf("/host/%d", host.ID)),
Text("Show"),
),
),
)
} else {
body = Div(
Class("text-danger"),
I(Class("ri-error-warning-line me-1")),
Text("Nothing yet!"),
)
}
card := Div(
Class("col-6"),
Div(
Class("card mb-3"),
Div(
Class("card-header"),
Text(host.Name),
),
Div(
Class("card-body"),
body,
),
),
)
nodes = append(nodes, card)
}
return c.HTML(http.StatusOK, page(
"home",
"Hosts",
Div(
Class("container-fluid"),
Div(
Class("row"),
Group(nodes),
),
),
))
}