Skip to content

Commit

Permalink
res calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Dec 31, 2023
1 parent 8dfaa58 commit bd76ad2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 0 additions & 1 deletion cmd/web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
30 changes: 29 additions & 1 deletion internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions templates/admin-reservations-calendar.page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,24 @@
{{define "content"}}
<div class="col-md-12">
Reservations Calendar content

<div class="text-center">
<h3>{{index .StringMap "this_month"}} {{index .StringMap "this_month_year"}}</h3>
</div>

<div class="float-left">
<a class="btn-sm btn-outline-secondary"
href='/admin/reservations-calendar?y={{index .StringMap "last_month_year"}}&m={{index .StringMap "last_month"}}'>
&lt;&lt;
</a>
</div>

<div class="float-right">
<a class="btn-sm btn-outline-secondary"
href='/admin/reservations-calendar?y={{index .StringMap "next_month_year"}}&m={{index .StringMap "next_month"}}'>
&gt;&gt;
</a>
</div>
<div class="clearfix"></div>
</div>
{{end}}

0 comments on commit bd76ad2

Please sign in to comment.