feat(webui): implement states list

This commit is contained in:
Julien Dessaux 2025-01-22 00:46:49 +01:00
parent 7885b19b54
commit 09885ef1e4
Signed by: adyxax
GPG key ID: F92E51B86E07177E
10 changed files with 117 additions and 12 deletions

29
pkg/webui/states.go Normal file
View file

@ -0,0 +1,29 @@
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 {
States []model.State
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store, no-cache")
states, err := db.LoadStatesByPath()
if err != nil {
errorResponse(w, http.StatusInternalServerError, err)
return
}
render(w, statesTemplates, http.StatusOK, StatesData{
States: states,
})
})
}