[webui] refactored states and versions routes
This commit is contained in:
parent
6fd1663d8c
commit
a83296b79a
8 changed files with 78 additions and 75 deletions
|
@ -17,10 +17,10 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range .States }}
|
{{ range .States }}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/state/{{ .Id }}">{{ .Path }}</a></td>
|
<td><a href="/states/{{ .Id }}">{{ .Path }}</a></td>
|
||||||
<td><a href="/state/{{ .Id }}">{{ .Updated }}</a></td>
|
<td><a href="/states/{{ .Id }}">{{ .Updated }}</a></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/state/{{ .Id }}">
|
<a href="/states/{{ .Id }}">
|
||||||
{{ if eq .Lock nil }}no{{ else }}
|
{{ if eq .Lock nil }}no{{ else }}
|
||||||
<span>yes</span>
|
<span>yes</span>
|
||||||
<div class="tooltip left max">
|
<div class="tooltip left max">
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range .Versions }}
|
{{ range .Versions }}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/version/{{ .Id }}">{{ index $.Usernames .AccountId }}</a></td>
|
<td><a href="/versions/{{ .Id }}">{{ index $.Usernames .AccountId }}</a></td>
|
||||||
<td><a href="/version/{{ .Id }}">{{ .Created }}</a></td>
|
<td><a href="/versions/{{ .Id }}">{{ .Created }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
|
@ -1,10 +0,0 @@
|
||||||
{{ define "main" }}
|
|
||||||
<main class="responsive" id="main">
|
|
||||||
<p>
|
|
||||||
Created by
|
|
||||||
<a href="/users/{{ .Account.Id }}">{{ .Account.Username }}</a>
|
|
||||||
at {{ .Version.Created }}
|
|
||||||
</p>
|
|
||||||
<pre>{{ .VersionData }}</pre>
|
|
||||||
</main>
|
|
||||||
{{ end }}
|
|
23
pkg/webui/html/versions.html
Normal file
23
pkg/webui/html/versions.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{{ define "main" }}
|
||||||
|
<main class="responsive" id="main">
|
||||||
|
<p>
|
||||||
|
Created by
|
||||||
|
<a href="/users/{{ .Account.Id }}">{{ .Account.Username }}</a>
|
||||||
|
at {{ .Version.Created }}
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<div class="tabs">
|
||||||
|
<a data-ui="#explorer" class="active">Explorer</a>
|
||||||
|
<a data-ui="#raw">Raw</a>
|
||||||
|
</div>
|
||||||
|
<div id="explorer" class="page padding active">
|
||||||
|
<article class="border medium no-padding center-align middle-align">
|
||||||
|
<progress class="circle large"></progress>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<div id="raw" class="page padding">
|
||||||
|
<pre><code id="raw-state">{{ .VersionData }}</code></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{{ end }}
|
|
@ -20,8 +20,8 @@ func addRoutes(
|
||||||
mux.Handle("POST /settings", requireLogin(handleSettingsPOST(db)))
|
mux.Handle("POST /settings", requireLogin(handleSettingsPOST(db)))
|
||||||
mux.Handle("GET /states", requireLogin(handleStatesGET(db)))
|
mux.Handle("GET /states", requireLogin(handleStatesGET(db)))
|
||||||
mux.Handle("POST /states", requireLogin(handleStatesPOST(db)))
|
mux.Handle("POST /states", requireLogin(handleStatesPOST(db)))
|
||||||
mux.Handle("GET /state/{id}", requireLogin(handleStateGET(db)))
|
mux.Handle("GET /states/{id}", requireLogin(handleStatesIdGET(db)))
|
||||||
mux.Handle("GET /static/", cache(http.FileServer(http.FS(staticFS))))
|
mux.Handle("GET /static/", cache(http.FileServer(http.FS(staticFS))))
|
||||||
mux.Handle("GET /version/{id}", requireLogin(handleVersionGET(db)))
|
mux.Handle("GET /versions/{id}", requireLogin(handleVersionsGET(db)))
|
||||||
mux.Handle("GET /", requireLogin(handleIndexGET()))
|
mux.Handle("GET /", requireLogin(handleIndexGET()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
var stateTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/state.html"))
|
|
||||||
|
|
||||||
func handleStateGET(db *database.DB) http.Handler {
|
|
||||||
type StatesData struct {
|
|
||||||
Page *Page
|
|
||||||
State *model.State
|
|
||||||
Usernames map[string]string
|
|
||||||
Versions []model.Version
|
|
||||||
}
|
|
||||||
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, 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: makePage(r, &Page{
|
|
||||||
Precedent: "/states",
|
|
||||||
Section: "states",
|
|
||||||
Title: state.Path,
|
|
||||||
}),
|
|
||||||
State: state,
|
|
||||||
Usernames: usernames,
|
|
||||||
Versions: versions,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"git.adyxax.org/adyxax/tfstated/pkg/database"
|
"git.adyxax.org/adyxax/tfstated/pkg/database"
|
||||||
"git.adyxax.org/adyxax/tfstated/pkg/model"
|
"git.adyxax.org/adyxax/tfstated/pkg/model"
|
||||||
|
"go.n16f.net/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StatesPage struct {
|
type StatesPage struct {
|
||||||
|
@ -22,6 +23,7 @@ type StatesPage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var statesTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/states.html"))
|
var statesTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/states.html"))
|
||||||
|
var statesIdTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/statesId.html"))
|
||||||
|
|
||||||
func handleStatesGET(db *database.DB) http.Handler {
|
func handleStatesGET(db *database.DB) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -86,7 +88,48 @@ func handleStatesPOST(db *database.DB) http.Handler {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
destination := path.Join("/version", version.Id.String())
|
destination := path.Join("/versions", version.Id.String())
|
||||||
http.Redirect(w, r, destination, http.StatusFound)
|
http.Redirect(w, r, destination, http.StatusFound)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleStatesIdGET(db *database.DB) http.Handler {
|
||||||
|
type StatesData struct {
|
||||||
|
Page *Page
|
||||||
|
State *model.State
|
||||||
|
Usernames map[string]string
|
||||||
|
Versions []model.Version
|
||||||
|
}
|
||||||
|
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, 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, statesIdTemplate, http.StatusOK, StatesData{
|
||||||
|
Page: makePage(r, &Page{
|
||||||
|
Precedent: "/states",
|
||||||
|
Section: "states",
|
||||||
|
Title: state.Path,
|
||||||
|
}),
|
||||||
|
State: state,
|
||||||
|
Usernames: usernames,
|
||||||
|
Versions: versions,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"go.n16f.net/uuid"
|
"go.n16f.net/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
var versionTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/version.html"))
|
var versionsTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/versions.html"))
|
||||||
|
|
||||||
func handleVersionGET(db *database.DB) http.Handler {
|
func handleVersionsGET(db *database.DB) http.Handler {
|
||||||
type VersionsData struct {
|
type VersionsData struct {
|
||||||
Page *Page
|
Page *Page
|
||||||
Account *model.Account
|
Account *model.Account
|
||||||
|
@ -46,9 +46,9 @@ func handleVersionGET(db *database.DB) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
versionData := string(version.Data[:])
|
versionData := string(version.Data[:])
|
||||||
render(w, versionTemplate, http.StatusOK, VersionsData{
|
render(w, versionsTemplate, http.StatusOK, VersionsData{
|
||||||
Page: makePage(r, &Page{
|
Page: makePage(r, &Page{
|
||||||
Precedent: path.Join("/state/", state.Id.String()),
|
Precedent: path.Join("/states/", state.Id.String()),
|
||||||
Section: "states",
|
Section: "states",
|
||||||
Title: state.Path,
|
Title: state.Path,
|
||||||
}),
|
}),
|
Loading…
Add table
Reference in a new issue