+ Locked: + {{ if eq .State.Lock nil }}no{{ else }} + yes +
{{ .State.Lock }}
+By | +Created | +
---|---|
{{ index $.Usernames .AccountId }} | +{{ .Created }} | +
From 26e10a9399bd6185741d0912ffa54c807ffef671 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 27 Jan 2025 22:00:51 +0100 Subject: feat(webui): implement state versions list --- pkg/webui/html/base.html | 8 +++++-- pkg/webui/html/state.html | 30 ++++++++++++++++++++++++++ pkg/webui/html/states.html | 2 +- pkg/webui/index.go | 5 +++-- pkg/webui/routes.go | 1 + pkg/webui/state.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++ pkg/webui/states.go | 2 +- pkg/webui/static/main.css | 3 +-- 8 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 pkg/webui/html/state.html create mode 100644 pkg/webui/state.go (limited to 'pkg/webui') diff --git a/pkg/webui/html/base.html b/pkg/webui/html/base.html index 06328e4..c0138ac 100644 --- a/pkg/webui/html/base.html +++ b/pkg/webui/html/base.html @@ -12,11 +12,10 @@ Login {{ else }} - + home_storage States -
+ Locked: + {{ if eq .State.Lock nil }}no{{ else }} + yes +
{{ .State.Lock }}
+By | +Created | +
---|---|
{{ index $.Usernames .AccountId }} | +{{ .Created }} | +
Path | diff --git a/pkg/webui/index.go b/pkg/webui/index.go index deea5d1..89e5ad6 100644 --- a/pkg/webui/index.go +++ b/pkg/webui/index.go @@ -6,8 +6,9 @@ import ( ) type Page struct { - Section string - Title string + Precedent string + Section string + Title string } func handleIndexGET() http.Handler { diff --git a/pkg/webui/routes.go b/pkg/webui/routes.go index 9bf04ec..4330630 100644 --- a/pkg/webui/routes.go +++ b/pkg/webui/routes.go @@ -17,6 +17,7 @@ func addRoutes( mux.Handle("POST /login", requireSession(handleLoginPOST(db))) mux.Handle("GET /logout", requireLogin(handleLogoutGET(db))) mux.Handle("GET /states", requireLogin(handleStatesGET(db))) + mux.Handle("GET /state/{id}", requireLogin(handleStateGET(db))) mux.Handle("GET /static/", cache(http.FileServer(http.FS(staticFS)))) mux.Handle("GET /", requireLogin(handleIndexGET())) } diff --git a/pkg/webui/state.go b/pkg/webui/state.go new file mode 100644 index 0000000..c7a6aaf --- /dev/null +++ b/pkg/webui/state.go @@ -0,0 +1,54 @@ +package webui + +import ( + "html/template" + "net/http" + "strconv" + + "git.adyxax.org/adyxax/tfstated/pkg/database" + "git.adyxax.org/adyxax/tfstated/pkg/model" +) + +var stateTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/state.html")) + +func handleStateGET(db *database.DB) http.Handler { + type StatesData struct { + Page + State *model.State + Usernames map[int]string + Versions []model.Version + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + stateIdStr := r.PathValue("id") + stateId, err := strconv.Atoi(stateIdStr) + if err != nil { + errorResponse(w, http.StatusBadRequest, err) + return + } + state, err := db.LoadStateById(stateId) + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + versions, err := db.LoadVersionsByState(state) + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + usernames, err := db.LoadAccountUsernames() + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + render(w, stateTemplate, http.StatusOK, StatesData{ + Page: Page{ + Precedent: "/states", + Section: "states", + Title: state.Path, + }, + State: state, + Usernames: usernames, + Versions: versions, + }) + }) +} diff --git a/pkg/webui/states.go b/pkg/webui/states.go index 0e956fb..d99d310 100644 --- a/pkg/webui/states.go +++ b/pkg/webui/states.go @@ -16,7 +16,7 @@ func handleStatesGET(db *database.DB) http.Handler { States []model.State } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - states, err := db.LoadStatesByPath() + states, err := db.LoadStates() if err != nil { errorResponse(w, http.StatusInternalServerError, err) return diff --git a/pkg/webui/static/main.css b/pkg/webui/static/main.css index f0fe350..ae56cd0 100644 --- a/pkg/webui/static/main.css +++ b/pkg/webui/static/main.css @@ -1,6 +1,5 @@ -.clickable-rows tbody a { +table tbody a { display: block; - padding: 0 1em 0; text-decoration: none; transition: all 0.25s ease-out; } -- cgit v1.2.3
---|