2024-02-11 19:28:00 +00:00
|
|
|
package handlers
|
2024-02-10 17:35:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"text/template"
|
|
|
|
|
2024-02-11 19:28:00 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/web/templates"
|
2024-02-12 10:22:14 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
2024-02-10 17:35:16 +00:00
|
|
|
)
|
|
|
|
|
2024-02-12 10:22:14 +00:00
|
|
|
type Settings struct {
|
|
|
|
*components.Base
|
2024-02-12 13:20:38 +00:00
|
|
|
SettingsPage *components.Page
|
|
|
|
SettingsPages []*components.Page
|
|
|
|
User *AuthenticatedUser
|
2024-02-12 10:22:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-12 13:20:38 +00:00
|
|
|
var SettingsPages = []*components.Page{
|
|
|
|
{Path: "/settings", Title: "Overview"},
|
|
|
|
{Path: "/settings/healthchecks", Title: "Healthchecks"},
|
|
|
|
{Path: "/settings/workers", Title: "Workers"},
|
2024-02-13 11:00:48 +00:00
|
|
|
{Path: "/temporal", Title: "Temporal"},
|
2024-02-12 13:20:38 +00:00
|
|
|
{Path: "/oauth2/logout", Title: "Logout"},
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *BaseHandler) SettingsOverviewGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
|
|
|
|
ts, err := template.ParseFS(templates.Templates,
|
|
|
|
"components/base.tmpl",
|
|
|
|
"components/settings.tmpl",
|
|
|
|
"pages/settings_overview.tmpl",
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ts.ExecuteTemplate(w, "base", &Settings{
|
|
|
|
Base: &components.Base{
|
|
|
|
Page: GetPageByTitle(Pages, "Settings"),
|
|
|
|
Pages: Pages,
|
|
|
|
},
|
|
|
|
SettingsPage: GetPageByTitle(SettingsPages, "Overview"),
|
|
|
|
SettingsPages: SettingsPages,
|
|
|
|
User: user,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *BaseHandler) SettingsHealthchecksGET(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
|
2024-02-11 19:28:00 +00:00
|
|
|
ts, err := template.ParseFS(templates.Templates,
|
2024-02-11 10:56:21 +00:00
|
|
|
"components/base.tmpl",
|
2024-02-12 13:20:38 +00:00
|
|
|
"components/settings.tmpl",
|
|
|
|
"pages/settings_healthchecks.tmpl",
|
2024-02-10 17:35:16 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-12 10:22:14 +00:00
|
|
|
err = ts.ExecuteTemplate(w, "base", &Settings{
|
|
|
|
Base: &components.Base{
|
2024-02-12 13:20:38 +00:00
|
|
|
Page: GetPageByTitle(Pages, "Settings"),
|
2024-02-12 10:22:14 +00:00
|
|
|
Pages: Pages,
|
|
|
|
},
|
2024-02-12 13:20:38 +00:00
|
|
|
SettingsPage: GetPageByTitle(SettingsPages, "Healthchecks"),
|
|
|
|
SettingsPages: SettingsPages,
|
|
|
|
User: user,
|
2024-02-12 10:22:14 +00:00
|
|
|
})
|
2024-02-10 17:35:16 +00:00
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|