chore(webui): improve the states id page
This commit is contained in:
parent
9bf75bfd37
commit
6fb2db436d
4 changed files with 106 additions and 45 deletions
56
pkg/webui/statesId.go
Normal file
56
pkg/webui/statesId.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package webui
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"git.adyxax.org/adyxax/tfstated/pkg/database"
|
||||
"git.adyxax.org/adyxax/tfstated/pkg/model"
|
||||
"go.n16f.net/uuid"
|
||||
)
|
||||
|
||||
type StatesIdPage struct {
|
||||
Page *Page
|
||||
Path string
|
||||
PathError bool
|
||||
PathDuplicate bool
|
||||
State *model.State
|
||||
Usernames map[string]string
|
||||
Versions []model.Version
|
||||
}
|
||||
|
||||
var statesIdTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/statesId.html"))
|
||||
|
||||
func handleStatesIdGET(db *database.DB) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var stateId uuid.UUID
|
||||
if err := stateId.Parse(r.PathValue("id")); err != nil {
|
||||
errorResponse(w, r, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
state, err := db.LoadStateById(stateId)
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
versions, err := db.LoadVersionsByState(state)
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
usernames, err := db.LoadAccountUsernames()
|
||||
if err != nil {
|
||||
errorResponse(w, r, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
render(w, statesIdTemplate, http.StatusOK, StatesIdPage{
|
||||
Page: makePage(r, &Page{
|
||||
Section: "states",
|
||||
Title: state.Path,
|
||||
}),
|
||||
State: state,
|
||||
Usernames: usernames,
|
||||
Versions: versions,
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue