diff --git a/src/core/admin/templates/groups.templ b/src/core/admin/templates/groups.templ index 51013da..4fb043c 100644 --- a/src/core/admin/templates/groups.templ +++ b/src/core/admin/templates/groups.templ @@ -42,12 +42,7 @@ templ GroupList(groups []GroupRow) {
- - +
} @@ -75,6 +70,34 @@ templ CreateGroupForm() { } +templ EditGroupForm(name, description string) { +
+
+

Edit Group

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+} + type GroupRow struct { Name string UserCount int diff --git a/src/core/admin/templates/groups_templ.go b/src/core/admin/templates/groups_templ.go index a981381..159d6a8 100644 --- a/src/core/admin/templates/groups_templ.go +++ b/src/core/admin/templates/groups_templ.go @@ -135,33 +135,20 @@ func GroupList(groups []GroupRow) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " members
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" hx-target=\"#group-detail\" hx-swap=\"innerHTML\">Edit") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -172,6 +159,35 @@ func GroupList(groups []GroupRow) templ.Component { } func CreateGroupForm() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var9 := templ.GetChildren(ctx) + if templ_7745c5c3_Var9 == nil { + templ_7745c5c3_Var9 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "

New Group

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func EditGroupForm(name, description string) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -192,7 +208,72 @@ func CreateGroupForm() templ.Component { templ_7745c5c3_Var10 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "

New Group

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "

Edit Group

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/src/core/admin/ui.go b/src/core/admin/ui.go index afe71bb..672703b 100644 --- a/src/core/admin/ui.go +++ b/src/core/admin/ui.go @@ -26,6 +26,8 @@ func (h *Handler) RegisterUIRoutes(mux *http.ServeMux, authMiddleware func(http. mux.Handle("DELETE /admin/groups/{name}", authMiddleware(http.HandlerFunc(h.deleteGroup))) mux.Handle("GET /admin/groups/create-form", authMiddleware(http.HandlerFunc(h.createGroupForm))) mux.Handle("GET /admin/groups/cancel-form", authMiddleware(http.HandlerFunc(h.cancelForm))) + mux.Handle("GET /admin/groups/edit-form/{name}", authMiddleware(http.HandlerFunc(h.editGroupForm))) + mux.Handle("PUT /admin/groups/{name}", authMiddleware(http.HandlerFunc(h.updateGroup))) } func (h *Handler) adminDashboard(w http.ResponseWriter, r *http.Request) { @@ -356,3 +358,26 @@ func (h *Handler) deleteGroup(w http.ResponseWriter, r *http.Request) { } h.groupList(w, r) } + +func (h *Handler) editGroupForm(w http.ResponseWriter, r *http.Request) { + name := r.PathValue("name") + g, err := h.groupStore.GetByName(name) + if err != nil || g == nil { + http.Error(w, "group not found", http.StatusNotFound) + return + } + component := templates.EditGroupForm(g.Name, g.Description) + component.Render(r.Context(), w) +} + +func (h *Handler) updateGroup(w http.ResponseWriter, r *http.Request) { + name := r.PathValue("name") + desc := r.FormValue("description") + // Update group description + _, err := h.groupStore.db.Exec(`UPDATE groups SET description = ? WHERE name = ?`, desc, name) + if err != nil { + http.Error(w, "update failed", http.StatusInternalServerError) + return + } + h.groupList(w, r) +}