diff --git a/cmd/web/routes.go b/cmd/web/routes.go index fcdbbf0..a36c51c 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -49,7 +49,6 @@ func routes(app *config.AppConfig) http.Handler { mux.Get("/reservations-new", handlers.Repo.AdminNewReservations) mux.Get("/reservations-all", handlers.Repo.AdminAllReservations) mux.Get("/reservations-calendar", handlers.Repo.AdminCalendarReservations) - mux.Get("/reservations-calendar", handlers.Repo.AdminCalendarReservations) mux.Get("/processes-reservation/{src}/{id}", handlers.Repo.AdminProcessReservations) mux.Get("/delete-reservation/{src}/{id}", handlers.Repo.AdminDeleteReservations) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 3c776d3..48f6a5b 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -537,7 +537,35 @@ func (m *Repository) AdminAllReservations(w http.ResponseWriter, r *http.Request // AdminCalendarReservations displays the reservations calendar func (m *Repository) AdminCalendarReservations(w http.ResponseWriter, r *http.Request) { - render.Template(w, r, "admin-reservations-calendar.page.tmpl", &models.TemplateData{}) + now := time.Now() + + if r.URL.Query().Get("y") != "" && r.URL.Query().Get("m") != "" { + year, _ := strconv.Atoi(r.URL.Query().Get("y")) + month, _ := strconv.Atoi(r.URL.Query().Get("m")) + now = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC) + } + + next := now.AddDate(0, 1, 0) + last := now.AddDate(0, -1, 0) + + nextMonth := next.Format("01") + nextMonthYear := next.Format("2006") + + lastMonth := last.Format("01") + lastMonthYear := last.Format("2006") + + stringMap := make(map[string]string) + stringMap["next_month"] = nextMonth + stringMap["next_month_year"] = nextMonthYear + stringMap["last_month"] = lastMonth + stringMap["last_month_year"] = lastMonthYear + + stringMap["this_month"] = now.Format("01") + stringMap["this_month_year"] = now.Format("2006") + + render.Template(w, r, "admin-reservations-calendar.page.tmpl", &models.TemplateData{ + StringMap: stringMap, + }) } // AdminShowReservation shows the reservations in the admin tool diff --git a/templates/admin-reservations-calendar.page.tmpl b/templates/admin-reservations-calendar.page.tmpl index 0ceb892..e46620a 100644 --- a/templates/admin-reservations-calendar.page.tmpl +++ b/templates/admin-reservations-calendar.page.tmpl @@ -7,5 +7,24 @@ {{define "content"}}
{{end}} \ No newline at end of file