From 2a7582211eafb324e76a488aba487cda3482ced6 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 11 Jul 2023 09:07:27 +0300 Subject: [PATCH] fix start of timeline --- app/helpers/timeline_helper.rb | 5 ++++- app/views/timeline/index.haml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/helpers/timeline_helper.rb b/app/helpers/timeline_helper.rb index 79a8038..a1cc0d3 100644 --- a/app/helpers/timeline_helper.rb +++ b/app/helpers/timeline_helper.rb @@ -9,6 +9,7 @@ module TimelineHelper def max_days @weeks * 7 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 @@ -18,11 +19,13 @@ module TimelineHelper def left_max Date.today.at_beginning_of_month + 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 - distance = ( member.leaving - member.arriving ).to_i + distance = ( member.leaving - start ).to_i max = max_days - started_days(member) distance > max ? max : distance end diff --git a/app/views/timeline/index.haml b/app/views/timeline/index.haml index 01f67cd..027bee4 100644 --- a/app/views/timeline/index.haml +++ b/app/views/timeline/index.haml @@ -18,7 +18,7 @@ - @members.each_with_index do |member , index| %tr{class: bg_for(index)} - if( (days = started_days(member)) > 0) - %td.bg-white{colspan: started_days(member)} + %td.bg-white{colspan: days } - if( (days = stay_days(member)) < 14) %td{colspan: days} = small_date(member.arriving)