56 lines
968 B
Go
56 lines
968 B
Go
package partial
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database"
|
|
. "maragu.dev/gomponents"
|
|
. "maragu.dev/gomponents/html"
|
|
)
|
|
|
|
func NavMenu(currentNode string) Node {
|
|
items := [][3]string{
|
|
[3]string{"home", "/", "All"},
|
|
}
|
|
|
|
for _, host := range database.Hosts() {
|
|
items = append(
|
|
items,
|
|
[3]string{
|
|
fmt.Sprintf("host_%d", host.ID),
|
|
fmt.Sprintf("/host/%d", host.ID),
|
|
host.Name,
|
|
},
|
|
)
|
|
}
|
|
|
|
return Div(
|
|
Class("d-flex flex-column flex-shrink-0 p-3 text-bg-dark"),
|
|
Style("width: 280px; height: 100vh"),
|
|
Ul(
|
|
Class("nav nav-pills flex-column mb-auto"),
|
|
Map(items, func(item [3]string) Node {
|
|
return NavMenuItem(item, currentNode == item[0])
|
|
}),
|
|
),
|
|
)
|
|
}
|
|
|
|
func NavMenuItem(item [3]string, isActive bool) Node {
|
|
class := "nav-link"
|
|
|
|
if isActive {
|
|
class += " active"
|
|
} else {
|
|
class += " text-white"
|
|
}
|
|
|
|
return Li(
|
|
Class("nav-item"),
|
|
A(
|
|
Class(class),
|
|
Href(item[1]),
|
|
Text(item[2]),
|
|
),
|
|
)
|
|
}
|