Marek Piasecki
2 years ago
8 changed files with 111 additions and 8 deletions
@ -0,0 +1,10 @@ |
|||
[ |
|||
{ "id": "8c73d0ca-d999-4081-1558-e5ee6a40fcc2", "start": "2023-01-31T23:00:00.000Z", "end": "2023-02-01T06:00:00.000Z" }, |
|||
{ "id": "4b24e6ab-bdc6-6b2c-e405-a8e01f0fde84", "start": "2023-02-01T09:00:00.000Z", "end": "2023-02-01T10:00:00.000Z" }, |
|||
{ "id": "086e3a96-2c74-3d2a-e839-ad10c82626d5", "start": "2023-02-01T10:15:00.000Z", "end": "2023-02-01T10:45:00.000Z" }, |
|||
{ "id": "087ddebe-dd41-7e39-bda8-f617d8c4385d", "start": "2023-02-01T11:30:00.000Z", "end": "2023-02-01T13:00:00.000Z" }, |
|||
{ "id": "5117e557-8d86-4180-9326-1ce0cf733982", "start": "2023-02-01T13:00:00.000Z", "end": "2023-02-01T13:10:00.000Z" }, |
|||
{ "id": "9e323a9e-adf9-605f-9386-c939a9a6af3f", "start": "2023-02-01T13:55:00.000Z", "end": "2023-02-01T14:30:00.000Z" }, |
|||
{ "id": "bd8fc476-ac50-3327-4ece-d73897796852", "start": "2023-02-01T20:00:00.000Z", "end": "2023-02-01T22:30:00.000Z" }, |
|||
{ "id": "0510de47-c86e-a64c-bb86-461c039b1012", "start": "2023-02-02T10:00:00.000Z", "end": "2023-02-02T20:00:00.000Z" } |
|||
] |
@ -0,0 +1,9 @@ |
|||
[ |
|||
{ "id": "8c73d0ca-d999-4081-1558-e5ee6a40fcc2", "start": "2023-01-31T23:00:00.000Z", "end": "2023-02-01T06:00:00.000Z" }, |
|||
{ "id": "4b24e6ab-bdc6-6b2c-e405-a8e01f0fde84", "start": "2023-02-01T09:00:00.000Z", "end": "2023-02-01T10:00:00.000Z" }, |
|||
{ "id": "086e3a96-2c74-3d2a-e839-ad10c82626d5", "start": "2023-02-01T10:15:00.000Z", "end": "2023-02-01T10:45:00.000Z" }, |
|||
{ "id": "087ddebe-dd41-7e39-bda8-f617d8c4385d", "start": "2023-02-01T11:30:00.000Z", "end": "2023-02-01T13:00:00.000Z" }, |
|||
{ "id": "5117e557-8d86-4180-9326-1ce0cf733982", "start": "2023-02-01T13:00:00.000Z", "end": "2023-02-01T13:10:00.000Z" }, |
|||
{ "id": "9e323a9e-adf9-605f-9386-c939a9a6af3f", "start": "2023-02-01T13:55:00.000Z", "end": "2023-02-01T14:30:00.000Z" }, |
|||
{ "id": "bd8fc476-ac50-3327-4ece-d73897796852", "start": "2023-02-01T20:00:00.000Z", "end": "2023-02-01T22:30:00.000Z" } |
|||
] |
@ -0,0 +1,71 @@ |
|||
import bookings from "../api/bookings_2023_02_01.json" # bookings.where ending_date >= $date and starting_date <= $date sort b sort_by starting_date |
|||
|
|||
# make objects |
|||
for booking in bookings |
|||
booking.start = new Date(booking.start) |
|||
booking.end = new Date(booking.end) |
|||
|
|||
import sh from "../ui/slot-size-input.imba" |
|||
|
|||
let h = |
|||
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 |
|||
|
|||
slots: do |
|||
#slots ||= h.calculate_slots! |
|||
|
|||
calculate_slots: do |
|||
let slots = [] |
|||
unless bookings.length |
|||
slots.push start: h.date!, end: h.next_day! |
|||
else |
|||
let first = bookings[0] |
|||
if first.start > h.date! |
|||
slots.push start: h.date!, end: first.start |
|||
|
|||
bookings.forEach do |booking,i| |
|||
let next = bookings[i+1] |
|||
if next |
|||
slots.push start: booking.end, end: next.start |
|||
|
|||
let last = bookings[-1] |
|||
|
|||
if last.end < h.next_day! |
|||
slots.push start: last.end, end: h.next_day! |
|||
|
|||
for slot in slots |
|||
h.adjust(slot, 'start') |
|||
h.adjust(slot, 'end') |
|||
|
|||
slot['duration'] = h.calculate_duration(slot) for slot in slots |
|||
slots |
|||
|
|||
adjust: do |slot, param| |
|||
let min = Number(slot[param]) |
|||
let min_mod = min % h.resolution |
|||
if min_mod != 0 |
|||
slot[param] = new Date(min + ( param == 'start' ? h.resolution : 0 ) - min_mod) |
|||
|
|||
calculate_duration: do |slot| |
|||
Number(slot.end) - Number(slot.start) |
|||
|
|||
duration: do |
|||
h._duration ||= h.calculate_duration end: R.param('size'), start: sh.zero! |
|||
|
|||
tag choose-slot |
|||
def render |
|||
h._duration = 0 # reset cache |
|||
<self> |
|||
if h.slots!.length |
|||
for d in h.slots! |
|||
if d.duration > h.duration! |
|||
<p> "{d.end}" |
|||
else |
|||
<h2> "No slot available this day" |
|||
<simple-date-input> |
|||
|
Loading…
Reference in new issue