69 lines
1.7 KiB
Ruby
69 lines
1.7 KiB
Ruby
module TimelineHelper
|
|
|
|
def week_pixels
|
|
70
|
|
end
|
|
def day_pixels
|
|
week_pixels / 7
|
|
end
|
|
def max_days
|
|
@weeks * 7
|
|
end
|
|
# number of days from start of month to start of stay
|
|
def started_days(member)
|
|
return 0 unless member.arriving
|
|
return 0 if member.arriving < Date.today.at_beginning_of_month
|
|
distance = (member.arriving - Date.today.at_beginning_of_month).to_i
|
|
distance > max_days ? max_days : distance
|
|
end
|
|
def left_max
|
|
Date.today.at_beginning_of_month + 3.months
|
|
end
|
|
|
|
# amount of days of the stay, maxed at the number fo weeks shown
|
|
def stay_days(member)
|
|
return 0 unless member.leaving
|
|
start = member.arriving
|
|
start = Date.today.at_beginning_of_month if member.arriving < Date.today.at_beginning_of_month
|
|
distance = ( member.leaving - start ).to_i
|
|
max = max_days - started_days(member)
|
|
distance > max ? max : distance
|
|
end
|
|
|
|
# weekly occupany, hash containing weeks to number of volunteer mapping
|
|
def weekly
|
|
data = {}
|
|
month_start = Date.today.at_beginning_of_month
|
|
( 0 ... @weeks ).each do |week|
|
|
data[ week ] = -1
|
|
end_week = month_start + week.weeks
|
|
@members.each do |mem|
|
|
next unless mem.arriving
|
|
next unless mem.leaving
|
|
next if mem.leaving <= end_week
|
|
next if mem.arriving >= (end_week - 7.days)
|
|
data[ week ] += 1
|
|
end
|
|
end
|
|
data
|
|
end
|
|
def bg_for(week)
|
|
[ "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]
|
|
end
|
|
def small_date(date)
|
|
date.strftime("%-d.%-m")
|
|
end
|
|
end
|