Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CalendarController < ApplicationController | ||
def month | ||
@date = Date.parse(params.fetch(:date, Date.today.to_s)) | ||
# @events = Event.where(start_date: @date.all_month) | ||
@events = Event.where(start_date: @date.all_month).group_by { |e| e.start_date.to_date } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
module ApplicationHelper | ||
def month_offset(date) | ||
date.beginning_of_month.wday - 1 | ||
end | ||
|
||
def today?(date) | ||
date == Date.today | ||
end | ||
|
||
def today_class(date) | ||
"bg-rose-200" if today?(date) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<%= link_to "<", calendar_month_path(date: date - 1.month) %> | ||
<%= link_to "Today", calendar_month_path %> | ||
<%= link_to ">", calendar_month_path(date: date + 1.month) %> | ||
<%= date.strftime('%B %Y')%> | ||
|
||
<div class="grid grid-cols-7"> | ||
<% Date::ABBR_DAYNAMES.rotate.each do |weekday| %> | ||
<div> | ||
<%= weekday %> | ||
</div> | ||
<% end %> | ||
<% month_offset(date).times do %> | ||
<div></div> | ||
<% end %> | ||
<% date.all_month.each do |day| %> | ||
<div class="border min-h-24 <%= today_class(day) %>"> | ||
<%= yield day %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= render 'calendar/month', date: @date do |day| %> | ||
<%= day.strftime('%d') %> | ||
<% @events[day]&.each do |event| %> | ||
<div class="rounded-md bg-rose-400 m-1"> | ||
<%= event.name %> | ||
<%= event.location %> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ | |
|
||
# Defines the root path route ("/") | ||
root "events#index" | ||
get "calendar/month", to: 'calendar#month' | ||
end |