use start of week not month

This commit is contained in:
Torsten 2023-08-27 22:58:33 +03:00
parent c444b649f4
commit 417644e764
3 changed files with 10 additions and 7 deletions

View File

@ -4,7 +4,7 @@ class TimelineController < ApplicationController
@weeks = (params[:weeks] || "12").to_i
@members = Member.visible_scope.
where("leaving > ? " , Date.today).
where("arriving < ? " , Date.today.at_beginning_of_month + @weeks.weeks).
where("arriving < ? " , helpers.start_day + @weeks.weeks).
order(:arriving).
page(1).per(50)
end

View File

@ -9,22 +9,25 @@ module TimelineHelper
def max_days
@weeks * 7
end
def start_day
Date.today.at_beginning_of_week - 1.week
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
return 0 if member.arriving < start_day
distance = (member.arriving - start_day).to_i
distance > max_days ? max_days : distance
end
def left_max
Date.today.at_beginning_of_month + 3.months
start_day + 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
start = start_day if member.arriving < start_day
distance = ( member.leaving - start ).to_i
max = max_days - started_days(member)
distance > max ? max : distance
@ -32,7 +35,7 @@ module TimelineHelper
# weekly occupany, hash containing weeks to number of volunteer mapping
def weekly
month_start = Date.today.at_beginning_of_month
month_start = start_day
( 0 ... @weeks ).collect do |week|
amount = -1
start_week = month_start + week.weeks

View File

@ -10,7 +10,7 @@
%tr
- (0...@weeks).each do |week|
%td{colspan: 7 , class: bg_for(week + 2) }
= small_date(Date.today.at_beginning_of_month + week.weeks)
= small_date(start_day + week.weeks)
%tr
- weekly.each_with_index do |amount , week |
%td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount