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-15 22:47:56 +00:00
|
|
|
SettingsSidebarActive *components.Page
|
|
|
|
SettingsSidebar []*components.Page
|
|
|
|
User *AuthenticatedUser
|
|
|
|
SettingsBreadcrumbs []*components.Page
|
2024-02-12 10:22:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-15 22:47:56 +00:00
|
|
|
func NewSettings(user *AuthenticatedUser, page *components.Page, breadCrumbs []*components.Page) *Settings {
|
|
|
|
return &Settings{
|
2024-02-12 13:20:38 +00:00
|
|
|
Base: &components.Base{
|
2024-02-15 22:47:56 +00:00
|
|
|
NavbarActive: GetPageByTitle(Pages, "Settings"),
|
|
|
|
Navbar: Pages,
|
2024-02-12 13:20:38 +00:00
|
|
|
},
|
2024-02-15 22:47:56 +00:00
|
|
|
SettingsSidebarActive: page,
|
|
|
|
SettingsSidebar: SettingsNavbar,
|
|
|
|
SettingsBreadcrumbs: breadCrumbs,
|
|
|
|
User: user,
|
2024-02-12 13:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 22:47:56 +00:00
|
|
|
var SettingsPages = []*components.Page{
|
|
|
|
{Path: "/settings", Title: "Overview", Breadcrumb: "Overview"},
|
|
|
|
{Path: "/settings/healthchecks", Title: "Healthchecks", Breadcrumb: "Healthchecks"},
|
|
|
|
{Path: "/settings/healthchecks/create", Title: "Healthchecks Create", Breadcrumb: "Create"},
|
|
|
|
{Path: "/settings/cronjobs", Title: "Cronjobs", Breadcrumb: "Cronjobs"},
|
|
|
|
{Path: "/settings/workers", Title: "Workers", Breadcrumb: "Workers"},
|
2024-02-18 21:37:17 +00:00
|
|
|
{Path: "/settings/workers/create", Title: "Workers Create", Breadcrumb: "Create"},
|
2024-02-19 14:23:17 +00:00
|
|
|
{Path: "/settings/temporal", Title: "Temporal", Breadcrumb: "Temporal"},
|
2024-02-15 22:47:56 +00:00
|
|
|
{Path: "/oauth2/logout", Title: "Logout", Breadcrumb: "Logout"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var SettingsNavbar = []*components.Page{
|
|
|
|
GetPageByTitle(SettingsPages, "Overview"),
|
|
|
|
GetPageByTitle(SettingsPages, "Healthchecks"),
|
|
|
|
GetPageByTitle(SettingsPages, "Cronjobs"),
|
|
|
|
GetPageByTitle(SettingsPages, "Workers"),
|
|
|
|
GetPageByTitle(SettingsPages, "Temporal"),
|
|
|
|
GetPageByTitle(SettingsPages, "Logout"),
|
|
|
|
}
|
|
|
|
|
2024-02-19 09:09:30 +00:00
|
|
|
func (h *BaseHandler) SettingsOverviewGET(w http.ResponseWriter, r *http.Request, principal *AuthenticatedPrincipal) {
|
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",
|
2024-02-15 22:47:56 +00:00
|
|
|
"pages/settings_overview.tmpl",
|
2024-02-10 17:35:16 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-15 22:47:56 +00:00
|
|
|
err = ts.ExecuteTemplate(w, "base", NewSettings(
|
2024-02-19 09:09:30 +00:00
|
|
|
principal.User,
|
2024-02-15 22:47:56 +00:00
|
|
|
GetPageByTitle(SettingsPages, "Overview"),
|
|
|
|
[]*components.Page{GetPageByTitle(SettingsPages, "Overview")},
|
|
|
|
))
|
2024-02-10 17:35:16 +00:00
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|