@ -1,4 +1,4 @@
import bookings from "../api/bookings_2023_02_01.json" # bookings.where ending_date >= $date and starting_date <= $date sort b sort_by starting_date
import bookings from "../api/bookings_2023_02_01.json" # bookings.where ending_date >= $date and starting_date <= $date + 3 days sort b sort_by starting_date
# make objects
for booking in bookings
@ -8,13 +8,10 @@ for booking in bookings
import sh from "../ui/slot-size-input.imba"
let h =
scope: 3days
resolution: 15minutes
date: do R.param('alt-day') || R.param('date')
next_day: do
return #next_day if #next_day
let day = new Date(h.date!)
day.setDate(day.getDate! + 1)
#next_day = day
scope_day: do h.move_date h.date!, h.scope
slots: do
#slots ||= h.calculate_slots!
@ -22,7 +19,7 @@ let h =
calculate_slots: do
let slots = []
unless bookings.length
slots.push start: h.date!, end: h.next _day!
slots.push start: h.date!, end: h.scope _day!
else
let first = bookings[0]
if first.start > h.date!
@ -35,8 +32,8 @@ let h =
let last = bookings[-1]
if last.end < h.next _day!
slots.push start: last.end, end: h.next_day!
if last.end < h.scope _day!
slots.push start: last.end, end: h.move_date(last.end, h.scope)
for slot in slots
h.adjust(slot, 'start')
@ -54,18 +51,40 @@ let h =
calculate_duration: do |slot|
Number(slot.end) - Number(slot.start)
duration: do
duration: do # size of booking in time
h._duration ||= h.calculate_duration end: R.param('size'), start: sh.zero!
move_date: do |date, interval|
new Date(Number(date) + interval)
let filtered_slots
let first_available
tag choose-slot
def render
h._duration = 0 # reset cache
h._duration = first_available = 0 # reset cache
filtered_slots = h.slots!.filter do |s| s.duration >= h.duration!
let day = h.date!; day = h.move_date(day, day.getTimezoneOffset! * 1minutes)
let next_day = h.move_date(h.date!, 1days)
<self>
if h.slots!.length
for d in h.slots!
if d.duration > h.duration!
<p> "{d.end}"
if filtered_slots .length
<time-slot data=day>
for i in [0 .. 94]
<time-slot data=day=h.move_date(day, h.resolution)>
else
<h2> "No slot available this day"
<simple-date-input>
<simple-date-input> if !filtered_slots.length or R.params['alt-date']
tag time-slot
def f n
"{if n < 10 then 0 else ''}{n}"
get free?
for slot in filtered_slots
if data >= slot.start and (h.move_date(data, h.duration!) <= slot.end)
first_available ||= data
return true
false
<self.active=free?> "{f data.getHours!}:{f data.getMinutes!}"