Dashboard nach Feld gruppieren und Verkaufs-Hinweise integrieren

This commit is contained in:
Kai
2026-02-16 14:40:04 +01:00
parent b1c502a919
commit 2255318993
4 changed files with 66 additions and 25 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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
}