Render yearly view

This commit is contained in:
0x8664b2
2022-08-23 14:51:20 -07:00
parent 86303fd320
commit 028dea3cb8
9 changed files with 59 additions and 9 deletions

View File

@@ -72,3 +72,4 @@ group :test do
end end
gem "tailwindcss-rails", "~> 2.0" gem "tailwindcss-rails", "~> 2.0"
gem "http"

View File

@@ -88,9 +88,23 @@ GEM
irb (>= 1.3.6) irb (>= 1.3.6)
reline (>= 0.3.1) reline (>= 0.3.1)
digest (3.1.0) digest (3.1.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
erubi (1.11.0) erubi (1.11.0)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
globalid (1.0.0) globalid (1.0.0)
activesupport (>= 5.0) activesupport (>= 5.0)
http (5.1.0)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.12.0) i18n (1.12.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
importmap-rails (1.1.5) importmap-rails (1.1.5)
@@ -102,6 +116,9 @@ GEM
jbuilder (2.11.5) jbuilder (2.11.5)
actionview (>= 5.0.0) actionview (>= 5.0.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
loofah (2.18.0) loofah (2.18.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
@@ -196,6 +213,9 @@ GEM
railties (>= 6.0.0) railties (>= 6.0.0)
tzinfo (2.0.5) tzinfo (2.0.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
web-console (4.2.0) web-console (4.2.0)
actionview (>= 6.0.0) actionview (>= 6.0.0)
activemodel (>= 6.0.0) activemodel (>= 6.0.0)
@@ -220,6 +240,7 @@ DEPENDENCIES
bootsnap bootsnap
capybara capybara
debug debug
http
importmap-rails importmap-rails
jbuilder jbuilder
puma (~> 5.0) puma (~> 5.0)

View File

@@ -1,6 +1,8 @@
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@year = 2022 Time.zone = 'Pacific Time (US & Canada)'
@year = params['year'].nil? ? Date.today.year : params['year'].to_i
@events = [Event.new]
end end
end end

View File

@@ -0,0 +1,10 @@
module HomeHelper
def days_events(events, day)
events.select do |event|
event.during? day
end
.sort_by do |e|
[-e.begin_at.to_time.to_i, e.end_at.to_time.to_i]
end
end
end

View File

@@ -1,2 +0,0 @@
module IndexHelper
end

12
app/models/event.rb Normal file
View File

@@ -0,0 +1,12 @@
class Event
attr_reader :begin_at, :end_at
def initialize
@begin_at = DateTime.now.beginning_of_day
@end_at = DateTime.now + 1.day
end
def during?(d)
self.begin_at <= d && d <= self.end_at
end
end

View File

@@ -1,18 +1,19 @@
<div class="bootstrap">
<div class="text-center"> <div class="text-center">
<%= first_day.strftime("%b") %> <%= first_day.strftime("%b") %>
</div> </div>
<div class="flex flex-col w-full"> <div class="flex flex-col w-full">
<% (first_day..first_day.end_of_month).each do |day| %> <% (first_day..first_day.end_of_month).each do |day| %>
<% todays_events = days_events(events, day) %>
<div class="relative border-t w-full flex h-6 <%= 'bg-gray-200' if day.on_weekend? %>"> <div class="relative border-t w-full flex h-6 <%= 'bg-gray-200' if day.on_weekend? %>">
<div class="text-xs font-bold <%= 'border-red-600 border-b-4' if day.today? %>" <div class="text-xs font-bold <%= 'border-red-600 border-b-4' if day.today? %>"
<%= raw('data-toggle="tooltip" title="Today"') if day.today? %> <%= raw("data-toggle='tooltip' title='#{day.strftime('%a, %m/%d/%y')}'") unless day.today? %> data-placement="right" > <%= raw('data-toggle="tooltip" title="Today"') if day.today? %> <%= raw("data-toggle='tooltip' title='#{day.strftime('%a, %m/%d/%y')}'") unless day.today? %> data-placement="right" >
<%= day.strftime('%d') %> <%= day.strftime('%d') %>
</div> </div>
<div class="w-full flex-grow flex justify-end">
<% todays_events.each do |event| %>
<div class="w-2 bg-red-700 cursor-pointer" title="test" data-toggle="tooltip" data-placement="right"></div>
<% end %>
</div>
</div> </div>
<% end %> <% end %>
</div> </div>
</div>

View File

@@ -4,6 +4,11 @@ first_days = (1..12).map do |index|
end end
%> %>
<div class="w-1/3 mx-auto flex justify-between pb-4">
<%= link_to (@year-1), root_path(year: @year-1) %>
<%= @year %>
<%= link_to (@year+1), root_path(year: @year+1) %>
</div>
<div class="container mx-auto flex justify-between"> <div class="container mx-auto flex justify-between">
<% first_days.each do |first_day| %> <% first_days.each do |first_day| %>
<div class="border-l w-full"> <div class="border-l w-full">

View File

@@ -12,7 +12,7 @@
</head> </head>
<body> <body>
<main class="container mx-auto mt-28 px-5 flex"> <main class=" mx-auto mt-28 px-5 ">
<%= yield %> <%= yield %>
</main> </main>
</body> </body>