From 0c751e2a3e3ed8cb26dce3ff1bfc4b4badd068dc Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 11 Jul 2023 13:46:00 +0300 Subject: [PATCH] fix date mixup in timeline --- app/helpers/timeline_helper.rb | 20 ++++++++++++-------- app/views/timeline/index.haml | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/helpers/timeline_helper.rb b/app/helpers/timeline_helper.rb index 29859bc..99b8641 100644 --- a/app/helpers/timeline_helper.rb +++ b/app/helpers/timeline_helper.rb @@ -32,20 +32,24 @@ module TimelineHelper # 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 + ( 0 ... @weeks ).collect do |week| + amount = -1 + start_week = month_start + week.weeks + end_week = start_week + 7.days + #puts "WEEK #{week} #{start_week} -- #{end_week}" @members.each do |mem| + puts "volunteer #{mem.name}" 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 + next if mem.leaving <= start_week + #puts "volunteer #{mem.name} leaving #{mem.leaving}" + next if mem.arriving >= end_week + #puts "volunteer #{mem.name} arriving #{mem.arriving}" + amount += 1 end + amount end - data end def bg_for(week) [ "bg-cyan-100", diff --git a/app/views/timeline/index.haml b/app/views/timeline/index.haml index 027bee4..3684a7a 100644 --- a/app/views/timeline/index.haml +++ b/app/views/timeline/index.haml @@ -12,7 +12,7 @@ %td{colspan: 7 , class: bg_for(week + 2) } = small_date(Date.today.at_beginning_of_month + week.weeks) %tr - - weekly.each do |week , amount| + - weekly.each_with_index do |amount , week | %td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount - @members.each_with_index do |member , index|