use start of week not month
This commit is contained in:
parent
c444b649f4
commit
417644e764
@ -4,7 +4,7 @@ class TimelineController < ApplicationController
|
|||||||
@weeks = (params[:weeks] || "12").to_i
|
@weeks = (params[:weeks] || "12").to_i
|
||||||
@members = Member.visible_scope.
|
@members = Member.visible_scope.
|
||||||
where("leaving > ? " , Date.today).
|
where("leaving > ? " , Date.today).
|
||||||
where("arriving < ? " , Date.today.at_beginning_of_month + @weeks.weeks).
|
where("arriving < ? " , helpers.start_day + @weeks.weeks).
|
||||||
order(:arriving).
|
order(:arriving).
|
||||||
page(1).per(50)
|
page(1).per(50)
|
||||||
end
|
end
|
||||||
|
@ -9,22 +9,25 @@ module TimelineHelper
|
|||||||
def max_days
|
def max_days
|
||||||
@weeks * 7
|
@weeks * 7
|
||||||
end
|
end
|
||||||
|
def start_day
|
||||||
|
Date.today.at_beginning_of_week - 1.week
|
||||||
|
end
|
||||||
# number of days from start of month to start of stay
|
# number of days from start of month to start of stay
|
||||||
def started_days(member)
|
def started_days(member)
|
||||||
return 0 unless member.arriving
|
return 0 unless member.arriving
|
||||||
return 0 if member.arriving < Date.today.at_beginning_of_month
|
return 0 if member.arriving < start_day
|
||||||
distance = (member.arriving - Date.today.at_beginning_of_month).to_i
|
distance = (member.arriving - start_day).to_i
|
||||||
distance > max_days ? max_days : distance
|
distance > max_days ? max_days : distance
|
||||||
end
|
end
|
||||||
def left_max
|
def left_max
|
||||||
Date.today.at_beginning_of_month + 3.months
|
start_day + 3.months
|
||||||
end
|
end
|
||||||
|
|
||||||
# amount of days of the stay, maxed at the number fo weeks shown
|
# amount of days of the stay, maxed at the number fo weeks shown
|
||||||
def stay_days(member)
|
def stay_days(member)
|
||||||
return 0 unless member.leaving
|
return 0 unless member.leaving
|
||||||
start = member.arriving
|
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
|
distance = ( member.leaving - start ).to_i
|
||||||
max = max_days - started_days(member)
|
max = max_days - started_days(member)
|
||||||
distance > max ? max : distance
|
distance > max ? max : distance
|
||||||
@ -32,7 +35,7 @@ module TimelineHelper
|
|||||||
|
|
||||||
# weekly occupany, hash containing weeks to number of volunteer mapping
|
# weekly occupany, hash containing weeks to number of volunteer mapping
|
||||||
def weekly
|
def weekly
|
||||||
month_start = Date.today.at_beginning_of_month
|
month_start = start_day
|
||||||
( 0 ... @weeks ).collect do |week|
|
( 0 ... @weeks ).collect do |week|
|
||||||
amount = -1
|
amount = -1
|
||||||
start_week = month_start + week.weeks
|
start_week = month_start + week.weeks
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
%tr
|
%tr
|
||||||
- (0...@weeks).each do |week|
|
- (0...@weeks).each do |week|
|
||||||
%td{colspan: 7 , class: bg_for(week + 2) }
|
%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
|
%tr
|
||||||
- weekly.each_with_index do |amount , week |
|
- weekly.each_with_index do |amount , week |
|
||||||
%td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount
|
%td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount
|
||||||
|
Loading…
Reference in New Issue
Block a user