2024-02-11 19:28:00 +00:00
|
|
|
package handlers
|
2024-02-10 17:35:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-02-29 22:42:56 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/internal/services"
|
2024-02-12 10:22:14 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
2024-02-20 10:24:04 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
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"},
|
2024-02-24 11:57:53 +00:00
|
|
|
{Path: "/settings/monitors", Title: "Monitors", Breadcrumb: "Monitors"},
|
|
|
|
{Path: "/settings/monitors/create", Title: "Monitors Create", Breadcrumb: "Create"},
|
2024-02-24 21:07:49 +00:00
|
|
|
{Path: "/settings/worker-groups", Title: "Worker Groups", Breadcrumb: "Worker Groups"},
|
|
|
|
{Path: "/settings/worker-groups/create", Title: "Worker Groups Create", Breadcrumb: "Create"},
|
2024-02-23 11:18:02 +00:00
|
|
|
{Path: "/settings/notifications", Title: "Notifications", Breadcrumb: "Notifications"},
|
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"),
|
2024-02-24 11:57:53 +00:00
|
|
|
GetPageByTitle(SettingsPages, "Monitors"),
|
2024-02-24 21:07:49 +00:00
|
|
|
GetPageByTitle(SettingsPages, "Worker Groups"),
|
2024-02-23 11:18:02 +00:00
|
|
|
GetPageByTitle(SettingsPages, "Notifications"),
|
2024-02-15 22:47:56 +00:00
|
|
|
GetPageByTitle(SettingsPages, "Temporal"),
|
|
|
|
GetPageByTitle(SettingsPages, "Logout"),
|
|
|
|
}
|
|
|
|
|
2024-02-29 22:42:56 +00:00
|
|
|
type SettingsOverview struct {
|
|
|
|
*Settings
|
|
|
|
WorkerGroupsCount int
|
|
|
|
MonitorsCount int
|
|
|
|
NotificationsCount int
|
|
|
|
History []*services.MonitorHistoryWithMonitor
|
|
|
|
}
|
|
|
|
|
2024-02-20 10:24:04 +00:00
|
|
|
func (h *BaseHandler) SettingsOverviewGET(c echo.Context) error {
|
|
|
|
cc := c.(AuthenticatedContext)
|
2024-02-29 22:42:56 +00:00
|
|
|
ctx := c.Request().Context()
|
|
|
|
|
|
|
|
workerGroups, err := services.CountWorkerGroups(ctx, h.db)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
monitors, err := services.CountMonitors(ctx, h.db)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
history, err := services.GetLastNMonitorHistory(ctx, h.db, 10)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-02-10 17:35:16 +00:00
|
|
|
|
2024-02-29 22:42:56 +00:00
|
|
|
return c.Render(http.StatusOK, "settings_overview.tmpl", SettingsOverview{
|
|
|
|
Settings: NewSettings(
|
|
|
|
cc.Principal.User,
|
|
|
|
GetPageByTitle(SettingsPages, "Overview"),
|
|
|
|
[]*components.Page{GetPageByTitle(SettingsPages, "Overview")},
|
|
|
|
),
|
|
|
|
WorkerGroupsCount: workerGroups,
|
|
|
|
MonitorsCount: monitors,
|
|
|
|
NotificationsCount: 42,
|
|
|
|
History: history,
|
|
|
|
})
|
2024-02-10 17:35:16 +00:00
|
|
|
}
|