volunteers/app/helpers/timeline_helper.rb
2023-06-03 18:09:23 +03:00

65 lines
1.5 KiB
Ruby

module TimelineHelper
def month_pixels
300
end
def day_pixels
month_pixels / 30
end
def max_pixels
(month_pixels * 3 ) / day_pixels
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
distance > max_pixels ? max_pixels : distance
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
distance > max_pixels ? max_pixels : distance
end
def weekly
data = {}
week = 0
while( week < 13 ) do
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
puts data
data
end
def bg_for(week)
case week % 5
when 0
"bg-cyan-50"
when 1
"bg-cyan-100"
when 2
"bg-cyan-200"
when 3
"bg-cyan-300"
when 4
"bg-cyan-400"
end
end
def small_date(date)
date.strftime("%-d.%-m")
end
end