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
|
|
|
|
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
|
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
|
|
|
|
Date.today.at_beginning_of_month + 3.months
|
|
|
|
end
|
|
|
|
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 - member.arriving ).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 weekly
|
|
|
|
data = {}
|
|
|
|
week = 0
|
2023-06-04 11:30:43 +02:00
|
|
|
while( week < @weeks ) do
|
2023-06-03 17:09:23 +02:00
|
|
|
data[ week ] = 0
|
|
|
|
start_week = Date.today.at_beginning_of_month + week.weeks
|
|
|
|
end_week = Date.today.at_beginning_of_month + (week + 1).weeks
|
|
|
|
@members.each do |mem|
|
|
|
|
next unless mem.arriving
|
|
|
|
next unless mem.leaving
|
|
|
|
next if mem.arriving > start_week
|
|
|
|
next if mem.leaving < end_week
|
|
|
|
data[ week ] += 1
|
|
|
|
end
|
|
|
|
week += 1
|
|
|
|
end
|
|
|
|
data
|
|
|
|
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
|