timeline wotking, renmed left column

This commit is contained in:
Torsten 2023-06-03 18:09:23 +03:00
parent b8dc0da001
commit 5a5f0585fb
14 changed files with 113 additions and 28 deletions

View File

@ -53,6 +53,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,6 @@
class TimelineController < ApplicationController
def index
@members = Member.visible_scope.where("leaving > ? " , Date.today).order(:arriving).page(1)
end
end

View File

@ -18,9 +18,9 @@ module MembersHelper
end end
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,64 @@
module TimelineHelper
def month_pixels
300
end
def day_pixels
month_pixels / 30
end
def max_pixels
(month_pixels * 3 ) / day_pixels
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_pixels ? max_pixels : distance
end
def left_max
Date.today.at_beginning_of_month + 3.months
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
distance > max_pixels ? max_pixels : distance
end
def weekly
data = {}
week = 0
while( week < 13 ) do
data[ week ] = 0
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
puts data
data
end
def bg_for(week)
case week % 5
when 0
"bg-cyan-50"
when 1
"bg-cyan-100"
when 2
"bg-cyan-200"
when 3
"bg-cyan-300"
when 4
"bg-cyan-400"
end
end
def small_date(date)
date.strftime("%-d.%-m")
end
end

View File

@ -5,7 +5,7 @@ class Member < ApplicationRecord
end end
def self.visible_scope def self.visible_scope
where.not(confirmed_at: nil).where.not(arrived: nil) where.not(confirmed_at: nil).where.not(arriving: nil)
end end
# Include default devise modules. Others available are: # Include default devise modules. Others available are:

View File

@ -1,4 +1,4 @@
#mobile-menu.absolute.top-0.left-0.w-full.hidden.z-10 #mobile-menu.absolute.top-0.leaving-0.w-full.hidden.z-10
.p-5.bg-white.border.rounded.shadow-sm .p-5.bg-white.border.rounded.shadow-sm
.flex.items-center.justify-between.mb-4 .flex.items-center.justify-between.mb-4
%div %div

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

@ -1,9 +0,0 @@
= paginate @members
.flex.flex-col.mx-10
- @members.each_with_index do |member , index|
.flex
.w-60= member.name
.mx-1= index + 1
.mx-1= distance_of_time_in_words_to_now member.arrived
.name= member.left - member.arrived

View File

@ -9,5 +9,5 @@
"data-glightbox" => "title: #{picture.text}" } do "data-glightbox" => "title: #{picture.text}" } do
= picture_for( picture , "absolute top-0 left-0 w-full h-full inset-0 object-cover hover:scale-105 ease-in duration-500") = picture_for( picture , "absolute top-0 left-0 w-full h-full inset-0 object-cover hover:scale-105 ease-in duration-500")
-unless picture.text.blank? -unless picture.text.blank?
.absolute.bottom-0.left-0.right-0.px-4.pb-1.bg-gray-800.opacity-70.transition-colors.group-hover:bg-black.group-hover:opacity-100 .absolute.bottom-0.leaving-0.right-0.px-4.pb-1.bg-gray-800.opacity-70.transition-colors.group-hover:bg-black.group-hover:opacity-100
.text-center.mt-2.text-white= picture.text .text-center.mt-2.text-white= picture.text

View File

@ -0,0 +1,20 @@
= paginate @members
.flex.flex-col.mx-10
.flex
.w-60 Weekly
- (0..12).each do |week|
%div{class: bg_for(week) , style: "width: #{7*day_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: #{7*day_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.bg-yellow-100{style: "width: #{day_pixels*stay_days(member)}px;"}
%div= small_date(member.arriving)
%div= small_date(member.leaving)
.name

View File

@ -5,7 +5,7 @@ Kaminari.configure do |config|
# config.max_per_page = nil # config.max_per_page = nil
# config.window = 4 # config.window = 4
# config.outer_window = 0 # config.outer_window = 0
# config.left = 0 # config.leaving = 0
# config.right = 0 # config.right = 0
# config.page_method_name = :page # config.page_method_name = :page
# config.param_name = :page # config.param_name = :page

View File

@ -7,11 +7,9 @@ Rails.application.routes.draw do
get "/members/edit_email" , to: "registrations#edit_email" get "/members/edit_email" , to: "registrations#edit_email"
end end
resources :members do get "timeline" , to: "timeline#index"
collection do
get :timeline resources :members
end
end
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