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) items := collectTasksForDate(plans, crops, products, stepMap, customTasks, month, d, yearOffset)
applyCompletion(items, doneMap) applyCompletion(items, doneMap)
sortTasks(items) 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{ out = append(out, CalendarMonth{
Offset: offset, Offset: offset,
@@ -46,6 +46,25 @@ func buildCalendar(plans []Plan, crops []Crop, products []Product, stepMap map[i
return out 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 { func collectTasksForDate(plans []Plan, crops []Crop, products []Product, stepMap map[int64][]CropStep, customTasks []CustomTask, month, day, yearOffset int) []Task {
var tasks []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), Calendar: buildCalendar(plans, crops, products, stepMap, customTasks, doneMap, settings.CurrentMonth, settings.CurrentDay, settings.DaysPerMonth, 14),
PlanningCount: len(plans), PlanningCount: len(plans),
} }
data.TodayGroups = groupTasksByField(data.TodayTasks)
a.renderTemplate(w, "templates/dashboard.html", data) a.renderTemplate(w, "templates/dashboard.html", data)
} }

View File

@@ -107,6 +107,7 @@ type MonthOption struct {
type CalendarDay struct { type CalendarDay struct {
Day int Day int
Tasks []Task Tasks []Task
Groups []FieldTaskGroup
} }
type CalendarMonth struct { type CalendarMonth struct {
@@ -123,11 +124,17 @@ type BasePage struct {
Info string Info string
} }
type FieldTaskGroup struct {
Field string
Tasks []Task
}
type DashboardPage struct { type DashboardPage struct {
BasePage BasePage
Settings Settings Settings Settings
CurrentMonth string CurrentMonth string
TodayTasks []Task TodayTasks []Task
TodayGroups []FieldTaskGroup
Calendar []CalendarMonth Calendar []CalendarMonth
PlanningCount int PlanningCount int
} }

View File

@@ -52,11 +52,15 @@
<section class="card"> <section class="card">
<h2>Heute</h2> <h2>Heute</h2>
{{if .TodayTasks}} {{if .TodayGroups}}
<ul class="tasks"> <ul class="tasks">
{{range .TodayTasks}} {{range .TodayGroups}}
<li>
<span><strong>{{.Field}}</strong></span>
<ul class="task-sublist">
{{range .Tasks}}
<li class="{{if .Completed}}done-task{{end}}"> <li class="{{if .Completed}}done-task{{end}}">
<span>{{.Field}}: {{.Message}}</span> <span>{{.Message}}</span>
<form method="post" action="/tasks/toggle" class="inline-form"> <form method="post" action="/tasks/toggle" class="inline-form">
<input type="hidden" name="uid" value="{{.UID}}"> <input type="hidden" name="uid" value="{{.UID}}">
<input type="hidden" name="month" value="{{.Month}}"> <input type="hidden" name="month" value="{{.Month}}">
@@ -68,6 +72,9 @@
</li> </li>
{{end}} {{end}}
</ul> </ul>
</li>
{{end}}
</ul>
{{else}} {{else}}
<p>Keine Aufgaben für den aktuellen Ingame-Tag.</p> <p>Keine Aufgaben für den aktuellen Ingame-Tag.</p>
{{end}} {{end}}
@@ -83,11 +90,15 @@
{{range .Days}} {{range .Days}}
<li> <li>
<strong>Tag {{.Day}}</strong> <strong>Tag {{.Day}}</strong>
{{if .Tasks}} {{if .Groups}}
<ul class="task-sublist">
{{range .Groups}}
<li>
<span><strong>{{.Field}}</strong></span>
<ul class="task-sublist"> <ul class="task-sublist">
{{range .Tasks}} {{range .Tasks}}
<li class="{{if .Completed}}done-task{{end}}"> <li class="{{if .Completed}}done-task{{end}}">
<span>{{.Field}}: {{.Message}}</span> <span>{{.Message}}</span>
<form method="post" action="/tasks/toggle" class="inline-form"> <form method="post" action="/tasks/toggle" class="inline-form">
<input type="hidden" name="uid" value="{{.UID}}"> <input type="hidden" name="uid" value="{{.UID}}">
<input type="hidden" name="month" value="{{.Month}}"> <input type="hidden" name="month" value="{{.Month}}">
@@ -99,6 +110,9 @@
</li> </li>
{{end}} {{end}}
</ul> </ul>
</li>
{{end}}
</ul>
{{else}} {{else}}
<span class="muted">Keine Einträge</span> <span class="muted">Keine Einträge</span>
{{end}} {{end}}