From 7c5df992ed62cd06055e3fecd73267ae5ef9e596 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sat, 10 Jun 2023 12:03:32 +0300 Subject: [PATCH] fix the timeline stay issue (right side) --- app/controllers/timeline_controller.rb | 6 +++++- app/helpers/timeline_helper.rb | 3 ++- app/views/timeline/index.haml | 7 ++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/timeline_controller.rb b/app/controllers/timeline_controller.rb index 39146d2..8c9f1d2 100644 --- a/app/controllers/timeline_controller.rb +++ b/app/controllers/timeline_controller.rb @@ -2,6 +2,10 @@ class TimelineController < ApplicationController def index @weeks = (params[:weeks] || "12").to_i - @members = Member.visible_scope.where("leaving > ? " , Date.today).order(:arriving).page(1).per(50) + @members = Member.visible_scope. + where("leaving > ? " , Date.today). + where("arriving < ? " , Date.today.at_beginning_of_month + @weeks.weeks). + order(:arriving). + page(1).per(50) end end diff --git a/app/helpers/timeline_helper.rb b/app/helpers/timeline_helper.rb index a03b9b7..0036bef 100644 --- a/app/helpers/timeline_helper.rb +++ b/app/helpers/timeline_helper.rb @@ -23,7 +23,8 @@ module TimelineHelper 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_days ? max_days : distance + max = max_days - started_days(member) + distance > max ? max : distance end def weekly data = {} diff --git a/app/views/timeline/index.haml b/app/views/timeline/index.haml index 5aa6570..f792983 100644 --- a/app/views/timeline/index.haml +++ b/app/views/timeline/index.haml @@ -4,20 +4,17 @@ .mx-2.mb-2{class: week == @weeks ? "bg-orange-100" : "bg-white"} =link_to week.to_s , timeline_path( weeks: week) .flex - .w-60 Weeks - (0...@weeks).each do |week| %div{class: bg_for(week) , style: "width: #{week_pixels}px;"} = (Date.today.at_beginning_of_month + week.weeks).day.to_s + "." = (Date.today.at_beginning_of_month + week.weeks).month .flex - .w-60 Weekly - weekly.each do |week , amount| %div{class: bg_for(week) , style: "width: #{week_pixels}px;"}= amount - @members.each_with_index do |member , index| .flex - .w-60= member.name .bg-white{style: "width: #{day_pixels*started_days(member)}px;"} - .flex.inline.justify-between{class: bg_for(index) ,style: "width: #{day_pixels*stay_days(member)}px;"} - %div= small_date(member.arriving) + .flex.pt-1.inline.justify-between{class: bg_for(index) ,style: "width: #{day_pixels*stay_days(member)}px;"} + %div= small_date(member.arriving) + " " + member.name %div= small_date(member.leaving) .name