Skip to content
Snippets Groups Projects
Commit 59a631cf authored by Arnaud Levy's avatar Arnaud Levy
Browse files

ics

parent 7ba80456
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ gem "hal_openscience", "~> 0"
# gem "hal_openscience", path: "../hal_openscience"
gem "has_scope", "~> 0"
gem "hash_dot"
gem "icalendar"
gem "i18n_data", "~> 0"
gem "i18n_date_range"
# gem "i18n_date_range", path: "../../noesya/i18n_date_range"
......
......@@ -302,6 +302,9 @@ GEM
i18n_date_range (2.0.0)
rails
rails-i18n
icalendar (2.10.1)
ice_cube (~> 0.16)
ice_cube (0.16.4)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
......@@ -661,6 +664,7 @@ DEPENDENCIES
hash_dot
i18n_data (~> 0)
i18n_date_range
icalendar
image_processing
jbuilder
jquery-rails
......
......@@ -148,12 +148,49 @@ class Communication::Website::Agenda::Event < ApplicationRecord
"#{Static.remove_trailing_slash website.url}#{Static.clean_path current_permalink_in_website(website).path}"
end
def to_ics
event = Icalendar::Event.new
event.dtstart = from_datetime
event.dtend = to_datetime if to_datetime.present?
event.summary = "#{title} #{subtitle}"
event.description = "#{summary}\n\n#{url}"
calendar = Icalendar::Calendar.new
calendar.prodid = 'icalendar-osuny'
calendar.add_event(event)
calendar.to_ical
end
def to_s
"#{title}"
end
protected
def from_datetime
from_hour.nil? ? from_day
: date_and_time(from_day, from_hour)
end
def to_datetime
if to_day.nil? && to_hour.nil?
# Pas de fin
nil
elsif to_day.nil? && to_hour.present?
# Heure de fin, donc on se base sur le jour de début
date_and_time(from_day, to_hour)
elsif to_day.present? && to_hour.nil?
# Jour de fin seul
to_day
elsif to_day.present? && to_hour.nil?
# Jour et heure de fin
date_and_time(to_day, to_hour)
end
end
def date_and_time(date, time)
DateTime.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone)
end
def check_accessibility
accessibility_merge_array blocks
end
......
......@@ -24,4 +24,7 @@ indentation = ' ' * depth
<%= indentation %> day: <%= event.to_day || event.from_day %>
<% if event.to_hour %>
<%= indentation %> hour: <%= event.to_hour.strftime "%H:%M" %>
<% end %>
\ No newline at end of file
<% end %>
<%= indentation %> files:
<%= indentation %> ics: >-
<%= indentation %> <%= prepare_text_for_static event.to_ics, depth + 3 %>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment