From 2255318993148315e12cddb38cab3926115a6cb2 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 16 Feb 2026 14:40:04 +0100 Subject: [PATCH] Dashboard nach Feld gruppieren und Verkaufs-Hinweise integrieren --- cmd/server/calendar.go | 21 +++++++++++- cmd/server/handlers_pages.go | 1 + cmd/server/types.go | 7 ++++ templates/dashboard.html | 62 ++++++++++++++++++++++-------------- 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/cmd/server/calendar.go b/cmd/server/calendar.go index 3fa4a15..6512453 100644 --- a/cmd/server/calendar.go +++ b/cmd/server/calendar.go @@ -33,7 +33,7 @@ func buildCalendar(plans []Plan, crops []Crop, products []Product, stepMap map[i items := collectTasksForDate(plans, crops, products, stepMap, customTasks, month, d, yearOffset) applyCompletion(items, doneMap) sortTasks(items) - days = append(days, CalendarDay{Day: d, Tasks: items}) + days = append(days, CalendarDay{Day: d, Tasks: items, Groups: groupTasksByField(items)}) } out = append(out, CalendarMonth{ Offset: offset, @@ -46,6 +46,25 @@ func buildCalendar(plans []Plan, crops []Crop, products []Product, stepMap map[i return out } +func groupTasksByField(tasks []Task) []FieldTaskGroup { + if len(tasks) == 0 { + return nil + } + order := make([]string, 0, len(tasks)) + grouped := make(map[string][]Task) + for _, t := range tasks { + if _, ok := grouped[t.Field]; !ok { + order = append(order, t.Field) + } + grouped[t.Field] = append(grouped[t.Field], t) + } + out := make([]FieldTaskGroup, 0, len(order)) + for _, field := range order { + out = append(out, FieldTaskGroup{Field: field, Tasks: grouped[field]}) + } + return out +} + func collectTasksForDate(plans []Plan, crops []Crop, products []Product, stepMap map[int64][]CropStep, customTasks []CustomTask, month, day, yearOffset int) []Task { var tasks []Task diff --git a/cmd/server/handlers_pages.go b/cmd/server/handlers_pages.go index d1318df..ef1dfe3 100644 --- a/cmd/server/handlers_pages.go +++ b/cmd/server/handlers_pages.go @@ -68,6 +68,7 @@ func (a *App) handleDashboard(w http.ResponseWriter, r *http.Request) { Calendar: buildCalendar(plans, crops, products, stepMap, customTasks, doneMap, settings.CurrentMonth, settings.CurrentDay, settings.DaysPerMonth, 14), PlanningCount: len(plans), } + data.TodayGroups = groupTasksByField(data.TodayTasks) a.renderTemplate(w, "templates/dashboard.html", data) } diff --git a/cmd/server/types.go b/cmd/server/types.go index 9016b1e..6601e54 100644 --- a/cmd/server/types.go +++ b/cmd/server/types.go @@ -107,6 +107,7 @@ type MonthOption struct { type CalendarDay struct { Day int Tasks []Task + Groups []FieldTaskGroup } type CalendarMonth struct { @@ -123,11 +124,17 @@ type BasePage struct { Info string } +type FieldTaskGroup struct { + Field string + Tasks []Task +} + type DashboardPage struct { BasePage Settings Settings CurrentMonth string TodayTasks []Task + TodayGroups []FieldTaskGroup Calendar []CalendarMonth PlanningCount int } diff --git a/templates/dashboard.html b/templates/dashboard.html index fc6903b..df09c77 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -52,19 +52,26 @@

Heute

- {{if .TodayTasks}} + {{if .TodayGroups}} @@ -83,19 +90,26 @@ {{range .Days}}
  • Tag {{.Day}} - {{if .Tasks}} + {{if .Groups}}
      - {{range .Tasks}} -
    • - {{.Field}}: {{.Message}} -
      - - - - - - -
      + {{range .Groups}} +
    • + {{.Field}} +
        + {{range .Tasks}} +
      • + {{.Message}} +
        + + + + + + +
        +
      • + {{end}} +
    • {{end}}