copy timeline here

This commit is contained in:
Torsten 2023-06-18 11:23:46 +03:00
parent 818af2f5e9
commit def9e6083d
10 changed files with 126 additions and 10 deletions

View File

@ -49,6 +49,6 @@ class MembersController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def member_params def member_params
params.require(:member).permit(:name, :public, :bio , :picture, params.require(:member).permit(:name, :public, :bio , :picture,
:picture_cache , :arrived ,:left) :picture_cache , :arriving ,:leaving)
end end
end end

View File

@ -0,0 +1,11 @@
class TimelineController < ApplicationController
def index
@weeks = (params[:weeks] || "12").to_i
@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

View File

@ -15,9 +15,9 @@ module MembersHelper
end end
def stayed(member) def stayed(member)
return "Not arrived" if member.arrived.blank? return "Not arrived" if member.arriving.blank?
text = member.arrived.to_s text = member.arriving.to_s
return text + " not left" if member.left.blank? return text + " not left" if member.leaving.blank?
text + " " + distance_of_time_in_words( member.left , member.arrived) text + " " + distance_of_time_in_words( member.leaving , member.arriving)
end end
end end

View File

@ -0,0 +1,63 @@
module TimelineHelper
def week_pixels
70
end
def day_pixels
week_pixels / 7
end
def max_days
@weeks * 7
end
def started_days(member)
return 0 unless member.arriving
return 0 if member.arriving < Date.today.at_beginning_of_month
distance = (member.arriving - Date.today.at_beginning_of_month).to_i
distance > max_days ? max_days : distance
end
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
max = max_days - started_days(member)
distance > max ? max : distance
end
def weekly
data = {}
week = 0
while( week < @weeks ) do
data[ week ] = -1
start_week = Date.today.at_beginning_of_month + week.weeks
end_week = Date.today.at_beginning_of_month + (week + 1).weeks
@members.each do |mem|
next unless mem.arriving
next unless mem.leaving
next if mem.arriving > start_week
next if mem.leaving < end_week
data[ week ] += 1
end
week += 1
end
data
end
def bg_for(week)
[ "bg-cyan-100",
"bg-blue-100",
"bg-violet-100",
"bg-fuchsia-100",
"bg-pink-100",
"bg-rose-100",
"bg-orange-100",
"bg-amber-100",
"bg-yellow-100",
"bg-lime-100",
"bg-green-100",
"bg-teal-100",
][week%12]
end
def small_date(date)
date.strftime("%-d.%-m")
end
end

View File

@ -4,6 +4,10 @@ class Member < ApplicationRecord
where.not(confirmed_at: nil).where.not(picture: nil) where.not(confirmed_at: nil).where.not(picture: nil)
end end
def self.visible_scope
where.not(confirmed_at: nil).where.not(arriving: nil)
end
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# , :lockable, :timeoutable, :trackable and :omniauthable # , :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,:confirmable, devise :database_authenticatable, :registerable,:confirmable,

View File

@ -15,8 +15,8 @@
.text-red-700= f.error_notification .text-red-700= f.error_notification
= f.input :name = f.input :name
.grid.grid-cols-2.gap-10 .grid.grid-cols-2.gap-10
= f.input :arrived = f.input :arriving
= f.input :left = f.input :leaving
.flex.h-16.mt-2.col-span-2 .flex.h-16.mt-2.col-span-2
= image_tag(@member.picture_url , class: "align-middle mr-4") if @member.picture? = image_tag(@member.picture_url , class: "align-middle mr-4") if @member.picture?
.w-full= f.input :picture , as: :file , .w-full= f.input :picture , as: :file ,

View File

@ -0,0 +1,30 @@
.mx-10
%table.table-fixed.w-full
%tr
- ((@weeks - 5)..(@weeks + 5)).each do |week|
%td.mx-2.mb-2{colspan: 4 , class: week == @weeks ? "bg-orange-100" : "bg-white"}
=link_to week.to_s , timeline_path( weeks: week)
%tr
- (0...@weeks*7).each do |week|
%td{width: 100.0 / (@weeks * 7) }
%tr
- (0...@weeks).each do |week|
%td{colspan: 7 , class: bg_for(week + 2) }
= small_date(Date.today.at_beginning_of_month + week.weeks)
%tr
- weekly.each do |week , amount|
%td{colspan: 7, class: bg_for(week + 2) , style: "width: #{week_pixels}px;"}= amount
- @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)}
- if( (days = stay_days(member)) < 14)
%td{colspan: days}
= small_date(member.arriving)
= member.name
= small_date(member.leaving)
-else
%td.py-1{colspan: 4,}= small_date(member.arriving)
%td{colspan: days - 8}= member.name
%td{colspan: 4}= small_date(member.leaving)

View File

@ -7,6 +7,8 @@ Rails.application.routes.draw do
get "/members/edit_email" , to: "registrations#edit_email" get "/members/edit_email" , to: "registrations#edit_email"
end end
get "timeline" , to: "timeline#index"
resources :members resources :members
mount Thredded::Engine => '/forum' mount Thredded::Engine => '/forum'

View File

@ -0,0 +1,6 @@
class FixColumnName < ActiveRecord::Migration[7.0]
def change
rename_column :members, :left, :leaving
rename_column :members, :arrived, :arriving
end
end

6
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_25_172223) do ActiveRecord::Schema[7.0].define(version: 2023_06_03_150133) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -42,8 +42,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_25_172223) do
t.datetime "confirmed_at" t.datetime "confirmed_at"
t.datetime "confirmation_sent_at" t.datetime "confirmation_sent_at"
t.string "unconfirmed_email" t.string "unconfirmed_email"
t.date "arrived" t.date "arriving"
t.date "left" t.date "leaving"
t.index ["email"], name: "index_members_on_email", unique: true t.index ["email"], name: "index_members_on_email", unique: true
t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true
end end