2023-06-03 17:09:23 +02:00
|
|
|
module TimelineHelper
|
|
|
|
|
2023-06-04 11:30:43 +02:00
|
|
|
def week_pixels
|
|
|
|
70
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
|
|
|
def day_pixels
|
2023-06-04 11:30:43 +02:00
|
|
|
week_pixels / 7
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
2023-06-04 11:30:43 +02:00
|
|
|
def max_days
|
|
|
|
@weeks * 7
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
2023-08-27 21:58:33 +02:00
|
|
|
def start_day
|
|
|
|
Date.today.at_beginning_of_week - 1.week
|
|
|
|
end
|
2023-07-11 08:07:27 +02:00
|
|
|
# number of days from start of month to start of stay
|
2023-06-03 17:09:23 +02:00
|
|
|
def started_days(member)
|
|
|
|
return 0 unless member.arriving
|
2023-08-27 21:58:33 +02:00
|
|
|
return 0 if member.arriving < start_day
|
|
|
|
distance = (member.arriving - start_day).to_i
|
2023-06-04 11:30:43 +02:00
|
|
|
distance > max_days ? max_days : distance
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
|
|
|
def left_max
|
2023-08-27 21:58:33 +02:00
|
|
|
start_day + 3.months
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
2023-07-11 08:07:27 +02:00
|
|
|
|
|
|
|
# amount of days of the stay, maxed at the number fo weeks shown
|
2023-06-03 17:09:23 +02:00
|
|
|
def stay_days(member)
|
|
|
|
return 0 unless member.leaving
|
|
|
|
start = member.arriving
|
2023-08-27 21:58:33 +02:00
|
|
|
start = start_day if member.arriving < start_day
|
2023-07-11 08:07:27 +02:00
|
|
|
distance = ( member.leaving - start ).to_i
|
2023-06-10 11:03:32 +02:00
|
|
|
max = max_days - started_days(member)
|
|
|
|
distance > max ? max : distance
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
2023-07-11 08:25:54 +02:00
|
|
|
|
|
|
|
# weekly occupany, hash containing weeks to number of volunteer mapping
|
2023-06-03 17:09:23 +02:00
|
|
|
def weekly
|
2023-08-27 21:58:33 +02:00
|
|
|
month_start = start_day
|
2023-07-11 12:46:00 +02:00
|
|
|
( 0 ... @weeks ).collect do |week|
|
|
|
|
amount = -1
|
|
|
|
start_week = month_start + week.weeks
|
|
|
|
end_week = start_week + 7.days
|
2023-07-14 12:35:53 +02:00
|
|
|
#puts "WEEK #{week} #{start_week} -- #{end_week}"
|
2023-06-03 17:09:23 +02:00
|
|
|
@members.each do |mem|
|
2023-07-14 12:35:53 +02:00
|
|
|
#puts "volunteer #{mem.name}"
|
2023-06-03 17:09:23 +02:00
|
|
|
next unless mem.arriving
|
|
|
|
next unless mem.leaving
|
2023-07-11 12:46:00 +02:00
|
|
|
next if mem.leaving <= start_week
|
2023-07-14 12:35:53 +02:00
|
|
|
#puts "volunteer #{mem.name} leaving #{mem.leaving}"
|
2023-07-11 12:46:00 +02:00
|
|
|
next if mem.arriving >= end_week
|
2023-07-14 12:35:53 +02:00
|
|
|
#puts "volunteer #{mem.name} arriving #{mem.arriving}"
|
2023-07-11 12:46:00 +02:00
|
|
|
amount += 1
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
2023-07-11 12:46:00 +02:00
|
|
|
amount
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def bg_for(week)
|
2023-06-04 11:30:43 +02:00
|
|
|
[ "bg-cyan-100",
|
|
|
|
"bg-blue-100",
|
|
|
|
"bg-violet-100",
|
|
|
|
"bg-fuchsia-100",
|
|
|
|
"bg-pink-100",
|
|
|
|
"bg-rose-100",
|
|
|
|
"bg-orange-100",
|
|
|
|
"bg-amber-100",
|
|
|
|
"bg-yellow-100",
|
|
|
|
"bg-lime-100",
|
|
|
|
"bg-green-100",
|
|
|
|
"bg-teal-100",
|
|
|
|
][week%12]
|
2023-06-03 17:09:23 +02:00
|
|
|
end
|
|
|
|
def small_date(date)
|
|
|
|
date.strftime("%-d.%-m")
|
|
|
|
end
|
|
|
|
end
|