colorgrade and more weeks

This commit is contained in:
Torsten 2023-06-04 12:30:43 +03:00
parent 6c2e11f8a6
commit 9dcc422f75
3 changed files with 32 additions and 28 deletions

View File

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

View File

@ -1,19 +1,19 @@
module TimelineHelper module TimelineHelper
def month_pixels def week_pixels
300 70
end end
def day_pixels def day_pixels
month_pixels / 30 week_pixels / 7
end end
def max_pixels def max_days
(month_pixels * 3 ) / day_pixels @weeks * 7
end end
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 < Date.today.at_beginning_of_month
distance = (member.arriving - Date.today.at_beginning_of_month).to_i distance = (member.arriving - Date.today.at_beginning_of_month).to_i
distance > max_pixels ? max_pixels : distance distance > max_days ? max_days : distance
end end
def left_max def left_max
Date.today.at_beginning_of_month + 3.months Date.today.at_beginning_of_month + 3.months
@ -23,12 +23,12 @@ module TimelineHelper
start = member.arriving start = member.arriving
start = Date.today.at_beginning_of_month if member.arriving < Date.today.at_beginning_of_month 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 - member.arriving ).to_i
distance > max_pixels ? max_pixels : distance distance > max_days ? max_days : distance
end end
def weekly def weekly
data = {} data = {}
week = 0 week = 0
while( week < 13 ) do while( week < @weeks ) do
data[ week ] = 0 data[ week ] = 0
start_week = Date.today.at_beginning_of_month + week.weeks start_week = Date.today.at_beginning_of_month + week.weeks
end_week = Date.today.at_beginning_of_month + (week + 1).weeks end_week = Date.today.at_beginning_of_month + (week + 1).weeks
@ -41,22 +41,22 @@ module TimelineHelper
end end
week += 1 week += 1
end end
puts data
data data
end end
def bg_for(week) def bg_for(week)
case week % 5 [ "bg-cyan-100",
when 0 "bg-blue-100",
"bg-cyan-50" "bg-violet-100",
when 1 "bg-fuchsia-100",
"bg-cyan-100" "bg-pink-100",
when 2 "bg-rose-100",
"bg-cyan-200" "bg-orange-100",
when 3 "bg-amber-100",
"bg-cyan-300" "bg-yellow-100",
when 4 "bg-lime-100",
"bg-cyan-400" "bg-green-100",
end "bg-teal-100",
][week%12]
end end
def small_date(date) def small_date(date)
date.strftime("%-d.%-m") date.strftime("%-d.%-m")

View File

@ -1,20 +1,23 @@
= paginate @members
.flex.flex-col.mx-10 .flex.flex-col.mx-10
.flex .flex
.w-60 Weekly - (5..25).each do |week|
- (0..12).each do |week| .mx-2.mb-2{class: week == @weeks ? "bg-orange-100" : "bg-white"}
%div{class: bg_for(week) , style: "width: #{7*day_pixels}px;"} =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).day.to_s + "."
= (Date.today.at_beginning_of_month + week.weeks).month = (Date.today.at_beginning_of_month + week.weeks).month
.flex .flex
.w-60 Weekly .w-60 Weekly
- weekly.each do |week , amount| - weekly.each do |week , amount|
%div{class: bg_for(week) , style: "width: #{7*day_pixels}px;"}= amount %div{class: bg_for(week) , style: "width: #{week_pixels}px;"}= amount
- @members.each_with_index do |member , index| - @members.each_with_index do |member , index|
.flex .flex
.w-60= member.name .w-60= member.name
.bg-white{style: "width: #{day_pixels*started_days(member)}px;"} .bg-white{style: "width: #{day_pixels*started_days(member)}px;"}
.flex.inline.justify-between.bg-yellow-100{style: "width: #{day_pixels*stay_days(member)}px;"} .flex.inline.justify-between{class: bg_for(index) ,style: "width: #{day_pixels*stay_days(member)}px;"}
%div= small_date(member.arriving) %div= small_date(member.arriving)
%div= small_date(member.leaving) %div= small_date(member.leaving)
.name .name