From 2fee76ea41f37e3a068273c05a98b892ab29228c Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Tue, 13 Jan 2026 14:09:50 -1000 Subject: Add Trello card creation and completion UI (Phase 3 Step 3) Implement interactive Trello card management with HTMX: Frontend: - Create trello-board.html partial with add card form - Add collapsible form with list selector and card title input - Add completion checkbox on each card - Update trello-boards.html to use new partial - Use HTMX for seamless partial updates (hx-post, hx-swap) Backend: - Add HandleCreateCard: creates card and re-renders board - Add HandleCompleteCard: marks card as closed - Register /cards and /cards/complete POST routes Features: - Add cards to any list via dropdown - Mark cards complete with checkbox (removes from view) - Real-time board updates without full page reload - Glassmorphism styling for form All tests pass. Full Trello write operations now available in UI. Co-Authored-By: Claude Sonnet 4.5 --- internal/handlers/handlers.go | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'internal') diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index ed100fc..8762035 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -438,3 +438,93 @@ func (h *Handler) fetchBoards(ctx context.Context, forceRefresh bool) ([]models. return boards, nil } + +// HandleCreateCard creates a new Trello card +func (h *Handler) HandleCreateCard(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + // Parse form data + if err := r.ParseForm(); err != nil { + http.Error(w, "Failed to parse form", http.StatusBadRequest) + log.Printf("Error parsing form: %v", err) + return + } + + boardID := r.FormValue("board_id") + listID := r.FormValue("list_id") + name := r.FormValue("name") + + if boardID == "" || listID == "" || name == "" { + http.Error(w, "Missing required fields", http.StatusBadRequest) + return + } + + // Create the card + _, err := h.trelloClient.CreateCard(ctx, listID, name, "", nil) + if err != nil { + http.Error(w, "Failed to create card", http.StatusInternalServerError) + log.Printf("Error creating card: %v", err) + return + } + + // Force refresh to get updated data + data, err := h.aggregateData(ctx, true) + if err != nil { + http.Error(w, "Failed to refresh data", http.StatusInternalServerError) + log.Printf("Error refreshing data: %v", err) + return + } + + // Find the specific board + var targetBoard *models.Board + for i := range data.Boards { + if data.Boards[i].ID == boardID { + targetBoard = &data.Boards[i] + break + } + } + + if targetBoard == nil { + http.Error(w, "Board not found", http.StatusNotFound) + return + } + + // Render the updated board + if err := h.templates.ExecuteTemplate(w, "trello-board", targetBoard); err != nil { + http.Error(w, "Failed to render template", http.StatusInternalServerError) + log.Printf("Error rendering board template: %v", err) + } +} + +// HandleCompleteCard marks a Trello card as complete +func (h *Handler) HandleCompleteCard(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + // Parse form data + if err := r.ParseForm(); err != nil { + http.Error(w, "Failed to parse form", http.StatusBadRequest) + log.Printf("Error parsing form: %v", err) + return + } + + cardID := r.FormValue("card_id") + + if cardID == "" { + http.Error(w, "Missing card_id", http.StatusBadRequest) + return + } + + // Mark card as closed (complete) + updates := map[string]interface{}{ + "closed": true, + } + + if err := h.trelloClient.UpdateCard(ctx, cardID, updates); err != nil { + http.Error(w, "Failed to complete card", http.StatusInternalServerError) + log.Printf("Error completing card: %v", err) + return + } + + // Return empty response (card will be removed from DOM) + w.WriteHeader(http.StatusOK) +} -- cgit v1.2.3