137 lines
3 KiB
Go
137 lines
3 KiB
Go
package web
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/dustin/go-humanize"
|
|
"github.com/labstack/echo/v5"
|
|
"github.com/spf13/cast"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/borgmatic"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database"
|
|
|
|
. "maragu.dev/gomponents"
|
|
|
|
// . "maragu.dev/gomponents/components"
|
|
. "maragu.dev/gomponents/html"
|
|
)
|
|
|
|
func Host(c *echo.Context) error {
|
|
id := cast.ToInt(c.Param("id"))
|
|
|
|
if id == 0 {
|
|
return c.HTML(http.StatusNotFound, "Not found.")
|
|
}
|
|
|
|
host := database.Host(id)
|
|
|
|
if host == nil {
|
|
return c.HTML(http.StatusNotFound, "Not found.")
|
|
}
|
|
|
|
var nodes []Node
|
|
|
|
if len(host.Infos) == 0 {
|
|
nodes = append(
|
|
nodes,
|
|
Div(
|
|
Class("text-muted"),
|
|
Text("Nothing yet!"),
|
|
),
|
|
)
|
|
} else {
|
|
|
|
for _, item := range host.Infos {
|
|
if infos := *item.Infos(); infos != nil {
|
|
for i := len(infos) - 1; i >= 0; i-- {
|
|
info := infos[i]
|
|
|
|
card := Div(
|
|
Class("col-12"),
|
|
Div(
|
|
Class("card mb-3"),
|
|
Div(
|
|
Class("card-header"),
|
|
Text(info.Repository.LastModified.Format("2006-01-02 15:04:05")),
|
|
),
|
|
Div(
|
|
Class("card-body"),
|
|
Div(
|
|
I(Class("ri-price-tag-3-line me-1")),
|
|
Text(info.Repository.Label),
|
|
),
|
|
Div(
|
|
I(Class("ri-map-pin-line me-1")),
|
|
Text(info.Repository.Location),
|
|
),
|
|
Div(
|
|
Class("mb-3"),
|
|
I(Class("ri-lock-line me-1")),
|
|
Text(info.Encryption.Mode),
|
|
),
|
|
Div(
|
|
Map(info.Archives, func(archive borgmatic.Archive) Node {
|
|
return Div(
|
|
Class("row"),
|
|
Div(
|
|
Class("col-12 col-md-4"),
|
|
I(Class("ri-store-3-fill me-1")),
|
|
Text(archive.Name),
|
|
),
|
|
Div(
|
|
Class("text-end col-12 col-md-4"),
|
|
Text(fmt.Sprintf("%2.fs", archive.Duration)),
|
|
I(Class("ri-time-fill mx-2")),
|
|
Text(fmt.Sprintf("%d", archive.Stats.Nfiles)),
|
|
I(Class("ri-file-fill ms-2")),
|
|
),
|
|
Div(
|
|
Class("text-end col-12 col-md-4"),
|
|
Div(
|
|
Class("row"),
|
|
Div(
|
|
Class("col-4 text-secondary"),
|
|
Text(humanize.Bytes(uint64(archive.Stats.OriginalSize))),
|
|
),
|
|
Div(
|
|
Class("col-4 text-primary"),
|
|
Text(humanize.Bytes(uint64(archive.Stats.DeduplicatedSize))),
|
|
),
|
|
Div(
|
|
Class("col-4 text-success"),
|
|
Text(humanize.Bytes(uint64(archive.Stats.CompressedSize))),
|
|
I(Class("ri-file-zip-fill ms-2")),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
|
|
nodes = append(nodes, card)
|
|
|
|
// for _, archive := range info.Archives {
|
|
//
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return c.HTML(http.StatusOK, page(
|
|
fmt.Sprintf("host_%d", host.ID),
|
|
host.Name,
|
|
Div(
|
|
Class("container-fluid"),
|
|
Div(
|
|
Class("row"),
|
|
Map(nodes, func(node Node) Node {
|
|
return node
|
|
}),
|
|
),
|
|
),
|
|
))
|
|
}
|