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)
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,19 +52,26 @@
|
|||||||
|
|
||||||
<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 class="{{if .Completed}}done-task{{end}}">
|
<li>
|
||||||
<span>{{.Field}}: {{.Message}}</span>
|
<span><strong>{{.Field}}</strong></span>
|
||||||
<form method="post" action="/tasks/toggle" class="inline-form">
|
<ul class="task-sublist">
|
||||||
<input type="hidden" name="uid" value="{{.UID}}">
|
{{range .Tasks}}
|
||||||
<input type="hidden" name="month" value="{{.Month}}">
|
<li class="{{if .Completed}}done-task{{end}}">
|
||||||
<input type="hidden" name="day" value="{{.Day}}">
|
<span>{{.Message}}</span>
|
||||||
<input type="hidden" name="year_offset" value="{{.YearOffset}}">
|
<form method="post" action="/tasks/toggle" class="inline-form">
|
||||||
<input type="hidden" name="completed" value="{{if .Completed}}1{{else}}0{{end}}">
|
<input type="hidden" name="uid" value="{{.UID}}">
|
||||||
<button type="submit" class="btn-small {{if .Completed}}secondary{{end}}">{{if .Completed}}Offen{{else}}Erledigt{{end}}</button>
|
<input type="hidden" name="month" value="{{.Month}}">
|
||||||
</form>
|
<input type="hidden" name="day" value="{{.Day}}">
|
||||||
|
<input type="hidden" name="year_offset" value="{{.YearOffset}}">
|
||||||
|
<input type="hidden" name="completed" value="{{if .Completed}}1{{else}}0{{end}}">
|
||||||
|
<button type="submit" class="btn-small {{if .Completed}}secondary{{end}}">{{if .Completed}}Offen{{else}}Erledigt{{end}}</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -83,19 +90,26 @@
|
|||||||
{{range .Days}}
|
{{range .Days}}
|
||||||
<li>
|
<li>
|
||||||
<strong>Tag {{.Day}}</strong>
|
<strong>Tag {{.Day}}</strong>
|
||||||
{{if .Tasks}}
|
{{if .Groups}}
|
||||||
<ul class="task-sublist">
|
<ul class="task-sublist">
|
||||||
{{range .Tasks}}
|
{{range .Groups}}
|
||||||
<li class="{{if .Completed}}done-task{{end}}">
|
<li>
|
||||||
<span>{{.Field}}: {{.Message}}</span>
|
<span><strong>{{.Field}}</strong></span>
|
||||||
<form method="post" action="/tasks/toggle" class="inline-form">
|
<ul class="task-sublist">
|
||||||
<input type="hidden" name="uid" value="{{.UID}}">
|
{{range .Tasks}}
|
||||||
<input type="hidden" name="month" value="{{.Month}}">
|
<li class="{{if .Completed}}done-task{{end}}">
|
||||||
<input type="hidden" name="day" value="{{.Day}}">
|
<span>{{.Message}}</span>
|
||||||
<input type="hidden" name="year_offset" value="{{.YearOffset}}">
|
<form method="post" action="/tasks/toggle" class="inline-form">
|
||||||
<input type="hidden" name="completed" value="{{if .Completed}}1{{else}}0{{end}}">
|
<input type="hidden" name="uid" value="{{.UID}}">
|
||||||
<button type="submit" class="btn-small {{if .Completed}}secondary{{end}}">{{if .Completed}}Offen{{else}}Erledigt{{end}}</button>
|
<input type="hidden" name="month" value="{{.Month}}">
|
||||||
</form>
|
<input type="hidden" name="day" value="{{.Day}}">
|
||||||
|
<input type="hidden" name="year_offset" value="{{.YearOffset}}">
|
||||||
|
<input type="hidden" name="completed" value="{{if .Completed}}1{{else}}0{{end}}">
|
||||||
|
<button type="submit" class="btn-small {{if .Completed}}secondary{{end}}">{{if .Completed}}Offen{{else}}Erledigt{{end}}</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user