summaryrefslogtreecommitdiff
path: root/internal/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers')
-rw-r--r--internal/handlers/handlers.go67
1 files changed, 66 insertions, 1 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index 6872ba7..f31fc56 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -28,12 +28,18 @@ type Handler struct {
// New creates a new Handler instance
func New(store *store.Store, todoist api.TodoistAPI, trello api.TrelloAPI, obsidian api.ObsidianAPI, planToEat api.PlanToEatAPI, cfg *config.Config) *Handler {
- // Parse templates
+ // Parse templates including partials
tmpl, err := template.ParseGlob("web/templates/*.html")
if err != nil {
log.Printf("Warning: failed to parse templates: %v", err)
}
+ // Also parse partials
+ tmpl, err = tmpl.ParseGlob("web/templates/partials/*.html")
+ if err != nil {
+ log.Printf("Warning: failed to parse partial templates: %v", err)
+ }
+
return &Handler{
store: store,
todoistClient: todoist,
@@ -136,6 +142,65 @@ func (h *Handler) HandleGetBoards(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(boards)
}
+// HandleTasksTab renders the tasks tab content (Trello + Todoist + PlanToEat)
+func (h *Handler) HandleTasksTab(w http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+
+ data, err := h.aggregateData(ctx, false)
+ if err != nil {
+ http.Error(w, "Failed to load tasks", http.StatusInternalServerError)
+ log.Printf("Error loading tasks tab: %v", err)
+ return
+ }
+
+ if err := h.templates.ExecuteTemplate(w, "tasks-tab", data); err != nil {
+ http.Error(w, "Failed to render template", http.StatusInternalServerError)
+ log.Printf("Error rendering tasks tab: %v", err)
+ }
+}
+
+// HandleNotesTab renders the notes tab content (Obsidian)
+func (h *Handler) HandleNotesTab(w http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+
+ data, err := h.aggregateData(ctx, false)
+ if err != nil {
+ http.Error(w, "Failed to load notes", http.StatusInternalServerError)
+ log.Printf("Error loading notes tab: %v", err)
+ return
+ }
+
+ if err := h.templates.ExecuteTemplate(w, "notes-tab", data); err != nil {
+ http.Error(w, "Failed to render template", http.StatusInternalServerError)
+ log.Printf("Error rendering notes tab: %v", err)
+ }
+}
+
+// HandleRefreshTab refreshes and re-renders the specified tab
+func (h *Handler) HandleRefreshTab(w http.ResponseWriter, r *http.Request) {
+ ctx := r.Context()
+ tab := r.URL.Query().Get("tab") // "tasks" or "notes"
+
+ // Force refresh
+ data, err := h.aggregateData(ctx, true)
+ if err != nil {
+ http.Error(w, "Failed to refresh", http.StatusInternalServerError)
+ log.Printf("Error refreshing tab: %v", err)
+ return
+ }
+
+ // Determine template to render
+ templateName := "tasks-tab"
+ if tab == "notes" {
+ templateName = "notes-tab"
+ }
+
+ if err := h.templates.ExecuteTemplate(w, templateName, data); err != nil {
+ http.Error(w, "Failed to render template", http.StatusInternalServerError)
+ log.Printf("Error rendering refreshed tab: %v", err)
+ }
+}
+
// aggregateData fetches and caches data from all sources
func (h *Handler) aggregateData(ctx context.Context, forceRefresh bool) (*models.DashboardData, error) {
data := &models.DashboardData{