Dashboard nach Feld gruppieren und Verkaufs-Hinweise integrieren
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -52,11 +52,15 @@
|
||||
|
||||
<section class="card">
|
||||
<h2>Heute</h2>
|
||||
{{if .TodayTasks}}
|
||||
{{if .TodayGroups}}
|
||||
<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}}">
|
||||
<span>{{.Field}}: {{.Message}}</span>
|
||||
<span>{{.Message}}</span>
|
||||
<form method="post" action="/tasks/toggle" class="inline-form">
|
||||
<input type="hidden" name="uid" value="{{.UID}}">
|
||||
<input type="hidden" name="month" value="{{.Month}}">
|
||||
@@ -68,6 +72,9 @@
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<p>Keine Aufgaben für den aktuellen Ingame-Tag.</p>
|
||||
{{end}}
|
||||
@@ -83,11 +90,15 @@
|
||||
{{range .Days}}
|
||||
<li>
|
||||
<strong>Tag {{.Day}}</strong>
|
||||
{{if .Tasks}}
|
||||
{{if .Groups}}
|
||||
<ul class="task-sublist">
|
||||
{{range .Groups}}
|
||||
<li>
|
||||
<span><strong>{{.Field}}</strong></span>
|
||||
<ul class="task-sublist">
|
||||
{{range .Tasks}}
|
||||
<li class="{{if .Completed}}done-task{{end}}">
|
||||
<span>{{.Field}}: {{.Message}}</span>
|
||||
<span>{{.Message}}</span>
|
||||
<form method="post" action="/tasks/toggle" class="inline-form">
|
||||
<input type="hidden" name="uid" value="{{.UID}}">
|
||||
<input type="hidden" name="month" value="{{.Month}}">
|
||||
@@ -99,6 +110,9 @@
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<span class="muted">Keine Einträge</span>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user