2025-01-22 00:46:49 +01:00
|
|
|
package webui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.adyxax.org/adyxax/tfstated/pkg/database"
|
|
|
|
"git.adyxax.org/adyxax/tfstated/pkg/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
var statesTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/states.html"))
|
|
|
|
|
|
|
|
func handleStatesGET(db *database.DB) http.Handler {
|
|
|
|
type StatesData struct {
|
2025-01-26 00:04:38 +01:00
|
|
|
Page
|
2025-01-22 00:46:49 +01:00
|
|
|
States []model.State
|
|
|
|
}
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2025-01-27 22:00:51 +01:00
|
|
|
states, err := db.LoadStates()
|
2025-01-22 00:46:49 +01:00
|
|
|
if err != nil {
|
|
|
|
errorResponse(w, http.StatusInternalServerError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
render(w, statesTemplates, http.StatusOK, StatesData{
|
2025-01-26 00:04:38 +01:00
|
|
|
Page: Page{Title: "States", Section: "states"},
|
2025-01-22 00:46:49 +01:00
|
|
|
States: states,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|