updates
This commit is contained in:
@@ -3,6 +3,6 @@ class HomeController < ApplicationController
|
||||
def index
|
||||
Time.zone = 'Pacific Time (US & Canada)'
|
||||
@year = params['year'].nil? ? Date.today.year : params['year'].to_i
|
||||
@events = [Event.new]
|
||||
@events = CalendarService.new.events + CalendarService.new.vacations
|
||||
end
|
||||
end
|
||||
|
||||
52
app/models/calendar_service.rb
Normal file
52
app/models/calendar_service.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
require 'http'
|
||||
|
||||
class CalendarService
|
||||
|
||||
def vacations
|
||||
Rails.cache.fetch("vacations", expires_in: 5.minutes) do
|
||||
entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/593FC5A0-746B-48C7-A57B-3A0315976412/?export", "ff00ff")
|
||||
end
|
||||
end
|
||||
|
||||
def events
|
||||
Rails.cache.fetch("events", expires_in: 5.minutes) do
|
||||
entries("https://static.nocoda.io/remote.php/dav/calendars/pkamin/774BE10B-AEAD-4D20-BF09-9C0FFD135E56/?export", "0000ff")
|
||||
end
|
||||
end
|
||||
|
||||
def sports
|
||||
entries("https://static.nocoda.io/remote.php/dav/calendars").map do |entry|
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def entries(url, color)
|
||||
#
|
||||
a = HTTP.basic_auth(user: 'pkamin', pass: 'QDH*@8fhWekxwWjeX8MQ3H').get(url).body.to_s
|
||||
# a = File.read('/Users/pkamin/Desktop/vacation.vcalendar')
|
||||
|
||||
b = a.split("\r\n")
|
||||
|
||||
events = []
|
||||
e = nil
|
||||
|
||||
b.each do |line|
|
||||
if line == "BEGIN:VEVENT"
|
||||
e = Event.new
|
||||
e.color = color
|
||||
elsif line == "END:VEVENT"
|
||||
events << e unless e.nil?
|
||||
elsif line.start_with?("DTSTART") && ! e.nil?
|
||||
e.begin_at = DateTime.parse(line.split(":").last)
|
||||
elsif line.start_with?("DTEND") && ! e.nil?
|
||||
e.end_at = DateTime.parse(line.split(":").last)
|
||||
e.end_at = e.end_at - 1.minute
|
||||
elsif line.start_with?("SUMMARY") && ! e.nil?
|
||||
e.name = line.split(":").last
|
||||
end
|
||||
end
|
||||
|
||||
events
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
class Event
|
||||
attr_reader :begin_at, :end_at
|
||||
attr_accessor :begin_at, :end_at, :name, :color
|
||||
|
||||
def initialize
|
||||
@begin_at = DateTime.now.beginning_of_day
|
||||
@end_at = DateTime.now + 1.day
|
||||
def initialize(begin_at = DateTime.now.beginning_of_day, end_at = DateTime.now.end_of_day)
|
||||
@begin_at = begin_at
|
||||
@end_at = end_at
|
||||
end
|
||||
|
||||
def during?(d)
|
||||
self.begin_at <= d && d <= self.end_at
|
||||
end
|
||||
|
||||
def first_day?(d)
|
||||
self.begin_at.beginning_of_day <= d && d <= self.begin_at.end_of_day
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,12 @@
|
||||
</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>
|
||||
<div class="text-xs">
|
||||
<% event.name if event.first_day?(day)%>
|
||||
</div>
|
||||
<div class="w-2 cursor-pointer" style="background-color: #<%=event.color %>;" title="<%= event.name %>" data-toggle="tooltip" data-placement="right">
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user