summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/handlers.go')
-rw-r--r--internal/handlers/handlers.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index c3e49ed..9ba6351 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -6,6 +6,8 @@ import (
"html/template"
"log"
"net/http"
+ "sort"
+ "strings"
"sync"
"time"
@@ -302,6 +304,47 @@ func (h *Handler) aggregateData(ctx context.Context, forceRefresh bool) (*models
wg.Wait()
+ // Filter Trello cards into tasks based on heuristic
+ var trelloTasks []models.Card
+ for _, board := range data.Boards {
+ for _, card := range board.Cards {
+ listNameLower := strings.ToLower(card.ListName)
+ isTask := card.DueDate != nil ||
+ strings.Contains(listNameLower, "todo") ||
+ strings.Contains(listNameLower, "doing") ||
+ strings.Contains(listNameLower, "progress") ||
+ strings.Contains(listNameLower, "task")
+
+ if isTask {
+ trelloTasks = append(trelloTasks, card)
+ }
+ }
+ }
+
+ // Sort trelloTasks: earliest due date first, nil last, then by board name
+ sort.Slice(trelloTasks, func(i, j int) bool {
+ // Both have due dates: compare dates
+ if trelloTasks[i].DueDate != nil && trelloTasks[j].DueDate != nil {
+ if !trelloTasks[i].DueDate.Equal(*trelloTasks[j].DueDate) {
+ return trelloTasks[i].DueDate.Before(*trelloTasks[j].DueDate)
+ }
+ // Same due date, fall through to board name comparison
+ }
+
+ // Only one has due date: that one comes first
+ if trelloTasks[i].DueDate != nil && trelloTasks[j].DueDate == nil {
+ return true
+ }
+ if trelloTasks[i].DueDate == nil && trelloTasks[j].DueDate != nil {
+ return false
+ }
+
+ // Both nil or same due date: sort by board name
+ return trelloTasks[i].BoardName < trelloTasks[j].BoardName
+ })
+
+ data.TrelloTasks = trelloTasks
+
return data, nil
}