From 9eb6483cb936e0409ba0caab25920b552248c60c Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Thu, 25 Apr 2024 12:29:43 +0200 Subject: [PATCH] Allow opening a booking or creating a new from the booking grid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I wanted to use a regular , but apparently rendering that many anchors is too resource-intensive for Firefox, and it is noticeably slower. It was even worse, in fact, because i had to have different content for the main grid and the grid show in the new booking form, as i did not want to have these links there, and had call a template for each cell: 3 months × ~30 days × ~100 campsites = 9000 calls! Using JavaScript for that is shameful, but it does not add much to the existing markup, and no need for template fuckery. I am using double-click to follow these links, instead of single click, because it would be too easy to misclik on the grid, but that forced me to add `user-select: none` to prevent the selection of text when double- clicking. --- pkg/booking/campsite.go | 8 ++++++-- web/static/camper.css | 1 + web/templates/admin/booking/grid.gohtml | 10 +++++++--- web/templates/admin/campsite/index.gohtml | 11 +++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/booking/campsite.go b/pkg/booking/campsite.go index 8acc07a..c5c0a14 100644 --- a/pkg/booking/campsite.go +++ b/pkg/booking/campsite.go @@ -71,12 +71,14 @@ type CampsiteEntry struct { ID int Label string Type string + TypeSlug string Active bool Selected bool Bookings map[time.Time]*CampsiteBooking } type CampsiteBooking struct { + URL string Holder string Status string Nights int @@ -89,6 +91,7 @@ func CollectCampsiteEntries(ctx context.Context, company *auth.Company, conn *da select campsite_id , campsite.label , campsite_type.name + , campsite_type.slug , campsite.active from campsite join campsite_type using (campsite_type_id) @@ -104,7 +107,7 @@ func CollectCampsiteEntries(ctx context.Context, company *auth.Company, conn *da var campsites []*CampsiteEntry for rows.Next() { entry := &CampsiteEntry{} - if err = rows.Scan(&entry.ID, &entry.Label, &entry.Type, &entry.Active); err != nil { + if err = rows.Scan(&entry.ID, &entry.Label, &entry.Type, &entry.TypeSlug, &entry.Active); err != nil { return nil, err } campsites = append(campsites, entry) @@ -122,6 +125,7 @@ func collectCampsiteBookings(ctx context.Context, company *auth.Company, conn *d rows, err := conn.Query(ctx, ` select campsite.label , lower(booking_campsite.stay * daterange($2::date, $3::date)) + , '/admin/bookings/' || booking.slug , holder_name , booking_status , upper(booking_campsite.stay * daterange($2::date, $3::date)) - lower(booking_campsite.stay * daterange($2::date, $3::date)) @@ -142,7 +146,7 @@ func collectCampsiteBookings(ctx context.Context, company *auth.Company, conn *d entry := &CampsiteBooking{} var label string var date time.Time - if err = rows.Scan(&label, &date, &entry.Holder, &entry.Status, &entry.Nights, &entry.Begin, &entry.End); err != nil { + if err = rows.Scan(&label, &date, &entry.URL, &entry.Holder, &entry.Status, &entry.Nights, &entry.Begin, &entry.End); err != nil { return err } campsite := campsites[label] diff --git a/web/static/camper.css b/web/static/camper.css index 8cb28c7..3f5b3a8 100644 --- a/web/static/camper.css +++ b/web/static/camper.css @@ -832,6 +832,7 @@ label[x-show] > span, label[x-show] > br { #campsites-booking tbody td { position: relative; + user-select: none; } #campsites-booking tbody div { diff --git a/web/templates/admin/booking/grid.gohtml b/web/templates/admin/booking/grid.gohtml index e349233..daa53d3 100644 --- a/web/templates/admin/booking/grid.gohtml +++ b/web/templates/admin/booking/grid.gohtml @@ -1,10 +1,12 @@ +{{- /*gotype: dev.tandem.ws/tandem/camper/pkg/booking.adminBookingForm */ -}}
{{ range .Months }} {{ range .Spans }} - + {{- end }} {{- end }} @@ -12,7 +14,8 @@ {{ range .Months }} - + {{- end }} @@ -36,10 +39,11 @@
{{ .Holder }}
{{- else -}} - + {{- end }} {{- end }} {{- end }} diff --git a/web/templates/admin/campsite/index.gohtml b/web/templates/admin/campsite/index.gohtml index ba19775..ecb9158 100644 --- a/web/templates/admin/campsite/index.gohtml +++ b/web/templates/admin/campsite/index.gohtml @@ -42,6 +42,17 @@ {{ else -}}

{{( gettext "No campsites added yet." )}}

{{- end }} + + {{- end }} {{ define "campsite-heading" -}}
{{( pgettext "Label" "header" )}}{{ pgettext .Name "month" }} {{ .Year }}{{ pgettext .Name "month" }} {{ .Year }}